mirror of
https://github.com/aclist/dztui.git
synced 2026-11-12 13:00:37 +01:00
feat: dynamic port validation
This commit is contained in:
1 parent
b119569cf5
commit
fdb6b342f7
6 files changed
+153
-149
No files matched your search
@@ -1,4 +1,4 @@
|
||||
from typing import Self, TYPE_CHECKING
|
||||
from typing import Literal, Self, TYPE_CHECKING
|
||||
|
||||
from dzgui.util.strings import atomic_buttons, connect_panel
|
||||
from dzgui.const.constants import (
|
||||
@@ -12,22 +12,24 @@ from dzgui.const.constants import (
|
||||
|
||||
import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk # noqa E402
|
||||
from gi.repository import Gtk, GLib # noqa E402
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from GLib import SOURCE_REMOVE
|
||||
from dzgui.controllers.mc import Controller
|
||||
|
||||
|
||||
class Icon(Gtk.Image):
|
||||
def __init__(self, name: str, l_margin=0) -> None:
|
||||
def __init__(self, name: str, l_margin: int = 0) -> None:
|
||||
super().__init__(icon_name=name,
|
||||
icon_size=Gtk.IconSize.BUTTON,
|
||||
margin_start=l_margin,
|
||||
ypad=2,
|
||||
)
|
||||
|
||||
|
||||
class LargeIcon(Gtk.Image):
|
||||
def __init__(self, name: str, l_margin=5) -> None:
|
||||
def __init__(self, name: str, l_margin: int = 5) -> None:
|
||||
super().__init__(icon_name=name,
|
||||
icon_size=Gtk.IconSize.LARGE_TOOLBAR,
|
||||
margin_start=l_margin
|
||||
@@ -40,6 +42,7 @@ class IconButton(Gtk.Button):
|
||||
self.icon = Icon(icon, l_margin=margin)
|
||||
self.set_image(self.icon)
|
||||
self.set_image_position(Gtk.PositionType.RIGHT)
|
||||
self.set_focus_on_click(False)
|
||||
|
||||
|
||||
class IconTextButton(IconButton):
|
||||
@@ -47,13 +50,10 @@ class IconTextButton(IconButton):
|
||||
super().__init__(icon, margin=5)
|
||||
self.set_label(label)
|
||||
|
||||
self.set_focus_on_click(False)
|
||||
|
||||
|
||||
class LargeIconTextButton(IconButton):
|
||||
def __init__(self, icon: str, label: str) -> None:
|
||||
super().__init__(icon)
|
||||
|
||||
self.set_label(label)
|
||||
self.set_image(LargeIcon(icon))
|
||||
|
||||
@@ -77,22 +77,60 @@ class WebButton(IconTextButton):
|
||||
|
||||
|
||||
class RefreshButton(IconTextButton):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(icon=REFRESH_ICON, label=atomic_buttons.refresh)
|
||||
def __init__(self, controller: "Controller") -> None:
|
||||
super().__init__(
|
||||
icon=REFRESH_ICON,
|
||||
label=atomic_buttons.refresh,
|
||||
)
|
||||
self.controller = controller
|
||||
self.time = 30
|
||||
|
||||
self.set_margin_top(10)
|
||||
self.set_margin_start(80)
|
||||
self.set_margin_end(80)
|
||||
self.set_tooltip_text(atomic_buttons.refresh_tooltip)
|
||||
|
||||
self.connect("clicked", self._on_refresh_clicked)
|
||||
|
||||
def _on_refresh_clicked(self, button: Self) -> None:
|
||||
self.set_sensitive(False)
|
||||
self.show_time(True)
|
||||
GLib.timeout_add_seconds(1, self.decrement)
|
||||
self.controller.refresh_tree()
|
||||
|
||||
def decrement(self) -> "SOURCE_REMOVE" | Literal[True]:
|
||||
self.time -= 1
|
||||
if self.time == 0:
|
||||
self.time = 30
|
||||
self.show_time(False)
|
||||
self.set_sensitive(True)
|
||||
return GLib.SOURCE_REMOVE
|
||||
self.show_time(True)
|
||||
return True
|
||||
|
||||
def show_time(self, state: bool) -> None:
|
||||
if state is True:
|
||||
self.set_label(f"{atomic_buttons.refresh} ({str(self.time)})")
|
||||
else:
|
||||
self.set_label(atomic_buttons.refresh)
|
||||
|
||||
|
||||
class KeysButton(IconTextButton):
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, controller: "Controller") -> None:
|
||||
super().__init__(icon=INPUT_KEYBOARD, label=atomic_buttons.keys)
|
||||
|
||||
self.controller = controller
|
||||
self.set_margin_top(10)
|
||||
self.set_margin_start(80)
|
||||
self.set_margin_end(80)
|
||||
|
||||
self.set_tooltip_text(atomic_buttons.keys_tooltip)
|
||||
|
||||
self.connect("clicked", self._on_keys_clicked)
|
||||
|
||||
def _on_keys_clicked(self, button: Gtk.Button) -> None:
|
||||
self.controller.open_keybindings()
|
||||
|
||||
|
||||
class SteamConnectButton(LargeIconTextButton):
|
||||
def __init__(self) -> None:
|
||||
|
||||
Reference in new issue
Block a user