From 6e8f904983869c1e7c223c7d05f837a15bf73b96 Mon Sep 17 00:00:00 2001 From: Jordan Ruthe Date: Wed, 18 Nov 2020 05:55:45 -0500 Subject: [PATCH] Update configuration for Save Config button --- KlippyGtk.py | 27 ++++++++----------- docs/changelog.md | 6 +++++ ks_includes/KlipperScreen.conf | 10 +++++++ ks_includes/config.py | 1 + panels/menu.py | 5 +++- screen.py | 49 +++++++++++++++++----------------- 6 files changed, 57 insertions(+), 41 deletions(-) diff --git a/KlippyGtk.py b/KlippyGtk.py index 6aac3906..5e3abfc8 100644 --- a/KlippyGtk.py +++ b/KlippyGtk.py @@ -112,10 +112,9 @@ class KlippyGtk: return b @staticmethod - def ConfirmDialog(screen, text, buttons, callback=None, *args): + def Dialog(screen, buttons, content, callback=None, *args): dialog = Gtk.Dialog() - #TODO: Factor other resolutions in - dialog.set_default_size(984, 580) + dialog.set_default_size(screen.width - 15, screen.height - 15) dialog.set_resizable(False) dialog.set_transient_for(screen) dialog.set_modal(True) @@ -126,27 +125,23 @@ class KlippyGtk: dialog.connect("response", callback, *args) dialog.get_style_context().add_class("dialog") + grid = Gtk.Grid() + grid.set_size_request(screen.width - 60, -1) + grid.set_vexpand(True) + grid.set_halign(Gtk.Align.CENTER) + grid.set_valign(Gtk.Align.CENTER) + grid.add(content) + content_area = dialog.get_content_area() content_area.set_margin_start(15) content_area.set_margin_end(15) content_area.set_margin_top(15) content_area.set_margin_bottom(15) - - label = Gtk.Label() - label.set_line_wrap(True) - label.set_size_request(800, -1) - label.set_markup(text) - label.get_style_context().add_class("text") - table = Gtk.Table(1, 1, False) - table.attach(label, 0, 1, 0, 1, Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL) - table.set_vexpand(True) - table.set_halign(Gtk.Align.CENTER) - table.set_valign(Gtk.Align.CENTER) - content_area.add(table) + content_area.add(grid) dialog.show_all() - return dialog + return dialog, grid @staticmethod diff --git a/docs/changelog.md b/docs/changelog.md index 2d8d4856..66e074e1 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,11 @@ ## Changelog +#### 2020 11 18 +* Changed configuration file format. +* Moved default configuration file to an include folder. +* Added ability to do a confirm dialog from a menu item when running a script +* Added "Save Config" button to default configuration's Configuration menu. + #### 2020 11 14 * Update print panel to include line wrapping for longer filenames diff --git a/ks_includes/KlipperScreen.conf b/ks_includes/KlipperScreen.conf index 199fbfbc..1f268aa4 100644 --- a/ks_includes/KlipperScreen.conf +++ b/ks_includes/KlipperScreen.conf @@ -106,6 +106,16 @@ name: System icon: info panel: system +[menu __main config save] +name: Save Config +icon: complete +method: printer.gcode.script +params: {"script":"SAVE_CONFIG"} +confirm: + Save configuration. + + Klipper will reboot + [menu __print temperature] name: Temperature icon: heat-up diff --git a/ks_includes/config.py b/ks_includes/config.py index 356835b2..5fe72b4d 100644 --- a/ks_includes/config.py +++ b/ks_includes/config.py @@ -94,6 +94,7 @@ class KlipperScreenConfig: "icon": cfg.get("icon"), "panel": cfg.get("panel", False), "method": cfg.get("method", False), + "confirm": cfg.get("confirm", False) } try: diff --git a/panels/menu.py b/panels/menu.py index ececa57a..a8d0c12c 100644 --- a/panels/menu.py +++ b/panels/menu.py @@ -47,7 +47,10 @@ class MenuPanel(ScreenPanel): b.connect("clicked", self.menu_item_clicked, item['panel'], item) elif item['method'] != False: params = item['params'] if item['params'] != False else {} - b.connect("clicked", self._screen._send_action, item['method'], params) + if item['confirm'] != False: + b.connect("clicked", self._screen._confirm_send_action, item['confirm'], item['method'], params) + else: + b.connect("clicked", self._screen._send_action, item['method'], params) else: b.connect("clicked", self._screen._go_to_submenu, key) diff --git a/screen.py b/screen.py index 04d225ba..70ac149a 100644 --- a/screen.py +++ b/screen.py @@ -203,21 +203,10 @@ class KlipperScreen(Gtk.Window): def show_error_modal(self, err): logger.exception("Showing error modal: %s", err) - dialog = Gtk.Dialog() - dialog.set_default_size(self.width - 15, self.height - 15) - dialog.set_resizable(False) - dialog.set_transient_for(self) - dialog.set_modal(True) - dialog.add_button(button_text="Cancel", response_id=Gtk.ResponseType.CANCEL) - dialog.connect("response", self.error_modal_response) - dialog.get_style_context().add_class("dialog") - - content_area = dialog.get_content_area() - content_area.set_margin_start(15) - content_area.set_margin_end(15) - content_area.set_margin_top(15) - content_area.set_margin_bottom(15) + buttons = [ + {"name":"Go Back","response": Gtk.ResponseType.CANCEL} + ] label = Gtk.Label() label.set_markup(("%s \n\nCheck /tmp/KlipperScreen.log for more information.\nPlease submit an issue " @@ -228,16 +217,7 @@ class KlipperScreen(Gtk.Window): label.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR) label.get_style_context().add_class("text") - grid = Gtk.Grid() - grid.add(label) - grid.set_size_request(self.width - 60, -1) - grid.set_vexpand(True) - grid.set_halign(Gtk.Align.CENTER) - grid.set_valign(Gtk.Align.CENTER) - - content_area.add(grid) - dialog.resize(self.width - 15, self.height - 15) - dialog.show_all() + dialog = KlippyGtk.Dialog(self, buttons, label, self.error_modal_response) def error_modal_response(self, widget, response_id): widget.destroy() @@ -366,6 +346,27 @@ class KlipperScreen(Gtk.Window): for sub in self.subscriptions: self.panels[sub].process_update(data) + def _confirm_send_action(self, widget, text, method, params): + buttons = [ + {"name":"Continue", "response": Gtk.ResponseType.OK}, + {"name":"Cancel","response": Gtk.ResponseType.CANCEL} + ] + + label = Gtk.Label() + label.set_markup(text) + label.set_hexpand(True) + label.set_halign(Gtk.Align.CENTER) + label.set_line_wrap(True) + label.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR) + label.get_style_context().add_class("text") + + dialog = KlippyGtk.Dialog(self, buttons, label, self._confirm_send_action_response, method, params) + + def _confirm_send_action_response(self, widget, response_id, method, params): + if response_id == Gtk.ResponseType.OK: + self._send_action(widget, method, params) + + widget.destroy() def _send_action(self, widget, method, params): self._ws.send_method(method, params)