Skip to content

Unsaved changes

“Save your changes to name before closing?” with Don’t save, Cancel and Save.

ui.unsaved_changes · Category: Dialogs · Full reference →

Unsaved changesUnsaved changes
  • When closing a tab or a window with unsaved edits.
from pyzed import ui
ui.dialog_layer(main_view(), ui.unsaved_changes("notes.py", on_save, on_discard, on_cancel))
Unsaved changes: A fileUnsaved changes: A file
A file
Code
ui.unsaved_changes("notes.py", on_save, on_discard, on_cancel)
Unsaved changes: width=360Unsaved changes: width=360
width=360
Code
ui.unsaved_changes("report.pzform", on_save, on_discard, on_cancel, width=360)

Unsaved changes has 3 events of its own, listed below. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.

Event Handler gets When
on_save () Save.
on_discard () Don’t save.
on_cancel () Cancel.

Handler gets is what Pyzed passes to your callable: () means nothing. Any handler can also be a message (a value that is not callable), which goes to update().

The same events written three ways. Imperative: methods of the app change self. Declarative: the handlers produce messages and one update() decides. Functional: a pure function draws an immutable state and asks for changes with set_state(...). See Imperative, declarative and functional.

class Notes(pz.App):
def __init__(self):
self.closing = True
def save(self):
self.closing = False # write the file, then close
def view(self):
dialog = ui.unsaved_changes("notes.py", self.save,
lambda: setattr(self, "closing", False), # on_discard
lambda: setattr(self, "closing", False)) # on_cancel
return ui.dialog_layer(main_view(), dialog if self.closing else None)
unsaved_changes(name, on_save, on_discard, on_cancel, *, width=440, theme=None)

“Save your changes to name before closing?” with Don’t save, Cancel and Save.

Property Default Description
name required File or document name.
width 440 Width: pixels, "fill", "shrink" or "fill:N" (proportion).
theme None Theme to use instead of the current one (pyzed.theme.current()).

Events: on_save, on_discard, on_cancel (events).

Full reference →