mirror of
https://github.com/aclist/dztui.git
synced 2026-11-08 11:00:48 +01:00
fix: update active maps combo on tab change
This commit is contained in:
1 parent
4d0bb2f4f8
commit
c3e2f6e4b4
13 files changed
+200
-231
No files matched your search
@@ -1,83 +0,0 @@
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk, GLib, Gdk, GObject, Pango # noqa
|
||||
|
||||
from dzgui.const.constants import NO_EXPAND, NO_FILL, NO_PADDING
|
||||
from dzgui.const.enum import Popup
|
||||
|
||||
|
||||
class EntryDialog(GenericDialog):
|
||||
def __init__(self, text: str, mode: Popup, link: str, button_type=None):
|
||||
super().__init__(text, mode)
|
||||
|
||||
"""
|
||||
Wraps Gtk.Entry in a dialog and provides basic response handling.
|
||||
Returns user input as a string or None.
|
||||
The Entry widget itself can be manipulated via the get_entry() method.
|
||||
"""
|
||||
|
||||
self.dialog = GenericDialog(text, mode)
|
||||
self.dialogBox = self.dialog.get_content_area()
|
||||
self.dialog.set_default_response(Gtk.ResponseType.OK)
|
||||
self.dialog.set_size_request(500, 0)
|
||||
|
||||
self.user_entry = Gtk.Entry()
|
||||
set_surrounding_margins(self.user_entry, 20)
|
||||
self.user_entry.set_margin_top(0)
|
||||
self.user_entry.set_size_request(250, 0)
|
||||
self.user_entry.set_activates_default(True)
|
||||
self.dialogBox.pack_start(self.user_entry, NO_EXPAND, NO_FILL, NO_PADDING)
|
||||
|
||||
if link:
|
||||
button = Gtk.Button(label=link)
|
||||
button.set_margin_start(60)
|
||||
button.set_margin_end(60)
|
||||
button.connect("clicked", self._on_button_clicked, button_type)
|
||||
self.dialogBox.pack_end(button, NO_EXPAND, NO_FILL, NO_PADDING)
|
||||
|
||||
self.ok = self.dialog.action_area.get_children()[1]
|
||||
self.ok.set_sensitive(False)
|
||||
self.user_entry.connect("insert-text", self._on_text_typed)
|
||||
self.user_entry.get_property("buffer").connect(
|
||||
"deleted-text", self._on_text_deleted
|
||||
)
|
||||
|
||||
def _is_valid_text(self, text: str) -> bool:
|
||||
if text.isspace():
|
||||
return False
|
||||
if len(text) == 0:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _on_text_deleted(
|
||||
self, buffer: Gtk.EntryBuffer, position: int, chars: int
|
||||
) -> None:
|
||||
text = buffer.get_text()
|
||||
state = self._is_valid_text(text)
|
||||
self.ok.set_sensitive(state)
|
||||
|
||||
def _on_text_typed(
|
||||
self, entry: Gtk.Entry, text: str, length: int, pos: int
|
||||
) -> None:
|
||||
state = self._is_valid_text(text)
|
||||
self.ok.set_sensitive(state)
|
||||
|
||||
def _on_button_clicked(self, button: Gtk.Button, enum: RowType) -> None:
|
||||
result = open_links.open_link_by_rowtype(enum)
|
||||
if result is False:
|
||||
AppNav.window.spawn_dialog(strings.something_wrong, Popup.NOTIFY)
|
||||
|
||||
def get_entry(self) -> Gtk.Entry:
|
||||
return self.user_entry
|
||||
|
||||
def get_input(self) -> str | None:
|
||||
self.dialog.show_all()
|
||||
|
||||
response = self.dialog.run()
|
||||
text = self.user_entry.get_text()
|
||||
self.dialog.destroy()
|
||||
if (response == Gtk.ResponseType.OK) and (text != ""):
|
||||
return text
|
||||
else:
|
||||
return None
|
||||
@@ -101,9 +101,7 @@ class NotifyDialog(GenericDialog):
|
||||
|
||||
|
||||
class WaitDialog(GenericDialog):
|
||||
def __init__(
|
||||
self, controller: "Controller", secondary: str, show_progress: bool = False
|
||||
):
|
||||
def __init__(self, controller: "Controller", secondary: str, jobs: int = 1):
|
||||
super().__init__(
|
||||
controller=controller,
|
||||
text=strings.wait,
|
||||
@@ -112,16 +110,26 @@ class WaitDialog(GenericDialog):
|
||||
secondary=secondary,
|
||||
)
|
||||
|
||||
self.jobs = jobs
|
||||
self.cur_job = 1
|
||||
|
||||
self.connect("delete-event", self._on_dialog_delete)
|
||||
content = self.get_content_area()
|
||||
spinner = Gtk.Spinner()
|
||||
self.prog = Gtk.ProgressBar()
|
||||
content.pack_end(spinner, NO_EXPAND, NO_FILL, 0)
|
||||
if show_progress:
|
||||
if self.jobs > 1:
|
||||
content.pack_end(self.prog, NO_EXPAND, NO_FILL, 0)
|
||||
else:
|
||||
spinner.start()
|
||||
|
||||
def increment(self, msg: str = "") -> None:
|
||||
if msg != "":
|
||||
self.format_secondary_text(msg)
|
||||
fraction = self.cur_job / self.jobs
|
||||
self.prog.set_fraction(fraction)
|
||||
self.cur_job += 1
|
||||
|
||||
def _on_dialog_delete(
|
||||
self, response_id: Gtk.ResponseType, event: Gdk.Event
|
||||
) -> Literal[True]:
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import textwrap
|
||||
from typing import Self, TYPE_CHECKING
|
||||
|
||||
from dzgui.const.enum import Popup, Preferences
|
||||
from dzgui.const.constants import NO_EXPAND, NO_FILL
|
||||
from dzgui.util.open_links import open_user_workshop
|
||||
from dzgui.util.strings import notice
|
||||
from dzgui.views.dialogs.generic import GenericDialog
|
||||
from dzgui.views.components.buttons import SteamTextButton, WebButton
|
||||
from dzgui.views.components.buttons import SteamTextButton
|
||||
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk, GLib, Gdk, GObject, Pango # noqa E402
|
||||
|
||||
@@ -18,9 +17,17 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
class WorkshopLinkDialog(GenericDialog):
|
||||
def __init__(self, controller: "Controller", text: str, button_label: str, uid: str):
|
||||
def __init__(
|
||||
self, controller: "Controller", text: str, button_label: str, uid: str
|
||||
):
|
||||
text = textwrap.dedent(text).replace("\n", " ")
|
||||
super().__init__(controller, text=notice, mtype=Gtk.MessageType.INFO, buttons=Gtk.ButtonsType.OK, secondary=text)
|
||||
super().__init__(
|
||||
controller,
|
||||
text=notice,
|
||||
mtype=Gtk.MessageType.INFO,
|
||||
buttons=Gtk.ButtonsType.OK,
|
||||
secondary=text,
|
||||
)
|
||||
self.controller = controller
|
||||
self.dialogBox = self.get_content_area()
|
||||
self.set_default_response(Gtk.ResponseType.OK)
|
||||
@@ -43,12 +50,10 @@ class WorkshopLinkDialog(GenericDialog):
|
||||
def _on_button_clicked(self, button: Gtk.Button, uid: str) -> None:
|
||||
# TODO: currently checks user id on instantiation
|
||||
self.controller.open_user_workshop(uid)
|
||||
#client = self.controller.query_config(Preferences.CLIENT)
|
||||
#open_user_workshop(uid, client)
|
||||
# client = self.controller.query_config(Preferences.CLIENT)
|
||||
# open_user_workshop(uid, client)
|
||||
|
||||
def _on_dialog_response(
|
||||
self, dialog: Self, resp: Gtk.ResponseType
|
||||
) -> None:
|
||||
def _on_dialog_response(self, dialog: Self, resp: Gtk.ResponseType) -> None:
|
||||
match resp:
|
||||
case Gtk.ResponseType.DELETE_EVENT:
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user