refactors and cleanup

This commit is contained in:
alfrix 2022-10-14 13:27:01 -03:00
parent e208873e46
commit 1305b40c41
8 changed files with 12 additions and 27 deletions

View File

@ -225,9 +225,9 @@ class KlippyGtk:
dialog.show_all()
# Change cursor to blank
if self.cursor:
dialog.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.ARROW))
dialog.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.ARROW))
else:
dialog.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.BLANK_CURSOR))
dialog.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.BLANK_CURSOR))
self.screen.dialogs.append(dialog)
return dialog

View File

@ -391,9 +391,7 @@ class KlipperScreenConfig:
def get_menu_name(self, menu="__main", subsection=""):
name = f"menu {menu} {subsection}" if subsection != "" else f"menu {menu}"
if name not in self.config:
return False
return self.config[name].get('name')
return False if name not in self.config else self.config[name].get('name')
def get_preheat_options(self):
index = "preheat "
@ -410,9 +408,7 @@ class KlipperScreenConfig:
if not name.startswith("printer "):
name = f"printer {name}"
if name not in self.config:
return None
return self.config[name]
return None if name not in self.config else self.config[name]
def get_printer_power_name(self):
return self.config['settings'].get("printer_power_name", "printer")

View File

@ -135,10 +135,8 @@ class KlippyFiles:
return filename in self.filelist
def file_metadata_exists(self, filename):
if not self.file_exists(filename):
return False
if "slicer" in self.files[filename]:
return True
if self.file_exists(filename):
return "slicer" in self.files[filename]
return False
def get_thumbnail_location(self, filename, small=False):

View File

@ -849,14 +849,11 @@ class JobStatusPanel(ScreenPanel):
def animate_label(self):
pos = self.filename_label['position']
current = self.filename_label['current']
complete = self.filename_label['complete']
if pos > (self.filename_label['length'] - self.filename_label['limit']):
self.filename_label['position'] = 0
self.labels['file'].set_label(complete)
self.labels['file'].set_label(self.filename_label['complete'])
else:
self.labels['file'].set_label(current[pos:self.filename_label['length']])
self.labels['file'].set_label(self.filename_label['current'][pos:self.filename_label['length']])
self.filename_label['position'] += 1
return True

View File

@ -109,9 +109,7 @@ class MenuPanel(ScreenPanel):
logging.debug(f"Template: '{enable}'")
j2_temp = Template(enable, autoescape=True)
result = j2_temp.render(self.j2_data)
if result == 'True':
return True
return False
return result == 'True'
except Exception as e:
logging.debug(f"Error evaluating enable statement: {enable}\n{e}")
return False

View File

@ -199,15 +199,13 @@ class MovePanel(ScreenPanel):
self.distance = distance
def move(self, widget, axis, direction):
speed = None
if self._config.get_config()['main'].getboolean(f"invert_{axis.lower()}", False):
direction = "-" if direction == "+" else "+"
dist = f"{direction}{self.distance}"
config_key = "move_speed_z" if axis == AXIS_Z else "move_speed_xy"
printer_cfg = self._config.get_printer_config(self._screen.connected_printer)
if printer_cfg is not None:
speed = printer_cfg.getint(config_key, None)
speed = None if printer_cfg is None else printer_cfg.getint(config_key, None)
if speed is None:
speed = self._config.get_config()['main'].getint(config_key, 20)

View File

@ -126,7 +126,7 @@ class PrintPanel(ScreenPanel):
if curdir != "gcodes" and fileinfo['modified'] > self.filelist[curdir]['modified']:
self.filelist[curdir]['modified'] = fileinfo['modified']
self.labels['directories'][curdir]['info'].set_markup(
f'<small>' + _("Modified")
'<small>' + _("Modified")
+ f' <b>{datetime.fromtimestamp(fileinfo["modified"]):%Y-%m-%d %H:%M}</b></small>'
)

View File

@ -102,12 +102,10 @@ class SettingsPanel(ScreenPanel):
dev.add(box)
elif option['type'] == "dropdown":
dropdown = Gtk.ComboBoxText()
i = 0
for opt in option['options']:
for i, opt in enumerate(option['options']):
dropdown.append(opt['value'], opt['name'])
if opt['value'] == self._config.get_config()[option['section']].get(opt_name, option['value']):
dropdown.set_active(i)
i += 1
dropdown.connect("changed", self.on_dropdown_change, option['section'], opt_name,
option['callback'] if "callback" in option else None)
dropdown.set_entry_text_column(0)