def __init__(self, root): super().__init__(root) self["padx"] = 4 self["pady"] = 4 self.version = version.version() self.title("Updates") self.resizable(FALSE, FALSE) placeWindow(self, 488, 127) try: newVersion = self.checkNewVersion() if newVersion: available = ( "There is a new version ({}.{}.{}) available.\n".format( *newVersion) + "Restart CMM to install the update.") optionWrite("DontShowVersion", self.version) else: available = "There is no new version available." except Exception: available = "Unable to get information about the newest version." text = "Your current version is {1}.{2}.{3}.\n\n{0}".format( available, *self.version) self.text = Text(self, height=4, width=58, relief="flat", background=self.cget("background")) self.text.grid(column=0, row=0, padx=6, pady=6) self.text.insert("end", text) self.close = ttk.Button(self, text="Close", command=self.destroy) self.close.grid(column=0, row=1, pady=7)
def saveSelectedParametersAsDefault(self): for parameter in Parameters().parameters: optionWrite( parameter[4], bool( eval(("self." + parameter[0].replace(" ", "") + "Var.get()"))))
def okFun(self): "closes the window and saves the selected batch time to root's batch time" if not self._checkText(): return self.root.selectedBatchTime = self.batchTime optionWrite("LastBatchTime", self.batchTime) self.destroy()
def __init__(self, root): super().__init__(root) self["padx"] = 4 self["pady"] = 4 self.version = version.version() self.title("Updates") self.resizable(FALSE, FALSE) placeWindow(self, 488, 127) try: newVersion = self.checkNewVersion() if newVersion: available = ("There is a new version ({}.{}.{}) available.\n".format(*newVersion) + "Restart CMM to install the update.") optionWrite("DontShowVersion", self.version) else: available = "There is no new version available." except Exception: available = "Unable to get information about the newest version." text = "Your current version is {1}.{2}.{3}.\n\n{0}".format(available, *self.version) self.text = Text(self, height = 4, width = 58, relief = "flat", background = self.cget("background")) self.text.grid(column = 0, row = 0, padx = 6, pady = 6) self.text.insert("end", text) self.close = ttk.Button(self, text = "Close", command = self.destroy) self.close.grid(column = 0, row = 1, pady = 7)
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)
def checkNewVersion(version): "checks whether there is a new version available" newVersion = returnSiteContent( "http://www.cmmanagerweb.appspot.com/version").split(".") try: from optionget import optionGet from version import version as currentVersion versionSeen = optionGet("DontShowVersion", currentVersion(), "list", True) except Exception: versionSeen = version for i in range(3): if int(newVersion[i]) > int(versionSeen[i]): code = returnSiteContent( "http://www.cmmanagerweb.appspot.com/code") curl = "https://raw.github.com/bahniks/CM_Manager_{}_{}_{}/master/Stuff/code.txt" curl = urlopen(curl.format(*newVersion)) ghcode = curl.read().strip() if int(code) != int(ghcode): return message = "New version of Carousel Maze Manager ({}.{}.{}) is available.\n".format( *newVersion ) + "Do you want to download and install the new version?" root = makeRoot() answ = messagebox.askyesnocancel( message=message, icon="question", title="New version available", default="yes", detail="Select 'No' to not be asked again.") if answ is None: pass elif answ: root.config(cursor="wait") try: download(newVersion) if "version" in sys.modules: imp.reload(sys.modules["version"]) except Exception as e: messagebox.showinfo( title="Error", icon="error", detail=e, message="Some problem with updating occured.") finally: root.config(cursor="") else: try: print(newVersion) from optionwrite import optionWrite optionWrite("DontShowVersion", newVersion, True) except Exception: pass root.destroy() break elif int(newVersion[i]) < int(versionSeen[i]): break
def changedTask(self): """called when mode is changed changes names in Options menu exchanges Process, Explore, Control notepages calls m.changeMode puts old filestorage in m.fs[m.mode] and the self.root.[...].fileStorage is reassigned saves old slaves of GUI's notebook and loads new renames GUI and saves the mode selection to options """ if self.task.get() != m.mode: if m.mode: oldname = m.fullname[m.mode] newname = m.fullname[self.task.get()] self.menu_options.entryconfigure( "Parameter settings (" + oldname + ")", label="Parameter settings (" + newname + ")") self.menu_options.entryconfigure(oldname + " options", label=newname + " options") if m.mode in m.slaves: m.slaves[m.mode][1] = self.root.selectFunction.select() m.changeMode(self.task.get()) if m.mode not in m.fs: m.fs[m.mode] = FileStorage() self.root.selectFunction.fileStorage = m.fs[m.mode] if m.mode not in m.slaves: m.slaves[m.mode] = [ m.Slaves(Processor(self.root.selectFunction), Explorer(self.root.selectFunction), Controller(self.root.selectFunction)), None ] self.root.processor = m.slaves[m.mode][0].processor self.root.explorer = m.slaves[m.mode][0].explorer self.root.controller = m.slaves[m.mode][0].controller self.root.changeSlaves() if m.slaves[m.mode][1]: self.root.selectFunction.select(m.slaves[m.mode][1]) self.root.changeTitle(m.name) optionWrite("DefaultTask", "'" + self.task.get() + "'", general=True)
def okFun(self): for row, option in enumerate(self.options): value = str(self.opts[row]["variable"].get()) if option[1][2] == "bool": value = bool(eval(value)) elif option[1][2] != "str": value = eval(value) else: if not value: value = "" else: value.replace('"', "'") if not value.endswith("'"): value += "'" if not value.startswith("'"): value = "'" + value optionWrite(option[1][0], value) self.destroy()
def changedTask(self): """called when mode is changed changes names in Options menu exchanges Process, Explore, Control notepages calls m.changeMode puts old filestorage in m.fs[m.mode] and the self.root.[...].fileStorage is reassigned saves old slaves of GUI's notebook and loads new renames GUI and saves the mode selection to options """ if self.task.get() != m.mode: if m.mode: oldname = m.fullname[m.mode] newname = m.fullname[self.task.get()] self.menu_options.entryconfigure("Parameter settings (" + oldname + ")", label = "Parameter settings (" + newname + ")") self.menu_options.entryconfigure(oldname + " options", label = newname + " options") if m.mode in m.slaves: m.slaves[m.mode][1] = self.root.selectFunction.select() m.changeMode(self.task.get()) if m.mode not in m.fs: m.fs[m.mode] = FileStorage() self.root.selectFunction.fileStorage = m.fs[m.mode] if m.mode not in m.slaves: m.slaves[m.mode] = [m.Slaves(Processor(self.root.selectFunction), Explorer(self.root.selectFunction), Controller(self.root.selectFunction) ), None ] self.root.processor = m.slaves[m.mode][0].processor self.root.explorer = m.slaves[m.mode][0].explorer self.root.controller = m.slaves[m.mode][0].controller self.root.changeSlaves() if m.slaves[m.mode][1]: self.root.selectFunction.select(m.slaves[m.mode][1]) self.root.changeTitle(m.name) optionWrite("DefaultTask", "'" + self.task.get() + "'", general = True)
def saveFun(self): optionWrite('WidthParTimeInChosen', self.TimeInChosenWidthVar.get()) optionWrite('AngleParTimeInChosen', self.TimeInChosenAngleVar.get()) optionWrite('ThigmotaxisPercentSize', self.thigmotaxisVar.get()) optionWrite('WidthParTimeInSectors', self.TimeInSectorsWidthVar.get()) self.totalDistance.save() self.maximumTimeImmobility.save() self.periodicity.save() self.percentMobility.save() self.speedAfterShock.save() self.outsidePoints.save()
def checkNewVersion(version): "checks whether there is a new version available" newVersion = returnSiteContent("http://www.cmmanagerweb.appspot.com/version").split(".") try: from optionget import optionGet from version import version as currentVersion versionSeen = optionGet("DontShowVersion", currentVersion(), "list") except Exception: versionSeen = version for i in range(3): if int(newVersion[i]) > int(versionSeen[i]): code = returnSiteContent("http://www.cmmanagerweb.appspot.com/code") curl = "https://raw.github.com/bahniks/CM_Manager_{}_{}_{}/master/Stuff/code.txt" curl = urlopen(curl.format(*newVersion)) ghcode = curl.read().strip() if int(code) != int(ghcode): return message = "New version of Carousel Maze Manager ({}.{}.{}) is available.\n".format( *newVersion) + "Do you want to download and install the new version?" root = makeRoot() answ = messagebox.askyesnocancel(message = message, icon = "question", title = "New version available", default = "yes", detail = "Select 'No' to not be asked again.") if answ is None: pass elif answ: root.config(cursor = "wait") try: download(newVersion) if "version" in sys.modules: imp.reload(sys.modules["version"]) except Exception as e: messagebox.showinfo(title = "Error", icon = "error", detail = e, message = "Some problem with updating occured.") finally: root.config(cursor = "") else: try: from optionwrite import optionWrite optionWrite("DontShowVersion", newVersion) except Exception: pass root.destroy() break
def saveFun(self): "saves all options" self.parametersF.saveSelectedParametersAsDefault() optionWrite("DefStartTime", self.timeFrame.startTimeVar.get(), False) optionWrite("DefStopTime", self.timeFrame.timeVar.get(), False) directory = self.fileDirectory.get().rstrip("\/") if os.path.exists(directory): optionWrite("FileDirectory", "r'" + directory + "'", False) 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 saveSelectedParametersAsDefault(self): for parameter in Parameters().parameters: optionWrite(parameter[4], bool(eval(("self." + parameter[0].replace(" ", "") + "Var.get()"))))
def saveSelectedParametersAsDefault(self): for name, parameter in m.parameters.items(): label = name.replace(" ", "") optionWrite("Def" + label, bool(eval(("self." + label + "Var.get()"))))
def save(self): for option in self.options: if option[1][2] == 'bool': optionWrite(option[1][0], bool(eval("self.{}Var.get()".format(option[1][0])))) else: optionWrite(option[1][0], eval("self.{}Var.get()".format(option[1][0])))
def resetFun(self): for count, option in enumerate(self.options): optionWrite(option[1][0], option[1][1]) self.opts[count]["variable"].set(option[1][1])
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 save(self): for row, option in enumerate(self.options): value = str(self.opts[row]["variable"].get()) value = bool(eval(value)) if option[1][2] == 'bool' else eval(value) optionWrite(option[1][0], value)