limits: add reset, allow to set above the configured maximum but turn the slider red

This commit is contained in:
alfrix authored and Alfredo Monclus committed 2022-05-31 11:14:42 -03:00
1 parent b9036901e7
commit ade8911ba6
2 files changed
+51 -40

No files matched your search

+47 -40
View File
@@ -15,7 +15,7 @@ class LimitsPanel(ScreenPanel):
def initialize(self, panel_name):
_ = self.lang.gettext
self.devices = {}
self.limits = {}
scroll = Gtk.ScrolledWindow()
scroll.set_property("overlay-scrolling", False)
@@ -23,32 +23,27 @@ class LimitsPanel(ScreenPanel):
scroll.add_events(Gdk.EventMask.TOUCH_MASK)
scroll.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
# Create a grid for all devices
self.labels['devices'] = Gtk.Grid()
scroll.add(self.labels['devices'])
# Create a box to contain all of the above
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
box.set_vexpand(True)
box.pack_start(scroll, True, True, 0)
# Create a grid for all limits
self.grid = Gtk.Grid()
scroll.add(self.grid)
conf = self._printer.get_config_section("printer")
self.options = [
{"name": _("Max Acceleration"), "units": _("mm/s^2"), "option": "max_accel",
"value": self.stn(conf['max_accel'])},
"max": self.stn(conf['max_accel'])},
{"name": _("Max Acceleration to Deceleration"), "units": _("mm/s^2"), "option": "max_accel_to_decel",
"value": self.stn(conf['max_accel_to_decel']) if "max_accel_to_decel" in conf else
"max": self.stn(conf['max_accel_to_decel']) if "max_accel_to_decel" in conf else
round(self.stn(conf['max_accel'])/2)},
{"name": _("Max Velocity"), "units": _("mm/s"), "option": "max_velocity",
"value": self.stn(conf["max_velocity"])},
"max": self.stn(conf["max_velocity"])},
{"name": _("Square Corner Velocity"), "units": _("mm/s"), "option": "square_corner_velocity",
"value": self.stn(conf['square_corner_velocity']) if "square_corner_velocity" in conf else 5}
"max": self.stn(conf['square_corner_velocity']) if "square_corner_velocity" in conf else 5}
]
for opt in self.options:
self.add_option(opt['option'], opt['name'], opt['units'], opt['value'])
self.add_option(opt['option'], opt['name'], opt['units'], opt['max'])
self.content.add(box)
self.content.add(scroll)
self.content.show_all()
def stn(self, str):
@@ -58,28 +53,31 @@ class LimitsPanel(ScreenPanel):
if (action != "notify_status_update"):
return
for opt in self.devices:
for opt in self.limits:
if "toolhead" in data and opt in data["toolhead"]:
self.update_option(opt, data["toolhead"][opt])
def update_option(self, option, value):
if option not in self.devices:
if option not in self.limits:
return
if self.devices[option]['scale'].has_grab():
if self.limits[option]['scale'].has_grab():
return
self.values[option] = int(value)
self.devices[option]['scale'].disconnect_by_func(self.set_opt_value)
self.devices[option]['scale'].set_value(self.values[option])
self.devices[option]['scale'].connect("button-release-event", self.set_opt_value, option)
self.limits[option]['scale'].disconnect_by_func(self.set_opt_value)
self.limits[option]['scale'].set_value(self.values[option])
for opt in self.options:
if opt["option"] == option:
if self.values[option] > opt["max"]:
self.limits[option]['scale'].get_style_context().add_class("option_slider_max")
else:
self.limits[option]['scale'].get_style_context().remove_class("option_slider_max")
self.limits[option]['scale'].connect("button-release-event", self.set_opt_value, option)
def add_option(self, option, optname, units, value):
logging.info("Adding option: %s" % option)
frame = Gtk.Frame()
frame.get_style_context().add_class("frame-item")
name = Gtk.Label()
name.set_markup("<big><b>%s</b></big> (%s)" % (optname, units))
name.set_hexpand(True)
@@ -89,7 +87,7 @@ class LimitsPanel(ScreenPanel):
name.set_line_wrap(True)
name.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
adj = Gtk.Adjustment(0, 0, value, 1, 5, 0)
adj = Gtk.Adjustment(0, 1, (value * 1.5), 1, 5, 0)
self.values[option] = value
scale = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=adj)
scale.set_value(self.values[option])
@@ -99,30 +97,39 @@ class LimitsPanel(ScreenPanel):
scale.get_style_context().add_class("option_slider")
scale.connect("button-release-event", self.set_opt_value, option)
labels = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
labels.add(name)
labels.add(scale)
reset = self._gtk.ButtonImage("refresh", None, "color1")
reset.connect("clicked", self.reset_value, option)
reset.set_hexpand(False)
dev = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
dev.set_hexpand(True)
dev.set_vexpand(False)
dev.add(labels)
frame.add(dev)
item = Gtk.Grid()
item.attach(name, 0, 0, 2, 1)
item.attach(scale, 0, 1, 1, 1)
item.attach(reset, 1, 1, 1, 1)
self.devices[option] = {
frame = Gtk.Frame()
frame.get_style_context().add_class("frame-item")
frame.add(item)
self.limits[option] = {
"row": frame,
"scale": scale,
}
devices = sorted(self.devices)
pos = devices.index(option)
limits = sorted(self.limits)
pos = limits.index(option)
self.labels['devices'].insert_row(pos)
self.labels['devices'].attach(self.devices[option]['row'], 0, pos, 1, 1)
self.labels['devices'].show_all()
self.grid.insert_row(pos)
self.grid.attach(self.limits[option]['row'], 0, pos, 1, 1)
self.grid.show_all()
def reset_value(self, widget, option):
for x in self.options:
if x["option"] == option:
self.update_option(option, x["max"])
self.set_opt_value(None, None, option)
def set_opt_value(self, widget, event, opt):
value = self.devices[opt]['scale'].get_value()
value = self.limits[opt]['scale'].get_value()
if opt == "max_accel":
self._screen._ws.klippy.gcode_script("SET_VELOCITY_LIMIT ACCEL=%s" % (value))
+4
View File
@@ -472,6 +472,10 @@ popover button {
background-color: rgba(0, 0, 0, 0.5);
}
.option_slider_max trough highlight, trough progress {
background-color: darkred;
}
/* Hardcoded values until creation of dynamic CSS updates */
.graph_label_hidden {padding-left: .9em;} /* .4em on top of normal button padding */
.graph_label_extruder {border-left-width: .4em; border-left-style: solid;}