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 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, 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)
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()
def loadConfig(self): self.active.set(IniFile.get_str(OCV.PRG_NAME, "tool", "CNC")) for tool in self.tools.values(): tool.load()