base_panel: simplify action bar buttons enable-disable
This commit is contained in:
parent
7b7c3838fc
commit
d0d79a64df
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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 = []
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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 = {}
|
||||
|
@ -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 = {}
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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']
|
||||
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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"]:
|
||||
|
@ -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()
|
||||
|
@ -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 = {}
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user