Skip to content

Commit

Permalink
panels: allow to call them without name
Browse files Browse the repository at this point in the history
  • Loading branch information
alfrix committed Jun 4, 2024
1 parent 4334535 commit 2d2e80c
Show file tree
Hide file tree
Showing 32 changed files with 48 additions and 23 deletions.
8 changes: 5 additions & 3 deletions ks_includes/screen_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ def get_file_image(self, filename, width=None, height=None, small=False):
return None

def menu_item_clicked(self, widget, item):
panel_args = {}
if 'name' in item:
panel_args['title'] = item['name']
if 'extra' in item:
self._screen.show_panel(item['panel'], item['name'], extra=item['extra'])
return
self._screen.show_panel(item['panel'], item['name'])
panel_args['extra'] = item['extra']
self._screen.show_panel(item['panel'], **panel_args)

def load_menu(self, widget, name, title=None):
logging.info(f"loading menu {name}")
Expand Down
3 changes: 0 additions & 3 deletions panels/base_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def __init__(self, screen, title=None):
self.control['estop'].connect("clicked", self.emergency_stop)
self.control['estop'].set_no_show_all(True)
self.shutdown = {
"name": None,
"panel": "shutdown",
"icon": "shutdown",
}
self.control['shutdown'] = self._gtk.Button('shutdown', scale=abscale)
self.control['shutdown'].connect("clicked", self.menu_item_clicked, self.shutdown)
Expand All @@ -47,7 +45,6 @@ def __init__(self, screen, title=None):
self.control['printer_select'].set_no_show_all(True)

self.shorcut = {
"name": "Macros",
"panel": "gcode_macros",
"icon": "custom-script",
}
Expand Down
1 change: 1 addition & 0 deletions panels/bed_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def find_closest(screws, point, max_distance):
class Panel(ScreenPanel):

def __init__(self, screen, title):
title = title or _("Bed Level")
super().__init__(screen, title)
self.screw_positions = {}
self.screws = []
Expand Down
1 change: 1 addition & 0 deletions panels/bed_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class Panel(ScreenPanel):

def __init__(self, screen, title):
title = title or _("Bed Mesh")
super().__init__(screen, title)
self.show_create = False
self.active_mesh = None
Expand Down
1 change: 1 addition & 0 deletions panels/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or _("Camera")
super().__init__(screen, title)
self.mpv = None
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
Expand Down
1 change: 1 addition & 0 deletions panels/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or _("Console")
super().__init__(screen, title)
self.autoscroll = True
self.hidetemps = True
Expand Down
1 change: 1 addition & 0 deletions panels/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or _("Example")
super().__init__(screen, title)

# Create gtk items here
Expand Down
1 change: 1 addition & 0 deletions panels/exclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or _("Exclude Object")
super().__init__(screen, title)
self._screen = screen
self.object_list = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, hexpand=True, vexpand=True)
Expand Down
3 changes: 1 addition & 2 deletions panels/extrude.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class Panel(ScreenPanel):

def __init__(self, screen, title):
title = title or _("Extrude")
super().__init__(screen, title)
self.current_extruder = self._printer.get_stat("toolhead", "extruder")
macros = self._printer.get_config_section_list("gcode_macro ")
Expand Down Expand Up @@ -47,11 +48,9 @@ def __init__(self, screen, title):
self.buttons['unload'].connect("clicked", self.load_unload, "-")
self.buttons['retract'].connect("clicked", self.extrude, "-")
self.buttons['temperature'].connect("clicked", self.menu_item_clicked, {
"name": "Temperature",
"panel": "temperature"
})
self.buttons['spoolman'].connect("clicked", self.menu_item_clicked, {
"name": "Spoolman",
"panel": "spoolman"
})

Expand Down
1 change: 1 addition & 0 deletions panels/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or _("Fan")
super().__init__(screen, title)
self.fan_speed = {}
self.devices = {}
Expand Down
1 change: 1 addition & 0 deletions panels/fine_tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Panel(ScreenPanel):
z_offset = 0.0

def __init__(self, screen, title):
title = title or _("Fine Tuning")
super().__init__(screen, title)
if self.ks_printer_cfg is not None:
bs = self.ks_printer_cfg.get("z_babystep_values", "")
Expand Down
1 change: 1 addition & 0 deletions panels/gcode_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or _("Macros")
super().__init__(screen, title)
self.sort_reverse = False
self.sort_btn = self._gtk.Button("arrow-up", _("Name"), "color1", self.bts, Gtk.PositionType.RIGHT, 1)
Expand Down
1 change: 1 addition & 0 deletions panels/gcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def format_label(widget):

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or (_("Print") if self._printer.extrudercount > 0 else _("Gcodes"))
super().__init__(screen, title)
sortdir = self._config.get_main_config().get("print_sort_dir", "name_asc")
sortdir = sortdir.split('_')
Expand Down
1 change: 1 addition & 0 deletions panels/input_shaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or _("Input Shaper")
super().__init__(screen, title)
self.freq_xy_adj = {}
self.freq_xy_combo = {}
Expand Down
14 changes: 7 additions & 7 deletions panels/job_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or (_("Printing") if self._printer.extrudercount > 0 else _("Job Status"))
super().__init__(screen, title)
self.grid = Gtk.Grid(column_homogeneous=True)
self.pos_z = 0.0
Expand Down Expand Up @@ -143,7 +144,7 @@ def create_status_grid(self, widget=None):
}
for button in buttons:
buttons[button].set_halign(Gtk.Align.START)
buttons['fan'].connect("clicked", self.menu_item_clicked, {"panel": "fan", "name": _("Fan")})
buttons['fan'].connect("clicked", self.menu_item_clicked, {"panel": "fan"})
self.buttons.update(buttons)

self.buttons['extruder'] = {}
Expand All @@ -153,7 +154,7 @@ def create_status_grid(self, widget=None):
Gtk.PositionType.LEFT, 1)
self.buttons['extruder'][extruder].set_label(self.labels[extruder].get_text())
self.buttons['extruder'][extruder].connect("clicked", self.menu_item_clicked,
{"panel": "temperature", "name": _("Temperature"),
{"panel": "temperature",
'extra': extruder})
self.buttons['extruder'][extruder].set_halign(Gtk.Align.START)

Expand Down Expand Up @@ -181,7 +182,7 @@ def create_status_grid(self, widget=None):

self.buttons['heater'][dev].set_label(self.labels[dev].get_text())
self.buttons['heater'][dev].connect("clicked", self.menu_item_clicked,
{"panel": "temperature", "name": _("Temperature"), "extra": dev})
{"panel": "temperature", "extra": dev})
self.buttons['heater'][dev].set_halign(Gtk.Align.START)
self.labels['temp_grid'].attach(self.buttons['heater'][dev], n, 0, 1, 1)
n += 1
Expand All @@ -205,8 +206,7 @@ def create_status_grid(self, widget=None):
self.labels[device] = Gtk.Label(label="-")
self.buttons['heater'][device].set_label(self.labels[device].get_text())
self.buttons['heater'][device].connect("clicked", self.menu_item_clicked,
{"panel": "temperature",
"name": _("Temperature")})
{"panel": "temperature"})
self.buttons['heater'][device].set_halign(Gtk.Align.START)
self.labels['temp_grid'].attach(self.buttons['heater'][device], n, 0, 1, 1)
n += 1
Expand Down Expand Up @@ -354,7 +354,7 @@ def create_buttons(self):
self.buttons['cancel'].connect("clicked", self.cancel)
self.buttons['control'].connect("clicked", self._screen._go_to_submenu, "")
self.buttons['fine_tune'].connect("clicked", self.menu_item_clicked, {
"panel": "fine_tune", "name": _("Fine Tuning")})
"panel": "fine_tune"})
self.buttons['menu'].connect("clicked", self.close_panel)
self.buttons['pause'].connect("clicked", self.pause)
self.buttons['restart'].connect("clicked", self.restart)
Expand Down Expand Up @@ -430,7 +430,7 @@ def cancel(self, widget):
def cancel_confirm(self, dialog, response_id):
self._gtk.remove_dialog(dialog)
if response_id == Gtk.ResponseType.APPLY:
self.menu_item_clicked(None, {"panel": "exclude", "name": _("Exclude Object")})
self.menu_item_clicked(None, {"panel": "exclude"})
return
if response_id == Gtk.ResponseType.CANCEL:
self.enable_button("pause", "cancel")
Expand Down
1 change: 1 addition & 0 deletions panels/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class Panel(ScreenPanel):

def __init__(self, screen, title):
title = title or _("Leds")
super().__init__(screen, title)
self.da_size = self._gtk.img_scale * 2
self.preview = Gtk.DrawingArea(width_request=self.da_size, height_request=self.da_size)
Expand Down
1 change: 1 addition & 0 deletions panels/limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class Panel(ScreenPanel):

def __init__(self, screen, title):
title = title or _("Limits")
super().__init__(screen, title)
self.limits = {}
self.options = None
Expand Down
1 change: 1 addition & 0 deletions panels/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Panel(ScreenPanel):
distance = distances[-2]

def __init__(self, screen, title):
title = title or _("Move")
super().__init__(screen, title)

if self.ks_printer_cfg is not None:
Expand Down
1 change: 1 addition & 0 deletions panels/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class Panel(ScreenPanel):

def __init__(self, screen, title):
title = title or _("Network")
super().__init__(screen, title)
try:
self.sdbus_nm = SdbusNm(self.popup_callback)
Expand Down
1 change: 1 addition & 0 deletions panels/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def remove_newlines(msg: str) -> str:

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or _("Notifications")
super().__init__(screen, title)
self.empty = _("Notification log empty")
self.tb = Gtk.TextBuffer(text=self.empty)
Expand Down
1 change: 1 addition & 0 deletions panels/pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class Panel(ScreenPanel):

def __init__(self, screen, title):
title = title or _("Pins")
super().__init__(screen, title)
self.devices = {}
# Create a grid for all devices
Expand Down
1 change: 1 addition & 0 deletions panels/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or _("Power")
super().__init__(screen, title)
self.devices = {}

Expand Down
1 change: 1 addition & 0 deletions panels/printer_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or _("Printer Select")
super().__init__(screen, title)
printers = self._config.get_printers()

Expand Down
1 change: 1 addition & 0 deletions panels/retraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class Panel(ScreenPanel):

def __init__(self, screen, title):
title = title or _("Retraction")
super().__init__(screen, title)
self.options = None
self.grid = Gtk.Grid()
Expand Down
1 change: 1 addition & 0 deletions panels/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or _("Settings")
super().__init__(screen, title)
self.printers = self.settings = self.langs = {}
self.menu = ['settings_menu']
Expand Down
1 change: 1 addition & 0 deletions panels/shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or _("Shutdown")
super().__init__(screen, title)

estop = self._gtk.Button("emergency", _("Emergency Stop"), "color2")
Expand Down
1 change: 1 addition & 0 deletions panels/spoolman.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def _on_material_filter_changed(self, sender):
self._filterable.refilter()

def __init__(self, screen, title):
title = title or "Spoolman"
super().__init__(screen, title)
self.apiClient = screen.apiclient
if self._config.get_main_config().getboolean("24htime", True):
Expand Down
1 change: 1 addition & 0 deletions panels/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or _("System")
super().__init__(screen, title)
self.current_row = 0
self.mem_multiplier = None
Expand Down
1 change: 1 addition & 0 deletions panels/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Panel(ScreenPanel):
active_heater = None

def __init__(self, screen, title, extra=None):
title = title or _("Temperature")
super().__init__(screen, title)
self.left_panel = None
self.devices = {}
Expand Down
1 change: 1 addition & 0 deletions panels/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

class Panel(ScreenPanel):
def __init__(self, screen, title):
title = title or _("Update")
super().__init__(screen, title)
self.labels = {}
self.update_status = None
Expand Down
1 change: 1 addition & 0 deletions panels/zcalibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Panel(ScreenPanel):
distance = distances[-2]

def __init__(self, screen, title):
title = title or _("Z Calibrate")
super().__init__(screen, title)
self.mesh_min = []
self.mesh_max = []
Expand Down
16 changes: 8 additions & 8 deletions screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def _load_panel(panel):
raise FileNotFoundError(os.strerror(2), "\n" + panel_path)
return import_module(f"panels.{panel}")

def show_panel(self, panel, title, remove_all=False, panel_name=None, **kwargs):
def show_panel(self, panel, title=None, remove_all=False, panel_name=None, **kwargs):
if panel_name is None:
panel_name = panel
try:
Expand Down Expand Up @@ -700,7 +700,7 @@ def set_screenblanking_timeout(self, time):

def show_printer_select(self, widget=None):
self.base_panel.show_heaters(False)
self.show_panel("printer_select", _("Printer Select"), remove_all=True)
self.show_panel("printer_select", remove_all=True)

def websocket_connection_cancel(self):
self.printer_initializing(
Expand Down Expand Up @@ -749,12 +749,12 @@ def state_error(self):
def state_paused(self):
self.state_printing()
if self._config.get_main_config().getboolean("auto_open_extrude", fallback=True):
self.show_panel("extrude", _("Extrude"))
self.show_panel("extrude")

def state_printing(self):
for dialog in self.dialogs:
self.gtk.remove_dialog(dialog)
self.show_panel("job_status", _("Printing"), remove_all=True)
self.show_panel("job_status", remove_all=True)

def state_ready(self, wait=True):
# Do not return to main menu if completing a job, timeouts/user input will return
Expand All @@ -765,7 +765,7 @@ def state_ready(self, wait=True):
self.printer.state = "not ready"
return
self.files.refresh_files()
self.show_panel("main_menu", None, remove_all=True, items=self._config.get_menu_items("__main"))
self.show_panel("main_menu", remove_all=True, items=self._config.get_menu_items("__main"))

def state_startup(self):
self.printer_initializing(_("Klipper is attempting to start"))
Expand Down Expand Up @@ -822,9 +822,9 @@ def _websocket_callback(self, action, data):
elif action == "notify_status_update" and self.printer.state != "shutdown":
self.printer.process_update(data)
if 'manual_probe' in data and data['manual_probe']['is_active'] and 'zcalibrate' not in self._cur_panels:
self.show_panel("zcalibrate", _('Z Calibrate'))
self.show_panel("zcalibrate")
if "screws_tilt_adjust" in data and 'bed_level' not in self._cur_panels:
self.show_panel("bed_level", _('Bed Level'))
self.show_panel("bed_level")
elif action == "notify_filelist_changed":
if self.files is not None:
self.files.process_update(data)
Expand Down Expand Up @@ -917,7 +917,7 @@ def enable_widget(self, *args):

def printer_initializing(self, msg, go_to_splash=False):
if 'splash_screen' not in self.panels or go_to_splash:
self.show_panel("splash_screen", None, remove_all=True)
self.show_panel("splash_screen", remove_all=True)
self.panels['splash_screen'].update_text(msg)
self.log_notification(msg, 0)

Expand Down

0 comments on commit 2d2e80c

Please sign in to comment.