mirror of
https://github.com/aclist/dztui.git
synced 2026-08-26 17:57:06 +02:00
chore: drop shrink to fit
This commit is contained in:
parent
891abcc049
commit
1715d4c110
@ -215,9 +215,8 @@ def query_direct(ip: str, qport: int, TIMEOUT: float = 3.0) -> dict | None:
|
||||
res["gameport"] = gameport
|
||||
res["ping"] = ping
|
||||
return res
|
||||
except TimeoutError:
|
||||
return None
|
||||
except KeyError:
|
||||
except Exception as e:
|
||||
logger.critical(e)
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@ -663,3 +663,6 @@ class Controller(GObject.GObject):
|
||||
treeview = self.get_active_treeview()
|
||||
model, treeiter = treeview.get_selection().get_selected()
|
||||
ServerModelManager(self, treeview).update_playercount(treeiter, record)
|
||||
|
||||
def get_window(self) -> "OuterWindow":
|
||||
return self.mediator.window
|
||||
|
||||
@ -22,7 +22,7 @@ class ConnectionManager:
|
||||
def __init__(self, controller: "Controller") -> None:
|
||||
|
||||
self.controller = controller
|
||||
self.thread_man = ThreadingManager(parent=controller)
|
||||
self.thread_man = ThreadingManager(controller)
|
||||
|
||||
@call_on_thread(dialog.querying)
|
||||
def connect_by_id(self, addr: str, key: str) -> None:
|
||||
|
||||
@ -29,9 +29,7 @@ def call_on_thread(dialog_str: str) -> Callable:
|
||||
"Attribute 'thread_man' must be of type 'ThreadingManager'"
|
||||
)
|
||||
self.thread_man.call_on_thread(dialog_str, stored)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
@ -46,20 +44,18 @@ class StoredFunc:
|
||||
|
||||
|
||||
class ThreadingManager:
|
||||
def __init__(self, parent: Gtk.Window) -> None:
|
||||
self.parent = parent
|
||||
def __init__(self, controller: "Controller") -> None:
|
||||
self.controller = controller
|
||||
self.jobs = 1
|
||||
self.cleanup_func = None
|
||||
self.destroy_first = False
|
||||
|
||||
# self.alternate_statusbar = None
|
||||
|
||||
def call_on_thread(self, dialog_str: str, func: StoredFunc) -> None:
|
||||
def callback() -> None:
|
||||
func.call()
|
||||
GLib.idle_add(self._destroy_on_idle)
|
||||
|
||||
self.wait_dialog = WaitDialog(self.parent, dialog_str, jobs=self.jobs)
|
||||
self.wait_dialog = WaitDialog(self.controller, dialog_str, jobs=self.jobs)
|
||||
self.wait_dialog.show_all()
|
||||
thread = threading.Thread(target=callback)
|
||||
thread.start()
|
||||
@ -73,13 +69,6 @@ class ThreadingManager:
|
||||
def increment_dialog_with_str(self, text: str) -> None:
|
||||
GLib.idle_add(lambda: self.wait_dialog.increment(text))
|
||||
|
||||
# TODO: this should not be delegated here, set in cleanup func
|
||||
# def set_alternate_statusbar(self, msg: str) -> None:
|
||||
# self.alternate_statusbar = msg
|
||||
|
||||
# def get_alternate_statusbar(self) -> Optional[str]:
|
||||
# return self.alternate_statusbar
|
||||
|
||||
def set_cleanup_func(self, func: StoredFunc, destroy_first: bool = False) -> None:
|
||||
if type(func) not in (StoredFunc, type(None)):
|
||||
msg = f"Callback function '{func}' is not of type StoredFunc or None"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import re
|
||||
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
from typing import Any, Optional, TYPE_CHECKING
|
||||
from warnings import deprecated
|
||||
|
||||
from dzgui.const.enum import FilterMode
|
||||
@ -17,6 +17,7 @@ import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository.Gtk import TreeIter
|
||||
|
||||
|
||||
class ProxyModelManager:
|
||||
"""
|
||||
Manages access to cached FastInsertListStore resources and
|
||||
@ -291,3 +292,8 @@ class ProxyModelManager:
|
||||
self.ping_cache = {}
|
||||
# if full:
|
||||
# self.control_model = None
|
||||
|
||||
def push(self, data: list[Any]) -> None:
|
||||
self.wipe_cache()
|
||||
self.set_control(data)
|
||||
self.filter(FilterMode.INITIAL)
|
||||
|
||||
@ -4,7 +4,7 @@ import threading
|
||||
from concurrent.futures import as_completed
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import Any, TYPE_CHECKING
|
||||
|
||||
import dzgui.api.servers as Servers
|
||||
from dzgui.const.enum import FilterMode, Preferences, ServerTab
|
||||
@ -34,6 +34,7 @@ logger = logging.getLogger(__name__)
|
||||
# TODO: failure should spawn error dialog
|
||||
# TODO: non failure with empty model: updates statusbar with help text
|
||||
|
||||
|
||||
@dataclass
|
||||
class NewPlayerCount:
|
||||
treeiter: Gtk.TreeIter
|
||||
@ -55,9 +56,7 @@ class ServerModelManager:
|
||||
|
||||
# NOTE: store filter man for access inside thread
|
||||
self.proxy_man = tv.get_proxy_man()
|
||||
|
||||
# FIXME: change WaitDialog to use parent window only
|
||||
self.thread_man = ThreadingManager(parent=controller)
|
||||
self.thread_man = ThreadingManager(self.controller)
|
||||
|
||||
# TODO: if first iteration, clear filter man control model
|
||||
# literal first load: iteration 1
|
||||
@ -233,7 +232,9 @@ class ServerModelManager:
|
||||
self.add_by_ip(addr)
|
||||
|
||||
@call_on_thread(dialog.querying)
|
||||
def update_playercount(self, treeiter: Gtk.TreeIter, record: Servers.Record) -> None:
|
||||
def update_playercount(
|
||||
self, treeiter: Gtk.TreeIter, record: Servers.Record
|
||||
) -> None:
|
||||
proxy_man = self._get_proxy_man()
|
||||
res = Servers.query_playercount(record)
|
||||
if res is None:
|
||||
@ -265,16 +266,22 @@ class ServerModelManager:
|
||||
# NOTE: abort early if Saved Servers tab was not loaded yet
|
||||
config_man.remove_saved_server(fqip)
|
||||
if proxy_man.has_control_model() is False:
|
||||
self.thread_man.set_cleanup_func(StoredFunc(self._cleanup_when_no_model))
|
||||
self.thread_man.set_cleanup_func(
|
||||
StoredFunc(self._cleanup_when_no_model)
|
||||
)
|
||||
return
|
||||
proxy_man.remove_row_from_control(record)
|
||||
else:
|
||||
if config_man.is_in_favs(fqip):
|
||||
self.thread_man.set_cleanup_func(StoredFunc(self._cleanup_when_no_model))
|
||||
self.thread_man.set_cleanup_func(
|
||||
StoredFunc(self._cleanup_when_no_model)
|
||||
)
|
||||
return
|
||||
config_man.add_saved_server(fqip)
|
||||
if proxy_man.has_control_model() is False:
|
||||
self.thread_man.set_cleanup_func(StoredFunc(self._cleanup_when_no_model))
|
||||
self.thread_man.set_cleanup_func(
|
||||
StoredFunc(self._cleanup_when_no_model)
|
||||
)
|
||||
return
|
||||
proxy_man.append_row_to_control(record)
|
||||
|
||||
@ -377,16 +384,9 @@ class ServerModelManager:
|
||||
dialog = ExceptionDialog(self.controller, api_warn_msg)
|
||||
dialog.run()
|
||||
|
||||
def _push_data(self, data: list) -> None:
|
||||
# TODO: consolidate these methods
|
||||
manager = self._get_proxy_man()
|
||||
manager.wipe_cache()
|
||||
manager.set_control(data)
|
||||
manager.filter(FilterMode.INITIAL)
|
||||
|
||||
# TODO: abstract for all methods
|
||||
def _push_data(self, data: list[Any]) -> None:
|
||||
self._get_proxy_man().push(data)
|
||||
self._sort_unique_maps(data)
|
||||
|
||||
self.thread_man.set_cleanup_func(StoredFunc(self._cleanup_on_success))
|
||||
|
||||
def _sort_unique_maps(self, data: list) -> None:
|
||||
|
||||
@ -6,8 +6,8 @@ from typing import Any, Optional, Self
|
||||
from warnings import deprecated
|
||||
|
||||
from dzgui.views.mixins.context_mixin import ContextMixin
|
||||
from dzgui.const.enum import ContextMenu, ContextMenuGroup, ServerTab
|
||||
from dzgui.api.servers import Record
|
||||
from dzgui.const.enum import ContextMenu, ContextMenuGroup, Preferences, ServerTab
|
||||
from dzgui.api.servers import ping, Record
|
||||
from dzgui.managers.filter_man import FilterManager
|
||||
from dzgui.model.proxy_model import ProxyModelManager
|
||||
from dzgui.util.dist import CalcDist
|
||||
@ -96,21 +96,7 @@ class ServerTreeView(ContextMixin, TreeView):
|
||||
w = width_map[column_title]
|
||||
column.set_fixed_width(w)
|
||||
if column_title == "Ping":
|
||||
# self.fancy_col = column
|
||||
# self.fancy_rend = renderer
|
||||
column.set_cell_data_func(renderer, self._get_ping)
|
||||
# if column_title == "Name":
|
||||
# column.set_fixed_width(800)
|
||||
# if column_title == "Map":
|
||||
# column.set_fixed_width(300)
|
||||
|
||||
# TODO: standardize widths based on column title and longest content
|
||||
# if column_title == "Name":
|
||||
# column.set_fixed_width(500)
|
||||
# if column_title == "Map":
|
||||
# column.set_fixed_width(200)
|
||||
# if column_title == "IP":
|
||||
# column.set_fixed_width(240)
|
||||
|
||||
column.connect("notify::fixed-width", self._on_col_width_changed)
|
||||
self.append_column(column)
|
||||
@ -167,28 +153,6 @@ class ServerTreeView(ContextMixin, TreeView):
|
||||
def get_proxy_man(self) -> ProxyModelManager:
|
||||
return self.proxy_man
|
||||
|
||||
# def shrink_to_fit(self) -> None:
|
||||
# cols = self.get_columns()
|
||||
# # TODO: run on only one treeview and propagate results
|
||||
# # TODO: does not shrink name, map, ip fields to fit
|
||||
# # TODO: col width changed signal is buggy on current treeview
|
||||
# for col in cols:
|
||||
# title = col.get_title()
|
||||
# if title == "Name":
|
||||
# continue
|
||||
# if title == "Map":
|
||||
# continue
|
||||
# if title == "IP":
|
||||
# continue
|
||||
# label = Gtk.Label(label=title)
|
||||
# pango = label.get_layout()
|
||||
# size = pango.get_pixel_size()
|
||||
# if size.width > 50:
|
||||
# width = size.width * 1.30
|
||||
# else:
|
||||
# width = size.width * 1.65
|
||||
# col.set_fixed_width(width)
|
||||
|
||||
def get_enum(self) -> None:
|
||||
return self.enum
|
||||
|
||||
@ -306,8 +270,6 @@ class ServerTreeView(ContextMixin, TreeView):
|
||||
return sels[0]
|
||||
|
||||
def is_in_favs(self) -> bool:
|
||||
from dzgui.const.enum import Preferences
|
||||
|
||||
record = self.get_record_string()
|
||||
ips = self.controller.get_config_man().lookup(Preferences.IP_LIST)
|
||||
if record in ips:
|
||||
@ -353,6 +315,11 @@ class ServerTreeView(ContextMixin, TreeView):
|
||||
def set_loaded(self, status: bool) -> None:
|
||||
self.loaded = status
|
||||
|
||||
@staticmethod
|
||||
def ping_server(model, _iter: Gtk.TreeIter, ip: str, qport: int, ping_column: int):
|
||||
_ping = ping(ip, qport)
|
||||
GLib.idle_add(lambda: model.set(_iter, ping_column, _ping))
|
||||
|
||||
def _get_ping(
|
||||
self,
|
||||
column: Gtk.TreeViewColumn,
|
||||
@ -361,11 +328,6 @@ class ServerTreeView(ContextMixin, TreeView):
|
||||
_iter: Gtk.TreeIter,
|
||||
data: Any,
|
||||
):
|
||||
def ping_server(model, _iter: Gtk.TreeIter, ip: str, qport: int):
|
||||
from dzgui.api.servers import ping
|
||||
|
||||
_ping = ping(ip, qport)
|
||||
GLib.idle_add(lambda: model.set(_iter, ping_column, _ping))
|
||||
|
||||
addr_column = 7
|
||||
qport_column = 8
|
||||
@ -375,18 +337,16 @@ class ServerTreeView(ContextMixin, TreeView):
|
||||
ip = addr[0]
|
||||
gameport = addr[1]
|
||||
qport = model.get_value(_iter, qport_column)
|
||||
# ping = model.get_value(_iter, ping_column)
|
||||
record = f"{addr}:{gameport}:{qport}"
|
||||
|
||||
if record in self.seen_cache:
|
||||
return
|
||||
self.seen_cache.append(record)
|
||||
|
||||
# TODO: use thread manager
|
||||
thread = threading.Thread(
|
||||
daemon=True,
|
||||
target=ping_server,
|
||||
args=(model, _iter, ip, qport),
|
||||
target=self.ping_server,
|
||||
args=(model, _iter, ip, qport, ping_column),
|
||||
)
|
||||
thread.start()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user