From 3d241cecb412607d3d2f49dc2df0d41aee994166 Mon Sep 17 00:00:00 2001 From: alfrix Date: Thu, 25 Apr 2024 14:37:16 -0300 Subject: [PATCH] printer_select: support custom icons #1240 --- docs/Theming.md | 15 ++++++++++++++- panels/printer_select.py | 9 ++++++++- styles/printers/readme.md | 7 +++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 styles/printers/readme.md diff --git a/docs/Theming.md b/docs/Theming.md index c50a671b..35e9a588 100644 --- a/docs/Theming.md +++ b/docs/Theming.md @@ -1,6 +1,19 @@ # Theming -To create a custom theme, create a folder in: _${KlipperScreen_Directory}/styles/_ +## Custom printer select icons + +When multiple printers are configured, their icons can be customized by placing an icon in: + +_${KlipperScreen_Directory}/styles/printers/_ + +* The name of the icon must be the exact printer name configured in KlipperScreen.conf +* The format should be svg or png. + +## Custom themes + +To create a custom theme, create a folder in: + +_${KlipperScreen_Directory}/styles/_ The folder name will be the theme name, in that folder create another folder named `images` this is where the icons should be placed. The icons must be SVG files with specific names that are defined in the code, use the default theme as a reference for the names or check the code. diff --git a/panels/printer_select.py b/panels/printer_select.py index ea781fdc..9d6cb9b9 100644 --- a/panels/printer_select.py +++ b/panels/printer_select.py @@ -4,6 +4,7 @@ gi.require_version("Gtk", "3.0") from gi.repository import Gtk, GLib from ks_includes.screen_panel import ScreenPanel from ks_includes.widgets.autogrid import AutoGrid +from ks_includes.KlippyGtk import find_widget class Panel(ScreenPanel): @@ -14,7 +15,13 @@ class Panel(ScreenPanel): printer_buttons = [] for i, printer in enumerate(printers): name = list(printer)[0] - self.labels[name] = self._gtk.Button("printer", name, f"color{1 + i % 4}", scale=2) + scale = 3 + self.labels[name] = self._gtk.Button("printer", name, f"color{1 + i % 4}", scale=scale) + scale *= self._gtk.img_scale + pixbuf = self._gtk.PixbufFromIcon(f"../../printers/{name}", scale, scale) + if pixbuf is not None: + image = find_widget(self.labels[name], Gtk.Image) + image.set_from_pixbuf(pixbuf) self.labels[name].connect("clicked", self.connect_printer, name) printer_buttons.append(self.labels[name]) grid = AutoGrid(printer_buttons, vertical=self._screen.vertical_mode) diff --git a/styles/printers/readme.md b/styles/printers/readme.md new file mode 100644 index 00000000..3faaaf04 --- /dev/null +++ b/styles/printers/readme.md @@ -0,0 +1,7 @@ +In this folder add the images for the printer selection screen when using multiple printers + +** No images will be provided from the main repo ** + +1. Supported formats: SVG (preferred) or PNG +2. The name of the image should be exactly equal to the printer name +