feat: button cooldown

This commit is contained in:
aclist 2026-01-09 20:03:22 +09:00
parent 91425cbcaa
commit 12d367fa7e
5 changed files with 39 additions and 17 deletions

View File

@ -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()

View File

@ -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)

View File

@ -539,3 +539,6 @@ connect_panel = ConnectPanel(
)
distance_suffix = "Distance: calculating..."
refresh = "Refresh"
refresh_tooltip = "Refresh server data"

View File

@ -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)

View File

@ -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