simplify name spliting

This commit is contained in:
alfrix 2022-07-15 19:11:49 -03:00 committed by Alfredo Monclus
parent 317f9df4b5
commit a0cff7ec56
6 changed files with 32 additions and 34 deletions

View File

@ -89,18 +89,20 @@ class Printer:
"target": 0
}
# Support for hiding devices by name
if not " ".join(x.split(" ")[1:]).startswith("_"):
name = x.split()[1] if len(x.split()) > 1 else x
if not name.startswith("_"):
self.tempdevcount += 1
if x == 'fan' \
or x.startswith('controller_fan ') \
or x.startswith('heater_fan ') \
or x.startswith('fan_generic '):
# Support for hiding devices by name
if not " ".join(x.split(" ")[1:]).startswith("_"):
name = x.split()[1] if len(x.split()) > 1 else x
if not name.startswith("_"):
self.fancount += 1
if x.startswith('output_pin '):
# Support for hiding devices by name
if not " ".join(x.split(" ")[1:]).startswith("_"):
if not x.split()[1].startswith("_"):
self.output_pin_count += 1
if x.startswith('bed_mesh '):
r = self.config[x]

View File

@ -186,8 +186,7 @@ class BasePanel(ScreenPanel):
# Users can fill the bar if they want
if n >= nlimit + 1:
break
name = device if (device.startswith("extruder") or device.startswith("heater_bed")) \
else " ".join(device.split(" ")[1:])
name = device.split()[1] if len(device.split()) > 1 else device
for item in titlebar_items:
if name == item:
self.control['temp_box'].add(self.labels[f"{device}_box"])
@ -235,9 +234,11 @@ class BasePanel(ScreenPanel):
name = ""
if not (device.startswith("extruder") or device.startswith("heater_bed")):
if self.titlebar_name_type == "full":
name = " ".join(device.split(" ")[1:]).capitalize().replace("_", " ") + ": "
name = device.split()[1] if len(device.split()) > 1 else device
name = f'{name.capitalize().replace("_", " ")}: '
elif self.titlebar_name_type == "short":
name = " ".join(device.split(" ")[1:])[:1].upper() + ": "
name = device.split()[1] if len(device.split()) > 1 else device
name = f"{name[:1].upper()}: "
self.labels[device].set_label(f"{name}{int(temp)}°")
with contextlib.suppress(KeyError):

View File

@ -62,7 +62,7 @@ class FanPanel(ScreenPanel):
logging.info(f"Adding fan: {fan}")
changeable = any(fan.startswith(x) or fan == x for x in CHANGEABLE_FANS)
name = Gtk.Label()
fan_name = _("Part Fan") if fan == "fan" else " ".join(fan.split(" ")[1:])
fan_name = _("Part Fan") if fan == "fan" else fan.split()[1]
name.set_markup(f"\n<big><b>{fan_name}</b></big>\n")
name.set_hexpand(True)
name.set_vexpand(True)
@ -130,7 +130,7 @@ class FanPanel(ScreenPanel):
fans = self._printer.get_fans()
for fan in fans:
# Support for hiding devices by name
name = " ".join(fan.split(" ")[1:]) if fan != "fan" else fan
name = fan.split()[1] if len(fan.split()) > 1 else fan
if name.startswith("_"):
continue
self.add_fan(fan)
@ -144,8 +144,7 @@ class FanPanel(ScreenPanel):
if fan == "fan":
self._screen._ws.klippy.gcode_script(KlippyGcodes.set_fan_speed(value))
else:
f = " ".join(fan.split(" ")[1:])
self._screen._ws.klippy.gcode_script(f"SET_FAN_SPEED FAN={f} SPEED={float(value) / 100}")
self._screen._ws.klippy.gcode_script(f"SET_FAN_SPEED FAN={fan.split()[1]} SPEED={float(value) / 100}")
# Check the speed in case it wasn't applied
GLib.timeout_add_seconds(1, self.check_fan_speed, fan)

View File

@ -68,13 +68,10 @@ class MainPanel(MenuPanel):
if temperature is None:
return False
if not (device.startswith("extruder") or device.startswith("heater_bed")):
devname = " ".join(device.split(" ")[1:])
# Support for hiding devices by name
if devname.startswith("_"):
return False
else:
devname = device
devname = device.split()[1] if len(device.split()) > 1 else device
# Support for hiding devices by name
if devname.startswith("_"):
return False
if device.startswith("extruder"):
i = sum(d.startswith('extruder') for d in self.devices)
@ -145,15 +142,16 @@ class MainPanel(MenuPanel):
self._screen.show_popup_message(_("Can't set above the maximum:") + f' {max_temp}')
return
temp = max(temp, 0)
name = self.active_heater.split()[1] if len(self.active_heater.split()) > 1 else self.active_heater
if self.active_heater.startswith('extruder'):
self._screen._ws.klippy.set_tool_temp(self._printer.get_tool_number(self.active_heater), temp)
elif self.active_heater == "heater_bed":
self._screen._ws.klippy.set_bed_temp(temp)
elif self.active_heater.startswith('heater_generic '):
self._screen._ws.klippy.set_heater_temp(" ".join(self.active_heater.split(" ")[1:]), temp)
self._screen._ws.klippy.set_heater_temp(name, temp)
elif self.active_heater.startswith('temperature_fan '):
self._screen._ws.klippy.set_temp_fan_temp(" ".join(self.active_heater.split(" ")[1:]), temp)
self._screen._ws.klippy.set_temp_fan_temp(name, temp)
else:
logging.info(f"Unknown heater: {self.active_heater}")
self._screen.show_popup_message(_("Unknown Heater") + " " + self.active_heater)

View File

@ -31,7 +31,7 @@ class OutputPinPanel(ScreenPanel):
output_pins = self._printer.get_output_pins()
for pin in output_pins:
# Support for hiding devices by name
name = " ".join(pin.split(" ")[1:])
name = pin.split()[1]
if name.startswith("_"):
continue
self.add_pin(pin)

View File

@ -46,7 +46,7 @@ class TemperaturePanel(ScreenPanel):
for h in selection:
if h.startswith("temperature_sensor "):
continue
name = " ".join(h.split(" ")[1:])
name = h.split()[1] if len(h.split()) > 1 else h
# Support for hiding devices by name
if name.startswith("_"):
continue
@ -157,6 +157,7 @@ class TemperaturePanel(ScreenPanel):
else:
for heater in self.active_heaters:
target = self._printer.get_dev_stat(heater, "target")
name = heater.split()[1] if len(heater.split()) > 1 else heater
if direction == "+":
target += int(self.tempdelta)
max_temp = int(float(self._printer.get_config_section(heater)['max_temp']))
@ -172,9 +173,9 @@ class TemperaturePanel(ScreenPanel):
elif heater.startswith('heater_bed'):
self._screen._ws.klippy.set_bed_temp(target)
elif heater.startswith('heater_generic '):
self._screen._ws.klippy.set_heater_temp(" ".join(heater.split(" ")[1:]), target)
self._screen._ws.klippy.set_heater_temp(name, target)
elif heater.startswith("temperature_fan "):
self._screen._ws.klippy.set_temp_fan_temp(" ".join(heater.split(" ")[1:]), target)
self._screen._ws.klippy.set_temp_fan_temp(name, target)
else:
logging.info(f"Unknown heater: {heater}")
self._screen.show_popup_message(_("Unknown Heater") + " " + heater)
@ -267,13 +268,10 @@ class TemperaturePanel(ScreenPanel):
if temperature is None:
return False
if not (device.startswith("extruder") or device.startswith("heater_bed")):
devname = " ".join(device.split(" ")[1:])
# Support for hiding devices by name
if devname.startswith("_"):
return False
else:
devname = device
devname = device.split()[1] if len(device.split()) > 1 else device
# Support for hiding devices by name
if devname.startswith("_"):
return False
if device.startswith("extruder"):
i = sum(d.startswith('extruder') for d in self.devices)
@ -342,7 +340,7 @@ class TemperaturePanel(ScreenPanel):
return True
def change_target_temp(self, temp):
name = self.active_heater.split()[1] if len(self.active_heater.split()) > 1 else self.active_heater
max_temp = int(float(self._printer.get_config_section(self.active_heater)['max_temp']))
if temp > max_temp:
self._screen.show_popup_message(_("Can't set above the maximum:") + f' {max_temp}')
@ -354,9 +352,9 @@ class TemperaturePanel(ScreenPanel):
elif self.active_heater == "heater_bed":
self._screen._ws.klippy.set_bed_temp(temp)
elif self.active_heater.startswith('heater_generic '):
self._screen._ws.klippy.set_heater_temp(" ".join(self.active_heater.split(" ")[1:]), temp)
self._screen._ws.klippy.set_heater_temp(name, temp)
elif self.active_heater.startswith('temperature_fan '):
self._screen._ws.klippy.set_temp_fan_temp(" ".join(self.active_heater.split(" ")[1:]), temp)
self._screen._ws.klippy.set_temp_fan_temp(name, temp)
else:
logging.info(f"Unknown heater: {self.active_heater}")
self._screen.show_popup_message(_("Unknown Heater") + " " + self.active_heater)