mirror of
https://github.com/aclist/dztui.git
synced 2026-11-01 07:32:44 +01:00
chore: consolidate filter enums
This commit is contained in:
1 parent
4bccaec427
commit
7b8388376c
6 files changed
+15
-23
No files matched your search
+3
-5
@@ -41,11 +41,9 @@ class CursorPosition(Enum):
|
|||||||
|
|
||||||
|
|
||||||
class FilterMode(Enum):
|
class FilterMode(Enum):
|
||||||
KEYWORD = 1
|
INITIAL = 1
|
||||||
MAP = 2
|
TOGGLE_OFF = 2
|
||||||
INITIAL = 3
|
TOGGLE_ON = 3
|
||||||
TOGGLE_OFF = 4
|
|
||||||
TOGGLE_ON = 5
|
|
||||||
|
|
||||||
|
|
||||||
class EnumWithAttrs(Enum):
|
class EnumWithAttrs(Enum):
|
||||||
|
|||||||
@@ -553,7 +553,7 @@ class Controller(GObject.GObject):
|
|||||||
|
|
||||||
def _on_map_selection_changed(self, emitter: Emitter, selection: str) -> None:
|
def _on_map_selection_changed(self, emitter: Emitter, selection: str) -> None:
|
||||||
smm = ServerModelManager(self, self.get_active_treeview())
|
smm = ServerModelManager(self, self.get_active_treeview())
|
||||||
smm.refilter(FilterMode.MAP)
|
smm.refilter(FilterMode.TOGGLE_ON)
|
||||||
|
|
||||||
def get_notebook(self) -> "Notebook":
|
def get_notebook(self) -> "Notebook":
|
||||||
return self.mediator.notebook
|
return self.mediator.notebook
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ class ConfigManager:
|
|||||||
self.config = prefs.paths.config
|
self.config = prefs.paths.config
|
||||||
|
|
||||||
def lookup(self, enum: Preferences) -> Any:
|
def lookup(self, enum: Preferences) -> Any:
|
||||||
# if path.is_file() is False:
|
|
||||||
# raise ConfigFileError("Not a valid file")
|
|
||||||
key = self.enum_to_key(enum)
|
key = self.enum_to_key(enum)
|
||||||
config = self.get_config()
|
config = self.get_config()
|
||||||
try:
|
try:
|
||||||
@@ -48,9 +46,11 @@ class ConfigManager:
|
|||||||
ips.append(record)
|
ips.append(record)
|
||||||
self.update_config(Preferences.IP_LIST, ips)
|
self.update_config(Preferences.IP_LIST, ips)
|
||||||
|
|
||||||
def remove_history_server(self, record: str) -> None:
|
def update_history_file(self, records: list[Any]) -> None:
|
||||||
print(record)
|
with open(self.prefs.paths.history, "w") as f:
|
||||||
pass
|
for record in records:
|
||||||
|
addr = f"{record[7]}:{record[8]}"
|
||||||
|
f.write(f"{addr}\n")
|
||||||
|
|
||||||
def remove_saved_server(self, record: str) -> None:
|
def remove_saved_server(self, record: str) -> None:
|
||||||
ips = self.lookup(Preferences.IP_LIST)
|
ips = self.lookup(Preferences.IP_LIST)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from dzgui.util import strings
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from dzgui.managers.filter_man import FilterManager
|
from dzgui.managers.filter_man import FilterManager
|
||||||
from dzgui.model.model_factory import FastInsertListStore
|
from dzgui.model.model_factory import FastInsertListStore
|
||||||
|
from dzgui.api.servers import Record
|
||||||
from dzgui.model.servers import NewPlayerCount
|
from dzgui.model.servers import NewPlayerCount
|
||||||
|
|
||||||
|
|
||||||
@@ -68,7 +69,6 @@ class ProxyModelManager:
|
|||||||
|
|
||||||
# TODO: consolidate with remove_row_from_control()
|
# TODO: consolidate with remove_row_from_control()
|
||||||
def remove_from_history(self, record: "Record") -> None:
|
def remove_from_history(self, record: "Record") -> None:
|
||||||
print(record)
|
|
||||||
addr = f"{record.ip}:{record.gameport}"
|
addr = f"{record.ip}:{record.gameport}"
|
||||||
qport = record.qport
|
qport = record.qport
|
||||||
for record in self.control_model:
|
for record in self.control_model:
|
||||||
@@ -85,7 +85,6 @@ class ProxyModelManager:
|
|||||||
return self.proxy_model
|
return self.proxy_model
|
||||||
|
|
||||||
def filter(self, mode: FilterMode, skip_cache: bool = False) -> None:
|
def filter(self, mode: FilterMode, skip_cache: bool = False) -> None:
|
||||||
# TODO: proxy model can fetch args directly from filter man, no need to process extra input
|
|
||||||
"""
|
"""
|
||||||
Native Gtk.TreeView.refilter() method was not performant enough
|
Native Gtk.TreeView.refilter() method was not performant enough
|
||||||
when running in the main loop with 40k+ records
|
when running in the main loop with 40k+ records
|
||||||
@@ -109,7 +108,7 @@ class ProxyModelManager:
|
|||||||
rows = self.filter_initial(filters)
|
rows = self.filter_initial(filters)
|
||||||
|
|
||||||
# TODO: consolidate into one enum
|
# TODO: consolidate into one enum
|
||||||
case FilterMode.MAP | FilterMode.KEYWORD | FilterMode.TOGGLE_ON:
|
case FilterMode.TOGGLE_ON:
|
||||||
rows = self.filter_toggle_on(filters)
|
rows = self.filter_toggle_on(filters)
|
||||||
|
|
||||||
case FilterMode.TOGGLE_OFF:
|
case FilterMode.TOGGLE_OFF:
|
||||||
|
|||||||
@@ -213,18 +213,13 @@ class ServerModelManager:
|
|||||||
|
|
||||||
def remove_from_history(self, record: Servers.Record) -> None:
|
def remove_from_history(self, record: Servers.Record) -> None:
|
||||||
"""Fully unthreaded, just removes a row"""
|
"""Fully unthreaded, just removes a row"""
|
||||||
port = record.ip
|
|
||||||
gport = record.gameport
|
|
||||||
qport = record.qport
|
|
||||||
|
|
||||||
fqip = f"{port}:{gport}:{qport}"
|
|
||||||
config_man = self.controller.get_config_man()
|
|
||||||
config_man.remove_history_server(fqip)
|
|
||||||
|
|
||||||
proxy_man = self._get_proxy_man()
|
proxy_man = self._get_proxy_man()
|
||||||
proxy_man.remove_from_history(record)
|
proxy_man.remove_from_history(record)
|
||||||
control_model = proxy_man.get_control()
|
control_model = proxy_man.get_control()
|
||||||
|
|
||||||
|
config_man = self.controller.get_config_man()
|
||||||
|
config_man.update_history_file(control_model)
|
||||||
|
|
||||||
self._sort_unique_maps(control_model)
|
self._sort_unique_maps(control_model)
|
||||||
proxy = proxy_man.get_proxy_model()
|
proxy = proxy_man.get_proxy_model()
|
||||||
self.tv.set_model(proxy)
|
self.tv.set_model(proxy)
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ class KeywordEntry(Gtk.Entry):
|
|||||||
|
|
||||||
ServerModelManager(
|
ServerModelManager(
|
||||||
self.controller, self.controller.get_active_treeview()
|
self.controller, self.controller.get_active_treeview()
|
||||||
).refilter(FilterMode.KEYWORD)
|
).refilter(FilterMode.TOGGLE_ON)
|
||||||
|
|
||||||
|
|
||||||
class FilterPanel(Gtk.Box):
|
class FilterPanel(Gtk.Box):
|
||||||
|
|||||||
Reference in new issue
Block a user