dialogs: add the ability to show dialogs without buttons for fullscreen view (click to close)

This commit is contained in:
alfrix 2024-04-07 12:26:59 -03:00
parent b1e71283a6
commit a18b198bf2
3 changed files with 26 additions and 25 deletions

View File

@ -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)

View File

@ -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")

View File

@ -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)