class TextOutputPopup(BasePopup): help_url = joinPath(getHelpUrlDir(), 'TextOutput.html') def __init__(self, parent, title='Text output'): BasePopup.__init__(self, parent=parent, title=title, modal=False, transient=False) def body(self, master): self.text = ScrolledText(master) self.text.pack(side=Tkinter.TOP, expand=Tkinter.YES, fill=Tkinter.BOTH) texts = ['Save text'] commands = [self.saveText] buttons = createHelpButtonList(master, texts=texts, commands=commands, help_url=self.help_url) buttons.pack() def saveText(self): fileSelectPopup = FileSelectPopup( self, file_types=[ FileType('Text', ['*.txt', '*.out', '*.text']), FileType('All', ['*']) ], title='Select text output save file') fileName = fileSelectPopup.getFile() if fileName: writeFile = 1 if os.path.exists(fileName): if not showYesNo('Overwrite file', 'Overwrite existing file %s?' % fileName): writeFile = 0 if writeFile: fout = open(fileName, 'w') fout.write(self.text.text_area.getText()) fout.close() def apply(self): return True