if not encpick and self savesaskuserself update(else dialog doesn' appear in rare cases askuser askstring('pyedit''enter unicode encoding for save'initialvalue=(self knownencoding or self savesencoding or sys getdefaultencoding(or '')if askusertrytext encode(askuserencpick askuser except (unicodeerrorlookuperror)lookuperrorbad name pass unicodeerrorcan' encode try config file if not encpick and self savesencodingtrytext encode(self savesencodingencpick self savesencoding except (unicodeerrorlookuperror)pass try platform default (utf on windowsif not encpicktrytext encode(sys getdefaultencoding()encpick sys getdefaultencoding(except (unicodeerrorlookuperror)pass open in text mode for endlines encoding if not encpickshowerror('pyedit''could not encode for file filenameelsetryfile open(filename' 'encoding=encpickfile write(textfile close(exceptshowerror('pyedit''could not write file filenameelseself setfilename(filenamemay be newly created self text edit_modified( clear modified flag self knownencoding encpick keep enc for next save don' clear undo/redo stksdef onnew(self)""start editing new file from scratch in current windowsee onclone to pop-up new independent edit window instead""if self text_edit_modified() if not askyesno('pyedit''text has changeddiscard changes?')return self setfilename(none complete gui programs