mirror of
https://github.com/aclist/dztui.git
synced 2026-08-26 17:57:06 +02:00
chore: move statusbar format method to format.py
This commit is contained in:
parent
618ee47e53
commit
2fc2eddf87
@ -42,7 +42,7 @@ from dzgui.util.diag import write_diagnostic
|
||||
from dzgui.util import cooldown, strings
|
||||
from dzgui.util._json import read_json, write_json
|
||||
from dzgui.util.open_links import open_workshop_page
|
||||
from dzgui.util.format import format_mods, pluralize
|
||||
from dzgui.util.format import format_mods, format_player_count, pluralize
|
||||
from dzgui.util.redact import redact_log
|
||||
|
||||
from dzgui.views.dialogs.filepicker import FilePicker
|
||||
@ -171,7 +171,7 @@ class Controller:
|
||||
widget.handler_block_by_func(func)
|
||||
else:
|
||||
widget.handler_unblock_by_func(func)
|
||||
# TODO
|
||||
# TODO: deprecated?
|
||||
#self.mediator.menu.sel_blocked = state
|
||||
|
||||
def toggle_debug_mode(self) -> None:
|
||||
@ -213,13 +213,16 @@ class Controller:
|
||||
|
||||
Gtk.main_quit()
|
||||
|
||||
def get_statusbar(self) -> str:
|
||||
return self.mediator.grid.statusbar.get_text()
|
||||
|
||||
def set_statusbar(self, text: str) -> None:
|
||||
self.mediator.grid.statusbar.set_text(text)
|
||||
|
||||
def delete_multiple_mods(self) -> None:
|
||||
sel = self.mediator.modtreeview.get_selection()
|
||||
model, pathlist = sel.get_selected_rows()
|
||||
# NOTE: reverse when multiple
|
||||
# NOTE: reverse when multiple selection
|
||||
for path in reversed(pathlist):
|
||||
self.delete_single_mod(path)
|
||||
|
||||
@ -254,7 +257,7 @@ class Controller:
|
||||
logger.critical(e)
|
||||
self.spawn_dialog(strings.something_wrong, Popup.NOTIFY)
|
||||
# TODO: suppress signals
|
||||
# then reenable (or it spawns twice)
|
||||
# then reenable (or it spawns dialog twice)
|
||||
self.mediator.grid.notebook.settings.populate_settings()
|
||||
return
|
||||
|
||||
@ -309,6 +312,7 @@ class Controller:
|
||||
self.mediator.grid.notebook.set_page_by_enum(page)
|
||||
|
||||
def open_page_by_button(self, button: "ContextualButton") -> None:
|
||||
# TODO: consolidate methods with set_page_by_enum
|
||||
match button.context:
|
||||
case ButtonType.EXIT:
|
||||
logger.info("Normal user exit")
|
||||
@ -316,7 +320,7 @@ class Controller:
|
||||
return
|
||||
case ButtonType.OPTIONS:
|
||||
self.mediator.grid.notebook.settings.populate_settings()
|
||||
self.mediator.grid.statusbar.refresh(None)
|
||||
self.set_statusbar("")
|
||||
case ButtonType.MODS:
|
||||
self.load_mods()
|
||||
case ButtonType.HELP:
|
||||
@ -577,42 +581,12 @@ class Controller:
|
||||
def update_server_status(self) -> None:
|
||||
treeview = self.mediator.notebook.servers.get_active_treeview()
|
||||
model = treeview.get_model()
|
||||
if model is None:
|
||||
players = 0
|
||||
hits = 0
|
||||
else:
|
||||
hits = len(model)
|
||||
players = 0
|
||||
for row in model:
|
||||
players += row[4]
|
||||
# TODO: move to util.format
|
||||
players_pretty = pluralize("players", players)
|
||||
hits_pretty = pluralize("matches", hits)
|
||||
formatted = (
|
||||
f"Found {hits:n} {hits_pretty} with {players:n} {players_pretty}"
|
||||
)
|
||||
suffix = " | Distance: calculating..."
|
||||
|
||||
if players == 0:
|
||||
suffix = ""
|
||||
self.mediator.statusbar.set_text(formatted + suffix)
|
||||
#self.players = formatted
|
||||
status = format_player_count(model)
|
||||
self.mediator.statusbar.set_text(status)
|
||||
|
||||
def propagate_column_width(self, col: Gtk.TreeViewColumn) -> None:
|
||||
GLib.idle_add(self.mediator.servers.update_tab_widths, col)
|
||||
# tabs = self.mediator.servers.get_tabs()
|
||||
# tree = self.mediator.servers.get_active_treeview()
|
||||
# width = col.get_width()
|
||||
# title = col.get_title()
|
||||
# for tab in tabs:
|
||||
# if tab == tree:
|
||||
# continue
|
||||
# for col in tab.get_columns():
|
||||
# if col.get_title() == title:
|
||||
# self.suppress_signal(tab, col, "_on_col_width_changed", True)
|
||||
# col.set_fixed_width(width)
|
||||
# self.suppress_signal(tab, col, "_on_col_width_changed", False)
|
||||
|
||||
|
||||
def set_crumbs_cache(self,text: str) -> None:
|
||||
self.crumbs_cache = text
|
||||
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
import re
|
||||
|
||||
from dzgui.util.localize import number
|
||||
from dzgui.util.strings import no_mods
|
||||
from dzgui.util.strings import no_mods, no_servers, distance_suffix
|
||||
|
||||
import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk # noqa E402
|
||||
|
||||
|
||||
def format_pango(text: str) -> str:
|
||||
@ -42,3 +46,20 @@ def format_mods(size: int, mods: int) -> str:
|
||||
l_size = number(size)
|
||||
plural = pluralize("mods", mods)
|
||||
return f"Found {mods:n} {plural} taking up {l_size} MiB"
|
||||
|
||||
|
||||
def format_player_count(model: Gtk.ListStore | None) -> str:
|
||||
players = 0
|
||||
hits: int
|
||||
status: str
|
||||
if model is None or len(model) == 0:
|
||||
return no_servers
|
||||
else:
|
||||
hits = len(model)
|
||||
for row in model:
|
||||
players += row[4]
|
||||
players_pretty = pluralize("players", players)
|
||||
hits_pretty = pluralize("matches", hits)
|
||||
suffix = distance_suffix
|
||||
status = f"Found {hits:n} {hits_pretty} with {players:n} {players_pretty}"
|
||||
return f"{status} | {suffix}"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user