create ks_printer_cfg

This commit is contained in:
alfrix 2022-11-16 10:38:17 -03:00
parent e4ff009ef6
commit 022954918c
3 changed files with 24 additions and 22 deletions

View File

@ -19,6 +19,7 @@ class ScreenPanel:
self.title = title self.title = title
self.devices = {} self.devices = {}
self.active_heaters = [] self.active_heaters = []
self.ks_printer_cfg = None
self.layout = Gtk.Layout() self.layout = Gtk.Layout()
self.layout.set_size(self._screen.width, self._screen.height) self.layout.set_size(self._screen.width, self._screen.height)

View File

@ -19,6 +19,7 @@ class BasePanel(ScreenPanel):
self.time_min = -1 self.time_min = -1
self.time_format = self._config.get_main_config().getboolean("24htime", True) self.time_format = self._config.get_main_config().getboolean("24htime", True)
self.time_update = None self.time_update = None
self.titlebar_items = []
self.titlebar_name_type = None self.titlebar_name_type = None
self.buttons_showing = { self.buttons_showing = {
'back': not back, 'back': not back,
@ -123,13 +124,6 @@ class BasePanel(ScreenPanel):
if not show or self._screen.printer.get_temp_store_devices() is None: if not show or self._screen.printer.get_temp_store_devices() is None:
return return
printer_cfg = self._config.get_printer_config(self._screen.connected_printer)
if printer_cfg is not None:
self.titlebar_name_type = printer_cfg.get("titlebar_name_type", None)
else:
self.titlebar_name_type = None
logging.info(f"Titlebar name type: {self.titlebar_name_type}")
img_size = self._gtk.img_scale * .5 img_size = self._gtk.img_scale * .5
for device in self._screen.printer.get_temp_store_devices(): for device in self._screen.printer.get_temp_store_devices():
self.labels[device] = Gtk.Label(label="100º") self.labels[device] = Gtk.Label(label="100º")
@ -156,21 +150,16 @@ class BasePanel(ScreenPanel):
n += 1 n += 1
# Options in the config have priority # Options in the config have priority
if printer_cfg is not None: for device in self._screen.printer.get_temp_store_devices():
titlebar_items = printer_cfg.get("titlebar_items", None) # Users can fill the bar if they want
if titlebar_items is not None: if n >= nlimit + 1:
titlebar_items = [str(i.strip()) for i in titlebar_items.split(',')] break
logging.info(f"Titlebar items: {titlebar_items}") name = device.split()[1] if len(device.split()) > 1 else device
for device in self._screen.printer.get_temp_store_devices(): for item in self.titlebar_items:
# Users can fill the bar if they want if name == item:
if n >= nlimit + 1: self.control['temp_box'].add(self.labels[f"{device}_box"])
break n += 1
name = device.split()[1] if len(device.split()) > 1 else device break
for item in titlebar_items:
if name == item:
self.control['temp_box'].add(self.labels[f"{device}_box"])
n += 1
break
# If there is enough space fill with heater_generic # If there is enough space fill with heater_generic
for device in self._screen.printer.get_temp_store_devices(): for device in self._screen.printer.get_temp_store_devices():
@ -321,3 +310,14 @@ class BasePanel(ScreenPanel):
elif show is False and self.buttons_showing['estop']: elif show is False and self.buttons_showing['estop']:
self.control['estop'].set_sensitive(False) self.control['estop'].set_sensitive(False)
self.buttons_showing['estop'] = False self.buttons_showing['estop'] = False
def set_ks_printer_cfg(self, printer):
self.ks_printer_cfg = self._config.get_printer_config(printer)
if self.ks_printer_cfg is not None:
self.titlebar_name_type = self.ks_printer_cfg.get("titlebar_name_type", None)
titlebar_items = self.ks_printer_cfg.get("titlebar_items", None)
if titlebar_items is not None:
self.titlebar_items = [str(i.strip()) for i in titlebar_items.split(',')]
logging.info(f"Titlebar name type: {self.titlebar_name_type} items: {self.titlebar_items}")
else:
self.titlebar_items = []

View File

@ -253,6 +253,7 @@ class KlipperScreen(Gtk.Window):
self.connecting = False self.connecting = False
self.connected_printer = name self.connected_printer = name
self.base_panel.set_ks_printer_cfg(name)
logging.debug(f"Connected to printer: {name}") logging.debug(f"Connected to printer: {name}")
def ws_subscribe(self): def ws_subscribe(self):