chore: abstract dialog strings

This commit is contained in:
aclist committed 2026-11-23 17:11:52 +09:00
1 parent 78e6ddb4da
commit ffc5f70083
6 files changed
+63 -68

No files matched your search

+9 -15
View File
@@ -42,15 +42,9 @@ from dzgui.api.steam import is_dayz_running
from dzgui.const.enum import NotebookPage, Preferences from dzgui.const.enum import NotebookPage, Preferences
from dzgui.init.proc import is_steam_running from dzgui.init.proc import is_steam_running
from dzgui.managers.threading import call_on_thread, StoredFunc, ThreadingManager from dzgui.managers.threading import call_on_thread, StoredFunc, ThreadingManager
from dzgui.strings.dialogs import ( from dzgui.strings import dialogs, errors, kb
waiting_for_launch,
waiting_for_mods,
waiting_for_directories,
)
from dzgui.strings import kb
from dzgui.strings.server_mods import checkmark, resync, invalid_mod from dzgui.strings.server_mods import checkmark, resync, invalid_mod
from dzgui.util.format import format_exception, format_mib from dzgui.util.format import format_exception, format_mib
from dzgui.util.strings import dialog, server_timeout
from dzgui.util.symlink import rebuild_symlinks from dzgui.util.symlink import rebuild_symlinks
from dzgui.views.dialogs.generic import ExceptionDialog from dzgui.views.dialogs.generic import ExceptionDialog
from dzgui.views.dialogs.servers import ServerDetailsDialog, ServerModDialog from dzgui.views.dialogs.servers import ServerDetailsDialog, ServerModDialog
@@ -103,12 +97,12 @@ class ConnectionManager:
self.remote_mod_ids: list[str] = [] self.remote_mod_ids: list[str] = []
self.missing_mods: list[tuple[str, str, int, int]] = [] self.missing_mods: list[tuple[str, str, int, int]] = []
@call_on_thread(dialog.querying) @call_on_thread(dialogs.querying)
def connect_by_ip(self, addr: str) -> None: def connect_by_ip(self, addr: str) -> None:
res = Servers.query_by_ip(addr) res = Servers.query_by_ip(addr)
self._prepare_connection(res) self._prepare_connection(res)
@call_on_thread(dialog.querying) @call_on_thread(dialogs.querying)
def connect_by_record(self, record: Servers.Record) -> None: def connect_by_record(self, record: Servers.Record) -> None:
res = Servers.query_by_record(record) res = Servers.query_by_record(record)
self._prepare_connection(res) self._prepare_connection(res)
@@ -230,7 +224,7 @@ class ConnectionManager:
except Exception: except Exception:
return False return False
@call_on_thread(dialog.querying) @call_on_thread(dialogs.querying)
def query_details(self, record: Servers.Record) -> None: def query_details(self, record: Servers.Record) -> None:
details = Servers.get_details(record) details = Servers.get_details(record)
if details is None: if details is None:
@@ -275,7 +269,7 @@ class ConnectionManager:
return alpha_mods, missing_mods return alpha_mods, missing_mods
@call_on_thread(dialog.querying) @call_on_thread(dialogs.querying)
def query_modlist_and_present(self, record: Servers.Record) -> None: def query_modlist_and_present(self, record: Servers.Record) -> None:
try: try:
mods, missing_mods = self._query_modlist(record) mods, missing_mods = self._query_modlist(record)
@@ -303,7 +297,7 @@ class ConnectionManager:
dialog.run() # type: ignore[no-untyped-call] dialog.run() # type: ignore[no-untyped-call]
def _server_timeout(self) -> None: def _server_timeout(self) -> None:
dialog = ExceptionDialog(self.controller, server_timeout) dialog = ExceptionDialog(self.controller, errors.server_timeout)
dialog.set_details_buffer(kb.DZG_006) dialog.set_details_buffer(kb.DZG_006)
dialog.show_all() dialog.show_all()
dialog.run() # type: ignore[no-untyped-call] dialog.run() # type: ignore[no-untyped-call]
@@ -328,7 +322,7 @@ class ConnectionManager:
self.thread_man.set_cleanup_func(func) self.thread_man.set_cleanup_func(func)
return return
self.thread_man.update_dialog(waiting_for_launch) self.thread_man.update_dialog(dialogs.waiting_for_launch)
while True: while True:
if self.controller.is_cancel_pending(): if self.controller.is_cancel_pending():
# TODO: some facility to also close spawned steam process # TODO: some facility to also close spawned steam process
@@ -361,7 +355,7 @@ class ConnectionManager:
self.thread_man.set_cleanup_func(func, destroy_first=True) self.thread_man.set_cleanup_func(func, destroy_first=True)
return return
self.thread_man.update_dialog(waiting_for_directories) self.thread_man.update_dialog(dialogs.waiting_for_directories)
for title, mod, stamp, size in self.missing_mods: for title, mod, stamp, size in self.missing_mods:
mod_path = self.workshop / mod mod_path = self.workshop / mod
@@ -387,7 +381,7 @@ class ConnectionManager:
# TODO: just push steam path directly # TODO: just push steam path directly
self._connect_steam(menu_only) self._connect_steam(menu_only)
@call_on_thread(waiting_for_mods, show_cancel=True) @call_on_thread(dialogs.waiting_for_mods, show_cancel=True)
def update_and_connect(self, menu_only: bool = False) -> None: def update_and_connect(self, menu_only: bool = False) -> None:
if len(self.missing_mods) > 0: if len(self.missing_mods) > 0:
self._update_mods(menu_only) self._update_mods(menu_only)
+10 -11
View File
@@ -14,8 +14,7 @@ from dzgui.const.constants import (
) )
from dzgui.const.enum import FilterMode, Preferences, ServerTab from dzgui.const.enum import FilterMode, Preferences, ServerTab
from dzgui.managers.threading import call_on_thread, StoredFunc, ThreadingManager from dzgui.managers.threading import call_on_thread, StoredFunc, ThreadingManager
from dzgui.strings import dialogs, kb from dzgui.strings import dialogs, errors, kb
from dzgui.util.strings import server_timeout, dialog
from dzgui.views.dialogs.generic import ExceptionDialog from dzgui.views.dialogs.generic import ExceptionDialog
import gi import gi
@@ -83,7 +82,7 @@ class ServerModelManager:
self.preserve_on_fail = True self.preserve_on_fail = True
self.load() self.load()
@call_on_thread(dialog.fetching) @call_on_thread(dialogs.fetching_server)
def _dump_api(self) -> None: def _dump_api(self) -> None:
# TODO: pass api key a priori in .load() call? # TODO: pass api key a priori in .load() call?
failure_func = StoredFunc(self._cleanup_on_failure) failure_func = StoredFunc(self._cleanup_on_failure)
@@ -126,7 +125,7 @@ class ServerModelManager:
parsed = Servers.parse_json(servers) parsed = Servers.parse_json(servers)
self._push_data(parsed) self._push_data(parsed)
@call_on_thread(dialog.scanning, show_cancel=True) @call_on_thread(dialogs.scanning_lan, show_cancel=True)
def dump_lan(self, port: int, early_abort: bool) -> None: def dump_lan(self, port: int, early_abort: bool) -> None:
self.first_iteration = True self.first_iteration = True
@@ -159,7 +158,7 @@ class ServerModelManager:
parsed = Servers.parse_json(servers) parsed = Servers.parse_json(servers)
self._push_data(parsed) self._push_data(parsed)
@call_on_thread(dialog.fetching) @call_on_thread(dialogs.fetching_server)
def _dump_ips(self, ips: list[str]) -> None: def _dump_ips(self, ips: list[str]) -> None:
job = Servers.query_direct job = Servers.query_direct
servers = [] servers = []
@@ -199,7 +198,7 @@ class ServerModelManager:
parsed = Servers.parse_json(servers) parsed = Servers.parse_json(servers)
self._push_data(parsed) self._push_data(parsed)
@call_on_thread(dialog.querying) @call_on_thread(dialogs.querying)
def add_by_ip(self, addr: str) -> None: def add_by_ip(self, addr: str) -> None:
self.preserve_on_fail = True self.preserve_on_fail = True
try: try:
@@ -212,7 +211,7 @@ class ServerModelManager:
) )
return return
@call_on_thread(dialog.querying) @call_on_thread(dialogs.querying)
def add_by_record(self, record: Servers.Record) -> None: def add_by_record(self, record: Servers.Record) -> None:
self.preserve_on_fail = True self.preserve_on_fail = True
# NOTE: rationale: a raw Record as shown in server browser may resolve to a different IP # NOTE: rationale: a raw Record as shown in server browser may resolve to a different IP
@@ -226,7 +225,7 @@ class ServerModelManager:
) )
return return
@call_on_thread(dialog.querying) @call_on_thread(dialogs.querying)
def remove_by_record(self, record: Servers.Record) -> None: def remove_by_record(self, record: Servers.Record) -> None:
self.preserve_on_fail = True self.preserve_on_fail = True
try: try:
@@ -287,7 +286,7 @@ class ServerModelManager:
config_man.remove_from_history_file(fqip) config_man.remove_from_history_file(fqip)
self.update_history() self.update_history()
@call_on_thread(dialog.querying) @call_on_thread(dialogs.querying)
def update_playercount( def update_playercount(
self, treeiter: Gtk.TreeIter, record: Servers.Record self, treeiter: Gtk.TreeIter, record: Servers.Record
) -> None: ) -> None:
@@ -448,7 +447,7 @@ class ServerModelManager:
# TODO: distinguish signals, e.g. "servers_failed_to_load", "servers_loaded_empty" # TODO: distinguish signals, e.g. "servers_failed_to_load", "servers_loaded_empty"
# customize statusbar and dialog accordingly # customize statusbar and dialog accordingly
if show_dialog: if show_dialog:
dialog = ExceptionDialog(self.controller, server_timeout) dialog = ExceptionDialog(self.controller, errors.server_timeout)
dialog.set_details_buffer(kb.DZG_006) dialog.set_details_buffer(kb.DZG_006)
dialog.show_all() dialog.show_all()
dialog.run() # type: ignore[no-untyped-call] dialog.run() # type: ignore[no-untyped-call]
@@ -471,7 +470,7 @@ class ServerModelManager:
def _get_proxy_man(self) -> "ProxyModelManager": def _get_proxy_man(self) -> "ProxyModelManager":
return self.proxy_man return self.proxy_man
@call_on_thread(dialog.filtering) @call_on_thread(dialogs.filtering)
def refilter(self, mode: FilterMode) -> None: def refilter(self, mode: FilterMode) -> None:
self.first_iteration = False self.first_iteration = False
proxy_man = self._get_proxy_man() proxy_man = self._get_proxy_man()
+33 -30
View File
@@ -1,36 +1,39 @@
default_header = "DZGUI - Dialog" # TODO: is this key in use?
error = "ERROR" caught_cancel_signal = "Caught cancel signal, cleaning up"
waiting_for_launch = "Waiting for DayZ to launch"
waiting_for_mods = "Queueing up mods (step 1/2)"
waiting_for_directories = "Steam is staging mods (step 2/2)"
fetching_update = "Fetching update"
failed_to_update = "Failed to update DZGUI executable"
update_success = "Updated successfully. Please exit and relaunch."
load_error_lan = "Failed to find any servers on your network.\nCheck the server query port or your firewall settings."
fetching_mods = "Fetching mod metadata"
deleting_mods = "Unsubscribing mods"
validating_mods = "Validating mods"
scanning_mods = "Scanning mods"
parsing_mods = "Parsing mods"
checking_api = "Checking API key" checking_api = "Checking API key"
confirm = "Confirmation"
running = "Running"
failed = "FAILED"
ok = "OK"
mission_dialog = "Set a mission folder location"
custom_mod_dialog = "Set location to a custom mods folder" custom_mod_dialog = "Set location to a custom mods folder"
debug_heading = "Debug" debug_heading = "Debug"
debug_secondary = "Launch arguments" debug_secondary = "Launch arguments"
default_header = "DZGUI - Dialog"
toggle_calc = "Toggle calculator" deleting_mods = "Unsubscribing mods"
error = "Error"
exit_app = "Exit"
failed = "FAILED"
failed_to_update = "Failed to update DZGUI executable"
fetching_server = "Fetching server metadata"
fetching_mods = "Fetching mod metadata"
fetching_update = "Fetching update"
filtering = "Filtering servers"
load_error_lan = "Failed to find any servers on your network.\nCheck the server query port or your firewall settings."
main_menu = "Return to main menu"
mission_dialog = "Set a mission folder location"
modlist = "Modlist"
notice = "Notice"
ok = "OK"
parsing_mods = "Parsing mods"
querying = "Querying server"
restart_required = "App relaunch required"
running = "Running"
scanning_lan = "Scanning LAN ports"
scanning_mods = "Scanning mods"
server_details = "Server details" server_details = "Server details"
server_message = "Server message" server_message = "Server message"
something_wrong = "Something went wrong. See the detailed error below."
caught_cancel_signal = "Caught cancel signal, cleaning up" toggle_calc = "Toggle calculator"
update_success = "Updated successfully. Please exit and relaunch."
validating_mods = "Validating mods"
wait = "Please wait"
waiting_for_directories = "Steam is staging mods (step 2/2)"
waiting_for_launch = "Waiting for DayZ to launch"
waiting_for_mods = "Queueing up mods (step 1/2)"
+1 -1
View File
@@ -15,7 +15,7 @@ class AbortDialog(ColorAwareApp, Gtk.MessageDialog): # type: ignore
def __init__(self, string: str, buttons: Gtk.ButtonsType) -> None: def __init__(self, string: str, buttons: Gtk.ButtonsType) -> None:
super().__init__( super().__init__(
title=dialogs.default_header, title=dialogs.default_header,
text=dialogs.error, text=(dialogs.error).upper(),
transient_for=None, transient_for=None,
buttons=buttons, buttons=buttons,
) )
+8 -9
View File
@@ -1,7 +1,6 @@
from typing import Literal, Self, TYPE_CHECKING from typing import Literal, Self, TYPE_CHECKING
from dzgui.strings import dialogs from dzgui.strings import dialogs
from dzgui.util import strings
from dzgui.views.components.buttons import ClipboardButton from dzgui.views.components.buttons import ClipboardButton
import gi import gi
@@ -52,7 +51,7 @@ class ConfirmationDialog(GenericDialog):
def __init__(self, controller: "Controller", secondary: str): def __init__(self, controller: "Controller", secondary: str):
super().__init__( super().__init__(
controller=controller, controller=controller,
text=strings.confirm, text=dialogs.confirm,
mtype=Gtk.MessageType.QUESTION, mtype=Gtk.MessageType.QUESTION,
buttons=Gtk.ButtonsType.OK_CANCEL, buttons=Gtk.ButtonsType.OK_CANCEL,
secondary=secondary, secondary=secondary,
@@ -63,7 +62,7 @@ class IgnoreDialog(GenericDialog):
def __init__(self, controller: "Controller", secondary: str): def __init__(self, controller: "Controller", secondary: str):
super().__init__( super().__init__(
controller=controller, controller=controller,
text=strings.confirm, text=dialogs.confirm,
mtype=Gtk.MessageType.QUESTION, mtype=Gtk.MessageType.QUESTION,
buttons=Gtk.ButtonsType.OK_CANCEL, buttons=Gtk.ButtonsType.OK_CANCEL,
secondary=secondary, secondary=secondary,
@@ -79,7 +78,7 @@ class NotifyDialog(GenericDialog):
def __init__(self, controller: "Controller", secondary: str): def __init__(self, controller: "Controller", secondary: str):
super().__init__( super().__init__(
controller=controller, controller=controller,
text=strings.notice, text=dialogs.notice,
mtype=Gtk.MessageType.INFO, mtype=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK, buttons=Gtk.ButtonsType.OK,
secondary=secondary, secondary=secondary,
@@ -96,7 +95,7 @@ class WaitDialog(GenericDialog):
): ):
super().__init__( super().__init__(
controller=controller, controller=controller,
text=strings.wait, text=dialogs.wait,
mtype=Gtk.MessageType.INFO, mtype=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.NONE, buttons=Gtk.ButtonsType.NONE,
secondary=secondary, secondary=secondary,
@@ -150,14 +149,14 @@ class QuitDialog(GenericDialog):
def __init__(self, controller: "Controller", secondary: str): def __init__(self, controller: "Controller", secondary: str):
super().__init__( super().__init__(
controller=controller, controller=controller,
text=strings.restart_required, text=dialogs.restart_required,
mtype=Gtk.MessageType.INFO, mtype=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.NONE, buttons=Gtk.ButtonsType.NONE,
secondary=secondary, secondary=secondary,
) )
self.controller = controller self.controller = controller
self.add_button(strings.exit_app, Gtk.ResponseType.OK) self.add_button(dialogs.exit_app, Gtk.ResponseType.OK)
self.connect("response", self._on_response) self.connect("response", self._on_response)
# TODO: superfluous with the above # TODO: superfluous with the above
@@ -250,8 +249,8 @@ class ExceptionDialog(TextBufferDialog):
def __init__(self, controller: "Controller", trace: str): def __init__(self, controller: "Controller", trace: str):
super().__init__( super().__init__(
controller=controller, controller=controller,
heading=strings.error_heading, heading=dialogs.error,
secondary=strings.something_wrong, secondary=dialogs.something_wrong,
text=trace, text=trace,
mtype=Gtk.MessageType.ERROR, mtype=Gtk.MessageType.ERROR,
) )
+2 -2
View File
@@ -1,7 +1,7 @@
import textwrap import textwrap
from typing import Self, TYPE_CHECKING from typing import Self, TYPE_CHECKING
from dzgui.util.strings import notice from dzgui.strings import dialogs
from dzgui.views.dialogs.generic import GenericDialog from dzgui.views.dialogs.generic import GenericDialog
from dzgui.views.components.buttons import SteamTextButton from dzgui.views.components.buttons import SteamTextButton
@@ -22,7 +22,7 @@ class WorkshopLinkDialog(GenericDialog):
text = textwrap.dedent(text).replace("\n", " ") text = textwrap.dedent(text).replace("\n", " ")
super().__init__( super().__init__(
controller, controller,
text=notice, text=dialogs.notice,
mtype=Gtk.MessageType.INFO, mtype=Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK, buttons=Gtk.ButtonsType.OK,
secondary=text, secondary=text,