TextEditor.init(self, loadFirst, loadEncode) # TextEditor adds middle
def start(self):
TextEditor.start(self) # GuiMaker start call
for i in range(len(self.toolBar)): # delete quit in toolbar
if self.toolBar[i][0] == 'Quit': # delete file menu items,
del self.toolBar[i] # or just disable file
break
if self.deleteFile:
for i in range(len(self.menuBar)):
if self.menuBar[i][0] == 'File':
del self.menuBar[i]
break
else:
for (name, key, items) in self.menuBar:
if name == 'File':
items.append([1,2,3,4,6])
################################################################################
standalone program run
################################################################################
def testPopup():
see PyView and PyMail for component tests
root = Tk()
TextEditorMainPopup(root)
TextEditorMainPopup(root)
Button(root, text='More', command=TextEditorMainPopup).pack(fill=X)
Button(root, text='Quit', command=root.quit).pack(fill=X)
root.mainloop()
def main(): # may be typed or clicked
try: # or associated on Windows
fname = sys.argv[1] # arg = optional filename
except IndexError: # build in default Tk root
fname = None
TextEditorMain(loadFirst=fname).pack(expand=YES, fill=BOTH) # pack optional
mainloop()
if name == 'main': # when run as a script
#testPopup()
main() # run .pyw for no DOS box
PyPhoto: An Image Viewer and Resizer
In Chapter 9, we wrote a simple thumbnail image viewer that scrolled its thumbnails
in a canvas. That program in turn built on techniques and code we developed at the
end of Chapter 8 to handle images. In both places, I promised that we’d eventually
meet a more full-featured extension of the ideas we deployed.
In this section, we finally wrap up the thumbnail images thread by studying PyPhoto—
an enhanced image viewing and resizing program. PyPhoto’s basic operation is
716 | Chapter 11: Complete GUI Programs