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
|
return b
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ConfirmDialog(screen, text, buttons, callback=None, *args):
|
def Dialog(screen, buttons, content, callback=None, *args):
|
||||||
dialog = Gtk.Dialog()
|
dialog = Gtk.Dialog()
|
||||||
#TODO: Factor other resolutions in
|
dialog.set_default_size(screen.width - 15, screen.height - 15)
|
||||||
dialog.set_default_size(984, 580)
|
|
||||||
dialog.set_resizable(False)
|
dialog.set_resizable(False)
|
||||||
dialog.set_transient_for(screen)
|
dialog.set_transient_for(screen)
|
||||||
dialog.set_modal(True)
|
dialog.set_modal(True)
|
||||||
@ -126,27 +125,23 @@ class KlippyGtk:
|
|||||||
dialog.connect("response", callback, *args)
|
dialog.connect("response", callback, *args)
|
||||||
dialog.get_style_context().add_class("dialog")
|
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 = dialog.get_content_area()
|
||||||
content_area.set_margin_start(15)
|
content_area.set_margin_start(15)
|
||||||
content_area.set_margin_end(15)
|
content_area.set_margin_end(15)
|
||||||
content_area.set_margin_top(15)
|
content_area.set_margin_top(15)
|
||||||
content_area.set_margin_bottom(15)
|
content_area.set_margin_bottom(15)
|
||||||
|
content_area.add(grid)
|
||||||
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)
|
|
||||||
|
|
||||||
dialog.show_all()
|
dialog.show_all()
|
||||||
|
|
||||||
return dialog
|
return dialog, grid
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
## Changelog
|
## 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
|
#### 2020 11 14
|
||||||
* Update print panel to include line wrapping for longer filenames
|
* Update print panel to include line wrapping for longer filenames
|
||||||
|
|
||||||
|
@ -106,6 +106,16 @@ name: System
|
|||||||
icon: info
|
icon: info
|
||||||
panel: system
|
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]
|
[menu __print temperature]
|
||||||
name: Temperature
|
name: Temperature
|
||||||
icon: heat-up
|
icon: heat-up
|
||||||
|
@ -94,6 +94,7 @@ class KlipperScreenConfig:
|
|||||||
"icon": cfg.get("icon"),
|
"icon": cfg.get("icon"),
|
||||||
"panel": cfg.get("panel", False),
|
"panel": cfg.get("panel", False),
|
||||||
"method": cfg.get("method", False),
|
"method": cfg.get("method", False),
|
||||||
|
"confirm": cfg.get("confirm", False)
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -47,6 +47,9 @@ class MenuPanel(ScreenPanel):
|
|||||||
b.connect("clicked", self.menu_item_clicked, item['panel'], item)
|
b.connect("clicked", self.menu_item_clicked, item['panel'], item)
|
||||||
elif item['method'] != False:
|
elif item['method'] != False:
|
||||||
params = item['params'] if item['params'] != False else {}
|
params = item['params'] if item['params'] != False else {}
|
||||||
|
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)
|
b.connect("clicked", self._screen._send_action, item['method'], params)
|
||||||
else:
|
else:
|
||||||
b.connect("clicked", self._screen._go_to_submenu, key)
|
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):
|
def show_error_modal(self, err):
|
||||||
logger.exception("Showing error modal: %s", 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)
|
buttons = [
|
||||||
dialog.connect("response", self.error_modal_response)
|
{"name":"Go Back","response": Gtk.ResponseType.CANCEL}
|
||||||
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)
|
|
||||||
|
|
||||||
label = Gtk.Label()
|
label = Gtk.Label()
|
||||||
label.set_markup(("%s \n\nCheck /tmp/KlipperScreen.log for more information.\nPlease submit an issue "
|
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.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
|
||||||
label.get_style_context().add_class("text")
|
label.get_style_context().add_class("text")
|
||||||
|
|
||||||
grid = Gtk.Grid()
|
dialog = KlippyGtk.Dialog(self, buttons, label, self.error_modal_response)
|
||||||
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()
|
|
||||||
|
|
||||||
def error_modal_response(self, widget, response_id):
|
def error_modal_response(self, widget, response_id):
|
||||||
widget.destroy()
|
widget.destroy()
|
||||||
@ -366,6 +346,27 @@ class KlipperScreen(Gtk.Window):
|
|||||||
for sub in self.subscriptions:
|
for sub in self.subscriptions:
|
||||||
self.panels[sub].process_update(data)
|
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):
|
def _send_action(self, widget, method, params):
|
||||||
self._ws.send_method(method, params)
|
self._ws.send_method(method, params)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user