mirror of
https://github.com/aclist/dztui.git
synced 2026-11-23 09:59:36 +01:00
chore: abstract context menu, crumbs, errors
This commit is contained in:
1 parent
a5529f079a
commit
78e6ddb4da
9 files changed
+77
-45
No files matched your search
+27
-30
@@ -2,10 +2,7 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
|
||||
from dzgui.strings import mod_panel
|
||||
from dzgui.strings import rows
|
||||
from dzgui.strings import side_buttons
|
||||
from dzgui.util import strings
|
||||
from dzgui.strings import crumbs, context_menu, mod_panel, rows, side_buttons
|
||||
|
||||
|
||||
class Port(Enum):
|
||||
@@ -86,21 +83,21 @@ class ContextMenuMeta:
|
||||
|
||||
|
||||
class ContextMenuItem(Enum):
|
||||
ADD_NOTE = ContextMenuMeta(strings.add_note)
|
||||
ADD_SERVER = ContextMenuMeta(strings.add)
|
||||
CONNECT = ContextMenuMeta(strings.connect)
|
||||
COPY_LOG_CLIPBOARD = ContextMenuMeta(strings.copy_log)
|
||||
COPY_SERVER_IP = ContextMenuMeta(strings.copy_ip)
|
||||
COPY_SERVER_NAME = ContextMenuMeta(strings.copy_name)
|
||||
UNSUB_MOD = ContextMenuMeta(strings.unsub_mod)
|
||||
VALIDATE_MOD = ContextMenuMeta(strings.validate_mod)
|
||||
OPEN_WORKSHOP = ContextMenuMeta(strings.open_workshop)
|
||||
REFRESH_PLAYERS = ContextMenuMeta(strings.refresh_players)
|
||||
REMOVE_HISTORY = ContextMenuMeta(strings.remove_history)
|
||||
REMOVE_SERVER = ContextMenuMeta(strings.remove)
|
||||
SET_FAV = ContextMenuMeta(strings.add_fav)
|
||||
SHOW_DETAILS = ContextMenuMeta(strings.show_details)
|
||||
SHOW_MODS = ContextMenuMeta(strings.show_mods)
|
||||
ADD_NOTE = ContextMenuMeta(context_menu.add_note)
|
||||
ADD_SERVER = ContextMenuMeta(context_menu.add)
|
||||
CONNECT = ContextMenuMeta(context_menu.connect)
|
||||
COPY_LOG_CLIPBOARD = ContextMenuMeta(context_menu.copy_log)
|
||||
COPY_SERVER_IP = ContextMenuMeta(context_menu.copy_ip)
|
||||
COPY_SERVER_NAME = ContextMenuMeta(context_menu.copy_name)
|
||||
UNSUB_MOD = ContextMenuMeta(context_menu.unsub_mod)
|
||||
VALIDATE_MOD = ContextMenuMeta(context_menu.validate_mod)
|
||||
OPEN_WORKSHOP = ContextMenuMeta(context_menu.open_workshop)
|
||||
REFRESH_PLAYERS = ContextMenuMeta(context_menu.refresh_players)
|
||||
REMOVE_HISTORY = ContextMenuMeta(context_menu.remove_history)
|
||||
REMOVE_SERVER = ContextMenuMeta(context_menu.remove)
|
||||
SET_FAV = ContextMenuMeta(context_menu.set_fav)
|
||||
SHOW_DETAILS = ContextMenuMeta(context_menu.show_details)
|
||||
SHOW_MODS = ContextMenuMeta(context_menu.show_mods)
|
||||
|
||||
@property
|
||||
def label(self) -> str:
|
||||
@@ -184,17 +181,17 @@ class Preferences(Enum):
|
||||
|
||||
|
||||
class NotebookPage(Enum):
|
||||
OFFLINE = NotebookMeta(strings.crumbs.offline, True)
|
||||
CHANGELOG = NotebookMeta(strings.crumbs.changelog, True)
|
||||
DEVELOPERS = NotebookMeta(strings.crumbs.developers, False)
|
||||
HELP = NotebookMeta(strings.crumbs._help, True)
|
||||
KEYS = NotebookMeta(strings.crumbs.keys, True)
|
||||
LOG = NotebookMeta(strings.crumbs.log, True)
|
||||
MODS = NotebookMeta(strings.crumbs.mods, True)
|
||||
OPTIONS = NotebookMeta(strings.crumbs.options, False)
|
||||
SERVERS = NotebookMeta(strings.crumbs.servers, True)
|
||||
THANKS = NotebookMeta(strings.crumbs.thanks, True)
|
||||
CONNECTION = NotebookMeta(strings.crumbs.connect, True)
|
||||
OFFLINE = NotebookMeta(crumbs.offline, True)
|
||||
CHANGELOG = NotebookMeta(crumbs.changelog, True)
|
||||
DEVELOPERS = NotebookMeta(crumbs.developers, False)
|
||||
HELP = NotebookMeta(crumbs._help, True)
|
||||
KEYS = NotebookMeta(crumbs.keys, True)
|
||||
LOG = NotebookMeta(crumbs.log, True)
|
||||
MODS = NotebookMeta(crumbs.mods, True)
|
||||
OPTIONS = NotebookMeta(crumbs.options, False)
|
||||
SERVERS = NotebookMeta(crumbs.servers, True)
|
||||
THANKS = NotebookMeta(crumbs.thanks, True)
|
||||
CONNECTION = NotebookMeta(crumbs.connect, True)
|
||||
|
||||
@property
|
||||
def crumbs(self) -> str:
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ from pathlib import Path
|
||||
from typing import TextIO
|
||||
|
||||
from dzgui.const.constants import LOCK_FILE
|
||||
from dzgui.util.strings import cannot_acquire_lock
|
||||
from dzgui.strings import errors
|
||||
from dzgui.views.dialogs.early_alert import EarlyAlertDialog
|
||||
|
||||
|
||||
@@ -21,6 +21,6 @@ def lock_acquire() -> TextIO:
|
||||
try:
|
||||
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
except OSError:
|
||||
EarlyAlertDialog(cannot_acquire_lock)
|
||||
EarlyAlertDialog(errors.cannot_acquire_lock)
|
||||
sys.exit(1)
|
||||
return lock
|
||||
@@ -0,0 +1,16 @@
|
||||
add = "Add to Saved Servers"
|
||||
add_note = "Add note"
|
||||
connect = "Connect"
|
||||
copy_ip = "Copy IP to clipboard"
|
||||
copy_log = "Copy record(s) to clipboard"
|
||||
copy_name = "Copy name to clipboard"
|
||||
edit_note = "Edit note"
|
||||
open_workshop = "Open in Steam Workshop"
|
||||
refresh_players = "Refresh player count"
|
||||
remove = "Remove from Saved Servers"
|
||||
remove_history = "Remove from history"
|
||||
set_fav = "Set as favorite"
|
||||
show_details = "Show server details"
|
||||
show_mods = "Show server-side mods"
|
||||
unsub_mod = "Unsubscribe mod"
|
||||
validate_mod = "Validate mod"
|
||||
@@ -0,0 +1,15 @@
|
||||
_help = "Help"
|
||||
changelog = "Help > Changelog"
|
||||
connect = "Connect"
|
||||
default = "Servers > "
|
||||
developers = "Options > Developers"
|
||||
keys = "Keybindings"
|
||||
log = "Help > Debug log"
|
||||
main_menu = "Main menu"
|
||||
mods = "Mods"
|
||||
offline = "Mods > Play offline"
|
||||
options = "Options"
|
||||
servers = "Servers > Server browser"
|
||||
thanks = "Help > Special thanks"
|
||||
something_wrong = "Something went wrong. See the detailed error below."
|
||||
workshop = "Enter/double click a row to open in Steam Workshop."
|
||||
@@ -1,7 +1,11 @@
|
||||
api_validation_error = (
|
||||
"API key validation error. Key was typed incorrectly or is defunct."
|
||||
)
|
||||
|
||||
api_popover = "API key validation failed."
|
||||
cannot_acquire_lock = "DZGUI is already open."
|
||||
config_not_found = "DZGUI configuration file not found. Please exit and restart."
|
||||
dayz_not_found = "Could not find a valid DayZ installation."
|
||||
no_mods = "No local mods found."
|
||||
no_servers = "No server metadata to list."
|
||||
server_timeout = "Timed out when querying server(s). Check IP or try again later."
|
||||
workshop_endpoint_error = "Steam Workshop service unavailable, try again later."
|
||||
@@ -2,8 +2,7 @@ import re
|
||||
from typing import Any
|
||||
|
||||
from dzgui.util.localize import number
|
||||
from dzgui.strings.generic import selectable_tree
|
||||
from dzgui.util.strings import no_mods, no_servers, workshop
|
||||
from dzgui.strings import crumbs, errors, generic
|
||||
|
||||
import gi
|
||||
|
||||
@@ -45,10 +44,10 @@ def format_hyperlinks(text: str) -> str:
|
||||
|
||||
def format_mods(size: int, mods: int) -> str:
|
||||
if mods == 0:
|
||||
return no_mods
|
||||
return errors.no_mods
|
||||
l_size = number(size)
|
||||
plural = pluralize("mods", mods)
|
||||
suffix = selectable_tree
|
||||
suffix = generic.selectable_tree
|
||||
return f"Found {mods:n} {plural} taking up {l_size} MiB. {suffix}"
|
||||
|
||||
|
||||
@@ -58,7 +57,7 @@ def format_mib(bits: int) -> float:
|
||||
|
||||
def format_server_mods(mods: int) -> str:
|
||||
plural = pluralize("mods", mods)
|
||||
return f"Found {mods:n} {plural}. {workshop}"
|
||||
return f"Found {mods:n} {plural}. {crumbs.workshop}"
|
||||
|
||||
|
||||
def format_player_count(model: Gtk.TreeModel | None, control: list[Any]) -> str:
|
||||
@@ -66,7 +65,7 @@ def format_player_count(model: Gtk.TreeModel | None, control: list[Any]) -> str:
|
||||
hits: int
|
||||
status: str
|
||||
if model is None:
|
||||
return no_servers
|
||||
return errors.no_servers
|
||||
else:
|
||||
hits = len(model)
|
||||
for row in model:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from dzgui.const.enum import NotebookPage
|
||||
from dzgui.util.strings import label_main_menu, crumbs
|
||||
from dzgui.strings import crumbs as _crumbs
|
||||
from dzgui.util.format import embolden
|
||||
|
||||
import gi
|
||||
@@ -19,7 +19,7 @@ class Breadcrumbs(Gtk.Label):
|
||||
def __init__(self, controller: "Controller") -> None:
|
||||
super().__init__(halign=Gtk.Align.START)
|
||||
|
||||
crumbs = embolden(label_main_menu)
|
||||
crumbs = embolden(_crumbs.main_menu)
|
||||
self.set_markup(crumbs)
|
||||
|
||||
notebook = controller.get_notebook()
|
||||
@@ -47,7 +47,7 @@ class Breadcrumbs(Gtk.Label):
|
||||
self.set_crumbs(crumbs)
|
||||
|
||||
def set_server_crumbs(self, suffix: str) -> None:
|
||||
self.set_crumbs(crumbs.default + suffix)
|
||||
self.set_crumbs(_crumbs.default + suffix)
|
||||
|
||||
def set_crumbs(self, crumbs: str) -> None:
|
||||
text = embolden(crumbs)
|
||||
|
||||
@@ -2,8 +2,8 @@ import logging
|
||||
|
||||
from dzgui.const.constants import APP_NAME
|
||||
from dzgui.const.enum import ContextMenuItem
|
||||
from dzgui.strings import context_menu
|
||||
from dzgui.util.keys import is_ctrl_mask, is_navkey
|
||||
from dzgui.util.strings import edit_note
|
||||
from dzgui.views.trees.tree_base import TreeView
|
||||
|
||||
import gi
|
||||
@@ -70,7 +70,7 @@ class ContextMixin(TreeView):
|
||||
|
||||
if row == ContextMenuItem.ADD_NOTE:
|
||||
if self.controller.has_note():
|
||||
item.set_label(edit_note)
|
||||
item.set_label(context_menu.edit_note)
|
||||
|
||||
return item
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ from dzgui.const.constants import (
|
||||
from dzgui.const.endpoints import STEAM_API_SETUP
|
||||
from dzgui.const.enum import Preferences, ServerTab
|
||||
from dzgui.const.icons import ICON_VIEW_CONCEAL, ICON_VIEW_REVEAL
|
||||
from dzgui.strings import errors
|
||||
from dzgui.strings import options
|
||||
from dzgui.util import strings, css, open_links
|
||||
from dzgui.views.components.box import ShortHBox, VBox
|
||||
@@ -440,7 +441,7 @@ class Options(ScrollableMixin, Gtk.ScrolledWindow): # type: ignore
|
||||
prefs = self.controller.get_prefs()
|
||||
# NOTE: re-check in case file was removed by user between runs
|
||||
if prefs.paths.config.is_file() is False:
|
||||
dialog = ExceptionDialog(self.controller, strings.config_not_found)
|
||||
dialog = ExceptionDialog(self.controller, errors.config_not_found)
|
||||
dialog.show_all()
|
||||
dialog.run() # type: ignore[no-untyped-call]
|
||||
raise OSError(f"Config file '{prefs.paths.config}' not found")
|
||||
|
||||
Reference in new issue
Block a user