mirror of
https://github.com/aclist/dztui.git
synced 2026-10-30 06:32:53 +01:00
chore: delegate config methods to ConfigManager
This commit is contained in:
1 parent
ed7f803d47
commit
f424b019ad
2 files changed
+110
-87
No files matched your search
+35
-85
@@ -155,8 +155,9 @@ class Controller(GObject.GObject):
|
|||||||
|
|
||||||
def query_config(self, key: Preferences) -> str | bool | list:
|
def query_config(self, key: Preferences) -> str | bool | list:
|
||||||
# return self.config_man.lookup(key)
|
# return self.config_man.lookup(key)
|
||||||
config = self.prefs.paths.config
|
return self.config_man.lookup(key)
|
||||||
return lookup(config, key)
|
# config = self.prefs.paths.config
|
||||||
|
# return lookup(config, key)
|
||||||
|
|
||||||
def is_auto_install(self) -> bool:
|
def is_auto_install(self) -> bool:
|
||||||
return self.query_config(Preferences.INSTALL)
|
return self.query_config(Preferences.INSTALL)
|
||||||
@@ -218,42 +219,8 @@ class Controller(GObject.GObject):
|
|||||||
# TODO: resolution manager or config manager
|
# TODO: resolution manager or config manager
|
||||||
def save_res_and_quit(self, *args: Any) -> None:
|
def save_res_and_quit(self, *args: Any) -> None:
|
||||||
treeview = self.get_active_treeview()
|
treeview = self.get_active_treeview()
|
||||||
columns = treeview.get_columns()
|
window = self.get_window()
|
||||||
|
self.config_man.save_res_and_quit(treeview, window)
|
||||||
# columns_file = self.config_man.get_columns()
|
|
||||||
columns_file = self.prefs.paths.columns
|
|
||||||
try:
|
|
||||||
data = JSON.read_json(columns_file)
|
|
||||||
except Exception as e:
|
|
||||||
logger.critical(e)
|
|
||||||
data = {"cols": {}}
|
|
||||||
|
|
||||||
for column in columns:
|
|
||||||
title = column.get_title()
|
|
||||||
size = column.get_width()
|
|
||||||
data["cols"][title] = size
|
|
||||||
|
|
||||||
try:
|
|
||||||
JSON.write_json(data, columns_file)
|
|
||||||
except Exception as e:
|
|
||||||
logger.critical(e)
|
|
||||||
|
|
||||||
logger.info("Normal user exit")
|
|
||||||
if self.mediator.window.props.is_maximized:
|
|
||||||
Gtk.main_quit()
|
|
||||||
return
|
|
||||||
|
|
||||||
w, h = self.mediator.window.get_size()
|
|
||||||
data = {"res": {"width": w, "height": h}}
|
|
||||||
|
|
||||||
# res_path = self.config_man.get_resolution()
|
|
||||||
res_path = self.prefs.paths.resolution
|
|
||||||
try:
|
|
||||||
write_json(data, res_path)
|
|
||||||
except Exception as e:
|
|
||||||
logger.critical(e)
|
|
||||||
|
|
||||||
Gtk.main_quit()
|
|
||||||
|
|
||||||
@deprecated("use statusbar internal contexts")
|
@deprecated("use statusbar internal contexts")
|
||||||
def remove_statusbar(self, context: str) -> None:
|
def remove_statusbar(self, context: str) -> None:
|
||||||
@@ -266,6 +233,7 @@ class Controller(GObject.GObject):
|
|||||||
msg_id = self.mediator.statusbar.set_text(text, context)
|
msg_id = self.mediator.statusbar.set_text(text, context)
|
||||||
return msg_id
|
return msg_id
|
||||||
|
|
||||||
|
# TODO: StatusBarManager
|
||||||
def set_statusbar_dist(self, haversine: "Haversine", enum: "ServerTab") -> None:
|
def set_statusbar_dist(self, haversine: "Haversine", enum: "ServerTab") -> None:
|
||||||
"""
|
"""
|
||||||
NOTE: prevents race condition when server tab changed,
|
NOTE: prevents race condition when server tab changed,
|
||||||
@@ -320,32 +288,34 @@ class Controller(GObject.GObject):
|
|||||||
|
|
||||||
self.cleanup_func = StoredFunc(self.load_mods_cleanup, model)
|
self.cleanup_func = StoredFunc(self.load_mods_cleanup, model)
|
||||||
|
|
||||||
def toggle_config(self, context: Preferences) -> None:
|
def toggle_config(self, key: Preferences) -> None:
|
||||||
config = self.prefs.paths.config
|
self.config_man.toggle_config(key)
|
||||||
try:
|
#config = self.prefs.paths.config
|
||||||
update.toggle_config(config, context)
|
#try:
|
||||||
# NOTE: 'use_miles' key is updated dynamically for statusbar unit
|
# update.toggle_config(config, context)
|
||||||
if context == Preferences.DIST:
|
# # NOTE: 'use_miles' key is updated dynamically for statusbar unit
|
||||||
self.prefs.use_miles = not self.prefs.use_miles
|
# if context == Preferences.DIST:
|
||||||
except Exception as e:
|
# self.prefs.use_miles = not self.prefs.use_miles
|
||||||
logger.critical(e)
|
#except Exception as e:
|
||||||
trace = traceback.format_exc()
|
# logger.critical(e)
|
||||||
dialog = ExceptionDialog(self, trace)
|
# trace = traceback.format_exc()
|
||||||
dialog.run()
|
# dialog = ExceptionDialog(self, trace)
|
||||||
|
# dialog.run()
|
||||||
|
|
||||||
def update_config(self, key: Preferences, value: str) -> None:
|
def update_config(self, key: Preferences, value: str) -> None:
|
||||||
try:
|
self.config_man.update_config(key, value)
|
||||||
update.write_config(self.prefs.paths.config, key, value)
|
#try:
|
||||||
except Exception as e:
|
# update.write_config(self.prefs.paths.config, key, value)
|
||||||
logger.critical(e)
|
#except Exception as e:
|
||||||
trace = traceback.format_exc()
|
# logger.critical(e)
|
||||||
dialog = ExceptionDialog(self, trace)
|
# trace = traceback.format_exc()
|
||||||
dialog.run()
|
# dialog = ExceptionDialog(self, trace)
|
||||||
# TODO: suppress signals
|
# dialog.run()
|
||||||
# then reenable (or it spawns dialog twice)
|
# # TODO: suppress signals
|
||||||
# TODO: do this on demand for certain changes
|
# # then reenable (or it spawns dialog twice)
|
||||||
self.mediator.grid.notebook.settings.populate_settings()
|
# # TODO: do this on demand for certain changes
|
||||||
return
|
# self.mediator.grid.notebook.settings.populate_settings()
|
||||||
|
# return
|
||||||
|
|
||||||
def open_keybindings(self) -> None:
|
def open_keybindings(self) -> None:
|
||||||
notebook = self.mediator.grid.notebook
|
notebook = self.mediator.grid.notebook
|
||||||
@@ -537,6 +507,7 @@ class Controller(GObject.GObject):
|
|||||||
dialog = ExceptionDialog(self, str(e))
|
dialog = ExceptionDialog(self, str(e))
|
||||||
dialog.run()
|
dialog.run()
|
||||||
|
|
||||||
|
# TODO: move to ConfigMan
|
||||||
@call_on_thread(strings.dialog.working)
|
@call_on_thread(strings.dialog.working)
|
||||||
def update_api_key(self, text: str, key: Preferences) -> None:
|
def update_api_key(self, text: str, key: Preferences) -> None:
|
||||||
if key is Preferences.STEAM:
|
if key is Preferences.STEAM:
|
||||||
@@ -552,29 +523,7 @@ class Controller(GObject.GObject):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def set_resolution(self, window: "OuterWindow") -> None:
|
def set_resolution(self, window: "OuterWindow") -> None:
|
||||||
if self.prefs.is_game_mode:
|
self.config_man.set_resolution(window)
|
||||||
window.fullscreen()
|
|
||||||
return
|
|
||||||
elif self.query_config(Preferences.WINDOW) is True:
|
|
||||||
window.fullscreen()
|
|
||||||
|
|
||||||
try:
|
|
||||||
data = read_json(self.prefs.paths.resolution)
|
|
||||||
valid_json = True
|
|
||||||
except Exception as e:
|
|
||||||
valid_json = False
|
|
||||||
logger.critical(e)
|
|
||||||
|
|
||||||
if valid_json:
|
|
||||||
res = data["res"]
|
|
||||||
w, h = res["width"], res["height"]
|
|
||||||
logger.info(f"Restoring window size to {w},{h}")
|
|
||||||
window.set_default_size(w, h)
|
|
||||||
else:
|
|
||||||
w = WINDOW_DEFAULT_X
|
|
||||||
h = WINDOW_DEFAULT_Y
|
|
||||||
logger.info(f"Using default window size {w},{h}")
|
|
||||||
window.set_default_size(w, h)
|
|
||||||
|
|
||||||
def propagate_column_width(self, col: Gtk.TreeViewColumn) -> None:
|
def propagate_column_width(self, col: Gtk.TreeViewColumn) -> None:
|
||||||
GLib.idle_add(self.mediator.servers.update_tab_widths, col)
|
GLib.idle_add(self.mediator.servers.update_tab_widths, col)
|
||||||
@@ -584,6 +533,7 @@ class Controller(GObject.GObject):
|
|||||||
treeview.set_loaded(False)
|
treeview.set_loaded(False)
|
||||||
ServerModelManager(self, treeview).refresh()
|
ServerModelManager(self, treeview).refresh()
|
||||||
|
|
||||||
|
# TODO: move to servermodelman
|
||||||
def get_player_count(self) -> str:
|
def get_player_count(self) -> str:
|
||||||
treeview = self.get_active_treeview()
|
treeview = self.get_active_treeview()
|
||||||
model = treeview.get_model()
|
model = treeview.get_model()
|
||||||
|
|||||||
@@ -3,20 +3,34 @@ import traceback
|
|||||||
|
|
||||||
from typing import Any, TYPE_CHECKING
|
from typing import Any, TYPE_CHECKING
|
||||||
|
|
||||||
from dzgui.const.constants import STEAM_CMD, FLATPAK_RUN_CMD, FLATPAK_SANDBOX
|
from dzgui.const.constants import (
|
||||||
|
STEAM_CMD,
|
||||||
|
FLATPAK_RUN_CMD,
|
||||||
|
FLATPAK_SANDBOX,
|
||||||
|
WINDOW_DEFAULT_X,
|
||||||
|
WINDOW_DEFAULT_Y,
|
||||||
|
)
|
||||||
from dzgui.const.enum import Preferences
|
from dzgui.const.enum import Preferences
|
||||||
from dzgui.views.dialogs.generic import ExceptionDialog
|
from dzgui.views.dialogs.generic import ExceptionDialog
|
||||||
from dzgui.util._json import read_json, write_json
|
from dzgui.util._json import read_json, write_json
|
||||||
|
|
||||||
|
import gi
|
||||||
|
|
||||||
|
gi.require_version("Gtk", "3.0")
|
||||||
|
from gi.repository.Gtk import main_quit # noqa E402
|
||||||
|
|
||||||
# import dzgui.api.servers as Servers
|
# import dzgui.api.servers as Servers
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from dzgui.config.userprefs import UserPrefs
|
from dzgui.config.userprefs import UserPrefs
|
||||||
|
from dzgui.views.base import OuterWindow
|
||||||
|
from dzgui.views.trees.tree_servers import ServerTreeView
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ConfigManager:
|
class ConfigManager:
|
||||||
def __init__(self, prefs: "UserPrefs") -> None:
|
def __init__(self, prefs: "UserPrefs") -> None:
|
||||||
|
self.prefs = prefs
|
||||||
self.config = prefs.paths.config
|
self.config = prefs.paths.config
|
||||||
|
|
||||||
def lookup(self, enum: Preferences) -> Any:
|
def lookup(self, enum: Preferences) -> Any:
|
||||||
@@ -41,7 +55,6 @@ class ConfigManager:
|
|||||||
# then reenable (or it spawns dialog twice)
|
# then reenable (or it spawns dialog twice)
|
||||||
# TODO: do this on demand if/when in options page
|
# TODO: do this on demand if/when in options page
|
||||||
# self.mediator.grid.notebook.settings.populate_settings()
|
# self.mediator.grid.notebook.settings.populate_settings()
|
||||||
return
|
|
||||||
|
|
||||||
def get_config(self) -> dict:
|
def get_config(self) -> dict:
|
||||||
# TODO: is this being called twice?
|
# TODO: is this being called twice?
|
||||||
@@ -102,3 +115,63 @@ class ConfigManager:
|
|||||||
dialog = ExceptionDialog(self, trace)
|
dialog = ExceptionDialog(self, trace)
|
||||||
dialog.run()
|
dialog.run()
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
def save_res_and_quit(self, tv: "ServerTreeView", window: "OuterWindow") -> None:
|
||||||
|
columns = tv.get_columns()
|
||||||
|
columns_file = self.prefs.paths.columns
|
||||||
|
try:
|
||||||
|
data = read_json(columns_file)
|
||||||
|
except Exception as e:
|
||||||
|
logger.critical(e)
|
||||||
|
data = {"cols": {}}
|
||||||
|
|
||||||
|
for column in columns:
|
||||||
|
title = column.get_title()
|
||||||
|
size = column.get_width()
|
||||||
|
data["cols"][title] = size
|
||||||
|
|
||||||
|
try:
|
||||||
|
write_json(data, columns_file)
|
||||||
|
except Exception as e:
|
||||||
|
logger.critical(e)
|
||||||
|
|
||||||
|
logger.info("Normal user exit")
|
||||||
|
if window.props.is_maximized:
|
||||||
|
main_quit()
|
||||||
|
return
|
||||||
|
|
||||||
|
w, h = window.get_size()
|
||||||
|
data = {"res": {"width": w, "height": h}}
|
||||||
|
|
||||||
|
res_path = self.prefs.paths.resolution
|
||||||
|
try:
|
||||||
|
write_json(data, res_path)
|
||||||
|
except Exception as e:
|
||||||
|
logger.critical(e)
|
||||||
|
|
||||||
|
main_quit()
|
||||||
|
|
||||||
|
def set_resolution(self, window: "OuterWindow") -> None:
|
||||||
|
if self.prefs.is_game_mode:
|
||||||
|
window.fullscreen()
|
||||||
|
return
|
||||||
|
elif self.lookup(Preferences.WINDOW) is True:
|
||||||
|
window.fullscreen()
|
||||||
|
|
||||||
|
try:
|
||||||
|
data = read_json(self.prefs.paths.resolution)
|
||||||
|
valid_json = True
|
||||||
|
except Exception as e:
|
||||||
|
valid_json = False
|
||||||
|
logger.critical(e)
|
||||||
|
|
||||||
|
if valid_json:
|
||||||
|
res = data["res"]
|
||||||
|
w, h = res["width"], res["height"]
|
||||||
|
logger.info(f"Restoring window size to {w},{h}")
|
||||||
|
window.set_default_size(w, h)
|
||||||
|
else:
|
||||||
|
w = WINDOW_DEFAULT_X
|
||||||
|
h = WINDOW_DEFAULT_Y
|
||||||
|
logger.info(f"Using default window size {w},{h}")
|
||||||
|
window.set_default_size(w, h)
|
||||||
Reference in new issue
Block a user