From 12d367fa7edbfed2df576317d89365ae040be0ce Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Fri, 9 Jan 2026 20:03:22 +0900 Subject: [PATCH] feat: button cooldown --- dzgui/controllers/mc.py | 3 +++ dzgui/main.py | 1 + dzgui/util/strings.py | 3 +++ dzgui/views/components/buttons.py | 15 ++++++------ dzgui/views/components/right_panel.py | 34 ++++++++++++++++++++------- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/dzgui/controllers/mc.py b/dzgui/controllers/mc.py index 78b2e2d..50495c3 100644 --- a/dzgui/controllers/mc.py +++ b/dzgui/controllers/mc.py @@ -292,6 +292,9 @@ class Controller: def start_cooldown(self) -> None: self.cooldown = cooldown.get_time() + def get_cooldown(self) -> None: + return self.cooldown + def manage_cooldown(self) -> bool: if cooldown.is_elapsed(self.cooldown): self.cooldown = cooldown.get_time() diff --git a/dzgui/main.py b/dzgui/main.py index 87b8410..a01a86c 100644 --- a/dzgui/main.py +++ b/dzgui/main.py @@ -79,6 +79,7 @@ def main() -> None: if XDG.resolution.parent.is_dir() is False: make_parents(XDG.resolution) + # TODO: test if XDG.debug.is_file() is False: make_parents(XDG.debug) diff --git a/dzgui/util/strings.py b/dzgui/util/strings.py index 23ecc9d..037b8e6 100644 --- a/dzgui/util/strings.py +++ b/dzgui/util/strings.py @@ -539,3 +539,6 @@ connect_panel = ConnectPanel( ) distance_suffix = "Distance: calculating..." + +refresh = "Refresh" +refresh_tooltip = "Refresh server data" diff --git a/dzgui/views/components/buttons.py b/dzgui/views/components/buttons.py index 62f56c4..2bcbe7e 100644 --- a/dzgui/views/components/buttons.py +++ b/dzgui/views/components/buttons.py @@ -1,3 +1,4 @@ +from dzgui.util.strings import refresh from dzgui.views.components.icon import Icon 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): - def __init__(self, icon: str, margin: int = 0): + def __init__(self, icon: str, margin: int = 0) -> None: super().__init__() i = Icon(icon, l_margin=margin) self.set_image(i) self.set_image_position(Gtk.PositionType.RIGHT) - class IconTextButton(IconButton): - def __init__(self, icon: str, label: str): + def __init__(self, icon: str, label: str) -> None: super().__init__(icon, margin=5) self.set_label(label) class WebButton(IconTextButton): - def __init__(self, label: str): + def __init__(self, label: str) -> None: super().__init__(icon=WEB_BROWSER, label=label) pass class RefreshButton(IconTextButton): - def __init__(self, label: str): - super().__init__(icon=REFRESH_ICON, label=label) + def __init__(self) -> None: + super().__init__(icon=REFRESH_ICON, label=refresh) self.set_margin_top(10) self.set_margin_start(80) self.set_margin_end(80) - class KeysButton(IconTextButton): - def __init__(self, label: str): + def __init__(self, label: str) -> None: super().__init__(icon=INPUT_KEYBOARD, label=label) self.set_margin_top(10) self.set_margin_start(80) diff --git a/dzgui/views/components/right_panel.py b/dzgui/views/components/right_panel.py index e5601f6..4f81e7e 100644 --- a/dzgui/views/components/right_panel.py +++ b/dzgui/views/components/right_panel.py @@ -1,6 +1,8 @@ +from typing import Literal, TYPE_CHECKING + import gi # noqa E402 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.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.buttons import RefreshButton, KeysButton 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 class RightPanel(Gtk.Box): def __init__(self, controller): super().__init__(spacing=6, orientation=Gtk.Orientation.VERTICAL) + self.time = 30 self.controller = controller self.controller.register_widget("right_panel", self) @@ -24,15 +30,12 @@ class RightPanel(Gtk.Box): self.filters_vbox = FilterPanel(controller) self.sel_panel = ModSelectionPanel(controller) - # TODO: strings, move strings into buttons.py - self.refresh_button = RefreshButton("Refresh") - # TODO: tooltip, strings - # TODO: update refresh button sensitivity on cooldown - self.refresh_button.set_tooltip_text("Refresh server data") + self.refresh_button = RefreshButton() + self.refresh_button.set_tooltip_text(refresh_tooltip) self.refresh_button.connect("clicked", self._on_refresh_clicked) - self.keys = KeysButton(strings.keys_button) - self.keys.set_tooltip_text(strings.keys_tooltip) + self.keys = KeysButton(keys_button) + self.keys.set_tooltip_text(keys_tooltip) self.keys.connect("clicked", self._on_question_clicked) 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.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: + 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() # TODO: reference