mirror of
https://github.com/aclist/dztui.git
synced 2026-10-29 14:12:45 +01:00
feat: button cooldown
This commit is contained in:
1 parent
91425cbcaa
commit
12d367fa7e
5 files changed
+39
-17
No files matched your search
@@ -292,6 +292,9 @@ class Controller:
|
|||||||
def start_cooldown(self) -> None:
|
def start_cooldown(self) -> None:
|
||||||
self.cooldown = cooldown.get_time()
|
self.cooldown = cooldown.get_time()
|
||||||
|
|
||||||
|
def get_cooldown(self) -> None:
|
||||||
|
return self.cooldown
|
||||||
|
|
||||||
def manage_cooldown(self) -> bool:
|
def manage_cooldown(self) -> bool:
|
||||||
if cooldown.is_elapsed(self.cooldown):
|
if cooldown.is_elapsed(self.cooldown):
|
||||||
self.cooldown = cooldown.get_time()
|
self.cooldown = cooldown.get_time()
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ def main() -> None:
|
|||||||
|
|
||||||
if XDG.resolution.parent.is_dir() is False:
|
if XDG.resolution.parent.is_dir() is False:
|
||||||
make_parents(XDG.resolution)
|
make_parents(XDG.resolution)
|
||||||
|
# TODO: test
|
||||||
if XDG.debug.is_file() is False:
|
if XDG.debug.is_file() is False:
|
||||||
make_parents(XDG.debug)
|
make_parents(XDG.debug)
|
||||||
|
|
||||||
|
|||||||
@@ -539,3 +539,6 @@ connect_panel = ConnectPanel(
|
|||||||
)
|
)
|
||||||
|
|
||||||
distance_suffix = "Distance: calculating..."
|
distance_suffix = "Distance: calculating..."
|
||||||
|
|
||||||
|
refresh = "Refresh"
|
||||||
|
refresh_tooltip = "Refresh server data"
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from dzgui.util.strings import refresh
|
||||||
from dzgui.views.components.icon import Icon
|
from dzgui.views.components.icon import Icon
|
||||||
from dzgui.const.constants import REFRESH_ICON, WEB_BROWSER, INPUT_KEYBOARD
|
from dzgui.const.constants import REFRESH_ICON, WEB_BROWSER, INPUT_KEYBOARD
|
||||||
|
|
||||||
@@ -7,35 +8,33 @@ from gi.repository import Gtk # noqa E402
|
|||||||
|
|
||||||
|
|
||||||
class IconButton(Gtk.Button):
|
class IconButton(Gtk.Button):
|
||||||
def __init__(self, icon: str, margin: int = 0):
|
def __init__(self, icon: str, margin: int = 0) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
i = Icon(icon, l_margin=margin)
|
i = Icon(icon, l_margin=margin)
|
||||||
self.set_image(i)
|
self.set_image(i)
|
||||||
self.set_image_position(Gtk.PositionType.RIGHT)
|
self.set_image_position(Gtk.PositionType.RIGHT)
|
||||||
|
|
||||||
|
|
||||||
class IconTextButton(IconButton):
|
class IconTextButton(IconButton):
|
||||||
def __init__(self, icon: str, label: str):
|
def __init__(self, icon: str, label: str) -> None:
|
||||||
super().__init__(icon, margin=5)
|
super().__init__(icon, margin=5)
|
||||||
self.set_label(label)
|
self.set_label(label)
|
||||||
|
|
||||||
|
|
||||||
class WebButton(IconTextButton):
|
class WebButton(IconTextButton):
|
||||||
def __init__(self, label: str):
|
def __init__(self, label: str) -> None:
|
||||||
super().__init__(icon=WEB_BROWSER, label=label)
|
super().__init__(icon=WEB_BROWSER, label=label)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class RefreshButton(IconTextButton):
|
class RefreshButton(IconTextButton):
|
||||||
def __init__(self, label: str):
|
def __init__(self) -> None:
|
||||||
super().__init__(icon=REFRESH_ICON, label=label)
|
super().__init__(icon=REFRESH_ICON, label=refresh)
|
||||||
self.set_margin_top(10)
|
self.set_margin_top(10)
|
||||||
self.set_margin_start(80)
|
self.set_margin_start(80)
|
||||||
self.set_margin_end(80)
|
self.set_margin_end(80)
|
||||||
|
|
||||||
|
|
||||||
class KeysButton(IconTextButton):
|
class KeysButton(IconTextButton):
|
||||||
def __init__(self, label: str):
|
def __init__(self, label: str) -> None:
|
||||||
super().__init__(icon=INPUT_KEYBOARD, label=label)
|
super().__init__(icon=INPUT_KEYBOARD, label=label)
|
||||||
self.set_margin_top(10)
|
self.set_margin_top(10)
|
||||||
self.set_margin_start(80)
|
self.set_margin_start(80)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
from typing import Literal, TYPE_CHECKING
|
||||||
|
|
||||||
import gi # noqa E402
|
import gi # noqa E402
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
from gi.repository import Gtk, Gdk
|
from gi.repository import Gtk, Gdk, GLib
|
||||||
|
|
||||||
from dzgui.const.enum import Preferences
|
from dzgui.const.enum import Preferences
|
||||||
from dzgui.views.components.buttonbox import ButtonBox
|
from dzgui.views.components.buttonbox import ButtonBox
|
||||||
@@ -9,13 +11,17 @@ from dzgui.views.components.mod_panel import ModSelectionPanel
|
|||||||
from dzgui.views.components.icon import Icon
|
from dzgui.views.components.icon import Icon
|
||||||
from dzgui.views.components.buttons import RefreshButton, KeysButton
|
from dzgui.views.components.buttons import RefreshButton, KeysButton
|
||||||
from dzgui.const.constants import NO_EXPAND, NO_FILL, EXPAND, FILL, INPUT_KEYBOARD, NO_PADDING
|
from dzgui.const.constants import NO_EXPAND, NO_FILL, EXPAND, FILL, INPUT_KEYBOARD, NO_PADDING
|
||||||
from dzgui.util import strings
|
from dzgui.util.strings import refresh_tooltip, refresh, keys_button, keys_tooltip
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from GLib import SOURCE_REMOVE
|
||||||
|
|
||||||
# TODO: refactor depends on ServerTreeView
|
# TODO: refactor depends on ServerTreeView
|
||||||
class RightPanel(Gtk.Box):
|
class RightPanel(Gtk.Box):
|
||||||
def __init__(self, controller):
|
def __init__(self, controller):
|
||||||
super().__init__(spacing=6, orientation=Gtk.Orientation.VERTICAL)
|
super().__init__(spacing=6, orientation=Gtk.Orientation.VERTICAL)
|
||||||
|
|
||||||
|
self.time = 30
|
||||||
|
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
self.controller.register_widget("right_panel", self)
|
self.controller.register_widget("right_panel", self)
|
||||||
@@ -24,15 +30,12 @@ class RightPanel(Gtk.Box):
|
|||||||
self.filters_vbox = FilterPanel(controller)
|
self.filters_vbox = FilterPanel(controller)
|
||||||
self.sel_panel = ModSelectionPanel(controller)
|
self.sel_panel = ModSelectionPanel(controller)
|
||||||
|
|
||||||
# TODO: strings, move strings into buttons.py
|
self.refresh_button = RefreshButton()
|
||||||
self.refresh_button = RefreshButton("Refresh")
|
self.refresh_button.set_tooltip_text(refresh_tooltip)
|
||||||
# TODO: tooltip, strings
|
|
||||||
# TODO: update refresh button sensitivity on cooldown
|
|
||||||
self.refresh_button.set_tooltip_text("Refresh server data")
|
|
||||||
self.refresh_button.connect("clicked", self._on_refresh_clicked)
|
self.refresh_button.connect("clicked", self._on_refresh_clicked)
|
||||||
|
|
||||||
self.keys = KeysButton(strings.keys_button)
|
self.keys = KeysButton(keys_button)
|
||||||
self.keys.set_tooltip_text(strings.keys_tooltip)
|
self.keys.set_tooltip_text(keys_tooltip)
|
||||||
self.keys.connect("clicked", self._on_question_clicked)
|
self.keys.connect("clicked", self._on_question_clicked)
|
||||||
|
|
||||||
for el in self.button_vbox, self.keys, self.filters_vbox, self.refresh_button:
|
for el in self.button_vbox, self.keys, self.filters_vbox, self.refresh_button:
|
||||||
@@ -49,7 +52,20 @@ class RightPanel(Gtk.Box):
|
|||||||
self.selected = "All maps"
|
self.selected = "All maps"
|
||||||
self.filters_vbox.set_unique_maps(rows)
|
self.filters_vbox.set_unique_maps(rows)
|
||||||
|
|
||||||
|
def decrement(self) -> "SOURCE_REMOVE" | Literal[True]:
|
||||||
|
self.time -= 1
|
||||||
|
if self.time == 0:
|
||||||
|
self.time = 30
|
||||||
|
self.refresh_button.set_label(refresh)
|
||||||
|
self.refresh_button.set_sensitive(True)
|
||||||
|
return GLib.SOURCE_REMOVE
|
||||||
|
self.refresh_button.set_label(f"{refresh} ({str(self.time)})")
|
||||||
|
return True
|
||||||
|
|
||||||
def _on_refresh_clicked(self, button: RefreshButton) -> None:
|
def _on_refresh_clicked(self, button: RefreshButton) -> None:
|
||||||
|
self.refresh_button.set_sensitive(False)
|
||||||
|
self.refresh_button.set_label(f"{refresh} ({str(self.time)})")
|
||||||
|
GLib.timeout_add_seconds(1, self.decrement)
|
||||||
self.controller.refresh_tree()
|
self.controller.refresh_tree()
|
||||||
|
|
||||||
# TODO: reference
|
# TODO: reference
|
||||||
|
|||||||
Reference in new issue
Block a user