Add printer limits panel
This commit is contained in:
1 parent
996777a6dd
commit
d7b8f4f1ed
4 files changed
+147
-1
No files matched your search
@@ -140,6 +140,11 @@ icon: z-farther
|
||||
panel: zcalibrate
|
||||
enable: {{ ((printer.bltouch is defined) or (printer.probe is defined)) }}
|
||||
|
||||
[menu __main config limits]
|
||||
name: {{ gettext('Limits') }}
|
||||
icon: fine-tune
|
||||
panel: limits
|
||||
|
||||
[menu __main config network]
|
||||
name: {{ gettext('Network') }}
|
||||
icon: network
|
||||
@@ -201,6 +206,11 @@ name: {{ gettext('Console') }}
|
||||
icon: console
|
||||
panel: console
|
||||
|
||||
[menu __print limits]
|
||||
name: {{ gettext('Limits') }}
|
||||
icon: fine-tune
|
||||
panel: limits
|
||||
|
||||
[menu __print network]
|
||||
name: {{ gettext('Network') }}
|
||||
icon: network
|
||||
|
||||
@@ -168,6 +168,11 @@ class Printer:
|
||||
return []
|
||||
return [i for i in list(self.config) if i.startswith(search)]
|
||||
|
||||
def get_config_section(self, section):
|
||||
if section in self.config:
|
||||
return self.config[section]
|
||||
return False
|
||||
|
||||
def get_config_section(self, section):
|
||||
if section not in self.config:
|
||||
return False
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
import gi
|
||||
import logging
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk, Gdk, GLib, Pango
|
||||
|
||||
from ks_includes.KlippyGcodes import KlippyGcodes
|
||||
from ks_includes.screen_panel import ScreenPanel
|
||||
|
||||
def create_panel(*args):
|
||||
return LimitsPanel(*args)
|
||||
|
||||
|
||||
class LimitsPanel(ScreenPanel):
|
||||
values = {}
|
||||
|
||||
def initialize(self, panel_name):
|
||||
_ = self.lang.gettext
|
||||
self.devices = {}
|
||||
|
||||
scroll = Gtk.ScrolledWindow()
|
||||
scroll.set_property("overlay-scrolling", False)
|
||||
scroll.set_vexpand(True)
|
||||
|
||||
# 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)
|
||||
|
||||
self.options = [
|
||||
{"name": _("Max Accelation"), "units": _("mm/s^2"), "option": "max_accel"},
|
||||
{"name": _("Max Acceleration to Deceleration"), "units": _("mm/s^2"), "option": "max_accel_to_decel"},
|
||||
{"name": _("Max Velocity"), "units": _("mm/s"), "option": "max_velocity"},
|
||||
{"name": _("Square Corner Velocity"), "units": _("mm/s"), "option": "square_corner_velocity"}
|
||||
]
|
||||
|
||||
for opt in self.options:
|
||||
self.add_option(opt['option'], opt['name'], opt['units'])
|
||||
|
||||
self.content.add(box)
|
||||
|
||||
def process_update(self, action, data):
|
||||
if (action != "notify_status_update"):
|
||||
return
|
||||
|
||||
for opt in self.devices:
|
||||
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:
|
||||
return
|
||||
|
||||
if self.devices[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("value-changed", self.set_opt_value, option)
|
||||
|
||||
def add_option(self, option, optname, units):
|
||||
logging.info("Adding option: %s" % option)
|
||||
|
||||
frame = Gtk.Frame()
|
||||
frame.set_property("shadow-type", Gtk.ShadowType.NONE)
|
||||
frame.get_style_context().add_class("frame-item")
|
||||
|
||||
conf = self._printer.get_config_section("printer")
|
||||
if conf is False or option not in conf:
|
||||
return
|
||||
|
||||
value = int(conf[option])
|
||||
|
||||
name = Gtk.Label()
|
||||
name.set_markup("<big><b>%s</b></big>" % (optname))
|
||||
name.set_hexpand(True)
|
||||
name.set_vexpand(True)
|
||||
name.set_halign(Gtk.Align.START)
|
||||
name.set_valign(Gtk.Align.CENTER)
|
||||
name.set_line_wrap(True)
|
||||
name.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
|
||||
|
||||
adj = Gtk.Adjustment(0, 0, value, 1, 5, 0)
|
||||
self.values[option] = value
|
||||
scale = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=adj)
|
||||
scale.set_value(self.values[option])
|
||||
scale.set_digits(0)
|
||||
scale.set_hexpand(True)
|
||||
scale.set_has_origin(True)
|
||||
scale.get_style_context().add_class("option_slider")
|
||||
scale.connect("value-changed", self.set_opt_value, option)
|
||||
|
||||
labels = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
labels.add(name)
|
||||
labels.add(scale)
|
||||
|
||||
dev = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
|
||||
dev.set_hexpand(True)
|
||||
dev.set_vexpand(False)
|
||||
dev.add(labels)
|
||||
frame.add(dev)
|
||||
|
||||
self.devices[option] = {
|
||||
"row": frame,
|
||||
"scale": scale,
|
||||
}
|
||||
|
||||
devices = sorted(self.devices)
|
||||
pos = devices.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()
|
||||
|
||||
def set_opt_value(self, widget, opt):
|
||||
value = self.devices[opt]['scale'].get_value()
|
||||
|
||||
if opt == "max_accel":
|
||||
self._screen._ws.klippy.gcode_script("SET_VELOCITY_LIMIT ACCEL=%s" % (value))
|
||||
elif opt == "max_accel_to_decel":
|
||||
self._screen._ws.klippy.gcode_script("SET_VELOCITY_LIMIT ACCEL_TO_DECEL=%s" % (value))
|
||||
elif opt == "max_velocity":
|
||||
self._screen._ws.klippy.gcode_script("SET_VELOCITY_LIMIT VELOCITY=%s" % (value))
|
||||
elif opt == "square_corner_velocity":
|
||||
self._screen._ws.klippy.gcode_script("SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY=%s" % (value))
|
||||
@@ -254,7 +254,8 @@ class KlipperScreen(Gtk.Window):
|
||||
"idle_timeout": ["state"],
|
||||
"pause_resume": ["is_paused"],
|
||||
"print_stats": ["print_duration", "total_duration", "filament_used", "filename", "state", "message"],
|
||||
"toolhead": ["homed_axes", "estimated_print_time", "print_time", "position", "extruder"],
|
||||
"toolhead": ["homed_axes", "estimated_print_time", "print_time", "position", "extruder",
|
||||
"max_accel", "max_accel_to_decel", "max_velocity", "square_corner_velocity"],
|
||||
"virtual_sdcard": ["file_position", "is_active", "progress"],
|
||||
"webhooks": ["state", "state_message"]
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user