mirror of
https://github.com/aclist/dztui.git
synced 2026-11-06 10:00:54 +01:00
chore: normalize dialogs
This commit is contained in:
1 parent
45bd0e16ec
commit
1bc21d6083
15 files changed
+283
-282
No files matched your search
@@ -1,6 +1,6 @@
|
||||
from typing import Callable, Self, TYPE_CHECKING
|
||||
from typing import Self, TYPE_CHECKING
|
||||
|
||||
from dzgui.util.strings import refresh, connect_panel
|
||||
from dzgui.util.strings import atomic_buttons, connect_panel
|
||||
from dzgui.const.constants import (
|
||||
CLIPBOARD,
|
||||
INPUT_KEYBOARD,
|
||||
@@ -47,6 +47,8 @@ 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:
|
||||
@@ -56,12 +58,14 @@ class LargeIconTextButton(IconButton):
|
||||
self.set_image(LargeIcon(icon))
|
||||
|
||||
|
||||
class ClipboardButton(IconButton):
|
||||
class ClipboardButton(IconTextButton):
|
||||
def __init__(self, controller: "Controller", data: str) -> None:
|
||||
super().__init__(CLIPBOARD)
|
||||
super().__init__(CLIPBOARD, atomic_buttons.copy)
|
||||
self.controller = controller
|
||||
self.connect("clicked", self._on_button_clicked, data)
|
||||
|
||||
self.set_tooltip_text("Copy IP to clipboard")
|
||||
|
||||
def _on_button_clicked(self, button: Self, data: str) -> None:
|
||||
self.controller.copy_clipboard(data)
|
||||
|
||||
@@ -74,19 +78,21 @@ class WebButton(IconTextButton):
|
||||
|
||||
class RefreshButton(IconTextButton):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(icon=REFRESH_ICON, label=refresh)
|
||||
super().__init__(icon=REFRESH_ICON, label=atomic_buttons.refresh)
|
||||
self.set_margin_top(10)
|
||||
self.set_margin_start(80)
|
||||
self.set_margin_end(80)
|
||||
|
||||
|
||||
class KeysButton(IconTextButton):
|
||||
def __init__(self, label: str) -> None:
|
||||
super().__init__(icon=INPUT_KEYBOARD, label=label)
|
||||
def __init__(self) -> None:
|
||||
super().__init__(icon=INPUT_KEYBOARD, label=atomic_buttons.keys)
|
||||
self.set_margin_top(10)
|
||||
self.set_margin_start(80)
|
||||
self.set_margin_end(80)
|
||||
|
||||
self.set_tooltip_text(atomic_buttons.keys_tooltip)
|
||||
|
||||
|
||||
class SteamConnectButton(LargeIconTextButton):
|
||||
def __init__(self) -> None:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from dzgui.api.servers import validate_ip
|
||||
from dzgui.const.constants import NO_EXPAND, NO_FILL, NO_PADDING
|
||||
from dzgui.util.css import add_class, remove_class
|
||||
from dzgui.util.strings import connect_panel
|
||||
from dzgui.views.components.buttons import AddButton, ClipboardButton, SteamConnectButton
|
||||
@@ -14,6 +13,9 @@ from gi.repository import Gtk, Gdk # noqa E402
|
||||
if TYPE_CHECKING:
|
||||
from dzgui.controllers.mc import Controller
|
||||
|
||||
COLS = 1
|
||||
ROWS = 1
|
||||
|
||||
class LanPanel(Gtk.Frame):
|
||||
def __init__(self, controller: "Controller") -> None:
|
||||
super().__init__(margin_top=10, margin_bottom=5)
|
||||
@@ -24,26 +26,24 @@ class LanPanel(Gtk.Frame):
|
||||
self.set_label_widget(label)
|
||||
|
||||
radio1 = Gtk.RadioButton.new_with_label(None, "Default port (27016)")
|
||||
radio2 = Gtk.RadioButton.new_from_widget(radio1)
|
||||
# TODO: new_with_label_from_widget
|
||||
radio2.set_label("Custom port")
|
||||
radio2 = Gtk.RadioButton.new_with_label_from_widget(radio1, "Custom port")
|
||||
|
||||
self.entry = Gtk.Entry(placeholder_text="Query port", sensitive=False)
|
||||
self.entry = Gtk.Entry(placeholder_text="Enter the query port (1-65535)", sensitive=False, hexpand=True)
|
||||
self.button = Gtk.Button(label="Scan")
|
||||
radio1.connect("toggled", self._on_radio_toggled)
|
||||
|
||||
# TODO: use grid, more column spacing
|
||||
hbox = Gtk.Box(margin=10, spacing=5, halign=Gtk.Align.START)
|
||||
hbox.pack_start(radio1, NO_EXPAND, NO_FILL, NO_PADDING)
|
||||
hbox.pack_start(radio2, NO_EXPAND, NO_FILL, NO_PADDING)
|
||||
hbox.pack_start(self.entry, NO_EXPAND, NO_FILL, NO_PADDING)
|
||||
hbox.pack_start(self.button, NO_EXPAND, NO_FILL, NO_PADDING)
|
||||
self.grid = Gtk.Grid(margin=10, vexpand=False, column_spacing=15, row_spacing=5)
|
||||
self.grid.attach(radio1, 0, 0, COLS, ROWS)
|
||||
# TODO: expression to attach in a line
|
||||
self.grid.attach_next_to(radio2, radio1, Gtk.PositionType.RIGHT, COLS, ROWS)
|
||||
self.grid.attach_next_to(self.entry, radio2, Gtk.PositionType.RIGHT, COLS, ROWS)
|
||||
self.grid.attach_next_to(self.button, self.entry, Gtk.PositionType.RIGHT, COLS, ROWS)
|
||||
|
||||
self.add(hbox)
|
||||
self.add(self.grid)
|
||||
|
||||
def _on_radio_toggled(self, button: Gtk.RadioButton) -> None:
|
||||
for el in self.entry, self.button:
|
||||
el.set_sensitive(not button.get_active())
|
||||
self.entry.set_sensitive(not button.get_active())
|
||||
# TODO: validate custom port entry
|
||||
|
||||
class AddPanel(Gtk.Frame):
|
||||
def __init__(self, controller: "Controller") -> None:
|
||||
@@ -52,14 +52,10 @@ class AddPanel(Gtk.Frame):
|
||||
label = BoldLabel("Connect")
|
||||
self.set_label_widget(label)
|
||||
|
||||
class ConnectPanel(Gtk.Box):
|
||||
def __init__(self, controller: "Controller") -> None:
|
||||
super().__init__(orientation=Gtk.Orientation.VERTICAL)
|
||||
|
||||
COLS = 1
|
||||
ROWS = 1
|
||||
self.classname = "invalid-entry"
|
||||
self.controller = controller
|
||||
self.add_server = AddButton()
|
||||
self.conn_server = SteamConnectButton()
|
||||
self.conn_server.set_sensitive(False)
|
||||
self.add_server.set_sensitive(False)
|
||||
|
||||
self.entry = Gtk.Entry(
|
||||
placeholder_text=connect_panel.placeholder,
|
||||
@@ -69,24 +65,6 @@ class ConnectPanel(Gtk.Box):
|
||||
self.entry.connect("key-press-event", self._on_entry_keypress)
|
||||
self.entry.connect("changed", self._on_text_changed)
|
||||
|
||||
user_fav, self.fav_ip = self.controller.get_favorite()
|
||||
|
||||
server_name = f"{user_fav} ({self.fav_ip})" if user_fav is not None else connect_panel.no_fav
|
||||
self.fav_label = Gtk.Label(label=server_name, track_visited_links=False, halign=Gtk.Align.START, hexpand=True)
|
||||
scrollable_label = Gtk.ScrolledWindow()
|
||||
scrollable_label.add(self.fav_label)
|
||||
|
||||
self.fav_button = SteamConnectButton()
|
||||
self.fav_edit = Gtk.Button(label=connect_panel.edit)
|
||||
|
||||
self.add_server = AddButton()
|
||||
self.conn_server = SteamConnectButton()
|
||||
|
||||
self.conn_server.set_sensitive(False)
|
||||
self.add_server.set_sensitive(False)
|
||||
if server_name is None:
|
||||
self.fav_button.set_sensitive(False)
|
||||
|
||||
self.grid = Gtk.Grid(margin=10, vexpand=False, column_spacing=15, row_spacing=5)
|
||||
self.grid.attach(self.entry, 0, 0, COLS, ROWS)
|
||||
|
||||
@@ -98,32 +76,7 @@ class ConnectPanel(Gtk.Box):
|
||||
for el, sibling, pos, h_span, v_span in els:
|
||||
self.grid.attach_next_to(el, sibling, pos, h_span, v_span)
|
||||
|
||||
self.lan = LanPanel(self.controller)
|
||||
self.add(self.lan)
|
||||
|
||||
label = BoldLabel("Favorite server")
|
||||
frame = Gtk.Frame(margin_top=10, margin_bottom=5, label_widget=label)
|
||||
b = ClipboardButton(self.controller, self.get_fav_ip())
|
||||
b.set_focus_on_click(False)
|
||||
b.set_tooltip_text("Copy IP to clipboard")
|
||||
|
||||
# FIXME: height of connect buttons is not equivalent
|
||||
grid = Gtk.Grid(margin=10, vexpand=False, column_spacing=15, row_spacing=5)
|
||||
grid.attach(scrollable_label, 0, 0, 3, ROWS)
|
||||
grid.attach_next_to(b, scrollable_label, Gtk.PositionType.RIGHT, COLS, ROWS)
|
||||
grid.attach_next_to(self.fav_button, b, Gtk.PositionType.RIGHT, COLS, ROWS)
|
||||
frame.add(grid)
|
||||
self.add(frame)
|
||||
|
||||
label = BoldLabel("Connect")
|
||||
frame = Gtk.Frame(margin_top=10, margin_bottom=5, label_widget=label)
|
||||
frame.add(self.grid)
|
||||
self.add(frame)
|
||||
|
||||
#self.lan.set_visible(False)
|
||||
|
||||
def get_fav_ip(self) -> str:
|
||||
return self.fav_ip
|
||||
self.add(self.grid)
|
||||
|
||||
def mark_valid(self) -> None:
|
||||
self.conn_server.set_sensitive(True)
|
||||
@@ -152,12 +105,53 @@ class ConnectPanel(Gtk.Box):
|
||||
else:
|
||||
self.mark_invalid()
|
||||
|
||||
def set_fav_label(self, text: str) -> None:
|
||||
# TODO: called by controller when changing fav
|
||||
self.fav_label.set_text(text)
|
||||
|
||||
def _on_entry_keypress(self, entry: Gtk.Entry, event: Gdk.EventKey) -> None:
|
||||
if event.keyval == Gdk.KEY_Escape:
|
||||
# NOTE: unselect text
|
||||
entry.select_region(0, 0)
|
||||
self.controller.grab_active_treeview()
|
||||
|
||||
|
||||
class ConnectPanel(Gtk.Box):
|
||||
def __init__(self, controller: "Controller") -> None:
|
||||
super().__init__(orientation=Gtk.Orientation.VERTICAL)
|
||||
|
||||
self.classname = "invalid-entry"
|
||||
self.controller = controller
|
||||
|
||||
user_fav, self.fav_ip = self.controller.get_favorite()
|
||||
|
||||
server_name = f"{user_fav} ({self.fav_ip})" if user_fav is not None else connect_panel.no_fav
|
||||
self.fav_label = Gtk.Label(label=server_name, track_visited_links=False, halign=Gtk.Align.START, hexpand=True)
|
||||
scrollable_label = Gtk.ScrolledWindow()
|
||||
scrollable_label.add(self.fav_label)
|
||||
|
||||
self.fav_button = SteamConnectButton()
|
||||
self.fav_edit = Gtk.Button(label=connect_panel.edit)
|
||||
if server_name is None:
|
||||
self.fav_button.set_sensitive(False)
|
||||
|
||||
self.lan = LanPanel(self.controller)
|
||||
self.add_panel = AddPanel(self.controller)
|
||||
|
||||
label = BoldLabel("Favorite server")
|
||||
frame = Gtk.Frame(margin_top=10, margin_bottom=5, label_widget=label)
|
||||
b = ClipboardButton(self.controller, self.get_fav_ip())
|
||||
|
||||
# FIXME: height of connect buttons is not equivalent
|
||||
grid = Gtk.Grid(margin=10, vexpand=False, column_spacing=15, row_spacing=5)
|
||||
grid.attach(scrollable_label, 0, 0, 3, ROWS)
|
||||
grid.attach_next_to(b, scrollable_label, Gtk.PositionType.RIGHT, COLS, ROWS)
|
||||
grid.attach_next_to(self.fav_button, b, Gtk.PositionType.RIGHT, COLS, ROWS)
|
||||
frame.add(grid)
|
||||
|
||||
for el in self.lan, frame, self.add_panel:
|
||||
self.add(el)
|
||||
|
||||
def get_fav_ip(self) -> str:
|
||||
return self.fav_ip
|
||||
|
||||
def set_fav_label(self, text: str) -> None:
|
||||
# TODO: called by controller when changing fav
|
||||
self.fav_label.set_text(text)
|
||||
|
||||
@@ -10,7 +10,7 @@ from dzgui.views.components.filter_panel import FilterPanel
|
||||
from dzgui.views.components.mod_panel import ModSelectionPanel
|
||||
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.strings import refresh_tooltip, refresh, keys_button, keys_tooltip
|
||||
from dzgui.util.strings import atomic_buttons
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from GLib import SOURCE_REMOVE
|
||||
@@ -31,14 +31,13 @@ class RightPanel(Gtk.Box):
|
||||
|
||||
self.refresh_button = RefreshButton()
|
||||
# TODO: consolidate into class
|
||||
self.refresh_button.set_tooltip_text(refresh_tooltip)
|
||||
#self.refresh_button.set_tooltip_text(refresh_tooltip)
|
||||
self.refresh_button.set_focus_on_click(False)
|
||||
self.refresh_button.connect("clicked", self._on_refresh_clicked)
|
||||
|
||||
self.keys = KeysButton(keys_button)
|
||||
self.keys.set_focus_on_click(False)
|
||||
self.keys.set_tooltip_text(keys_tooltip)
|
||||
self.keys = KeysButton()
|
||||
self.keys.connect("clicked", self._on_keys_clicked)
|
||||
#self.keys.set_focus_on_click(False)
|
||||
|
||||
for el in self.button_vbox, self.keys, self.filters_vbox, self.refresh_button:
|
||||
self.pack_start(el, NO_EXPAND, FILL, NO_PADDING)
|
||||
@@ -61,13 +60,14 @@ class RightPanel(Gtk.Box):
|
||||
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)})")
|
||||
# TODO: abstract this formatting logic
|
||||
self.refresh_button.set_label(f"{atomic_buttons.refresh} ({str(self.time)})")
|
||||
return True
|
||||
|
||||
def _on_refresh_clicked(self, button: RefreshButton) -> None:
|
||||
# TODO: could be internal to refresh button class
|
||||
self.refresh_button.set_sensitive(False)
|
||||
self.refresh_button.set_label(f"{refresh} ({str(self.time)})")
|
||||
self.refresh_button.set_label(f"{atomic_buttons.refresh} ({str(self.time)})")
|
||||
GLib.timeout_add_seconds(1, self.decrement)
|
||||
self.controller.refresh_tree()
|
||||
|
||||
|
||||
Reference in new issue
Block a user