config: deprecate get_main_config_option

This commit is contained in:
alfrix 2022-06-27 11:17:04 -03:00 committed by Alfredo Monclus
parent 88ea416110
commit a445b89f13
7 changed files with 16 additions and 19 deletions

View File

@ -92,7 +92,7 @@ class KlipperScreenConfig:
item[name]['moonraker_api_key'] = "redacted" item[name]['moonraker_api_key'] = "redacted"
logging.debug("Configured printers: %s" % json.dumps(conf_printers_debug, indent=2)) logging.debug("Configured printers: %s" % json.dumps(conf_printers_debug, indent=2))
lang = self.get_main_config_option("language", None) lang = self.get_main_config().get("language", None)
lang = [lang] if lang is not None and lang != "default" else None lang = [lang] if lang is not None and lang != "default" else None
logging.info("Detected language: %s" % lang) logging.info("Detected language: %s" % lang)
self.lang = gettext.translation('KlipperScreen', localedir='ks_includes/locales', languages=lang, self.lang = gettext.translation('KlipperScreen', localedir='ks_includes/locales', languages=lang,
@ -292,9 +292,6 @@ class KlipperScreenConfig:
def get_main_config(self): def get_main_config(self):
return self.config['main'] return self.config['main']
def get_main_config_option(self, option, default=None):
return self.config['main'].get(option, default)
def get_menu_items(self, menu="__main", subsection=""): def get_menu_items(self, menu="__main", subsection=""):
if subsection != "": if subsection != "":
subsection = subsection + " " subsection = subsection + " "

View File

@ -37,7 +37,7 @@ class ScreenPanel:
def emergency_stop(self, widget): def emergency_stop(self, widget):
_ = self.lang.gettext _ = self.lang.gettext
if self._config.get_main_config_option('confirm_estop') == "True": if self._config.get_main_config().getboolean('confirm_estop'):
self._screen._confirm_send_action(widget, _("Are you sure you want to run Emergency Stop?"), self._screen._confirm_send_action(widget, _("Are you sure you want to run Emergency Stop?"),
"printer.emergency_stop") "printer.emergency_stop")
else: else:

View File

@ -15,7 +15,7 @@ class BasePanel(ScreenPanel):
super().__init__(screen, title, back, action_bar, printer_name) super().__init__(screen, title, back, action_bar, printer_name)
self.current_panel = None self.current_panel = None
self.time_min = -1 self.time_min = -1
self.time_format = self._config.get_main_config_option("24htime") self.time_format = self._config.get_main_config().getboolean("24htime", True)
self.time_update = None self.time_update = None
self.titlebar_name_type = None self.titlebar_name_type = None
self.buttons_showing = { self.buttons_showing = {
@ -298,9 +298,9 @@ class BasePanel(ScreenPanel):
def update_time(self): def update_time(self):
now = datetime.datetime.now() now = datetime.datetime.now()
confopt = self._config.get_main_config_option("24htime") confopt = self._config.get_main_config().getboolean("24htime", True)
if now.minute != self.time_min or self.time_format != confopt: if now.minute != self.time_min or self.time_format != confopt:
if confopt == "True": if confopt:
self.control['time'].set_text(now.strftime("%H:%M")) self.control['time'].set_text(now.strftime("%H:%M"))
else: else:
self.control['time'].set_text(now.strftime("%I:%M %p")) self.control['time'].set_text(now.strftime("%I:%M %p"))

View File

@ -108,7 +108,7 @@ class MainPanel(MenuPanel):
image = "fan" image = "fan"
class_name = "graph_label_fan_%s" % f class_name = "graph_label_fan_%s" % f
type = "fan" type = "fan"
elif self._config.get_main_config_option('only_heaters') == "True": elif self._config.get_main_config().getboolean("only_heaters", False):
return False return False
else: else:
s = 1 s = 1

View File

@ -29,7 +29,7 @@ class PrintPanel(ScreenPanel):
} }
self.sort_icon = ["arrow-up", "arrow-down"] self.sort_icon = ["arrow-up", "arrow-down"]
sortdir = self._config.get_main_config_option("print_sort_dir", "name_asc") sortdir = self._config.get_main_config().get("print_sort_dir", "name_asc")
sortdir = sortdir.split('_') sortdir = sortdir.split('_')
if sortdir[0] not in ["name", "date"] or sortdir[1] not in ["asc", "desc"]: if sortdir[0] not in ["name", "date"] or sortdir[1] not in ["asc", "desc"]:
sortdir = ["name", "asc"] sortdir = ["name", "asc"]

View File

@ -313,7 +313,7 @@ class TemperaturePanel(ScreenPanel):
image = "fan" image = "fan"
class_name = "graph_label_fan_%s" % f class_name = "graph_label_fan_%s" % f
type = "fan" type = "fan"
elif self._config.get_main_config_option('only_heaters') == "True": elif self._config.get_main_config().getboolean("only_heaters", False):
return False return False
else: else:
s = 1 s = 1

View File

@ -117,10 +117,10 @@ class KlipperScreen(Gtk.Window):
else: else:
self.vertical_mode = False self.vertical_mode = False
logging.info("Screen resolution: %sx%s" % (self.width, self.height)) logging.info("Screen resolution: %sx%s" % (self.width, self.height))
self.theme = self._config.get_main_config_option('theme') self.theme = self._config.get_main_config().get('theme')
self.show_cursor = self._config.get_main_config().getboolean("show_cursor", fallback=False) self.show_cursor = self._config.get_main_config().getboolean("show_cursor", fallback=False)
self.gtk = KlippyGtk(self, self.width, self.height, self.theme, self.show_cursor, self.gtk = KlippyGtk(self, self.width, self.height, self.theme, self.show_cursor,
self._config.get_main_config_option("font_size", "medium")) self._config.get_main_config().get("font_size", "medium"))
self.init_style() self.init_style()
self.base_panel = BasePanel(self, title="Base Panel", back=False) self.base_panel = BasePanel(self, title="Base Panel", back=False)
@ -130,7 +130,7 @@ class KlipperScreen(Gtk.Window):
self.printer_initializing(_("Initializing")) self.printer_initializing(_("Initializing"))
self.set_screenblanking_timeout(self._config.get_main_config_option('screen_blanking')) self.set_screenblanking_timeout(self._config.get_main_config().get('screen_blanking'))
# Move mouse to 0,0 # Move mouse to 0,0
os.system("/usr/bin/xdotool mousemove 0 0") os.system("/usr/bin/xdotool mousemove 0 0")
@ -166,7 +166,7 @@ class KlipperScreen(Gtk.Window):
if self.printer.get_state() not in ["disconnected", "error", "startup", "shutdown"]: if self.printer.get_state() not in ["disconnected", "error", "startup", "shutdown"]:
self.base_panel.show_heaters(True) self.base_panel.show_heaters(True)
self.base_panel.show_printer_select(True) self.base_panel.show_printer_select(True)
self.base_panel.show_macro_shortcut(self._config.get_main_config_option('side_macro_shortcut')) self.base_panel.show_macro_shortcut(self._config.get_main_config().get('side_macro_shortcut'))
return return
# Cleanup # Cleanup
@ -439,7 +439,7 @@ class KlipperScreen(Gtk.Window):
def restart_ks(self, widget, response_id): def restart_ks(self, widget, response_id):
if response_id == Gtk.ResponseType.OK: if response_id == Gtk.ResponseType.OK:
logging.debug("Restarting") logging.debug("Restarting")
os.system("sudo systemctl restart %s" % self._config.get_main_config_option('service')) os.system("sudo systemctl restart %s" % self._config.get_main_config().get('service'))
widget.destroy() widget.destroy()
def init_style(self): def init_style(self):
@ -636,7 +636,7 @@ class KlipperScreen(Gtk.Window):
def wake_screen(self): def wake_screen(self):
# Wake the screen (it will go to standby as configured) # Wake the screen (it will go to standby as configured)
if self._config.get_main_config_option('screen_blanking') != "off": if self._config.get_main_config().get('screen_blanking') != "off":
logging.debug("Screen wake up") logging.debug("Screen wake up")
os.system("xset -display :0 dpms force on") os.system("xset -display :0 dpms force on")
self.close_screensaver() self.close_screensaver()
@ -644,7 +644,7 @@ class KlipperScreen(Gtk.Window):
def set_dpms(self, use_dpms): def set_dpms(self, use_dpms):
self.use_dpms = use_dpms self.use_dpms = use_dpms
logging.info("DPMS set to: %s" % self.use_dpms) logging.info("DPMS set to: %s" % self.use_dpms)
self.set_screenblanking_timeout(self._config.get_main_config_option('screen_blanking')) self.set_screenblanking_timeout(self._config.get_main_config().get('screen_blanking'))
def set_screenblanking_timeout(self, time): def set_screenblanking_timeout(self, time):
os.system("xset -display :0 s noblank") os.system("xset -display :0 s noblank")
@ -773,7 +773,7 @@ class KlipperScreen(Gtk.Window):
if "job_status" in self._cur_panels or "main_menu" in self._cur_panels: if "job_status" in self._cur_panels or "main_menu" in self._cur_panels:
return return
self.base_panel.show_macro_shortcut(self._config.get_main_config_option('side_macro_shortcut')) self.base_panel.show_macro_shortcut(self._config.get_main_config().get('side_macro_shortcut'))
if prev_state not in ['paused', 'printing']: if prev_state not in ['paused', 'printing']:
self.init_printer() self.init_printer()
self.base_panel._printer = self.printer self.base_panel._printer = self.printer