From a18b198bf215cbb35e05a8c331c6d7d9812ada3b Mon Sep 17 00:00:00 2001 From: alfrix Date: Sun, 7 Apr 2024 12:26:59 -0300 Subject: [PATCH] dialogs: add the ability to show dialogs without buttons for fullscreen view (click to close) --- ks_includes/KlippyGtk.py | 41 +++++++++++++++++------------- ks_includes/widgets/heatergraph.py | 5 +--- panels/job_status.py | 5 +--- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/ks_includes/KlippyGtk.py b/ks_includes/KlippyGtk.py index 7ca57d4e..ced8f081 100644 --- a/ks_includes/KlippyGtk.py +++ b/ks_includes/KlippyGtk.py @@ -196,30 +196,37 @@ class KlippyGtk: spinner.hide() widget.set_sensitive(True) + def dialog_content_decouple(self, widget, event, dialog): + self.remove_dialog(dialog) + def Dialog(self, title, buttons, content, callback=None, *args): dialog = Gtk.Dialog(title=title, modal=True, transient_for=self.screen, default_width=self.width, default_height=self.height) if not self.screen.windowed: dialog.fullscreen() - max_buttons = 3 if self.screen.vertical_mode else 4 - if len(buttons) > max_buttons: - buttons = buttons[:max_buttons] - if len(buttons) > 2: - dialog.get_action_area().set_layout(Gtk.ButtonBoxStyle.EXPAND) - button_hsize = -1 - else: - button_hsize = int((self.width / 3)) - for button in buttons: - if 'style' in button: - style = button['style'] + if buttons: + max_buttons = 3 if self.screen.vertical_mode else 4 + if len(buttons) > max_buttons: + buttons = buttons[:max_buttons] + if len(buttons) > 2: + dialog.get_action_area().set_layout(Gtk.ButtonBoxStyle.EXPAND) + button_hsize = -1 else: - style = 'dialog-default' - dialog.add_button(button['name'], button['response']) - button = dialog.get_widget_for_response(button['response']) - button.set_size_request(button_hsize, self.dialog_buttons_height) - button.get_style_context().add_class(style) - format_label(button, 2) + button_hsize = int((self.width / 3)) + for button in buttons: + style = button['style'] if 'style' in button else 'dialog-default' + dialog.add_button(button['name'], button['response']) + button = dialog.get_widget_for_response(button['response']) + button.set_size_request(button_hsize, self.dialog_buttons_height) + button.get_style_context().add_class(style) + format_label(button, 2) + else: + # No buttons means clicking anywhere closes the dialog + content.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK) + content.connect("button-release-event", self.dialog_content_decouple, dialog) + dialog.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK) + dialog.connect("button-release-event", self.remove_dialog) dialog.connect("response", self.screen.reset_screensaver_timeout) dialog.connect("response", callback, *args) diff --git a/ks_includes/widgets/heatergraph.py b/ks_includes/widgets/heatergraph.py index 235d4cf9..487ea770 100644 --- a/ks_includes/widgets/heatergraph.py +++ b/ks_includes/widgets/heatergraph.py @@ -35,11 +35,8 @@ class HeaterGraph(Gtk.DrawingArea): return self.fullscreen def show_fullscreen_graph(self): - buttons = [ - {"name": _("Close"), "response": Gtk.ResponseType.CANCEL} - ] self.fs_graph = HeaterGraph(self._screen, self.printer, self.font_size * 2, fullscreen=True, store=self.store) - self._gtk.Dialog(_("Temperature"), buttons, self.fs_graph, self.close_fullscreen_graph) + self._gtk.Dialog(_("Temperature"), None, self.fs_graph, self.close_fullscreen_graph) def close_fullscreen_graph(self, dialog, response_id): logging.info("Closing graph") diff --git a/panels/job_status.py b/panels/job_status.py index f46429c9..203d2773 100644 --- a/panels/job_status.py +++ b/panels/job_status.py @@ -749,15 +749,12 @@ class Panel(ScreenPanel): image.set_from_pixbuf(pixbuf) def show_fullscreen_thumbnail(self, widget): - buttons = [ - {"name": _("Close"), "response": Gtk.ResponseType.CANCEL} - ] pixbuf = self.get_file_image(self.filename, self._screen.width * .9, self._screen.height * .75) if pixbuf is None: return image = Gtk.Image.new_from_pixbuf(pixbuf) image.set_vexpand(True) - self._gtk.Dialog(self.filename, buttons, image, self.close_fullscreen_thumbnail) + self._gtk.Dialog(self.filename, None, image, self.close_fullscreen_thumbnail) def close_fullscreen_thumbnail(self, dialog, response_id): self._gtk.remove_dialog(dialog)