From d0d79a64df447f526842e71b6622ae711b45feae Mon Sep 17 00:00:00 2001 From: alfrix Date: Mon, 21 Nov 2022 08:50:12 -0300 Subject: [PATCH] base_panel: simplify action bar buttons enable-disable --- ks_includes/screen_panel.py | 2 +- panels/base_panel.py | 32 +++++++++++++------------------- panels/bed_level.py | 4 ++-- panels/bed_mesh.py | 4 ++-- panels/console.py | 4 ++-- panels/example.py | 4 ++-- panels/exclude.py | 4 ++-- panels/extrude.py | 4 ++-- panels/fan.py | 4 ++-- panels/fine_tune.py | 4 ++-- panels/gcode_macros.py | 4 ++-- panels/input_shaper.py | 4 ++-- panels/job_status.py | 4 ++-- panels/limits.py | 4 ++-- panels/main_menu.py | 4 ++-- panels/menu.py | 4 ++-- panels/move.py | 4 ++-- panels/network.py | 4 ++-- panels/pins.py | 4 ++-- panels/power.py | 4 ++-- panels/print.py | 4 ++-- panels/printer_select.py | 4 ++-- panels/retraction.py | 4 ++-- panels/settings.py | 4 ++-- panels/splash_screen.py | 4 ++-- panels/system.py | 4 ++-- panels/temperature.py | 4 ++-- panels/zcalibrate.py | 4 ++-- screen.py | 2 +- 29 files changed, 67 insertions(+), 73 deletions(-) diff --git a/ks_includes/screen_panel.py b/ks_includes/screen_panel.py index 5512e48b..43b375eb 100644 --- a/ks_includes/screen_panel.py +++ b/ks_includes/screen_panel.py @@ -14,7 +14,7 @@ class ScreenPanel: _gtk = None ks_printer_cfg = None - def __init__(self, screen, title, back=True): + def __init__(self, screen, title): self.menu = None ScreenPanel._screen = screen ScreenPanel._config = screen._config diff --git a/panels/base_panel.py b/panels/base_panel.py index 9112accf..be182de6 100644 --- a/panels/base_panel.py +++ b/panels/base_panel.py @@ -14,8 +14,8 @@ from ks_includes.screen_panel import ScreenPanel class BasePanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.current_panel = None self.time_min = -1 self.time_format = self._config.get_main_config().getboolean("24htime", True) @@ -23,10 +23,8 @@ class BasePanel(ScreenPanel): self.titlebar_items = [] self.titlebar_name_type = None self.buttons_showing = { - 'back': not back, 'macros_shortcut': False, - 'printer_select': False, - 'estop': False, + 'printer_select': len(self._config.get_printers()) > 1, } self.current_extruder = None # Action bar buttons @@ -67,10 +65,12 @@ class BasePanel(ScreenPanel): self.action_bar.get_style_context().add_class('action_bar') self.action_bar.add(self.control['back']) self.action_bar.add(self.control['home']) - if len(self._config.get_printers()) > 1: + self.show_back(False) + 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.show_estop(False) # Titlebar @@ -245,14 +245,12 @@ class BasePanel(ScreenPanel): self.content.remove(widget) def show_back(self, show=True): - if show is True and self.buttons_showing['back'] is False: + if show: self.control['back'].set_sensitive(True) self.control['home'].set_sensitive(True) - self.buttons_showing['back'] = True - elif show is False and self.buttons_showing['back'] is True: - self.control['back'].set_sensitive(False) - self.control['home'].set_sensitive(False) - self.buttons_showing['back'] = False + return + self.control['back'].set_sensitive(False) + self.control['home'].set_sensitive(False) def show_macro_shortcut(self, show=True): if show is True and self.buttons_showing['macros_shortcut'] is False: @@ -268,8 +266,6 @@ class BasePanel(ScreenPanel): self.buttons_showing['macros_shortcut'] = False def show_printer_select(self, show=True): - if len(self._config.get_printers()) <= 1: - return if show and self.buttons_showing['printer_select'] is False: self.action_bar.add(self.control['printer_select']) self.action_bar.reorder_child(self.control['printer_select'], 2) @@ -306,12 +302,10 @@ class BasePanel(ScreenPanel): return True def show_estop(self, show=True): - if show and self.buttons_showing['estop'] is False: + if show: self.control['estop'].set_sensitive(True) - self.buttons_showing['estop'] = True - elif show is False and self.buttons_showing['estop']: - self.control['estop'].set_sensitive(False) - self.buttons_showing['estop'] = False + return + self.control['estop'].set_sensitive(False) def set_ks_printer_cfg(self, printer): ScreenPanel.ks_printer_cfg = self._config.get_printer_config(printer) diff --git a/panels/bed_level.py b/panels/bed_level.py index f7c96aab..45e9378b 100644 --- a/panels/bed_level.py +++ b/panels/bed_level.py @@ -16,8 +16,8 @@ def create_panel(*args): class BedLevelPanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.response_count = 0 self.screw_dict = {} self.screws = [] diff --git a/panels/bed_mesh.py b/panels/bed_mesh.py index 00395588..63e224df 100644 --- a/panels/bed_mesh.py +++ b/panels/bed_mesh.py @@ -17,8 +17,8 @@ def create_panel(*args): class BedMeshPanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.clear = None self.profiles = {} self.show_create = False diff --git a/panels/console.py b/panels/console.py index cc30ac53..a79d6523 100644 --- a/panels/console.py +++ b/panels/console.py @@ -24,8 +24,8 @@ COLORS = { class ConsolePanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.autoscroll = True self.hidetemps = True self._screen._ws.send_method("server.gcode_store", {"count": 100}, self.gcode_response) diff --git a/panels/example.py b/panels/example.py index 1c3f319a..486c2a7f 100644 --- a/panels/example.py +++ b/panels/example.py @@ -11,8 +11,8 @@ def create_panel(*args): class ExamplePanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) # Create gtk items here diff --git a/panels/exclude.py b/panels/exclude.py index fae205ec..818d18e1 100644 --- a/panels/exclude.py +++ b/panels/exclude.py @@ -15,8 +15,8 @@ def create_panel(*args): class ExcludeObjectPanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self._screen = screen self.object_list = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) self.object_list.set_valign(Gtk.Align.CENTER) diff --git a/panels/extrude.py b/panels/extrude.py index 057c63a0..20025b1a 100644 --- a/panels/extrude.py +++ b/panels/extrude.py @@ -16,8 +16,8 @@ def create_panel(*args): class ExtrudePanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.current_extruder = self._printer.get_stat("toolhead", "extruder") macros = self._screen.printer.get_gcode_macros() self.load_filament = any("LOAD_FILAMENT" in macro.upper() for macro in macros) diff --git a/panels/fan.py b/panels/fan.py index e48f4ef4..022a3e17 100644 --- a/panels/fan.py +++ b/panels/fan.py @@ -17,8 +17,8 @@ CHANGEABLE_FANS = ["fan", "fan_generic"] class FanPanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.fan_speed = {} self.devices = {} # Create a grid for all devices diff --git a/panels/fine_tune.py b/panels/fine_tune.py index 44b17d74..b15ddd9f 100644 --- a/panels/fine_tune.py +++ b/panels/fine_tune.py @@ -22,8 +22,8 @@ class FineTunePanel(ScreenPanel): percent_delta = percent_deltas[-2] speed = extrusion = 100 - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) if self.ks_printer_cfg is not None: bs = self.ks_printer_cfg.get("z_babystep_values", "0.01, 0.05") if re.match(r'^[0-9,\.\s]+$', bs): diff --git a/panels/gcode_macros.py b/panels/gcode_macros.py index 52be8584..209cc55d 100644 --- a/panels/gcode_macros.py +++ b/panels/gcode_macros.py @@ -13,8 +13,8 @@ def create_panel(*args): class MacroPanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.sort_reverse = False self.sort_lbl = _("Name") self.sort_btn = self._gtk.ButtonImage("arrow-up", self.sort_lbl, "color1", .5, Gtk.PositionType.RIGHT, 1) diff --git a/panels/input_shaper.py b/panels/input_shaper.py index b25da872..8cf339e8 100644 --- a/panels/input_shaper.py +++ b/panels/input_shaper.py @@ -22,8 +22,8 @@ SHAPERS = ['zv', 'mzv', 'zvd', 'ei', '2hump_ei', '3hump_ei'] class InputShaperPanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.freq_xy_adj = {} self.freq_xy_combo = {} self.calibrate_btn = self._gtk.ButtonImage("move", _('Finding ADXL'), "color1", lines=1) diff --git a/panels/job_status.py b/panels/job_status.py index 01fd5dbd..cd0e3454 100644 --- a/panels/job_status.py +++ b/panels/job_status.py @@ -18,8 +18,8 @@ def create_panel(*args): class JobStatusPanel(ScreenPanel): - def __init__(self, screen, title, back=False): - super().__init__(screen, title, False) + def __init__(self, screen, title): + super().__init__(screen, title) self.extrusion_button = None self.elapsed_button = None self.left_button = None diff --git a/panels/limits.py b/panels/limits.py index d52aab6f..e1fe85f3 100644 --- a/panels/limits.py +++ b/panels/limits.py @@ -14,8 +14,8 @@ def create_panel(*args): class LimitsPanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.limits = {} self.options = None self.values = {} diff --git a/panels/main_menu.py b/panels/main_menu.py index d30f9b5f..83f5dfad 100644 --- a/panels/main_menu.py +++ b/panels/main_menu.py @@ -15,8 +15,8 @@ def create_panel(*args): class MainPanel(MenuPanel): - def __init__(self, screen, title, back=False): - super().__init__(screen, title, False) + def __init__(self, screen, title): + super().__init__(screen, title) self.left_panel = None self.items = None self.devices = {} diff --git a/panels/menu.py b/panels/menu.py index 0985c1d9..02b72fc4 100644 --- a/panels/menu.py +++ b/panels/menu.py @@ -17,8 +17,8 @@ class MenuPanel(ScreenPanel): i = 0 j2_data = None - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.items = None self.grid = self._gtk.HomogeneousGrid() diff --git a/panels/move.py b/panels/move.py index 2c7b1f7f..7e8e685d 100644 --- a/panels/move.py +++ b/panels/move.py @@ -17,8 +17,8 @@ class MovePanel(ScreenPanel): distances = ['.1', '.5', '1', '5', '10', '25', '50'] distance = distances[-2] - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.settings = {} self.menu = ['move_menu'] diff --git a/panels/network.py b/panels/network.py index 0a44a363..535cb48b 100644 --- a/panels/network.py +++ b/panels/network.py @@ -18,8 +18,8 @@ def create_panel(*args): class NetworkPanel(ScreenPanel): initialized = False - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.show_add = False self.networks = {} self.interface = None diff --git a/panels/pins.py b/panels/pins.py index a2d45d39..c24ef448 100644 --- a/panels/pins.py +++ b/panels/pins.py @@ -14,8 +14,8 @@ def create_panel(*args): class OutputPinPanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.devices = {} # Create a grid for all devices self.labels['devices'] = Gtk.Grid() diff --git a/panels/power.py b/panels/power.py index e2da7b36..fb187056 100644 --- a/panels/power.py +++ b/panels/power.py @@ -13,8 +13,8 @@ def create_panel(*args): class PowerPanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.devices = {} # Create a grid for all devices diff --git a/panels/print.py b/panels/print.py index 06415377..afa79824 100644 --- a/panels/print.py +++ b/panels/print.py @@ -20,8 +20,8 @@ class PrintPanel(ScreenPanel): dir_panels = {} filelist = {'gcodes': {'directories': [], 'files': []}} - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) sortdir = self._config.get_main_config().get("print_sort_dir", "name_asc") sortdir = sortdir.split('_') if sortdir[0] not in ["name", "date"] or sortdir[1] not in ["asc", "desc"]: diff --git a/panels/printer_select.py b/panels/printer_select.py index 8df778d9..28ba41d2 100644 --- a/panels/printer_select.py +++ b/panels/printer_select.py @@ -10,8 +10,8 @@ def create_panel(*args): class PrinterSelect(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, False) + def __init__(self, screen, title): + super().__init__(screen, title) printers = self._config.get_printers() grid = self._gtk.HomogeneousGrid() diff --git a/panels/retraction.py b/panels/retraction.py index 1d09c3af..a809afed 100644 --- a/panels/retraction.py +++ b/panels/retraction.py @@ -15,8 +15,8 @@ def create_panel(*args): class FWRetractionPanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.options = None self.grid = Gtk.Grid() self.values = {} diff --git a/panels/settings.py b/panels/settings.py index e3bd05c5..d7d12689 100644 --- a/panels/settings.py +++ b/panels/settings.py @@ -11,8 +11,8 @@ def create_panel(*args): class SettingsPanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.printers = self.settings = {} self.menu = ['settings_menu'] options = self._config.get_configurable_options().copy() diff --git a/panels/splash_screen.py b/panels/splash_screen.py index 3fbf90c8..1c83ffd1 100644 --- a/panels/splash_screen.py +++ b/panels/splash_screen.py @@ -15,8 +15,8 @@ def create_panel(*args): class SplashScreenPanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) image = self._gtk.Image("klipper", self._screen.width / 5, self._screen.height * .5) self.labels['text'] = Gtk.Label(_("Initializing printer...")) self.labels['text'].set_line_wrap(True) diff --git a/panels/system.py b/panels/system.py index 409df913..b8895db4 100644 --- a/panels/system.py +++ b/panels/system.py @@ -28,8 +28,8 @@ ALLOWED_SERVICES = ( class SystemPanel(ScreenPanel): - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.refresh = None self.update_status = None self.update_dialog = None diff --git a/panels/temperature.py b/panels/temperature.py index e4fc4c52..1aa4b0f1 100644 --- a/panels/temperature.py +++ b/panels/temperature.py @@ -19,8 +19,8 @@ class TemperaturePanel(ScreenPanel): graph_update = None active_heater = None - def __init__(self, screen, title, back=True): - super().__init__(screen, title, back) + def __init__(self, screen, title): + super().__init__(screen, title) self.popover_timeout = None self.left_panel = None self.popover_device = None diff --git a/panels/zcalibrate.py b/panels/zcalibrate.py index 70d77232..e622a472 100644 --- a/panels/zcalibrate.py +++ b/panels/zcalibrate.py @@ -18,8 +18,8 @@ class ZCalibratePanel(ScreenPanel): distances = ['.01', '.05', '.1', '.5', '1', '5'] distance = distances[-2] - def __init__(self, screen, title, back=True): - super().__init__(screen, title, False) + def __init__(self, screen, title): + super().__init__(screen, title) self.z_offset = None self.probe = self._screen.printer.get_probe() if self.probe: diff --git a/screen.py b/screen.py index a4cf5140..305e6205 100644 --- a/screen.py +++ b/screen.py @@ -116,7 +116,7 @@ class KlipperScreen(Gtk.Window): self.init_style() self.set_icon_from_file(os.path.join(klipperscreendir, "styles", "icon.svg")) - self.base_panel = BasePanel(self, title="Base Panel", back=False) + self.base_panel = BasePanel(self, title="Base Panel") self.add(self.base_panel.get()) self.show_all() if show_cursor: