def close_dialog(window): if window.changed: prompt = 'Save changes to ' + window.gettitle() + ' ?' if stdwin.askync(prompt, 1): save_dialog(window) if window.changed: return # Save failed (not) cancelled windows.remove(window) del window.textobject
def revert_dialog(window): if not window.filename: stdwin.message('This window has no file to revert from') return if window.changed: prompt = 'Really read ' + window.filename + ' back from file?' if not stdwin.askync(prompt, 1): return try: fp = open(window.filename, 'r') except RuntimeError: stdwin.message(filename + ': cannot open') return contents = fp.read() del fp # Close the file window.textobject.settext(contents) window.changed = 0 fix_docsize(window)
def askyesno(prompt, default): try: return stdwin.askync(prompt, default) except KeyboardInterrupt: return 0
def askync(prompt, yesorno): return stdwin.askync(prompt, yesorno)