base_panel improvements
* generalize macro shortcut to allow changing it in the future * action_bar functionality is now handled in one place for better maintainability
This commit is contained in:
parent
aa25a96f2b
commit
bd98e758ec
@ -259,7 +259,7 @@ class KlipperScreenConfig:
|
|||||||
{"24htime": {"section": "main", "name": _("24 Hour Time"), "type": "binary", "value": "True"}},
|
{"24htime": {"section": "main", "name": _("24 Hour Time"), "type": "binary", "value": "True"}},
|
||||||
{"side_macro_shortcut": {
|
{"side_macro_shortcut": {
|
||||||
"section": "main", "name": _("Macro shortcut on sidebar"), "type": "binary",
|
"section": "main", "name": _("Macro shortcut on sidebar"), "type": "binary",
|
||||||
"value": "True", "callback": screen.toggle_macro_shortcut}},
|
"value": "True", "callback": screen.toggle_shortcut}},
|
||||||
{"font_size": {
|
{"font_size": {
|
||||||
"section": "main", "name": _("Font Size"), "type": "dropdown",
|
"section": "main", "name": _("Font Size"), "type": "dropdown",
|
||||||
"value": "medium", "callback": screen.restart_ks, "options": [
|
"value": "medium", "callback": screen.restart_ks, "options": [
|
||||||
|
@ -21,10 +21,6 @@ class BasePanel(ScreenPanel):
|
|||||||
self.time_update = None
|
self.time_update = None
|
||||||
self.titlebar_items = []
|
self.titlebar_items = []
|
||||||
self.titlebar_name_type = None
|
self.titlebar_name_type = None
|
||||||
self.buttons_showing = {
|
|
||||||
'macros_shortcut': False,
|
|
||||||
'printer_select': len(self._config.get_printers()) > 1,
|
|
||||||
}
|
|
||||||
self.current_extruder = None
|
self.current_extruder = None
|
||||||
# Action bar buttons
|
# Action bar buttons
|
||||||
abscale = self.bts * 1.1
|
abscale = self.bts * 1.1
|
||||||
@ -32,19 +28,22 @@ class BasePanel(ScreenPanel):
|
|||||||
self.control['back'].connect("clicked", self.back)
|
self.control['back'].connect("clicked", self.back)
|
||||||
self.control['home'] = self._gtk.Button('main', scale=abscale)
|
self.control['home'] = self._gtk.Button('main', scale=abscale)
|
||||||
self.control['home'].connect("clicked", self._screen._menu_go_back, True)
|
self.control['home'].connect("clicked", self._screen._menu_go_back, True)
|
||||||
|
|
||||||
if len(self._config.get_printers()) > 1:
|
|
||||||
self.control['printer_select'] = self._gtk.Button('shuffle', scale=abscale)
|
|
||||||
self.control['printer_select'].connect("clicked", self._screen.show_printer_select)
|
|
||||||
|
|
||||||
self.control['macros_shortcut'] = self._gtk.Button('custom-script', scale=abscale)
|
|
||||||
self.control['macros_shortcut'].connect("clicked", self.menu_item_clicked, {
|
|
||||||
"name": "Macros",
|
|
||||||
"panel": "gcode_macros"
|
|
||||||
})
|
|
||||||
|
|
||||||
self.control['estop'] = self._gtk.Button('emergency', scale=abscale)
|
self.control['estop'] = self._gtk.Button('emergency', scale=abscale)
|
||||||
self.control['estop'].connect("clicked", self.emergency_stop)
|
self.control['estop'].connect("clicked", self.emergency_stop)
|
||||||
|
for control in self.control:
|
||||||
|
self.set_control_sensitive(False, control)
|
||||||
|
self.control['printer_select'] = self._gtk.Button('shuffle', scale=abscale)
|
||||||
|
self.control['printer_select'].connect("clicked", self._screen.show_printer_select)
|
||||||
|
self.control['printer_select'].set_no_show_all(True)
|
||||||
|
|
||||||
|
self.shorcut = {
|
||||||
|
"name": "Macros",
|
||||||
|
"panel": "gcode_macros",
|
||||||
|
"icon": "custom-script",
|
||||||
|
}
|
||||||
|
self.control['shortcut'] = self._gtk.Button(self.shorcut['icon'], scale=abscale)
|
||||||
|
self.control['shortcut'].connect("clicked", self.menu_item_clicked, self.shorcut)
|
||||||
|
self.control['shortcut'].set_no_show_all(True)
|
||||||
|
|
||||||
# Any action bar button should close the keyboard
|
# Any action bar button should close the keyboard
|
||||||
for item in self.control:
|
for item in self.control:
|
||||||
@ -62,13 +61,10 @@ class BasePanel(ScreenPanel):
|
|||||||
self.action_bar.set_size_request(self._gtk.action_bar_width, self._gtk.action_bar_height)
|
self.action_bar.set_size_request(self._gtk.action_bar_width, self._gtk.action_bar_height)
|
||||||
self.action_bar.add(self.control['back'])
|
self.action_bar.add(self.control['back'])
|
||||||
self.action_bar.add(self.control['home'])
|
self.action_bar.add(self.control['home'])
|
||||||
self.show_back(False)
|
self.action_bar.add(self.control['printer_select'])
|
||||||
self.show_home(False)
|
self.action_bar.add(self.control['shortcut'])
|
||||||
if self.buttons_showing['printer_select']:
|
|
||||||
self.action_bar.add(self.control['printer_select'])
|
|
||||||
self.show_macro_shortcut(self._config.get_main_config().getboolean('side_macro_shortcut', True))
|
|
||||||
self.action_bar.add(self.control['estop'])
|
self.action_bar.add(self.control['estop'])
|
||||||
self.show_estop(False)
|
self.show_printer_select(len(self._config.get_printers()) > 1)
|
||||||
|
|
||||||
# Titlebar
|
# Titlebar
|
||||||
|
|
||||||
@ -113,11 +109,12 @@ class BasePanel(ScreenPanel):
|
|||||||
try:
|
try:
|
||||||
for child in self.control['temp_box'].get_children():
|
for child in self.control['temp_box'].get_children():
|
||||||
self.control['temp_box'].remove(child)
|
self.control['temp_box'].remove(child)
|
||||||
if not show or self._printer.get_temp_store_devices() is None:
|
devices = (self._printer.get_tools() + self._printer.get_heaters())
|
||||||
|
if not show or not devices:
|
||||||
return
|
return
|
||||||
|
|
||||||
img_size = self._gtk.img_scale * self.bts
|
img_size = self._gtk.img_scale * self.bts
|
||||||
for device in self._printer.get_temp_store_devices():
|
for device in devices:
|
||||||
self.labels[device] = Gtk.Label()
|
self.labels[device] = Gtk.Label()
|
||||||
self.labels[device].set_ellipsize(Pango.EllipsizeMode.START)
|
self.labels[device].set_ellipsize(Pango.EllipsizeMode.START)
|
||||||
|
|
||||||
@ -142,7 +139,7 @@ class BasePanel(ScreenPanel):
|
|||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
# Options in the config have priority
|
# Options in the config have priority
|
||||||
for device in self._printer.get_temp_store_devices():
|
for device in devices:
|
||||||
# Users can fill the bar if they want
|
# Users can fill the bar if they want
|
||||||
if n >= nlimit + 1:
|
if n >= nlimit + 1:
|
||||||
break
|
break
|
||||||
@ -154,7 +151,7 @@ class BasePanel(ScreenPanel):
|
|||||||
break
|
break
|
||||||
|
|
||||||
# If there is enough space fill with heater_generic
|
# If there is enough space fill with heater_generic
|
||||||
for device in self._printer.get_temp_store_devices():
|
for device in self._printer.get_heaters():
|
||||||
if n >= nlimit:
|
if n >= nlimit:
|
||||||
break
|
break
|
||||||
if device.startswith("heater_generic"):
|
if device.startswith("heater_generic"):
|
||||||
@ -189,6 +186,12 @@ class BasePanel(ScreenPanel):
|
|||||||
self.time_update = GLib.timeout_add_seconds(1, self.update_time)
|
self.time_update = GLib.timeout_add_seconds(1, self.update_time)
|
||||||
|
|
||||||
def add_content(self, panel):
|
def add_content(self, panel):
|
||||||
|
show = self._printer.state not in ('disconnected', 'startup', 'shutdown', 'error')
|
||||||
|
self.show_shortcut(show and self._config.get_main_config().getboolean('side_macro_shortcut', True))
|
||||||
|
self.show_heaters(show)
|
||||||
|
self.set_control_sensitive(show, control='estop')
|
||||||
|
for control in ('back', 'home'):
|
||||||
|
self.set_control_sensitive(len(self._screen._cur_panels) > 1, control=control)
|
||||||
self.current_panel = panel
|
self.current_panel = panel
|
||||||
self.set_title(panel.title)
|
self.set_title(panel.title)
|
||||||
self.content.add(panel.content)
|
self.content.add(panel.content)
|
||||||
@ -196,9 +199,7 @@ class BasePanel(ScreenPanel):
|
|||||||
def back(self, widget=None):
|
def back(self, widget=None):
|
||||||
if self.current_panel is None:
|
if self.current_panel is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._screen.remove_keyboard()
|
self._screen.remove_keyboard()
|
||||||
|
|
||||||
if hasattr(self.current_panel, "back") \
|
if hasattr(self.current_panel, "back") \
|
||||||
and not self.current_panel.back() \
|
and not self.current_panel.back() \
|
||||||
or not hasattr(self.current_panel, "back"):
|
or not hasattr(self.current_panel, "back"):
|
||||||
@ -227,7 +228,7 @@ class BasePanel(ScreenPanel):
|
|||||||
|
|
||||||
if action != "notify_status_update" or self._screen.printer is None:
|
if action != "notify_status_update" or self._screen.printer is None:
|
||||||
return
|
return
|
||||||
devices = self._printer.get_temp_store_devices()
|
devices = (self._printer.get_tools() + self._printer.get_heaters())
|
||||||
if devices is not None:
|
if devices is not None:
|
||||||
for device in devices:
|
for device in devices:
|
||||||
temp = self._printer.get_dev_stat(device, "temperature")
|
temp = self._printer.get_dev_stat(device, "temperature")
|
||||||
@ -255,37 +256,15 @@ class BasePanel(ScreenPanel):
|
|||||||
def remove(self, widget):
|
def remove(self, widget):
|
||||||
self.content.remove(widget)
|
self.content.remove(widget)
|
||||||
|
|
||||||
def show_back(self, show=True):
|
def set_control_sensitive(self, value=True, control='shortcut'):
|
||||||
self.control['back'].set_sensitive(show)
|
self.control[control].set_sensitive(value)
|
||||||
|
|
||||||
def show_home(self, show=True):
|
def show_shortcut(self, show=True):
|
||||||
self.control['home'].set_sensitive(show)
|
self.control['shortcut'].set_visible(show)
|
||||||
|
self.set_control_sensitive(self._screen._cur_panels[-1] != self.shorcut['panel'])
|
||||||
def show_macro_shortcut(self, show=True):
|
|
||||||
if show is True and self.buttons_showing['macros_shortcut'] is False:
|
|
||||||
self.action_bar.add(self.control['macros_shortcut'])
|
|
||||||
if self.buttons_showing['printer_select'] is False:
|
|
||||||
self.action_bar.reorder_child(self.control['macros_shortcut'], 2)
|
|
||||||
else:
|
|
||||||
self.action_bar.reorder_child(self.control['macros_shortcut'], 3)
|
|
||||||
self.control['macros_shortcut'].show()
|
|
||||||
self.buttons_showing['macros_shortcut'] = True
|
|
||||||
elif show is False and self.buttons_showing['macros_shortcut'] is True:
|
|
||||||
self.action_bar.remove(self.control['macros_shortcut'])
|
|
||||||
self.buttons_showing['macros_shortcut'] = False
|
|
||||||
|
|
||||||
def toggle_macro_shorcut_sensitive(self, value=True):
|
|
||||||
self.control['macros_shortcut'].set_sensitive(value)
|
|
||||||
|
|
||||||
def show_printer_select(self, show=True):
|
def show_printer_select(self, show=True):
|
||||||
if show and self.buttons_showing['printer_select'] is False:
|
self.control['printer_select'].set_visible(show)
|
||||||
self.action_bar.add(self.control['printer_select'])
|
|
||||||
self.action_bar.reorder_child(self.control['printer_select'], 2)
|
|
||||||
self.buttons_showing['printer_select'] = True
|
|
||||||
self.control['printer_select'].show()
|
|
||||||
elif show is False and self.buttons_showing['printer_select']:
|
|
||||||
self.action_bar.remove(self.control['printer_select'])
|
|
||||||
self.buttons_showing['printer_select'] = False
|
|
||||||
|
|
||||||
def set_title(self, title):
|
def set_title(self, title):
|
||||||
if not title:
|
if not title:
|
||||||
@ -313,12 +292,6 @@ class BasePanel(ScreenPanel):
|
|||||||
self.time_format = confopt
|
self.time_format = confopt
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def show_estop(self, show=True):
|
|
||||||
if show:
|
|
||||||
self.control['estop'].set_sensitive(True)
|
|
||||||
return
|
|
||||||
self.control['estop'].set_sensitive(False)
|
|
||||||
|
|
||||||
def set_ks_printer_cfg(self, printer):
|
def set_ks_printer_cfg(self, printer):
|
||||||
ScreenPanel.ks_printer_cfg = self._config.get_printer_config(printer)
|
ScreenPanel.ks_printer_cfg = self._config.get_printer_config(printer)
|
||||||
if self.ks_printer_cfg is not None:
|
if self.ks_printer_cfg is not None:
|
||||||
|
@ -47,10 +47,6 @@ class Panel(ScreenPanel):
|
|||||||
while len(self.menu) > 1:
|
while len(self.menu) > 1:
|
||||||
self.unload_menu()
|
self.unload_menu()
|
||||||
self.reload_macros()
|
self.reload_macros()
|
||||||
self._screen.base_panel.toggle_macro_shorcut_sensitive(False)
|
|
||||||
|
|
||||||
def deactivate(self):
|
|
||||||
self._screen.base_panel.toggle_macro_shorcut_sensitive(True)
|
|
||||||
|
|
||||||
def add_gcode_macro(self, macro):
|
def add_gcode_macro(self, macro):
|
||||||
# Support for hiding macros by name
|
# Support for hiding macros by name
|
||||||
|
@ -349,7 +349,6 @@ class Panel(ScreenPanel):
|
|||||||
def activate(self):
|
def activate(self):
|
||||||
if self.flow_timeout is None:
|
if self.flow_timeout is None:
|
||||||
self.flow_timeout = GLib.timeout_add_seconds(2, self.update_flow)
|
self.flow_timeout = GLib.timeout_add_seconds(2, self.update_flow)
|
||||||
self._screen.base_panel_show_all()
|
|
||||||
|
|
||||||
def deactivate(self):
|
def deactivate(self):
|
||||||
if self.flow_timeout is not None:
|
if self.flow_timeout is not None:
|
||||||
|
@ -82,7 +82,6 @@ class Panel(MenuPanel):
|
|||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
self.update_graph_visibility()
|
self.update_graph_visibility()
|
||||||
self._screen.base_panel_show_all()
|
|
||||||
|
|
||||||
def deactivate(self):
|
def deactivate(self):
|
||||||
if self.graph_update is not None:
|
if self.graph_update is not None:
|
||||||
@ -265,7 +264,7 @@ class Panel(MenuPanel):
|
|||||||
self.main_menu.attach(self.labels['menu'], 1, 0, 1, 1)
|
self.main_menu.attach(self.labels['menu'], 1, 0, 1, 1)
|
||||||
self.main_menu.show_all()
|
self.main_menu.show_all()
|
||||||
self.numpad_visible = False
|
self.numpad_visible = False
|
||||||
self._screen.base_panel.show_back(False)
|
self._screen.base_panel.set_control_sensitive(False, control='back')
|
||||||
|
|
||||||
def process_update(self, action, data):
|
def process_update(self, action, data):
|
||||||
if action != "notify_status_update":
|
if action != "notify_status_update":
|
||||||
@ -301,7 +300,7 @@ class Panel(MenuPanel):
|
|||||||
self.main_menu.attach(self.labels["keypad"], 1, 0, 1, 1)
|
self.main_menu.attach(self.labels["keypad"], 1, 0, 1, 1)
|
||||||
self.main_menu.show_all()
|
self.main_menu.show_all()
|
||||||
self.numpad_visible = True
|
self.numpad_visible = True
|
||||||
self._screen.base_panel.show_back(True)
|
self._screen.base_panel.set_control_sensitive(True, control='back')
|
||||||
|
|
||||||
def update_graph(self):
|
def update_graph(self):
|
||||||
self.labels['da'].queue_draw()
|
self.labels['da'].queue_draw()
|
||||||
|
@ -91,9 +91,6 @@ class Panel(ScreenPanel):
|
|||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
self.check_power_status()
|
self.check_power_status()
|
||||||
self._screen.base_panel.show_macro_shortcut(False)
|
|
||||||
self._screen.base_panel.show_heaters(False)
|
|
||||||
self._screen.base_panel.show_estop(False)
|
|
||||||
|
|
||||||
def check_power_status(self):
|
def check_power_status(self):
|
||||||
if 'power' in self.labels:
|
if 'power' in self.labels:
|
||||||
|
13
screen.py
13
screen.py
@ -299,8 +299,6 @@ class KlipperScreen(Gtk.Window):
|
|||||||
def attach_panel(self, panel):
|
def attach_panel(self, panel):
|
||||||
self.base_panel.add_content(self.panels[panel])
|
self.base_panel.add_content(self.panels[panel])
|
||||||
logging.debug(f"Current panel hierarchy: {' > '.join(self._cur_panels)}")
|
logging.debug(f"Current panel hierarchy: {' > '.join(self._cur_panels)}")
|
||||||
self.base_panel.show_back(len(self._cur_panels) > 1)
|
|
||||||
self.base_panel.show_home(len(self._cur_panels) > 1)
|
|
||||||
if hasattr(self.panels[panel], "process_update"):
|
if hasattr(self.panels[panel], "process_update"):
|
||||||
self.process_update("notify_status_update", self.printer.data)
|
self.process_update("notify_status_update", self.printer.data)
|
||||||
self.process_update("notify_busy", self.printer.busy)
|
self.process_update("notify_busy", self.printer.busy)
|
||||||
@ -656,7 +654,6 @@ class KlipperScreen(Gtk.Window):
|
|||||||
|
|
||||||
def state_printing(self):
|
def state_printing(self):
|
||||||
self.close_screensaver()
|
self.close_screensaver()
|
||||||
self.base_panel_show_all()
|
|
||||||
for dialog in self.dialogs:
|
for dialog in self.dialogs:
|
||||||
self.gtk.remove_dialog(dialog)
|
self.gtk.remove_dialog(dialog)
|
||||||
self.show_panel("job_status", _("Printing"), remove_all=True)
|
self.show_panel("job_status", _("Printing"), remove_all=True)
|
||||||
@ -670,7 +667,6 @@ class KlipperScreen(Gtk.Window):
|
|||||||
self.printer.state = "not ready"
|
self.printer.state = "not ready"
|
||||||
return
|
return
|
||||||
self.show_panel("main_menu", None, remove_all=True, items=self._config.get_menu_items("__main"))
|
self.show_panel("main_menu", None, remove_all=True, items=self._config.get_menu_items("__main"))
|
||||||
self.base_panel_show_all()
|
|
||||||
|
|
||||||
def state_startup(self):
|
def state_startup(self):
|
||||||
self.printer_initializing(_("Klipper is attempting to start"))
|
self.printer_initializing(_("Klipper is attempting to start"))
|
||||||
@ -681,8 +677,8 @@ class KlipperScreen(Gtk.Window):
|
|||||||
msg = msg if "ready" not in msg else ""
|
msg = msg if "ready" not in msg else ""
|
||||||
self.printer_initializing(_("Klipper has shutdown") + "\n\n" + msg, remove=True)
|
self.printer_initializing(_("Klipper has shutdown") + "\n\n" + msg, remove=True)
|
||||||
|
|
||||||
def toggle_macro_shortcut(self, value):
|
def toggle_shortcut(self, value):
|
||||||
self.base_panel.show_macro_shortcut(value)
|
self.base_panel.show_shortcut(value)
|
||||||
|
|
||||||
def change_language(self, widget, lang):
|
def change_language(self, widget, lang):
|
||||||
self._config.install_language(lang)
|
self._config.install_language(lang)
|
||||||
@ -915,11 +911,6 @@ class KlipperScreen(Gtk.Window):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
logging.error("Couldn't get the temperature store size")
|
logging.error("Couldn't get the temperature store size")
|
||||||
|
|
||||||
def base_panel_show_all(self):
|
|
||||||
self.base_panel.show_macro_shortcut(self._config.get_main_config().getboolean('side_macro_shortcut', True))
|
|
||||||
self.base_panel.show_heaters(True)
|
|
||||||
self.base_panel.show_estop(True)
|
|
||||||
|
|
||||||
def show_keyboard(self, entry=None, event=None):
|
def show_keyboard(self, entry=None, event=None):
|
||||||
if self.keyboard is not None:
|
if self.keyboard is not None:
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user