self.currfile = name # for save
self.filelabel.config(text=str(name))
def setKnownEncoding(self, encoding='utf-8'): # 2.1: for saves if inserted
self.knownEncoding = encoding # else saves use config, ask?
def setBg(self, color):
self.text.config(bg=color) # to set manually from code
def setFg(self, color):
self.text.config(fg=color) # 'black', hexstring
def setFont(self, font):
self.text.config(font=font) # ('family', size, 'style')
def setHeight(self, lines): # default = 24h x 80w
self.text.config(height=lines) # may also be from textCongif.py
def setWidth(self, chars):
self.text.config(width=chars)
def clearModified(self):
self.text.edit_modified(0) # clear modified flag
def isModified(self):
return self.text_edit_modified() # changed since last reset?
def help(self):
showinfo('About PyEdit', helptext % ((Version,)*2))
################################################################################
Ready-to-use editor classes
mixes in a GuiMaker Frame subclass which builds menu and toolbars
these classes are common use cases, but other configurations are possible;
call TextEditorMain().mainloop() to start PyEdit as a standalone program;
redefine/extend onQuit in a subclass to catch exit or destroy (see PyView);
caveat: could use windows.py for icons, but quit protocol is custom here.
################################################################################
#-------------------------------------------------------------------------------
2.1: on quit(), don't silently exit entire app if any other changed edit
windows are open in the process - changes would be lost because all other
windows are closed too, including multiple Tk editor parents; uses a list
to keep track of all PyEdit window instances open in process; this may be
too broad (if we destroy() instead of quit(), need only check children
of parent being destroyed), but better to err on side of being too inclusive;
onQuit moved here because varies per window type and is not present for all;
assumes a TextEditorMainPopup is never a parent to other editor windows -
Toplevel children are destroyed with their parents; this does not address
closes outside the scope of PyEdit classes here (tkinter quit is available
on every widget, and any widget type may be a Toplevel parent!); client is
responsible for checking for editor content changes in all uncovered cases;
note that tkinter's bind event won't help here, because its callback
cannot run GUI operations such as text change tests and fetches - see the
book and destroyer.py for more details on this event;
#-------------------------------------------------------------------------------
PyEdit: A Text Editor Program/Object | 713