class OptionsCM(Toplevel): "options window reachable from menu" def __init__(self, root): super().__init__(root) self.title("Options") self.grab_set() self.focus_set() self.resizable(FALSE, FALSE) placeWindow(self, 824, 844) self["padx"] = 10 self["pady"] = 10 self.parametersF = ParameterFrame(self, "Default parameters") # default filetype of processor output self.fileTypeVar = StringVar() self.fileTypeVar.set(optionGet("DefProcessOutputFileType", ".txt", "str")) self.fileTypeFrame = ttk.Labelframe(self, text = "Default output filetype") self.txtRadioBut = ttk.Radiobutton(self.fileTypeFrame, text = ".txt", variable = self.fileTypeVar, value = ".txt") self.csvRadioBut = ttk.Radiobutton(self.fileTypeFrame, text = ".csv", variable = self.fileTypeVar, value = ".csv") self.txtRadioBut.grid(row = 1, column = 0, padx = 2, pady = 2, sticky = W) self.csvRadioBut.grid(row = 0, column = 0, padx = 2, pady = 2, sticky = W) # output separator self.separatorVar = StringVar() self.separatorVar.set(optionGet("ResultSeparator", ",", "str")) self.separatorFrame = ttk.Labelframe(self, text = "Result separator") self.commaRadioBut = ttk.Radiobutton(self.separatorFrame, text = "Comma", variable = self.separatorVar, value = ",") self.semicolonRadioBut = ttk.Radiobutton(self.separatorFrame, text = "Semicolon", variable = self.separatorVar, value = ";") self.tabRadioBut = ttk.Radiobutton(self.separatorFrame, text = "Tab", variable = self.separatorVar, value = "\t") self.commaRadioBut.grid(row = 0, padx = 2, pady = 2, sticky = W) self.semicolonRadioBut.grid(row = 1, padx = 2, pady = 2, sticky = W) self.tabRadioBut.grid(row = 2, padx = 2, pady = 2, sticky = W) # save filename as full path self.saveFilenameAs = RadioFrame(self, text = "Save (show) filename as:", optionName = "SaveFullPath", default = "Basename", options = ["Basename", "Full path", "Unique path"]) # selection of directories self.directoriesFrame = ttk.Frame(self) self.directoriesFrame.columnconfigure(0, weight = 1) self.directoryOptions = [ ("Default directory for file selection", "FileDirectory", os.getcwd()), ("Default directory for results", "ResultDirectory", os.getcwd()), ("Directory for saving of processing logs", "LogDirectory", os.path.join(os.getcwd(), "Stuff", "Logs")), ("Directory for images", "ImageDirectory", os.getcwd()), ("Directory for saving of selected files", "SelectedFilesDirectory", os.path.join(os.getcwd(), "Stuff", "Selected files"))] for count, option in enumerate(self.directoryOptions): exec("""self.{1} = ChooseDirectoryFrame(self.directoriesFrame, '{0}', '{1}', \ r'{2}')""".format(*option)) exec("self.{}.grid(row = {}, column = 0, pady = 2, padx = 2, sticky = (E, W))".format( option[1], count)) # default time self.timeLabFrame = ttk.Labelframe(self, text = "Default time") self.timeFrame = TimeFrame(self.timeLabFrame) self.timeFrame.grid(row = 0, column = 0) # processor options self.processorOptions = OptionFrame(self, text = "Default process options") # checking messages self.messageCheckingFrame = ttk.Labelframe(self, text = "Messages and new versions") self.messageCheckingVar = BooleanVar() self.messageCheckingVar.set(optionGet("CheckMessages", True, "bool")) self.messageCheckingChB = ttk.Checkbutton(self.messageCheckingFrame, variable = self.messageCheckingVar, onvalue = True, offvalue = False, text = "Check messages and new versions") self.messageCheckingChB.grid(column = 0, row = 0) # buttons self.buttonFrame = ttk.Frame(self) self.buttonFrame.columnconfigure(1, weight = 1) self.saveBut = ttk.Button(self.buttonFrame, text = "Save", command = self.saveFun) self.okBut = ttk.Button(self.buttonFrame, text = "Ok", command = self.okFun) self.cancelBut = ttk.Button(self.buttonFrame, text = "Cancel", command = self.cancelFun) self.saveBut.grid(column = 0, row = 0, padx = 3, pady = 2, sticky = (W)) self.okBut.grid(column = 1, row = 0, padx = 3, pady = 2) self.cancelBut.grid(column = 2, row = 0, padx = 3, pady = 2, sticky = (E)) # grid of self contents self.parametersF.grid(row = 0, column = 0, columnspan = 4, sticky = (N, W), padx = 4, pady = 2) self.fileTypeFrame.grid(row = 2, column = 0, columnspan = 2, padx = 3, pady = 4, sticky = (W, N, E, S)) self.buttonFrame.grid(row = 8, column = 0, columnspan = 4, padx = 3, pady = 4,\ sticky = (E, W, N, S)) self.separatorFrame.grid(row = 3, column = 0, columnspan = 2, padx = 3, pady = 4, sticky = (W, N, E)) self.saveFilenameAs.grid(row = 2, column = 2, padx = 3, pady = 4, sticky = (N, W, E)) self.directoriesFrame.grid(row = 5, column = 0, columnspan = 5, padx = 3, pady = 8, sticky = (N, W, E)) self.timeLabFrame.grid(row = 2, column = 3, padx = 3, pady = 4, sticky = (N, W)) self.processorOptions.grid(row = 3, column = 2, pady = 4, padx = 4, sticky = (N, W), columnspan = 2, rowspan = 2) self.messageCheckingFrame.grid(row = 4, column = 0, columnspan = 2, sticky = (N, W), pady = 3, padx = 3) def saveFun(self): "saves all options" for parameter in Parameters().parameters: optionWrite(parameter[4], bool(eval(("self.parametersF." +\ parameter[0].replace(" ", "") + "Var.get()" )))) optionWrite("DefProcessOutputFileType", "'" + self.fileTypeVar.get() + "'") optionWrite("SaveFullPath", self.saveFilenameAs.get()) optionWrite("ResultSeparator", "'" + self.separatorVar.get() + "'") optionWrite("DefStartTime", self.timeFrame.startTimeVar.get()) optionWrite("DefStopTime", self.timeFrame.timeVar.get()) optionWrite("ProcessWhat", "'" + self.processorOptions.processWhat.get() + "'") optionWrite("RemoveReflectionsWhere", "'" + self.processorOptions.removeReflectionsWhere.get() + "'") optionWrite("DefSaveTags", self.processorOptions.saveTags.get()) optionWrite("DefClearFilesAfterProcessing", self.processorOptions.clearFilesAfterProcessing.get()) optionWrite("CheckMessages", bool(self.messageCheckingVar.get())) for option in self.directoryOptions: directory = eval("self.{}.get()".format(option[1])).rstrip("\/") if os.path.exists(directory): optionWrite(option[1], "r'" + directory + "'") else: messagebox.showinfo(message = "Directory " + directory + " does not exist.", icon = "error", parent = self, title = "Error", detail = "Choose an existing directory.") return False return True def okFun(self): "saves options and exits" if self.saveFun(): self.destroy() def cancelFun(self): "destroys the window" self.destroy()
class OptionsCM(Toplevel): "options window reachable from menu" def __init__(self, root): super().__init__(root) self.title("Options") self.grab_set() self.focus_set() self.resizable(FALSE, FALSE) placeWindow(self, 824, 844) self["padx"] = 10 self["pady"] = 10 self.parametersF = ParameterFrame(self, "Default parameters") # default filetype of processor output self.fileTypeVar = StringVar() self.fileTypeVar.set( optionGet("DefProcessOutputFileType", ".txt", "str")) self.fileTypeFrame = ttk.Labelframe(self, text="Default output filetype") self.txtRadioBut = ttk.Radiobutton(self.fileTypeFrame, text=".txt", variable=self.fileTypeVar, value=".txt") self.csvRadioBut = ttk.Radiobutton(self.fileTypeFrame, text=".csv", variable=self.fileTypeVar, value=".csv") self.txtRadioBut.grid(row=1, column=0, padx=2, pady=2, sticky=W) self.csvRadioBut.grid(row=0, column=0, padx=2, pady=2, sticky=W) # output separator self.separatorVar = StringVar() self.separatorVar.set(optionGet("ResultSeparator", ",", "str")) self.separatorFrame = ttk.Labelframe(self, text="Result separator") self.commaRadioBut = ttk.Radiobutton(self.separatorFrame, text="Comma", variable=self.separatorVar, value=",") self.semicolonRadioBut = ttk.Radiobutton(self.separatorFrame, text="Semicolon", variable=self.separatorVar, value=";") self.tabRadioBut = ttk.Radiobutton(self.separatorFrame, text="Tab", variable=self.separatorVar, value="\t") self.commaRadioBut.grid(row=0, padx=2, pady=2, sticky=W) self.semicolonRadioBut.grid(row=1, padx=2, pady=2, sticky=W) self.tabRadioBut.grid(row=2, padx=2, pady=2, sticky=W) # save filename as full path self.saveFilenameAs = RadioFrame( self, text="Save (show) filename as:", optionName="SaveFullPath", default="Basename", options=["Basename", "Full path", "Unique path"]) # selection of directories self.directoriesFrame = ttk.Frame(self) self.directoriesFrame.columnconfigure(0, weight=1) self.directoryOptions = [ ("Default directory for file selection", "FileDirectory", os.getcwd()), ("Default directory for results", "ResultDirectory", os.getcwd()), ("Directory for saving of processing logs", "LogDirectory", os.path.join(os.getcwd(), "Stuff", "Logs")), ("Directory for images", "ImageDirectory", os.getcwd()), ("Directory for saving of selected files", "SelectedFilesDirectory", os.path.join(os.getcwd(), "Stuff", "Selected files")) ] for count, option in enumerate(self.directoryOptions): exec( """self.{1} = ChooseDirectoryFrame(self.directoriesFrame, '{0}', '{1}', \ r'{2}')""".format(*option)) exec( "self.{}.grid(row = {}, column = 0, pady = 2, padx = 2, sticky = (E, W))" .format(option[1], count)) # default time self.timeLabFrame = ttk.Labelframe(self, text="Default time") self.timeFrame = TimeFrame(self.timeLabFrame) self.timeFrame.grid(row=0, column=0) # processor options self.processorOptions = OptionFrame(self, text="Default process options") # checking messages self.messageCheckingFrame = ttk.Labelframe( self, text="Messages and new versions") self.messageCheckingVar = BooleanVar() self.messageCheckingVar.set(optionGet("CheckMessages", True, "bool")) self.messageCheckingChB = ttk.Checkbutton( self.messageCheckingFrame, variable=self.messageCheckingVar, onvalue=True, offvalue=False, text="Check messages and new versions") self.messageCheckingChB.grid(column=0, row=0) # buttons self.buttonFrame = ttk.Frame(self) self.buttonFrame.columnconfigure(1, weight=1) self.saveBut = ttk.Button(self.buttonFrame, text="Save", command=self.saveFun) self.okBut = ttk.Button(self.buttonFrame, text="Ok", command=self.okFun) self.cancelBut = ttk.Button(self.buttonFrame, text="Cancel", command=self.cancelFun) self.saveBut.grid(column=0, row=0, padx=3, pady=2, sticky=(W)) self.okBut.grid(column=1, row=0, padx=3, pady=2) self.cancelBut.grid(column=2, row=0, padx=3, pady=2, sticky=(E)) # grid of self contents self.parametersF.grid(row=0, column=0, columnspan=4, sticky=(N, W), padx=4, pady=2) self.fileTypeFrame.grid(row=2, column=0, columnspan=2, padx=3, pady=4, sticky=(W, N, E, S)) self.buttonFrame.grid(row = 8, column = 0, columnspan = 4, padx = 3, pady = 4,\ sticky = (E, W, N, S)) self.separatorFrame.grid(row=3, column=0, columnspan=2, padx=3, pady=4, sticky=(W, N, E)) self.saveFilenameAs.grid(row=2, column=2, padx=3, pady=4, sticky=(N, W, E)) self.directoriesFrame.grid(row=5, column=0, columnspan=5, padx=3, pady=8, sticky=(N, W, E)) self.timeLabFrame.grid(row=2, column=3, padx=3, pady=4, sticky=(N, W)) self.processorOptions.grid(row=3, column=2, pady=4, padx=4, sticky=(N, W), columnspan=2, rowspan=2) self.messageCheckingFrame.grid(row=4, column=0, columnspan=2, sticky=(N, W), pady=3, padx=3) def saveFun(self): "saves all options" for parameter in Parameters().parameters: optionWrite(parameter[4], bool(eval(("self.parametersF." +\ parameter[0].replace(" ", "") + "Var.get()" )))) optionWrite("DefProcessOutputFileType", "'" + self.fileTypeVar.get() + "'") optionWrite("SaveFullPath", self.saveFilenameAs.get()) optionWrite("ResultSeparator", "'" + self.separatorVar.get() + "'") optionWrite("DefStartTime", self.timeFrame.startTimeVar.get()) optionWrite("DefStopTime", self.timeFrame.timeVar.get()) optionWrite("ProcessWhat", "'" + self.processorOptions.processWhat.get() + "'") optionWrite( "RemoveReflectionsWhere", "'" + self.processorOptions.removeReflectionsWhere.get() + "'") optionWrite("DefSaveTags", self.processorOptions.saveTags.get()) optionWrite("DefClearFilesAfterProcessing", self.processorOptions.clearFilesAfterProcessing.get()) optionWrite("CheckMessages", bool(self.messageCheckingVar.get())) for option in self.directoryOptions: directory = eval("self.{}.get()".format(option[1])).rstrip("\/") if os.path.exists(directory): optionWrite(option[1], "r'" + directory + "'") else: messagebox.showinfo(message="Directory " + directory + " does not exist.", icon="error", parent=self, title="Error", detail="Choose an existing directory.") return False return True def okFun(self): "saves options and exits" if self.saveFun(): self.destroy() def cancelFun(self): "destroys the window" self.destroy()
class GeneralOptions(OptionsCM, Toplevel): def __init__(self, root): super(OptionsCM, self).__init__(root) self.root = root self.title("General options") self.grab_set() self.focus_set() self.resizable(FALSE, FALSE) placeWindow(self, 554, 499) self["padx"] = 10 self["pady"] = 10 # default filetype of processor output self.fileTypeVar = StringVar() self.fileTypeVar.set(optionGet("DefProcessOutputFileType", ".txt", "str", True)) self.fileTypeFrame = ttk.Labelframe(self, text = "Default output filetype") self.txtRadioBut = ttk.Radiobutton(self.fileTypeFrame, text = ".txt", variable = self.fileTypeVar, value = ".txt") self.csvRadioBut = ttk.Radiobutton(self.fileTypeFrame, text = ".csv", variable = self.fileTypeVar, value = ".csv") self.txtRadioBut.grid(row = 1, column = 0, padx = 2, pady = 2, sticky = W) self.csvRadioBut.grid(row = 0, column = 0, padx = 2, pady = 2, sticky = W) # output separator self.separatorVar = StringVar() self.separatorVar.set(optionGet("ResultSeparator", ",", "str", True)) self.separatorFrame = ttk.Labelframe(self, text = "Result separator") self.commaRadioBut = ttk.Radiobutton(self.separatorFrame, text = "Comma", variable = self.separatorVar, value = ",") self.semicolonRadioBut = ttk.Radiobutton(self.separatorFrame, text = "Semicolon", variable = self.separatorVar, value = ";") self.tabRadioBut = ttk.Radiobutton(self.separatorFrame, text = "Tab", variable = self.separatorVar, value = "\t") self.commaRadioBut.grid(row = 0, padx = 2, pady = 2, sticky = W) self.semicolonRadioBut.grid(row = 1, padx = 2, pady = 2, sticky = W) self.tabRadioBut.grid(row = 2, padx = 2, pady = 2, sticky = W) # selection of directories self.directoriesFrame = ttk.Frame(self) self.directoriesFrame.columnconfigure(0, weight = 1) self.directoryOptions = [ ("Default directory for results", "ResultDirectory", os.getcwd(), True), ("Directory for saving of processing logs", "LogDirectory", os.path.join(os.getcwd(), "Stuff", "Logs"), True), ("Directory for images", "ImageDirectory", os.getcwd(), True), ("Directory for saving of selected files", "SelectedFilesDirectory", os.path.join(os.getcwd(), "Stuff", "Selected files"), True)] for count, option in enumerate(self.directoryOptions): exec("""self.{1} = ChooseDirectoryFrame(self.directoriesFrame, '{0}', '{1}', \ r'{2}', {3})""".format(*option)) exec("self.{}.grid(row = {}, column = 0, pady = 2, padx = 2, sticky = (E, W))".format( option[1], count)) # save filename as full path self.saveFilenameAs = RadioFrame(self, text = "Save (show) filename as:", optionName = "SaveFullPath", default = "Basename", options = ["Basename", "Full path", "Unique path"]) # processor options self.processorOptions = OptionFrame(self, text = "Default process options") self._createButtons() self.commentColor = ttk.Button(self, text = "Comment color", command = self.chooseCommentColor) self.commentColor.grid(column = 2, row = 0, padx = 2, pady = 2) self.fileTypeFrame.grid(row = 0, column = 0, padx = 3, pady = 4, sticky = (W, N, E, S)) self.buttonFrame.grid(row = 3, column = 0, columnspan = 3, padx = 3, pady = 6, sticky = (E, W, N, S)) self.separatorFrame.grid(row = 1, column = 0, padx = 3, pady = 4, sticky = (W, N, E)) self.saveFilenameAs.grid(row = 0, column = 1, padx = 3, pady = 4, sticky = (N, W, E)) self.processorOptions.grid(row = 1, column = 1, pady = 4, padx = 4, sticky = (N, W)) self.directoriesFrame.grid(row = 2, column = 0, columnspan = 3, padx = 3, pady = 4) def saveFun(self): "saves all options" optionWrite("DefProcessOutputFileType", "'" + self.fileTypeVar.get() + "'", True) optionWrite("SaveFullPath", self.saveFilenameAs.get(), True) optionWrite("ResultSeparator", "'" + self.separatorVar.get() + "'", True) optionWrite("ProcessWhat", "'" + self.processorOptions.processWhat.get() + "'", True) optionWrite("RemoveReflectionsWhere", "'" + self.processorOptions.removeReflectionsWhere.get() + "'", True) optionWrite("DefSaveTags", self.processorOptions.saveTags.get(), True) optionWrite("DefSaveComments", self.processorOptions.saveComments.get(), True) optionWrite("DefShowResults", self.processorOptions.showResults.get(), True) for option in self.directoryOptions: directory = eval("self.{}.get()".format(option[1])).rstrip("\/") if os.path.exists(directory): optionWrite(option[1], "r'" + directory + "'", option[3]) else: messagebox.showinfo(message = "Directory " + directory + " does not exist.", icon = "error", parent = self, title = "Error", detail = "Choose an existing directory.") return False return True def chooseCommentColor(self): "opens dialog for choosing color of comments and immediately saves the selected color" color = colorchooser.askcolor(initialcolor = optionGet("CommentColor", "grey90", 'str', True), parent = self) if color and len(color) > 1 and color[1]: selected = color[1] optionWrite("CommentColor", "'" + selected + "'", True) self.root.explorer.fileFrame.tree.tag_configure("comment", background = selected) self.root.controller.contentTree.tag_configure("comment", background = selected)