Skip to content

Commit

Permalink
Reset button with question
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLauinger77 committed Jun 11, 2024
1 parent 6f119fa commit 6bcada8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions photocollage/gtkgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ def make_window(self):
self.btn_save.connect("clicked", self.save_poster)
box.pack_start(self.btn_save, False, False, 0)

self.btn_reset = Gtk.Button(label=_("Reset"))
self.btn_reset.set_image(Gtk.Image.new_from_stock(
Gtk.STOCK_REMOVE, Gtk.IconSize.LARGE_TOOLBAR))
self.btn_reset.set_always_show_image(True)
self.btn_reset.connect("clicked", self.reset)
box.pack_start(self.btn_reset, False, False, 0)

# -----------------------
# Tools pan
# -----------------------
Expand Down Expand Up @@ -321,6 +328,7 @@ def make_window(self):
box.pack_start(self.img_preview, True, True, 0)

self.btn_save.set_sensitive(False)
self.btn_reset.set_sensitive(False)

self.btn_undo.set_sensitive(False)
self.btn_redo.set_sensitive(False)
Expand Down Expand Up @@ -397,6 +405,7 @@ def on_complete(img):
self.img_preview.set_collage(img, collage)
compdialog.destroy()
self.btn_save.set_sensitive(True)
self.btn_reset.set_sensitive(True)

def on_fail(exception):
dialog = ErrorDialog(self, "{}:\n\n{}".format(
Expand All @@ -405,6 +414,7 @@ def on_fail(exception):
dialog.run()
dialog.destroy()
self.btn_save.set_sensitive(False)
self.btn_reset.set_sensitive(False)

t = render.RenderingTask(
collage.page,
Expand All @@ -421,6 +431,22 @@ def on_fail(exception):
t.abort()
compdialog.destroy()

def reset(self, button):
dialog = Gtk.MessageDialog(
win, Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO,
_("Reset"))
dialog.format_secondary_text(_("Do you really want to reset ?"))
response = dialog.run()
dialog.destroy()
if response == Gtk.ResponseType.YES:
win.img_preview.collage.photolist = None
win.img_preview.image = None
win.img_preview.mode = win.img_preview.INSENSITIVE
win.img_preview.parent.history_index = \
len(win.img_preview.parent.history)
win.img_preview.parent.update_tool_buttons()

def render_from_new_collage(self, collage):
self.history.append(collage)
self.history_index = len(self.history) - 1
Expand Down Expand Up @@ -514,6 +540,8 @@ def update_tool_buttons(self):
self.lbl_history_index.set_label(" ")
self.btn_save.set_sensitive(
self.history_index < len(self.history))
self.btn_reset.set_sensitive(
self.history_index < len(self.history))
self.btn_new_layout.set_sensitive(
self.history_index < len(self.history))

Expand Down Expand Up @@ -875,6 +903,7 @@ def main():
# Enable threading. Without that, threads hang!
GObject.threads_init()

global win
win = PhotoCollageWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Expand Down

0 comments on commit 6bcada8

Please sign in to comment.