Update configuration for Save Config button
This commit is contained in:
parent
cc5b87eefe
commit
6e8f904983
27
KlippyGtk.py
27
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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
||||
|
49
screen.py
49
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user