Compare commits

..
14 Commits
Author SHA1 Message Date
alfrix d2d2c82041 feat: camera support, using mpv as backend
it should be able to play any video or stream that mpv itself can handle

close #67 close #129
2022-12-11 09:20:06 -03:00
alfrix 1375c823c9 job_status: clear_file after error 2022-12-11 09:20:06 -03:00
alfrix 74338a7f3e splash: fix power_device appearing if configured in ks.conf but not available in the server 2022-12-11 09:20:06 -03:00
alfrix 778cd84ba8 panels do not call screen.show_all 2022-12-11 09:17:18 -03:00
alfrix a83f499c0c rename graph to heatergraph 2022-12-11 09:17:18 -03:00
alfrix 70d7564a78 shorten _screen.printer to _printer 2022-12-11 09:17:18 -03:00
alfrix f31ae7a829 hide popups from panel initialization
ideally the initialization should not contain this commands but at the moment klipper nor moonraker provide a way to identify the required status
2022-12-11 09:17:18 -03:00
alfrix 701ff35652 installer: if pip fails upgrade and retry once 2022-12-11 09:17:18 -03:00
alfrix 7120c424d4 gtk: resizability
doesn't rescale the fonts or images
2022-12-11 09:17:18 -03:00
alfrix 413e822fa5 screen: separate matchbox-keyboard 2022-12-11 09:17:18 -03:00
alfrix 75c716f9a1 screen: convert state execute into a function since it doesn't depend on self 2022-12-11 09:17:18 -03:00
alfrix 41a8ebf084 print: add move/rename, make delete a visible button close #636 2022-12-11 09:17:18 -03:00
Selim 57ce346d69 Turkish language update (#836) 2022-12-11 08:35:58 -03:00
alfrix 753be13a0c exclude: fix list not showing 2022-12-05 14:29:58 -03:00
30 changed files with 419 additions and 260 deletions

No files matched your search

+3
View File
@@ -90,6 +90,9 @@ screw_rotation: 0
# Define distances and speeds for the extrude panel. CSV list 2 to 4 integers
extrude_distances: 5, 10, 15, 25
extrude_speeds: 1, 2, 5, 25
# Camera configuration
camera_url: http://127.0.0.1/webcam/?action=stream
```
## Preheat Options
+19 -40
View File
@@ -27,44 +27,52 @@ def format_label(widget, lines=2):
class KlippyGtk:
labels = {}
def __init__(self, screen, width, height, theme, cursor, fontsize_type):
def __init__(self, screen):
self.screen = screen
self.width = width
self.height = height
self.themedir = os.path.join(pathlib.Path(__file__).parent.resolve().parent, "styles", theme, "images")
self.cursor = cursor
self.font_size_type = fontsize_type
self.themedir = os.path.join(pathlib.Path(__file__).parent.resolve().parent, "styles", screen.theme, "images")
self.cursor = screen.show_cursor
self.font_size_type = screen._config.get_main_config().get("font_size", "medium")
self.width = screen.width
self.height = screen.height
self.font_ratio = [33, 49] if self.screen.vertical_mode else [43, 29]
self.font_size = min(self.width / self.font_ratio[0], self.height / self.font_ratio[1])
self.img_scale = self.font_size * 2
self.button_image_scale = 1.38
self.bsidescale = .65 # Buttons with image at the side
if fontsize_type == "max":
if self.font_size_type == "max":
self.font_size = self.font_size * 1.2
self.bsidescale = .7
elif fontsize_type == "extralarge":
elif self.font_size_type == "extralarge":
self.font_size = self.font_size * 1.14
self.img_scale = self.img_scale * 0.7
self.bsidescale = 1
elif fontsize_type == "large":
elif self.font_size_type == "large":
self.font_size = self.font_size * 1.09
self.img_scale = self.img_scale * 0.9
self.bsidescale = .8
elif fontsize_type == "small":
elif self.font_size_type == "small":
self.font_size = self.font_size * 0.91
self.bsidescale = .55
self.img_width = self.font_size * 3
self.img_height = self.font_size * 3
self.titlebar_height = self.font_size * 2
logging.info(f"Font size: {self.font_size} ({fontsize_type})")
logging.info(f"Font size: {self.font_size:.1f} ({self.font_size_type})")
if self.screen.vertical_mode:
self.action_bar_width = int(self.width)
self.action_bar_height = int(self.height * .1)
self.content_width = self.width
self.content_height = self.height - self.titlebar_height - self.action_bar_height
else:
self.action_bar_width = int(self.width * .1)
self.action_bar_height = int(self.height)
self.content_width = self.width - self.action_bar_width
self.content_height = self.height - self.titlebar_height
self.keyboard_height = self.content_height * 0.5
if (self.height / self.width) >= 3: # Ultra-tall
self.keyboard_height = self.keyboard_height * 0.5
self.color_list = {} # This is set by screen.py init_style()
for key in self.color_list:
@@ -72,35 +80,6 @@ class KlippyGtk:
rgb = [int(self.color_list[key]['base'][i:i + 2], 16) for i in range(0, 6, 2)]
self.color_list[key]['rgb'] = rgb
def get_action_bar_width(self):
return self.action_bar_width
def get_action_bar_height(self):
return self.action_bar_height
def get_content_width(self):
if self.screen.vertical_mode:
return self.width
return self.width - self.action_bar_width
def get_content_height(self):
if self.screen.vertical_mode:
return self.height - self.titlebar_height - self.action_bar_height
return self.height - self.titlebar_height
def get_font_size(self):
return self.font_size
def get_titlebar_height(self):
return self.titlebar_height
def get_keyboard_height(self):
if (self.height / self.width) >= 3:
# Ultra-tall
return self.get_content_height() * 0.25
else:
return self.get_content_height() * 0.5
def get_temp_color(self, device):
# logging.debug("Color list %s" % self.color_list)
if device not in self.color_list:
+1 -1
View File
@@ -165,7 +165,7 @@ class KlipperScreenConfig:
strs = (
'moonraker_api_key', 'moonraker_host', 'titlebar_name_type',
'screw_positions', 'power_devices', 'titlebar_items', 'z_babystep_values',
'extrude_distances', "extrude_speeds",
'extrude_distances', "extrude_speeds", "camera_url",
)
numbers = (
'moonraker_port', 'move_speed_xy', 'move_speed_z',
+13
View File
@@ -128,6 +128,12 @@ icon: motor-off
method: printer.gcode.script
params: {"script":"M18"}
[menu __main actions camera]
name: {{ gettext('Camera') }}
icon: camera
panel: camera
enable: {{ camera_configured }}
[menu __main actions console]
name: {{ gettext('Console') }}
icon: console
@@ -231,6 +237,13 @@ icon: custom-script
panel: gcode_macros
enable: {{ printer.gcode_macros.count > 0 }}
[menu __print camera]
name: {{ gettext('Camera') }}
icon: camera
panel: camera
enable: {{ camera_configured }}
[menu __print console]
name: {{ gettext('Console') }}
icon: console
Binary file not shown.
@@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-30 18:17-0300\n"
"PO-Revision-Date: 2022-11-30 18:15-0300\n"
"PO-Revision-Date: 2022-12-10 14:52+0300\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: tr\n"
@@ -16,7 +16,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.2.1\n"
"X-Generator: Poedit 3.2\n"
#, python-format
msgid "%s will be updated to version"
@@ -327,7 +327,7 @@ msgid "Invalid"
msgstr "Geçersiz"
msgid "Invalid password"
msgstr ""
msgstr "Geçersiz şifre"
msgid "Invert X"
msgstr "X Ters çevir"
@@ -526,7 +526,7 @@ msgid "Profile Name:"
msgstr "Profil ismi:"
msgid "Provide KlipperScreen.log when asking for help.\n"
msgstr ""
msgstr "Yardım isterken KlipperScreen.log dosyasını sağlayın.\n"
msgid "Quad Gantry Level"
msgstr "Dörtlü Köprü Seviyesi"
-5
View File
@@ -26,8 +26,6 @@ class ScreenPanel:
self.title = title
self.devices = {}
self.active_heaters = []
self.layout = Gtk.Layout()
self.layout.set_size(screen.width, screen.height)
self.content = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.content.get_style_context().add_class("content")
self.content.set_hexpand(True)
@@ -65,9 +63,6 @@ class ScreenPanel:
def menu_item_clicked(self, widget, panel, item):
self._screen.show_panel(panel, item['panel'], item['name'], 1, False)
def show_all(self):
self._screen.show_all()
def load_menu(self, widget, name, title=None):
if f"{name}_menu" not in self.labels:
return
File renamed without changes.
+12 -18
View File
@@ -59,9 +59,8 @@ class BasePanel(ScreenPanel):
else:
self.action_bar.set_hexpand(False)
self.action_bar.set_vexpand(True)
self.action_bar.set_size_request(self._gtk.get_action_bar_width(), self._gtk.get_action_bar_height())
self.action_bar.get_style_context().add_class('action_bar')
self.action_bar.set_size_request(self._gtk.action_bar_width, self._gtk.action_bar_height)
self.action_bar.add(self.control['back'])
self.action_bar.add(self.control['home'])
self.show_back(False)
@@ -88,7 +87,7 @@ class BasePanel(ScreenPanel):
self.control['time_box'].pack_end(self.control['time'], True, True, 10)
self.titlebar = Gtk.Box(spacing=5)
self.titlebar.set_size_request(self._gtk.get_content_width(), self._gtk.get_titlebar_height())
self.titlebar.get_style_context().add_class("title_bar")
self.titlebar.set_valign(Gtk.Align.CENTER)
self.titlebar.add(self.control['temp_box'])
self.titlebar.add(self.titlelbl)
@@ -96,9 +95,6 @@ class BasePanel(ScreenPanel):
# Main layout
self.main_grid = Gtk.Grid()
# To achieve rezisability this needs to be removed
# The main issue is that currently the content doesn't expand correctly
self.main_grid.set_size_request(self._screen.width, self._screen.height)
if self._screen.vertical_mode:
self.main_grid.attach(self.titlebar, 0, 0, 1, 1)
@@ -111,19 +107,17 @@ class BasePanel(ScreenPanel):
self.main_grid.attach(self.titlebar, 1, 0, 1, 1)
self.main_grid.attach(self.content, 1, 1, 1, 1)
# Layout is and content are on screen_panel
self.layout.add(self.main_grid)
self.update_time()
def show_heaters(self, show=True):
try:
for child in self.control['temp_box'].get_children():
self.control['temp_box'].remove(child)
if not show or self._screen.printer.get_temp_store_devices() is None:
if not show or self._printer.get_temp_store_devices() is None:
return
img_size = self._gtk.img_scale * self.bts
for device in self._screen.printer.get_temp_store_devices():
for device in self._printer.get_temp_store_devices():
self.labels[device] = Gtk.Label(label="100º")
self.labels[device].set_ellipsize(Pango.EllipsizeMode.START)
@@ -137,18 +131,18 @@ class BasePanel(ScreenPanel):
nlimit = int(round(log(self._screen.width, 10) * 5 - 10.5))
n = 0
if self._screen.printer.get_tools():
self.current_extruder = self._screen.printer.get_stat("toolhead", "extruder")
if self._printer.get_tools():
self.current_extruder = self._printer.get_stat("toolhead", "extruder")
if self.current_extruder and f"{self.current_extruder}_box" in self.labels:
self.control['temp_box'].add(self.labels[f"{self.current_extruder}_box"])
n += 1
if self._screen.printer.has_heated_bed():
if self._printer.has_heated_bed():
self.control['temp_box'].add(self.labels['heater_bed_box'])
n += 1
# Options in the config have priority
for device in self._screen.printer.get_temp_store_devices():
for device in self._printer.get_temp_store_devices():
# Users can fill the bar if they want
if n >= nlimit + 1:
break
@@ -160,7 +154,7 @@ class BasePanel(ScreenPanel):
break
# If there is enough space fill with heater_generic
for device in self._screen.printer.get_temp_store_devices():
for device in self._printer.get_temp_store_devices():
if n >= nlimit:
break
if device.startswith("heater_generic"):
@@ -172,7 +166,7 @@ class BasePanel(ScreenPanel):
def get_icon(self, device, img_size):
if device.startswith("extruder"):
if self._screen.printer.extrudercount > 1:
if self._printer.extrudercount > 1:
if device == "extruder":
device = "extruder0"
return self._gtk.Image(f"extruder-{device[8:]}", img_size, img_size)
@@ -233,10 +227,10 @@ class BasePanel(ScreenPanel):
if action != "notify_status_update" or self._screen.printer is None:
return
devices = self._screen.printer.get_temp_store_devices()
devices = self._printer.get_temp_store_devices()
if devices is not None:
for device in devices:
temp = self._screen.printer.get_dev_stat(device, "temperature")
temp = self._printer.get_dev_stat(device, "temperature")
if temp is not None and device in self.labels:
name = ""
if not (device.startswith("extruder") or device.startswith("heater_bed")):
+6 -6
View File
@@ -33,7 +33,7 @@ class BedLevelPanel(ScreenPanel):
grid = self._gtk.HomogeneousGrid()
grid.attach(self.buttons['dm'], 0, 0, 1, 1)
if "screws_tilt_adjust" in self._screen.printer.get_config_section_list():
if "screws_tilt_adjust" in self._printer.get_config_section_list():
self.buttons['screws'] = self._gtk.Button("refresh", _("Screws Adjust"), "color4")
self.buttons['screws'].connect("clicked", self.screws_tilt_calculate)
grid.attach(self.buttons['screws'], 0, 1, 1, 1)
@@ -41,7 +41,7 @@ class BedLevelPanel(ScreenPanel):
self.screws = self._get_screws("screws_tilt_adjust")
logging.info(f"screws_tilt_adjust: {self.screws}")
probe = self._screen.printer.get_probe()
probe = self._printer.get_probe()
if probe:
if "x_offset" in probe:
self.x_offset = round(float(probe['x_offset']), 1)
@@ -57,7 +57,7 @@ class BedLevelPanel(ScreenPanel):
self.screws = new_screws
logging.info(f"screws with offset: {self.screws}")
elif "bed_screws" in self._screen.printer.get_config_section_list():
elif "bed_screws" in self._printer.get_config_section_list():
self.screws = self._get_screws("bed_screws")
logging.info(f"bed_screws: {self.screws}")
@@ -262,7 +262,7 @@ class BedLevelPanel(ScreenPanel):
self.buttons[key].set_label(f"{value}")
def go_to_position(self, widget, position):
if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz":
if self._printer.get_stat("toolhead", "homed_axes") != "xyz":
self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME)
logging.debug(f"Going to position: {position}")
script = [
@@ -335,7 +335,7 @@ class BedLevelPanel(ScreenPanel):
def _get_screws(self, config_section_name):
screws = []
config_section = self._screen.printer.get_config_section(config_section_name)
config_section = self._printer.get_config_section(config_section_name)
for item in config_section:
logging.debug(f"{config_section_name}: {config_section[item]}")
result = re.match(r"([\-0-9\.]+)\s*,\s*([\-0-9\.]+)", config_section[item])
@@ -347,7 +347,7 @@ class BedLevelPanel(ScreenPanel):
return sorted(screws, key=lambda s: (float(s[1]), float(s[0])))
def screws_tilt_calculate(self, widget):
if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz":
if self._printer.get_stat("toolhead", "homed_axes") != "xyz":
self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME)
self.response_count = 0
self.buttons['screws'].set_sensitive(False)
+5 -5
View File
@@ -54,11 +54,11 @@ class BedMeshPanel(ScreenPanel):
grid = self._gtk.HomogeneousGrid()
grid.set_row_homogeneous(False)
grid.attach(topbar, 0, 0, 2, 1)
self.labels['map'] = BedMap(self._gtk.get_font_size(), self.active_mesh)
self.labels['map'] = BedMap(self._gtk.font_size, self.active_mesh)
if self._screen.vertical_mode:
grid.attach(self.labels['map'], 0, 2, 2, 1)
grid.attach(scroll, 0, 3, 2, 1)
self.labels['map'].set_size_request(self._gtk.get_content_width(), self._gtk.get_content_height() * .4)
self.labels['map'].set_size_request(self._gtk.content_width, self._gtk.content_height * .4)
else:
grid.attach(self.labels['map'], 0, 2, 1, 1)
grid.attach(scroll, 1, 2, 1, 1)
@@ -68,7 +68,7 @@ class BedMeshPanel(ScreenPanel):
def activate(self):
self.load_meshes()
with contextlib.suppress(KeyError):
self.activate_mesh(self._screen.printer.get_stat("bed_mesh", "profile_name"))
self.activate_mesh(self._printer.get_stat("bed_mesh", "profile_name"))
def activate_mesh(self, profile):
if self.active_mesh is not None:
@@ -268,13 +268,13 @@ class BedMeshPanel(ScreenPanel):
def calibrate_mesh(self, widget):
self._screen.show_popup_message(_("Calibrating"), level=1)
if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz":
if self._printer.get_stat("toolhead", "homed_axes") != "xyz":
self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME)
self._screen._ws.klippy.gcode_script("BED_MESH_CALIBRATE")
# Load zcalibrate to do a manual mesh
if not self._screen.printer.get_probe():
if not self._printer.get_probe():
self.menu_item_clicked(widget, "refresh", {"name": _("Mesh calibrate"), "panel": "zcalibrate"})
def send_clear_mesh(self, widget):
+85
View File
@@ -0,0 +1,85 @@
import mpv
import logging
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
from ks_includes.screen_panel import ScreenPanel
def create_panel(*args):
return CameraPanel(*args)
class CameraPanel(ScreenPanel):
def __init__(self, screen, title):
super().__init__(screen, title)
self.mpv = None
self.da = Gtk.DrawingArea()
self.da.set_hexpand(True)
self.da.set_vexpand(True)
fs = self._gtk.Button("move", _("Fullscreen"), None, self.bts, Gtk.PositionType.LEFT, 1)
fs.connect("clicked", self.play)
fs.set_hexpand(True)
fs.set_vexpand(False)
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
box.add(self.da)
box.add(fs)
self.content.add(box)
self.content.show_all()
self.url = self.ks_printer_cfg.get("camera_url", "http://127.0.0.1/webcam/?action=stream").replace('"', '')
logging.debug(f"Camera URL: {self.url}")
# wayland has no primary monitor with that we can detect it
self.wayland = Gdk.Display.get_default().get_primary_monitor() is None
# gpu output driver doesn't work on a pi3 and the autoselected sdl doesn't size correctly
# consider adding a software switch to enable the gpu backend if set by the user
self.vo = 'x11' if self.wayland else 'wlshm'
def activate(self):
self.play()
def deactivate(self):
if self.mpv:
self.mpv.terminate()
self.mpv = None
def play(self, fs=None):
# Create mpv after show or the 'window' property will be None
self.mpv = mpv.MPV(
log_handler=self.log,
vo=self.vo,
profile='sw-fast',
)
# On wayland mpv cannot be embedded at least for now
# https://github.com/mpv-player/mpv/issues/9654
if fs or self.wayland:
self.mpv.fullscreen = True
@self.mpv.on_key_press('MBTN_LEFT' or 'MBTN_LEFT_DBL')
def clicked():
self.mpv.quit(0)
else:
self.mpv.wid = f'{self.da.get_property("window").get_xid()}'
@self.mpv.on_key_press('MBTN_LEFT' or 'MBTN_LEFT_DBL')
def clicked():
self._screen.show_popup_message(self.url, level=1)
self.mpv.play(self.url)
if fs or self.wayland:
try:
self.mpv.wait_for_playback()
except mpv.ShutdownError:
logging.info('Exiting Fullscreen')
except Exception as e:
logging.exception(e)
self.mpv.terminate()
self.mpv = None
if self.wayland:
self._screen._menu_go_back()
else:
self.play()
@staticmethod
def log(loglevel, component, message):
logging.debug(f'[{loglevel}] {component}: {message}')
+4 -3
View File
@@ -43,18 +43,18 @@ class ExcludeObjectPanel(ScreenPanel):
grid.attach(Gtk.Separator(), 0, 1, 2, 1)
if self.objects and "polygon" in self.objects[0]:
self.labels['map'] = ObjectMap(self._screen, self._printer, self._gtk.get_font_size())
self.labels['map'] = ObjectMap(self._screen, self._printer, self._gtk.font_size)
if self._screen.vertical_mode:
grid.attach(self.labels['map'], 0, 2, 2, 1)
grid.attach(scroll, 0, 3, 2, 1)
scroll.set_size_request(self._gtk.get_content_width(), -1)
scroll.set_size_request(self._gtk.content_width, -1)
else:
grid.attach(self.labels['map'], 0, 2, 1, 1)
grid.attach(scroll, 1, 2, 1, 1)
scroll.set_size_request((self._screen.width * .9) // 2, -1)
else:
grid.attach(scroll, 0, 2, 2, 1)
scroll.set_size_request(self._gtk.get_content_width(), -1)
scroll.set_size_request(self._gtk.content_width, -1)
self.content.add(grid)
self.content.show_all()
@@ -102,6 +102,7 @@ class ExcludeObjectPanel(ScreenPanel):
for obj in self.objects:
logging.info(f"Adding {obj['name']}")
self.add_object(obj["name"])
self.content.show_all()
with contextlib.suppress(KeyError):
# Update current objects
if data["exclude_object"]["current_object"]:
+3 -3
View File
@@ -19,7 +19,7 @@ class ExtrudePanel(ScreenPanel):
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()
macros = self._printer.get_gcode_macros()
self.load_filament = any("LOAD_FILAMENT" in macro.upper() for macro in macros)
self.unload_filament = any("UNLOAD_FILAMENT" in macro.upper() for macro in macros)
@@ -134,8 +134,8 @@ class ExtrudePanel(ScreenPanel):
self.labels[x]['label'].set_halign(Gtk.Align.CENTER)
self.labels[x]['label'].set_hexpand(True)
self.labels[x]['label'].set_ellipsize(Pango.EllipsizeMode.END)
self.labels[x]['switch'].set_property("width-request", round(self._gtk.get_font_size() * 2))
self.labels[x]['switch'].set_property("height-request", round(self._gtk.get_font_size()))
self.labels[x]['switch'].set_property("width-request", round(self._gtk.font_size * 2))
self.labels[x]['switch'].set_property("height-request", round(self._gtk.font_size))
self.labels[x]['switch'].connect("notify::active", self.enable_disable_fs, name, x)
self.labels[x]['box'].pack_start(self.labels[x]['label'], True, True, 5)
self.labels[x]['box'].pack_start(self.labels[x]['switch'], False, False, 5)
+2 -2
View File
@@ -165,8 +165,8 @@ class MacroPanel(ScreenPanel):
switch.set_vexpand(False)
switch.set_active(self._config.get_config().getboolean(option['section'], opt_name, fallback=True))
switch.connect("notify::active", self.switch_config_option, option['section'], opt_name)
switch.set_property("width-request", round(self._gtk.get_font_size() * 7))
switch.set_property("height-request", round(self._gtk.get_font_size() * 3.5))
switch.set_property("width-request", round(self._gtk.font_size * 7))
switch.set_property("height-request", round(self._gtk.font_size * 3.5))
box.add(switch)
dev = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
+4 -10
View File
@@ -113,7 +113,7 @@ class InputShaperPanel(ScreenPanel):
def start_calibration(self, widget, method):
self.labels['popover'].popdown()
if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz":
if self._printer.get_stat("toolhead", "homed_axes") != "xyz":
self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME)
self.calibrating_axis = method
if method == "x":
@@ -152,17 +152,11 @@ class InputShaperPanel(ScreenPanel):
def activate(self):
# This will return the current values
self._screen._ws.klippy.gcode_script(
'SET_INPUT_SHAPER'
)
self._screen._ws.klippy.gcode_script('SET_INPUT_SHAPER')
# Check for the accelerometer
self._screen._ws.klippy.gcode_script(
'ACCELEROMETER_QUERY'
)
self._screen._ws.klippy.gcode_script('ACCELEROMETER_QUERY')
# Send at least two commands, with my accelerometer the first command after a reboot will fail
self._screen._ws.klippy.gcode_script(
'MEASURE_AXES_NOISE'
)
self._screen._ws.klippy.gcode_script('MEASURE_AXES_NOISE')
def process_update(self, action, data):
if action != "notify_gcode_response":
+18 -15
View File
@@ -122,7 +122,7 @@ class JobStatusPanel(ScreenPanel):
self.labels['thumbnail'] = self._gtk.Image("file", self._screen.width / 4, self._screen.height / 4)
self.labels['info_grid'] = Gtk.Grid()
self.labels['info_grid'].attach(self.labels['thumbnail'], 0, 0, 1, 1)
if self._screen.printer.get_tools():
if self._printer.get_tools():
self.current_extruder = self._printer.get_stat("toolhead", "extruder")
diameter = float(self._printer.get_config_section(self.current_extruder)['filament_diameter'])
self.fila_section = pi * ((diameter / 2) ** 2)
@@ -159,7 +159,7 @@ class JobStatusPanel(ScreenPanel):
nlimit = 2 if self._screen.width <= 480 else 3
n = 0
self.buttons['extruder'] = {}
if self._screen.printer.get_tools():
if self._printer.get_tools():
for i, extruder in enumerate(self._printer.get_tools()):
self.labels[extruder] = Gtk.Label("-")
self.buttons['extruder'][extruder] = self._gtk.Button(f"extruder-{i}", "", None, self.bts,
@@ -183,7 +183,7 @@ class JobStatusPanel(ScreenPanel):
self.buttons['heater']['heater_bed'].set_halign(Gtk.Align.START)
self.labels['temp_grid'].attach(self.buttons['heater']['heater_bed'], n, 0, 1, 1)
n += 1
for dev in self._screen.printer.get_heaters():
for dev in self._printer.get_heaters():
if n >= nlimit:
break
if dev.startswith("heater_generic"):
@@ -201,7 +201,7 @@ class JobStatusPanel(ScreenPanel):
if titlebar_items is not None:
titlebar_items = [str(i.strip()) for i in titlebar_items.split(',')]
logging.info(f"Titlebar items: {titlebar_items}")
for device in self._screen.printer.get_heaters():
for device in self._printer.get_heaters():
if device.startswith("temperature_sensor"):
name = " ".join(device.split(" ")[1:])
for item in titlebar_items:
@@ -227,9 +227,9 @@ class JobStatusPanel(ScreenPanel):
szfe.set_column_homogeneous(True)
szfe.attach(self.buttons['speed'], 0, 0, 3, 1)
szfe.attach(self.buttons['z'], 2, 0, 2, 1)
if self._screen.printer.get_tools():
if self._printer.get_tools():
szfe.attach(self.buttons['extrusion'], 0, 1, 3, 1)
if self._screen.printer.get_fans():
if self._printer.get_fans():
szfe.attach(self.buttons['fan'], 2, 1, 2, 1)
info = Gtk.Grid()
@@ -340,7 +340,7 @@ class JobStatusPanel(ScreenPanel):
r = min(w, h) * .42
ctx.set_source_rgb(0.13, 0.13, 0.13)
ctx.set_line_width(self._gtk.get_font_size() * .75)
ctx.set_line_width(self._gtk.font_size * .75)
ctx.translate(w / 2, h / 2)
ctx.arc(0, 0, r, 0, 2 * pi)
ctx.stroke()
@@ -422,6 +422,9 @@ class JobStatusPanel(ScreenPanel):
def restart(self, widget):
if self.filename != "none":
if self.state == "error":
script = {"script": "SDCARD_RESET_FILE"}
self._screen._send_action(None, "printer.gcode.script", script)
self._screen._ws.klippy.print_start(self.filename)
self.new_print()
@@ -583,7 +586,7 @@ class JobStatusPanel(ScreenPanel):
fan_label = ""
for fan in self.fans:
with contextlib.suppress(KeyError):
self.fans[fan]['speed'] = f"{self._screen.printer.get_fan_speed(fan) * 100:3.0f}%"
self.fans[fan]['speed'] = f"{self._printer.get_fan_speed(fan) * 100:3.0f}%"
fan_label += f" {self.fans[fan]['name']}{self.fans[fan]['speed']}"
if fan_label:
self.buttons['fan'].set_label(fan_label[:12])
@@ -742,16 +745,16 @@ class JobStatusPanel(ScreenPanel):
self.enable_button("resume", "cancel")
self.can_close = False
else:
offset = self._screen.printer.get_stat("gcode_move", "homing_origin")
offset = self._printer.get_stat("gcode_move", "homing_origin")
self.zoffset = float(offset[2]) if offset else 0
if self.zoffset != 0:
endstop = (self._screen.printer.config_section_exists("stepper_z") and
not self._screen.printer.get_config_section("stepper_z")['endstop_pin'].startswith("probe"))
endstop = (self._printer.config_section_exists("stepper_z") and
not self._printer.get_config_section("stepper_z")['endstop_pin'].startswith("probe"))
if endstop:
self.buttons['button_grid'].attach(self.buttons["save_offset_endstop"], 0, 0, 1, 1)
else:
self.buttons['button_grid'].attach(Gtk.Label(""), 0, 0, 1, 1)
if self._screen.printer.get_probe():
if self._printer.get_probe():
self.buttons['button_grid'].attach(self.buttons["save_offset_probe"], 1, 0, 1, 1)
else:
self.buttons['button_grid'].attach(Gtk.Label(""), 1, 0, 1, 1)
@@ -764,7 +767,7 @@ class JobStatusPanel(ScreenPanel):
if self.state != "cancelling":
self.buttons['button_grid'].attach(self.buttons['menu'], 3, 0, 1, 1)
self.can_close = True
self.show_all()
self.content.show_all()
def show_file_thumbnail(self):
if self._files.has_thumbnail(self.filename):
@@ -773,7 +776,7 @@ class JobStatusPanel(ScreenPanel):
height = self._screen.height / 4
else:
width = self._screen.width / 3
height = self._gtk.get_content_height() * 0.47
height = self._gtk.content_height * 0.47
pixbuf = self.get_file_image(self.filename, width, height)
if pixbuf is not None:
self.labels['thumbnail'].set_from_pixbuf(pixbuf)
@@ -785,7 +788,7 @@ class JobStatusPanel(ScreenPanel):
"complete": self.labels['file'].get_label(),
"current": self.labels['file'].get_label(),
"position": 0,
"limit": (self._screen.width * 37 / 480) // (self._gtk.get_font_size() / 11),
"limit": (self._screen.width * 37 / 480) // (self._gtk.font_size / 11),
"length": len(self.labels['file'].get_label())
}
if self.animation_timeout is None and (self.filename_label['length'] - self.filename_label['limit']) > 0:
+3 -4
View File
@@ -6,7 +6,7 @@ gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib
from panels.menu import MenuPanel
from ks_includes.widgets.graph import HeaterGraph
from ks_includes.widgets.heatergraph import HeaterGraph
from ks_includes.widgets.keypad import Keypad
@@ -47,7 +47,6 @@ class MainPanel(MenuPanel):
grid.attach(self.labels['menu'], 1, 0, 1, 1)
self.grid = grid
self.content.add(self.grid)
self.layout.show_all()
def update_graph_visibility(self):
if self.left_panel is None or not self._printer.get_temp_store_devices():
@@ -209,12 +208,12 @@ class MainPanel(MenuPanel):
name = Gtk.Label("")
temp = Gtk.Label(_("Temp (°C)"))
temp.set_size_request(self._gtk.font_size * 6, -1)
temp.get_style_context().add_class("heater-grid-temp")
self.labels['devices'].attach(name, 0, 0, 1, 1)
self.labels['devices'].attach(temp, 1, 0, 1, 1)
self.labels['da'] = HeaterGraph(self._printer, self._gtk.get_font_size())
self.labels['da'] = HeaterGraph(self._printer, self._gtk.font_size)
self.labels['da'].set_vexpand(True)
scroll = self._gtk.ScrolledWindow()
+2 -5
View File
@@ -31,10 +31,6 @@ class MenuPanel(ScreenPanel):
self.content.add(scroll)
def activate(self):
self.j2_data = self._printer.get_printer_status_data()
self.j2_data.update({
'moonraker_connected': self._screen._ws.connected
})
if self._screen.vertical_mode:
self.arrangeMenuItems(self.items, 3)
else:
@@ -99,7 +95,8 @@ class MenuPanel(ScreenPanel):
if enable == "{{ moonraker_connected }}":
logging.info(f"moonraker connected {self._screen._ws.connected}")
return self._screen._ws.connected
elif enable == "{{ camera_configured }}":
return self.ks_printer_cfg.get("camera_url", None) is not None
self.j2_data = self._printer.get_printer_status_data()
try:
j2_temp = Template(enable, autoescape=True)
+4 -4
View File
@@ -82,7 +82,7 @@ class MovePanel(ScreenPanel):
grid.attach(self.buttons['z_tilt'], 2, 0, 1, 1)
elif self._printer.config_section_exists("quad_gantry_level"):
grid.attach(self.buttons['quad_gantry_level'], 2, 0, 1, 1)
elif "delta" in self._screen.printer.get_config_section("printer")['kinematics']:
elif "delta" in self._printer.get_config_section("printer")['kinematics']:
grid.attach(self.buttons['motors_off'], 2, 0, 1, 1)
else:
grid.attach(self.buttons['home_xy'], 2, 0, 1, 1)
@@ -164,7 +164,7 @@ class MovePanel(ScreenPanel):
return
if action != "notify_status_update":
return
homed_axes = self._screen.printer.get_stat("toolhead", "homed_axes")
homed_axes = self._printer.get_stat("toolhead", "homed_axes")
if homed_axes == "xyz":
if "gcode_move" in data and "gcode_position" in data["gcode_move"]:
self.labels['pos_x'].set_text(f"X: {data['gcode_move']['gcode_position'][0]:.2f}")
@@ -233,8 +233,8 @@ class MovePanel(ScreenPanel):
switch.set_vexpand(False)
switch.set_active(self._config.get_config().getboolean(option['section'], opt_name))
switch.connect("notify::active", self.switch_config_option, option['section'], opt_name)
switch.set_property("width-request", round(self._gtk.get_font_size() * 7))
switch.set_property("height-request", round(self._gtk.get_font_size() * 3.5))
switch.set_property("width-request", round(self._gtk.font_size * 7))
switch.set_property("height-request", round(self._gtk.font_size * 3.5))
box.add(switch)
dev.add(box)
elif option['type'] == "scale":
-1
View File
@@ -166,7 +166,6 @@ class NetworkPanel(ScreenPanel):
delete = self._gtk.Button("delete", style="color3")
delete.connect("clicked", self.remove_wifi_network, ssid)
delete.set_size_request(60, 0)
delete.set_hexpand(False)
delete.set_halign(Gtk.Align.END)
+6 -6
View File
@@ -30,10 +30,10 @@ class PowerPanel(ScreenPanel):
self.content.add(scroll)
def activate(self):
devices = self._screen.printer.get_power_devices()
devices = self._printer.get_power_devices()
for x in devices:
self.devices[x]['switch'].disconnect_by_func(self.on_switch)
self.devices[x]['switch'].set_active(self._screen.printer.get_power_device_status(x) == "on")
self.devices[x]['switch'].set_active(self._printer.get_power_device_status(x) == "on")
self.devices[x]['switch'].connect("notify::active", self.on_switch, x)
@@ -49,10 +49,10 @@ class PowerPanel(ScreenPanel):
switch = Gtk.Switch()
switch.set_hexpand(False)
switch.set_active(self._screen.printer.get_power_device_status(device) == "on")
switch.set_active(self._printer.get_power_device_status(device) == "on")
switch.connect("notify::active", self.on_switch, device)
switch.set_property("width-request", round(self._gtk.get_font_size() * 7))
switch.set_property("height-request", round(self._gtk.get_font_size() * 3.5))
switch.set_property("width-request", round(self._gtk.font_size * 7))
switch.set_property("height-request", round(self._gtk.font_size * 3.5))
labels = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
labels.add(name)
@@ -77,7 +77,7 @@ class PowerPanel(ScreenPanel):
self.labels['devices'].show_all()
def load_power_devices(self):
devices = self._screen.printer.get_power_devices()
devices = self._printer.get_power_devices()
for x in devices:
self.add_device(x)
+103 -35
View File
@@ -37,6 +37,7 @@ class PrintPanel(ScreenPanel):
self.directories = {}
self.labels['directories'] = {}
self.labels['files'] = {}
self.source = ""
self.time_24 = self._config.get_main_config().getboolean("24htime", True)
logging.info(f"24h time is {self.time_24}")
@@ -62,23 +63,25 @@ class PrintPanel(ScreenPanel):
pbox.add(self.labels['path'])
self.labels['path_box'] = pbox
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
box.set_vexpand(True)
box.pack_start(sbox, False, False, 0)
box.pack_start(pbox, False, False, 0)
box.pack_start(self.scroll, True, True, 0)
self.main = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
self.main.set_vexpand(True)
self.main.pack_start(sbox, False, False, 0)
self.main.pack_start(pbox, False, False, 0)
self.main.pack_start(self.scroll, True, True, 0)
self.dir_panels['gcodes'] = Gtk.Grid()
GLib.idle_add(self.reload_files)
self.scroll.add(self.dir_panels['gcodes'])
self.content.add(box)
self.content.add(self.main)
self._screen.files.add_file_callback(self._callback)
self.showing_rename = False
def activate(self):
if self.cur_directory != "gcodes":
self.change_dir(None, "gcodes")
self._refresh_files()
def add_directory(self, directory, show=True):
parent_dir = os.path.dirname(directory)
@@ -126,8 +129,10 @@ class PrintPanel(ScreenPanel):
if self.time_24:
time = f':<b> {datetime.fromtimestamp(fileinfo["modified"]):%Y-%m-%d %H:%M}</b>'
else:
time = f':<b> {datetime.fromtimestamp(fileinfo["modified"]):%Y-%m-%d %I:%M %p}<b>'
self.labels['directories'][curdir]['info'].set_markup(_("Modified") + time)
time = f':<b> {datetime.fromtimestamp(fileinfo["modified"]):%Y-%m-%d %I:%M %p}</b>'
info = _("Modified") + time
info += "\n" + _("Size") + f':<b> {self.format_size(fileinfo["size"])}</b>'
self.labels['directories'][curdir]['info'].set_markup(info)
self.filelist[directory]['files'].append(filename)
if filepath not in self.files:
@@ -160,49 +165,59 @@ class PrintPanel(ScreenPanel):
name.set_line_wrap_mode(Pango.WrapMode.CHAR)
info = Gtk.Label()
info.set_hexpand(True)
info.set_halign(Gtk.Align.START)
info.get_style_context().add_class("print-info")
labels = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
labels.add(name)
labels.add(info)
labels.set_vexpand(True)
labels.set_valign(Gtk.Align.CENTER)
labels.set_halign(Gtk.Align.START)
delete = self._gtk.Button("delete", style="color1", scale=self.bts)
delete.set_hexpand(False)
rename = self._gtk.Button("files", style="color2", scale=self.bts)
rename.set_hexpand(False)
actions = self._gtk.Button("load", style="color3")
actions.set_hexpand(False)
actions.set_halign(Gtk.Align.END)
if filename:
action = self._gtk.Button("print", style="color3")
action.connect("clicked", self.confirm_print, fullpath)
info.set_markup(self.get_file_info_str(fullpath))
actions.connect("clicked", self.confirm_print, fullpath)
icon = Gtk.Button()
icon.connect("clicked", self.confirm_delete_file, f"gcodes/{fullpath}")
icon.connect("clicked", self.confirm_print, fullpath)
delete.connect("clicked", self.confirm_delete_file, f"gcodes/{fullpath}")
rename.connect("clicked", self.show_rename, f"gcodes/{fullpath}")
GLib.idle_add(self.image_load, fullpath)
else:
actions.connect("clicked", self.change_dir, fullpath)
action = self._gtk.Button("load", style="color3")
action.connect("clicked", self.change_dir, fullpath)
icon = self._gtk.Button("folder")
icon.connect("clicked", self.confirm_delete_directory, fullpath)
icon.connect("clicked", self.change_dir, fullpath)
delete.connect("clicked", self.confirm_delete_directory, fullpath)
rename.connect("clicked", self.show_rename, fullpath)
icon.set_hexpand(False)
action.set_hexpand(False)
action.set_halign(Gtk.Align.END)
delete.connect("clicked", self.confirm_delete_file, f"gcodes/{fullpath}")
row = Gtk.Grid()
row.get_style_context().add_class("frame-item")
row.set_hexpand(True)
row.set_vexpand(False)
row.attach(icon, 0, 0, 1, 2)
row.attach(name, 1, 0, 3, 1)
row.attach(info, 1, 1, 1, 1)
row.attach(rename, 2, 1, 1, 1)
row.attach(delete, 3, 1, 1, 1)
file = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
file.get_style_context().add_class("frame-item")
file.set_hexpand(True)
file.set_vexpand(False)
file.add(icon)
file.add(labels)
if not filename or (filename and os.path.splitext(filename)[1] in [".gcode", ".g", ".gco"]):
file.add(actions)
row.attach(action, 4, 0, 1, 2)
if filename is not None:
self.files[fullpath] = file
self.files[fullpath] = row
self.labels['files'][fullpath] = {
"icon": icon,
"info": info,
"name": name
}
else:
self.directories[fullpath] = file
self.directories[fullpath] = row
self.labels['directories'][fullpath] = {
"info": info,
"name": name
@@ -237,6 +252,9 @@ class PrintPanel(ScreenPanel):
)
def back(self):
if self.showing_rename:
self.hide_rename()
return True
if os.path.dirname(self.cur_directory):
self.change_dir(None, os.path.dirname(self.cur_directory))
return True
@@ -388,10 +406,60 @@ class PrintPanel(ScreenPanel):
for file in updatedfiles:
self.update_file(file)
def _refresh_files(self, widget):
def _refresh_files(self, widget=None):
self._files.refresh_files()
def process_update(self, action, data):
if action == "notify_gcode_response" and "unknown" in data.lower():
self._screen.show_popup_message(data)
return
def show_rename(self, widget, fullpath):
self.source = fullpath
logging.info(self.source)
for child in self.content.get_children():
self.content.remove(child)
if "rename_file" not in self.labels:
lbl = self._gtk.Label(_("Rename/Move:"))
lbl.set_halign(Gtk.Align.START)
lbl.set_hexpand(False)
self.labels['new_name'] = Gtk.Entry()
self.labels['new_name'].set_text(fullpath)
self.labels['new_name'].set_hexpand(True)
self.labels['new_name'].connect("activate", self.rename)
self.labels['new_name'].connect("focus-in-event", self._screen.show_keyboard)
save = self._gtk.Button("complete", _("Save"), "color3")
save.set_hexpand(False)
save.connect("clicked", self.rename)
box = Gtk.Box()
box.pack_start(self.labels['new_name'], True, True, 5)
box.pack_start(save, False, False, 5)
self.labels['rename_file'] = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)
self.labels['rename_file'].set_valign(Gtk.Align.CENTER)
self.labels['rename_file'].set_hexpand(True)
self.labels['rename_file'].set_vexpand(True)
self.labels['rename_file'].pack_start(lbl, True, True, 5)
self.labels['rename_file'].pack_start(box, True, True, 5)
self.content.add(self.labels['rename_file'])
self.labels['new_name'].set_text(fullpath[7:])
self.labels['new_name'].grab_focus_without_selecting()
self.showing_rename = True
def hide_rename(self):
self._screen.remove_keyboard()
for child in self.content.get_children():
self.content.remove(child)
self.content.add(self.main)
self.content.show()
self.showing_rename = False
def rename(self, widget):
params = {"source": self.source, "dest": f"gcodes/{self.labels['new_name'].get_text()}"}
self._screen._send_action(
widget,
"server.files.move",
params
)
self.back()
GLib.timeout_add_seconds(2, self._refresh_files)
+6 -6
View File
@@ -17,7 +17,7 @@ class SplashScreenPanel(ScreenPanel):
def __init__(self, screen, title):
super().__init__(screen, title)
image = self._gtk.Image("klipper", self._gtk.get_content_width() * .2, self._gtk.get_content_height() * .5)
image = self._gtk.Image("klipper", self._gtk.content_width * .2, self._gtk.content_height * .5)
self.labels['text'] = Gtk.Label(_("Initializing printer..."))
self.labels['text'].set_line_wrap(True)
self.labels['text'].set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
@@ -42,7 +42,7 @@ class SplashScreenPanel(ScreenPanel):
self.labels['actions'].set_vexpand(False)
self.labels['actions'].set_halign(Gtk.Align.CENTER)
self.labels['actions'].set_homogeneous(True)
self.labels['actions'].set_size_request(self._gtk.get_content_width(), -1)
self.labels['actions'].set_size_request(self._gtk.content_width, -1)
scroll = self._gtk.ScrolledWindow()
scroll.set_hexpand(True)
@@ -74,7 +74,7 @@ class SplashScreenPanel(ScreenPanel):
self.clear_action_bar()
if self.ks_printer_cfg is not None and self._screen._ws.connected:
power_devices = self.ks_printer_cfg.get("power_devices", "")
if power_devices:
if power_devices and self._printer.get_power_devices():
logging.info(f"Associated power devices: {power_devices}")
self.add_power_button(power_devices)
@@ -103,13 +103,13 @@ class SplashScreenPanel(ScreenPanel):
def check_power_status(self):
if 'power' in self.labels:
devices = self._screen.printer.get_power_devices()
devices = self._printer.get_power_devices()
if devices is not None:
for device in devices:
if self._screen.printer.get_power_device_status(device) == "off":
if self._printer.get_power_device_status(device) == "off":
self.labels['power'].set_sensitive(True)
break
elif self._screen.printer.get_power_device_status(device) == "on":
elif self._printer.get_power_device_status(device) == "on":
self.labels['power'].set_sensitive(False)
def firmware_restart(self, widget):
+4 -5
View File
@@ -7,7 +7,7 @@ gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib
from ks_includes.screen_panel import ScreenPanel
from ks_includes.widgets.graph import HeaterGraph
from ks_includes.widgets.heatergraph import HeaterGraph
from ks_includes.widgets.keypad import Keypad
@@ -43,7 +43,7 @@ class TemperaturePanel(ScreenPanel):
self.show_preheat = True
selection.extend(self._printer.get_heaters())
else:
current_extruder = self._screen.printer.get_stat("toolhead", "extruder")
current_extruder = self._printer.get_stat("toolhead", "extruder")
if current_extruder:
selection.append(current_extruder)
@@ -64,7 +64,6 @@ class TemperaturePanel(ScreenPanel):
self.grid.attach(self.create_right_panel(), 1, 0, 1, 1)
self.content.add(self.grid)
self.layout.show_all()
def create_right_panel(self):
cooldown = self._gtk.Button('cool-down', _('Cooldown'), "color4", self.bts, Gtk.PositionType.LEFT, 1)
@@ -428,12 +427,12 @@ class TemperaturePanel(ScreenPanel):
name = Gtk.Label("")
temp = Gtk.Label(_("Temp (°C)"))
temp.set_size_request(self._gtk.font_size * 6, -1)
temp.get_style_context().add_class("heater-grid-temp")
self.labels['devices'].attach(name, 0, 0, 1, 1)
self.labels['devices'].attach(temp, 1, 0, 1, 1)
self.labels['da'] = HeaterGraph(self._printer, self._gtk.get_font_size())
self.labels['da'] = HeaterGraph(self._printer, self._gtk.font_size)
self.labels['da'].set_vexpand(True)
scroll = self._gtk.ScrolledWindow()
+10 -10
View File
@@ -21,7 +21,7 @@ class ZCalibratePanel(ScreenPanel):
def __init__(self, screen, title):
super().__init__(screen, title)
self.z_offset = None
self.probe = self._screen.printer.get_probe()
self.probe = self._printer.get_probe()
if self.probe:
self.z_offset = float(self.probe['z_offset'])
logging.info(f"Z offset: {self.z_offset}")
@@ -51,7 +51,7 @@ class ZCalibratePanel(ScreenPanel):
functions = []
pobox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
if self._printer.config_section_exists("stepper_z") \
and not self._screen.printer.get_config_section("stepper_z")['endstop_pin'].startswith("probe"):
and not self._printer.get_config_section("stepper_z")['endstop_pin'].startswith("probe"):
self._add_button("Endstop", "endstop", pobox)
functions.append("endstop")
if self.probe:
@@ -61,7 +61,7 @@ class ZCalibratePanel(ScreenPanel):
# This is used to do a manual bed mesh if there is no probe
self._add_button("Bed mesh", "mesh", pobox)
functions.append("mesh")
if "delta" in self._screen.printer.get_config_section("printer")['kinematics']:
if "delta" in self._printer.get_config_section("printer")['kinematics']:
if "probe" in functions:
self._add_button("Delta Automatic", "delta", pobox)
functions.append("delta")
@@ -132,7 +132,7 @@ class ZCalibratePanel(ScreenPanel):
def start_calibration(self, widget, method):
self.labels['popover'].popdown()
if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz":
if self._printer.get_stat("toolhead", "homed_axes") != "xyz":
self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME)
if method == "probe":
@@ -166,8 +166,8 @@ class ZCalibratePanel(ScreenPanel):
speed = self.probe['speed']
# Use safe_z_home position
if "safe_z_home" in self._screen.printer.get_config_section_list():
safe_z = self._screen.printer.get_config_section("safe_z_home")
if "safe_z_home" in self._printer.get_config_section_list():
safe_z = self._printer.get_config_section("safe_z_home")
safe_z_xy = safe_z['home_xy_position']
safe_z_xy = [str(i.strip()) for i in safe_z_xy.split(',')]
if x_position is None:
@@ -188,7 +188,7 @@ class ZCalibratePanel(ScreenPanel):
if x_position is not None and y_position is not None:
logging.debug(f"Configured probing position X: {x_position} Y: {y_position}")
self._screen._ws.klippy.gcode_script(f'G0 X{x_position} Y{y_position} F3000')
elif "delta" in self._screen.printer.get_config_section("printer")['kinematics']:
elif "delta" in self._printer.get_config_section("printer")['kinematics']:
logging.info("Detected delta kinematics calibrating at 0,0")
self._screen._ws.klippy.gcode_script('G0 X0 Y0 F3000')
else:
@@ -197,8 +197,8 @@ class ZCalibratePanel(ScreenPanel):
def _calculate_position(self):
logging.debug("Position not configured, probing the middle of the bed")
try:
xmax = float(self._screen.printer.get_config_section("stepper_x")['position_max'])
ymax = float(self._screen.printer.get_config_section("stepper_y")['position_max'])
xmax = float(self._printer.get_config_section("stepper_x")['position_max'])
ymax = float(self._printer.get_config_section("stepper_y")['position_max'])
except KeyError:
logging.error("Couldn't get max position from stepper_x and stepper_y")
return
@@ -231,7 +231,7 @@ class ZCalibratePanel(ScreenPanel):
self.process_busy(data)
return
if action == "notify_status_update":
if self._screen.printer.get_stat("toolhead", "homed_axes") != "xyz":
if self._printer.get_stat("toolhead", "homed_axes") != "xyz":
self.widgets['zposition'].set_text("Z: ?")
elif "gcode_move" in data and "gcode_position" in data['gcode_move']:
self.update_position(data['gcode_move']['gcode_position'])
+68 -63
View File
@@ -66,6 +66,10 @@ def set_text_direction(lang=None):
return True
def state_execute(callback):
callback()
class KlipperScreen(Gtk.Window):
""" Class for creating a screen for Klipper via HDMI """
_cur_panels = []
@@ -106,6 +110,7 @@ class KlipperScreen(Gtk.Window):
self.lang_ltr = set_text_direction(self._config.get_main_config().get("language", None))
self.connect("key-press-event", self._key_press_event)
self.connect("configure_event", self.update_size)
monitor = Gdk.Display.get_default().get_primary_monitor()
if monitor is None:
monitor = Gdk.Display.get_default().get_monitor(0)
@@ -114,22 +119,21 @@ class KlipperScreen(Gtk.Window):
self.width = self._config.get_main_config().getint("width", monitor.get_geometry().width)
self.height = self._config.get_main_config().getint("height", monitor.get_geometry().height)
self.set_default_size(self.width, self.height)
self.set_resizable(False)
self.set_resizable(True)
if not (self._config.get_main_config().get("width") or self._config.get_main_config().get("height")):
self.fullscreen()
self.vertical_mode = self.width < self.height
logging.info(f"Screen resolution: {self.width}x{self.height}")
self.theme = self._config.get_main_config().get('theme')
show_cursor = self._config.get_main_config().getboolean("show_cursor", fallback=False)
self.gtk = KlippyGtk(self, self.width, self.height, self.theme, show_cursor,
self._config.get_main_config().get("font_size", "medium"))
self.show_cursor = self._config.get_main_config().getboolean("show_cursor", fallback=False)
self.gtk = KlippyGtk(self)
self.init_style()
self.set_icon_from_file(os.path.join(klipperscreendir, "styles", "icon.svg"))
self.base_panel = BasePanel(self, title="Base Panel")
self.add(self.base_panel.layout)
self.add(self.base_panel.main_grid)
self.show_all()
if show_cursor:
if self.show_cursor:
self.get_window().set_cursor(
Gdk.Cursor.new_for_display(Gdk.Display.get_default(), Gdk.CursorType.ARROW))
os.system("xsetroot -cursor_name arrow")
@@ -187,7 +191,7 @@ class KlipperScreen(Gtk.Window):
break
self.apiclient = KlippyRest(data["moonraker_host"], data["moonraker_port"], data["moonraker_api_key"])
self.printer = Printer(self.state_execute)
self.printer = Printer(state_execute)
self.printer.state_callbacks = {
"disconnected": self.state_disconnected,
"error": self.state_error,
@@ -313,32 +317,23 @@ class KlipperScreen(Gtk.Window):
msg.get_child().set_line_wrap(True)
msg.get_child().set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
msg.connect("clicked", self.close_popup_message)
close = Gtk.Button(label="<b><big>X</big></b>")
close.set_hexpand(False)
close.set_vexpand(True)
close.get_child().set_use_markup(True)
close.set_can_focus(False)
close.connect("clicked", self.close_popup_message)
box = Gtk.Box()
box.set_size_request(self.width, -1)
box.set_halign(Gtk.Align.CENTER)
box.get_style_context().add_class("message_popup")
msg.get_style_context().add_class("message_popup")
if level == 1:
box.get_style_context().add_class("message_popup_echo")
msg.get_style_context().add_class("message_popup_echo")
elif level == 2:
box.get_style_context().add_class("message_popup_warning")
msg.get_style_context().add_class("message_popup_warning")
else:
box.get_style_context().add_class("message_popup_error")
msg.get_style_context().add_class("message_popup_error")
box.add(msg)
box.add(close)
popup = Gtk.Popover.new(self.base_panel.titlebar)
popup.get_style_context().add_class("message_popup_popover")
popup.set_size_request(self.width, -1)
popup.set_halign(Gtk.Align.CENTER)
popup.add(msg)
popup.popup()
self.base_panel.layout.put(box, 0, 0)
self.show_all()
self.popup_message = box
self.popup_message = popup
self.popup_message.show_all()
if self._config.get_main_config().getboolean('autoclose_popups', True):
GLib.timeout_add_seconds(10, self.close_popup_message)
@@ -348,8 +343,7 @@ class KlipperScreen(Gtk.Window):
def close_popup_message(self, widget=None):
if self.popup_message is None:
return
self.base_panel.layout.remove(self.popup_message)
self.popup_message.popdown()
self.popup_message = None
def show_error_modal(self, err, e=""):
@@ -444,7 +438,7 @@ class KlipperScreen(Gtk.Window):
style_options['graph_colors']['sensor']['colors'][i]
)
css_data = css_data.replace("KS_FONT_SIZE", f"{self.gtk.get_font_size()}")
css_data = css_data.replace("KS_FONT_SIZE", f"{self.gtk.font_size}")
style_provider = Gtk.CssProvider()
style_provider.load_from_data(css_data.encode())
@@ -534,7 +528,8 @@ class KlipperScreen(Gtk.Window):
box.pack_start(close, True, True, 0)
box.set_halign(Gtk.Align.CENTER)
box.get_style_context().add_class("screensaver")
self.base_panel.layout.put(box, 0, 0)
self.remove(self.base_panel.main_grid)
self.add(box)
# Avoid leaving a cursor-handle
close.grab_focus()
@@ -547,8 +542,9 @@ class KlipperScreen(Gtk.Window):
if self.screensaver is None:
return False
logging.debug("Closing Screensaver")
self.base_panel.layout.remove(self.screensaver)
self.remove(self.screensaver)
self.screensaver = None
self.add(self.base_panel.main_grid)
if self.use_dpms:
self.wake_screen()
else:
@@ -624,9 +620,6 @@ class KlipperScreen(Gtk.Window):
def process_busy_state(self, busy):
self.process_update("notify_busy", busy)
def state_execute(self, callback):
callback()
def websocket_disconnected(self, msg):
self.printer_initializing(msg, remove=True)
self.connecting = True
@@ -731,6 +724,9 @@ class KlipperScreen(Gtk.Window):
self.show_popup_message(data[6:], 1)
elif data.startswith("!! "):
self.show_popup_message(data[3:], 3)
elif "unknown" in data.lower() and \
not ("TESTZ" in data or "MEASURE_AXES_NOISE" in data or "ACCELEROMETER_QUERY" in data):
self.show_popup_message(data)
if "SAVE_CONFIG" in data and self.printer.state == "ready":
script = {"script": "SAVE_CONFIG"}
self._confirm_send_action(
@@ -911,35 +907,10 @@ class KlipperScreen(Gtk.Window):
return
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
box.set_size_request(self.gtk.get_content_width(), self.gtk.get_keyboard_height())
box.set_size_request(self.gtk.content_width, self.gtk.keyboard_height)
if self._config.get_main_config().getboolean("use-matchbox-keyboard", False):
env = os.environ.copy()
usrkbd = os.path.expanduser("~/.matchbox/keyboard.xml")
if os.path.isfile(usrkbd):
env["MB_KBD_CONFIG"] = usrkbd
else:
env["MB_KBD_CONFIG"] = "ks_includes/locales/keyboard.xml"
p = subprocess.Popen(["matchbox-keyboard", "--xid"], stdout=subprocess.PIPE,
stderr=subprocess.PIPE, env=env)
xid = int(p.stdout.readline())
logging.debug(f"XID {xid}")
logging.debug(f"PID {p.pid}")
keyboard = Gtk.Socket()
box.get_style_context().add_class("keyboard_matchbox")
box.pack_start(keyboard, True, True, 0)
self.base_panel.content.pack_end(box, False, False, 0)
self.show_all()
keyboard.add_id(xid)
self.keyboard = {
"box": box,
"process": p,
"socket": keyboard
}
return
return self._show_matchbox_keyboard(box)
if entry is None:
logging.debug("Error: no entry provided for keyboard")
return
@@ -949,6 +920,34 @@ class KlipperScreen(Gtk.Window):
self.base_panel.content.pack_end(box, False, False, 0)
self.base_panel.content.show_all()
def _show_matchbox_keyboard(self, box):
env = os.environ.copy()
usrkbd = os.path.expanduser("~/.matchbox/keyboard.xml")
if os.path.isfile(usrkbd):
env["MB_KBD_CONFIG"] = usrkbd
else:
env["MB_KBD_CONFIG"] = "ks_includes/locales/keyboard.xml"
p = subprocess.Popen(["matchbox-keyboard", "--xid"], stdout=subprocess.PIPE,
stderr=subprocess.PIPE, env=env)
xid = int(p.stdout.readline())
logging.debug(f"XID {xid}")
logging.debug(f"PID {p.pid}")
keyboard = Gtk.Socket()
box.get_style_context().add_class("keyboard_matchbox")
box.pack_start(keyboard, True, True, 0)
self.base_panel.content.pack_end(box, False, False, 0)
self.show_all()
keyboard.add_id(xid)
self.keyboard = {
"box": box,
"process": p,
"socket": keyboard
}
return
def remove_keyboard(self, widget=None, event=None):
if self.keyboard is None:
return
@@ -964,6 +963,12 @@ class KlipperScreen(Gtk.Window):
elif keyval_name == "BackSpace" and len(self._cur_panels) > 1 and self.keyboard is None:
self.base_panel.back()
def update_size(self, *args):
self.width, self.height = self.get_size()
if self.vertical_mode != (self.width < self.height):
self.reload_panels()
self.vertical_mode = self.width < self.height
def main():
version = functions.get_software_version()
+12 -6
View File
@@ -9,11 +9,11 @@ FBDEV="xserver-xorg-video-fbdev"
PYTHON="python3-virtualenv virtualenv python3-distutils"
PYGOBJECT="libgirepository1.0-dev gcc libcairo2-dev pkg-config python3-dev gir1.2-gtk-3.0"
MISC="librsvg2-common libopenjp2-7 libatlas-base-dev wireless-tools libdbus-glib-1-dev autoconf"
OPTIONAL="xserver-xorg-legacy fonts-nanum fonts-ipafont"
OPTIONAL="xserver-xorg-legacy fonts-nanum fonts-ipafont, libmpv-dev"
# moonraker will check this list when updating
# if new packages are required for existing installs add them below too.
PKGLIST="libdbus-glib-1-dev autoconf fonts-ipafont"
PKGLIST="libdbus-glib-1-dev autoconf fonts-ipafont, libmpv-dev"
Red='\033[0;31m'
Green='\033[0;32m'
@@ -109,10 +109,16 @@ create_virtualenv()
source ${KSENV}/bin/activate
pip --disable-pip-version-check install -r ${KSPATH}/scripts/KlipperScreen-requirements.txt
if [ $? -gt 0 ]; then
echo "Error: pip install exited with status code $?"
echo "Unable to install dependencies, aborting install."
deactivate
exit 1
echo_error "Error: pip install exited with status code $?"
echo_text "Trying again with new tools..."
sudo apt-get install -y build-essential cmake
pip install --upgrade pip setuptools
pip install -r ${KSPATH}/scripts/KlipperScreen-requirements.txt
if [ $? -gt 0 ]; then
echo_error "Unable to install dependencies, aborting install."
deactivate
exit 1
fi
fi
deactivate
echo_ok "Virtual enviroment created"
+2 -1
View File
@@ -4,4 +4,5 @@ requests==2.28.1
websocket-client==1.4.2
pycairo==1.22.0
PyGObject==3.42.2
python-networkmanager==2.2
python-networkmanager==2.2
python-mpv==0.5.2
+20 -2
View File
@@ -203,7 +203,12 @@ trough {
}
.action_bar {
/*border-right: 2px solid #444;*/
/* min-width: 4.5em; */
/* min-height: 4.5em; */
}
.title_bar {
min-height: 2em;
}
.content {
@@ -293,6 +298,10 @@ trough {
padding: 0 .5em;
}
.heater-grid-temp {
min-width: 8em;
}
.keyboard_box {
margin-top: 35px;
}
@@ -307,8 +316,17 @@ trough {
border-radius: 0.7em;
}
.message_popup_popover {
border: 0;
background-color: Transparent;
padding: 0;
}
.message_popup {
border-bottom: .1em solid white;
border: .1em solid white;
border-radius: 1em;
padding: 1em;
margin: 0;
}
.message_popup button{