def save(self, filename): """manage the saving of the file based on extension""" fn, ext = os.path.splitext(filename) ext = ext.lower() if ext == ".probe" or ext == ".xyz": # save probe if not self.gcode.probe.isEmpty(): self.gcode.probe.save(filename) if filename is not None: self._saveConfigFile() elif ext == ".orient": # save orientation file return self.gcode.orient.save(filename) elif ext == ".txt": # save gcode as txt: # only enabled blocks and no OKKCNC metadata or comments return self.gcode.saveNGC(filename, False) elif ext == ".okk": # save gcode with OKKCNC metadata return self.gcode.saveOKK(filename) elif ext == ".ngc": # save gcode with OKKCNC metadata and comments return self.gcode.saveNGC(filename, True) else: if filename is not None: self.gcode.filename = filename self._saveConfigFile() IniFile.add_recent_file(self.gcode.filename) return self.gcode.save()
def _saveConfigFile(self, filename=None): if filename is None: filename = self.gcode.filename IniFile.save_lastfile(filename) IniFile.set_value("File", "probe", os.path.basename(self.gcode.probe.filename))
def _get(self, key, typ, default): if typ in ("float", "mm"): return IniFile.get_float(self.name, key, default) elif typ == "int": return IniFile.get_int(self.name, key, default) elif typ == "bool": return IniFile.get_int(self.name, key, default) else: return IniFile.get_str(self.name, key, default)
def populate_tooltable(): """Popultae tooltable list for use with CAM Buttons It reuse the existing EndMill data saved in inifile""" n_tools = IniFile.get_int("EndMill", "n", 0) for idx in range(0, n_tools): t_index = IniFile.get_int("EndMill", "number.{}".format(idx), 0) t_dia = IniFile.get_float("EndMill", "diameter.{}".format(idx), 0) #print("Tool number: {} diameter: {}".format(t_index, t_dia)) OCV.tooltable.append((t_index, t_dia)) print(OCV.tooltable)
def writeValues(self, outfile): IniFile.writeHeader(self.name, outfile) outfile.write(self.cacheParams) indexes = self.content.keys() indexes.sort() for i in indexes: for pos in self.content[i]: IniFile.writeHeader( self.name + ".blk_" + str(i) + "_" + str(pos), outfile) outfile.write(self.content[i][pos])
def languageChange(self): lang = self.language.get() # find translation for a, b in OCV.PRG_LANGUAGES.items(): if b == lang: if OCV.language == a: return OCV.language = a IniFile.set_value(OCV.PRG_NAME, "language", OCV.language) tkMessageBox.showinfo(_("Language change"), _("Please restart the program."), parent=self.winfo_toplevel()) return
def saveConfig(self): # Connection IniFile.set_value("Connection", "controller", OCV.APP.controller) IniFile.set_value("Connection", "port", self.portCombo.get().split("\t")[0]) IniFile.set_value("Connection", "baud", self.baudCombo.get()) IniFile.set_value("Connection", "openserial", self.autostart.get())
def load(self, filename): """Load a file into editor""" fn, ext = os.path.splitext(filename) ext = ext.lower() if ext == ".probe": if filename is not None: self.gcode.probe.filename = filename self._saveConfigFile() self.gcode.probe.load(filename) elif ext == ".orient": # save orientation file self.gcode.orient.load(filename) else: self.gcode.load(filename) IniFile.add_recent_file(filename)
def loadRecent(self, recent): filename = IniFile.get_recent_file(recent) if filename is None: return self.load(filename)
def load(self): """Load from a configuration file""" # Load lists lists = [] for var in self.variables: n, t, d, l = var[:4] if t == "list": lists.append(n) if lists: for p in lists: self.listdb[p] = [] for i in range(1000): key = "_{0}.{1}".format(p, i) value = IniFile.get_str(self.name, key).strip() if value: self.listdb[p].append(value) else: break # Check if there is a current try: self.current = int(OCV.config.get(self.name, "current")) except: self.current = None # Load values if self.current is not None: self.num = self._get("n", "int", 0) for i in range(self.num): key = "name.{0}".format(i) self.values[key] = IniFile.get_str(self.name, key) for var in self.variables: n, t, d, l = var[:4] key = "{0}.{1}".format(n, i) self.values[key] = self._get(key, t, d) else: for var in self.variables: n, t, d, l = var[:4] self.values[n] = self._get(n, t, d) self.update()
def __init__(self): # 通过配置文件获取IEDriverServer.exe路径 configfile = os.path.join(os.getcwd(), 'config.conf') cf = IniFile.ConfigFile(configfile) IEDriverServer = cf.GetValue("section", "IEDriverServer") # 每抓取一页数据延迟的时间,单位为秒,默认为5秒 self.pageDelay = 5 pageInteralDelay = cf.GetValue("section", "pageInteralDelay") if pageInteralDelay: self.pageDelay = int(pageInteralDelay) os.environ["webdriver.ie.driver"] = IEDriverServer self.driver = webdriver.Ie(IEDriverServer)
def load_icons(): """load icons and images in internal dictionaries""" OCV.icons = {} for img in glob.glob("{0}{1}icons{1}*.gif".format(OCV.PRG_PATH, os.sep)): name, ext = os.path.splitext(os.path.basename(img)) try: OCV.icons[name] = Tk.PhotoImage(file=img) if IniFile.get_bool("CNC", "doublesizeicon"): OCV.icons[name] = OCV.icons[name].zoom(2, 2) except Tk.TclError: pass # Images OCV.images = {} for img in glob.glob("{0}{1}images{1}*.gif".format(OCV.PRG_PATH, os.sep)): name, ext = os.path.splitext(os.path.basename(img)) try: OCV.images[name] = Tk.PhotoImage(file=img) if IniFile.get_bool("CNC", "doublesizeicon"): OCV.images[name] = OCV.images[name].zoom(2, 2) except Tk.TclError: pass
def _saveConfigFile(self, filename=None): if filename is None: filename = self.gcode.filename IniFile.set_value("File", "dir", os.path.dirname(os.path.abspath(filename))) IniFile.set_value("File", "file", os.path.basename(filename)) IniFile.set_value("File", "probe", os.path.basename(self.gcode.probe.filename))
def __init__(self): self.m_bLangRestartReminder = True p = PathName() strFile = p.GetIniDirectory() #print strFile #TOFIX strFile += '/atol.ini' ini = IniFile() inifileloaded = False self.m_strCurLang = 'en' if ini.Load(strFile): inifileloaded = true strValue = ini.GetValue('Default', 'Language', '') if (strValue != ''): self.m_strCurLang = strValue else: #// francesco: not sure, if there exists already a translated mo file #// m_strCurLang = wxLANGUAGE_DEFAULT; self.m_strCurLang = '' else: self.m_strCurLang = '' self.FindLanguages()
def __init__(self, master, app): CNCRibbon.ButtonGroup.__init__(self, master, "User", app) self.grid3rows() b_num = IniFile.get_int("Buttons", "n", 6) for idx in range(1, b_num): but = Utils.UserButton(self.frame, OCV.APP, idx, anchor=Tk.W, background=OCV.COLOR_BACKGROUND) col, row = divmod(idx - 1, 3) but.grid(row=row, column=col, sticky=Tk.NSEW) self.addWidget(but)
def set_predefined_steps(): """set pre defined steps used in ControlPage""" # Predefined XY steppings try: OCV.psxy1 = IniFile.get_float("Control", "psxy1") except Exception: OCV.psxy1 = 1.0 try: OCV.psxy2 = IniFile.get_float("Control", "psxy2") except Exception: OCV.psxy2 = 1.0 try: OCV.psxy3 = IniFile.get_float("Control", "psxy3") except Exception: OCV.psxy3 = 10.0 try: OCV.psxy4 = IniFile.get_float("Control", "psxy4") except Exception: OCV.psxy4 = 90.0 # Predefined Z steppings try: OCV.psz1 = IniFile.get_float("Control", "psz1") except Exception: OCV.psz1 = 0.1 try: OCV.psz2 = IniFile.get_float("Control", "psz2") except Exception: OCV.psz2 = 1.0 try: OCV.psz3 = IniFile.get_float("Control", "psz3") except Exception: OCV.psz3 = 5.0 try: OCV.psz4 = IniFile.get_float("Control", "psz4") except Exception: OCV.psz4 = 10.0
def set_debug_flags(): if IniFile.get_bool("Debug", "generic"): OCV.DEBUG = True if IniFile.get_bool("Debug", "graph"): OCV.DEBUG_GRAPH = True if IniFile.get_bool("Debug", "interface"): OCV.DEBUG_INT = True if IniFile.get_bool("Debug", "coms"): OCV.DEBUG_COM = True if IniFile.get_bool("Debug", "sio"): OCV.DEBUG_SER = True if IniFile.get_bool("Debug", "gpar"): OCV.DEBUG_PAR = True OCV.DEBUG_HEUR = IniFile.get_bool("Debug", "heur")
def createMenu(self): menu = Tk.Menu(self, tearoff=0, activebackground=OCV.COLOR_ACTIVE) for i in range(OCV.maxRecent): filename = IniFile.get_recent_file(i) if filename is None: break path = os.path.dirname(filename) fn = os.path.basename(filename) menu.add_command( label="{0:d} {1}".format(i+1, fn), compound=Tk.LEFT, image=OCV.icons["new"], accelerator=path, # Show as accelerator in order to be aligned command=lambda s=self, i=i: s.event_generate( "<<Recent{0:d}>>".format(i))) if i == 0: # no entry self.event_generate("<<Open>>") return None return menu
def Save(self): strFile = self.CalcFileName() ini = IniFile() ini.SetPath(strFile) #ini.Load()#strFile) nTotalCount = len(self.m_lstBookmarks) ini.SetValue(self.g_szSection, 'Count', nTotalCount) for i in range(nTotalCount): strKey = '%d_Title' % i ini.SetValue(self.g_szSection, strKey, self.m_lstBookmarks[i].m_strTitle) strKey = '%d_Path' % i ini.SetValue(self.g_szSection, strKey, self.m_lstBookmarks[i].m_strPath) if not ini.Save(): return False return True
def set_predefined_steps(): """set pre defined steps used in ControlPage""" # Predefined XY steppings try: OCV.step1 = IniFile.get_float("Control", "step1") except Exception: OCV.step1 = 1.0 try: OCV.step2 = IniFile.get_float("Control", "step2") except Exception: OCV.step2 = 1.0 try: OCV.step3 = IniFile.get_float("Control", "step3") except Exception: OCV.step3 = 10.0 # Predefined Z steppings try: OCV.zstep1 = IniFile.get_float("Control", "zstep1") except Exception: OCV.zstep1 = 0.1 try: OCV.zstep2 = IniFile.get_float("Control", "zstep2") except Exception: OCV.zstep2 = 1.0 try: OCV.zstep3 = IniFile.get_float("Control", "zstep3") except Exception: OCV.zstep3 = 5.0 try: OCV.zstep4 = IniFile.get_float("Control", "zstep4") except Exception: OCV.zstep4 = 10.0
def Load(self): strFile = self.CalcFileName() ini = IniFile() if not ini.Load(strFile): return False nTotalCount = int(ini.GetValue('Bookmarks', 'Count', 0)) #print nTotalCount strKey = '' for i in range(nTotalCount): strKey = '%d_Title' % i strTitle = ini.GetValue(self.g_szSection, strKey, '') strKey = '%d_Path' % i strPath = ini.GetValue(self.g_szSection, strKey, '') item = BrowseBookmark(strTitle, strPath) if (item.IsValid()): self.m_lstBookmarks.append(item) return True
def quit(self, event=None): IniFile.save_command_history() Pendant.stop()
def __init__(self, master, app): CNCRibbon.PageLabelFrame.__init__( self, master, "Serial", _("Serial"), app) self.autostart = Tk.BooleanVar() col, row = 0, 0 b = Tk.Label(self, text=_("Port:")) b.grid(row=row, column=col, sticky=Tk.E) self.addWidget(b) self.portCombo = tkExtra.Combobox( self, False, background=tkExtra.GLOBAL_CONTROL_BACKGROUND, width=16, command=self.comportClean) self.portCombo.grid(row=row, column=col+1, sticky=Tk.EW) tkExtra.Balloon.set( self.portCombo, _("Select (or manual enter) port to connect")) self.portCombo.set(IniFile.get_str("Connection","port")) self.addWidget(self.portCombo) self.comportRefresh() row += 1 b = Tk.Label(self, text=_("Baud:")) b.grid(row=row, column=col, sticky=Tk.E) self.baudCombo = tkExtra.Combobox( self, True, background=tkExtra.GLOBAL_CONTROL_BACKGROUND) self.baudCombo.grid(row=row, column=col+1, sticky=Tk.EW) tkExtra.Balloon.set(self.baudCombo, _("Select connection baud rate")) self.baudCombo.fill(BAUDS) self.baudCombo.set(IniFile.get_str("Connection","baud","115200")) self.addWidget(self.baudCombo) row += 1 b = Tk.Label(self, text=_("Controller:")) b.grid(row=row, column=col, sticky=Tk.E) self.ctrlCombo = tkExtra.Combobox( self, True, background=tkExtra.GLOBAL_CONTROL_BACKGROUND, command=self.ctrlChange) self.ctrlCombo.grid(row=row, column=col+1, sticky=Tk.EW) tkExtra.Balloon.set(self.ctrlCombo, _("Select controller board")) self.ctrlCombo.fill(OCV.TK_MAIN.controllerList()) self.ctrlCombo.set(OCV.TK_MAIN.controller) self.addWidget(self.ctrlCombo) row += 1 b = Tk.Checkbutton( self, text=_("Connect on startup"), variable=self.autostart) b.grid(row=row, column=col, columnspan=2, sticky=Tk.W) tkExtra.Balloon.set( b, _("Connect to serial on startup of the program")) self.autostart.set(IniFile.get_bool("Connection","openserial")) self.addWidget(b) col += 2 self.comrefBtn = Ribbon.LabelButton( self, image=OCV.icons["refresh"], text=_("Refresh"), compound=Tk.TOP, command=lambda s=self: s.comportRefresh(True), background=OCV.COLOR_BG) self.comrefBtn.grid( row=row, column=col, padx=0, pady=0, sticky=Tk.NSEW) tkExtra.Balloon.set(self.comrefBtn, _("Refresh list of serial ports")) #col += 2 row = 0 self.connectBtn = Ribbon.LabelButton( self, image=OCV.icons["serial48"], text=_("Open"), compound=Tk.TOP, command=lambda s=self: s.event_generate("<<Connect>>"), background=OCV.COLOR_BG) self.connectBtn.grid( row=row, column=col, rowspan=3, padx=0, pady=0, sticky=Tk.NSEW) tkExtra.Balloon.set(self.connectBtn, _("Open/Close serial port")) self.grid_columnconfigure(1, weight=1)
def main_interface(self): """Generate main interface widgets moved from __main__.py """ # --- Ribbon --- OCV.RIBBON = Ribbon.TabRibbonFrame(self) OCV.RIBBON.pack(side=Tk.TOP, fill=Tk.X) # Main frame self.paned = Tk.PanedWindow(self, orient=Tk.HORIZONTAL) self.paned.pack(fill=Tk.BOTH, expand=Tk.YES) # Status bar frame = Tk.Frame(self) frame.pack(side=Tk.BOTTOM, fill=Tk.X) OCV.STATUSBAR = tkExtra.ProgressBar(frame, height=20, relief=Tk.SUNKEN) OCV.STATUSBAR.pack(side=Tk.LEFT, fill=Tk.X, expand=Tk.YES) OCV.STATUSBAR.configText(fill="DarkBlue", justify=Tk.LEFT, anchor=Tk.W) self.statusz = Tk.Label(frame, foreground="DarkRed", relief=Tk.SUNKEN, anchor=Tk.W, width=10) self.statusz.pack(side=Tk.RIGHT) self.statusy = Tk.Label(frame, foreground="DarkRed", relief=Tk.SUNKEN, anchor=Tk.W, width=10) self.statusy.pack(side=Tk.RIGHT) self.statusx = Tk.Label(frame, foreground="DarkRed", relief=Tk.SUNKEN, anchor=Tk.W, width=10) self.statusx.pack(side=Tk.RIGHT) # Buffer bar OCV.BUFFERBAR = tkExtra.ProgressBar(frame, height=20, width=40, relief=Tk.SUNKEN) OCV.BUFFERBAR.pack(side=Tk.RIGHT, expand=Tk.NO) OCV.BUFFERBAR.setLimits(0, 100) tkExtra.Balloon.set(OCV.BUFFERBAR, _("Controller buffer fill")) # --- Left side --- self.Lframe = Tk.Frame(self.paned) self.paned.add(self.Lframe) #, minsize=340) self.pageframe = Tk.Frame(self.Lframe) self.pageframe.pack(side=Tk.TOP, expand=Tk.YES, fill=Tk.BOTH) OCV.RIBBON.setPageFrame(self.pageframe) # Command bar cmd_f = Tk.Frame(self.Lframe) cmd_f.pack(side=Tk.BOTTOM, fill=Tk.X) self.cmdlabel = Tk.Label(cmd_f, text=_("Command:")) self.cmdlabel.pack(side=Tk.LEFT) OCV.CMD_W = Tk.Entry(cmd_f, relief=Tk.SUNKEN, background="White") OCV.CMD_W.pack(side=Tk.RIGHT, fill=Tk.X, expand=Tk.YES) tkExtra.Balloon.set( OCV.CMD_W, _("MDI Command line: Accept g-code commands or macro " \ "commands (RESET/HOME...) or editor commands " \ "(move,inkscape, round...) [Space or Ctrl-Space]")) # --- Right side --- self.Rframe = Tk.Frame(self.paned) self.paned.add(self.Rframe) # --- Canvas --- OCV.CANVAS_F = CNCCanvas.CanvasFrame(self.Rframe, self) OCV.CANVAS_F.pack(side=Tk.TOP, fill=Tk.BOTH, expand=Tk.YES) self.linebuffer = Tk.Label(self.Rframe, background="khaki") self.proc_line = Tk.StringVar() self.linebuffer.configure(height=1, anchor=Tk.W, textvariable=self.proc_line) self.linebuffer.pack(side=Tk.BOTTOM, fill=Tk.X) # fist create Pages self.pages = {} for cls in (ControlPage, EditorPage, FilePage, ProbePage, TerminalPage, ToolsPage): page = cls(OCV.RIBBON, self) self.pages[page.name] = page # then add their properties (in separate loop) errors = [] for name, page in self.pages.items(): for page_name in IniFile.get_str(OCV.PRG_NAME, "{0}.ribbon".format( page.name)).split(): try: page.addRibbonGroup(page_name) except KeyError: errors.append(page_name) for page_name in IniFile.get_str(OCV.PRG_NAME, "{0}.page".format(page.name)).split(): last = page_name[-1] try: if last == "*": page.addPageFrame(page_name[:-1], fill=Tk.BOTH, expand=Tk.TRUE) else: page.addPageFrame(page_name) except KeyError: errors.append(page_name) if errors: tkMessageBox.showwarning( "OKKCNC configuration", "The following pages \"{0}\" are found in " \ "your <HOME>/.OKKCNC initialization file, " \ "which are either spelled wrongly or " \ "no longer exist in OKKCNC".format(" ".join(errors)), parent=self)
#!/usr/bin/python """ This module is used for return variables that are in a parameters file """ import IniFile PARAMETERS = IniFile.IniFileClass("config.cfg") print PARAMETERS.find_parameter("Second", "DEF")
def loadConfig(self): self.active.set(IniFile.get_str(OCV.PRG_NAME, "tool", "CNC")) for tool in self.tools.values(): tool.load()
def saveConfig(self): IniFile.set_value(OCV.PRG_NAME, "tool", self.active.get()) for tool in self.tools.values(): tool.save()
def saveConfig(self): IniFile.set_value("Control", "step", self.step.get()) IniFile.set_value("Control", "zstep", self.zstep.get())
def edit_pre_step(self, caller): """edit a preselected step value This method is valid for all the preselction buttons correct step is found using "caller" parameter """ print("edit_pre_step caller > ", caller) retval = Utils.ask_for_value(self, caller) if retval is None: return print("retval > ", retval) if caller in ("S1", "S2", "S3"): if caller == "S1": wid = self.nametowidget("step_1") OCV.step1 = retval bal_text = "Step1 = {0}".format(OCV.step1) IniFile.set_value("Control", "step1", retval) elif caller == "S2": wid = self.nametowidget("step_2") OCV.step2 = retval bal_text = "Step2 = {0}".format(OCV.step2) IniFile.set_value("Control", "step2", retval) elif caller == "S3": wid = self.nametowidget("step_3") OCV.step3 = retval IniFile.set_value("Control", "step3", retval) bal_text = "Step2 = {0}".format(OCV.step3) elif caller in ("ZS1", "ZS2", "ZS3", "ZS4"): if caller == "ZS1": wid = self.nametowidget("zstep_1") OCV.zstep1 = retval bal_text = "Zstep1 = {0}".format(OCV.zstep1) IniFile.set_value("Control", "zstep1", retval) elif caller == "ZS2": wid = self.nametowidget("zstep_2") OCV.zstep2 = retval bal_text = "Zstep2 = {0}".format(OCV.zstep2) IniFile.set_value("Control", "zstep2", retval) elif caller == "ZS3": wid = self.nametowidget("zstep_3") OCV.zstep3 = retval bal_text = "Zstep2 = {0}".format(OCV.zstep3) IniFile.set_value("Control", "zstep3", retval) elif caller == "ZS4": wid = self.nametowidget("zstep_4") OCV.zstep4 = retval bal_text = "Zstep4 = {0}".format(OCV.zstep4) IniFile.set_value("Control", "zstep4", retval) if wid is not None: wid.configure(text=retval) tkExtra.Balloon.set(wid, bal_text)
def load_sender_config(self): self.controllerSet(IniFile.get_str("Connection", "controller")) Pendant.port = IniFile.get_int("Connection", "pendantport", Pendant.port) GCode.LOOP_MERGE = IniFile.get_bool("File", "dxfloopmerge") IniFile.loadHistory()