def execute(self): if STAT.flood: printInfo(_("Button flood clicked, flood disactivated")) COMMAND.flood(LINUXCNC.FLOOD_OFF) else: printInfo(_("Button flood clicked, flood activated")) COMMAND.flood(LINUXCNC.FLOOD_ON)
def execute(self): if STAT.mist: printInfo(_("Button mist clicked, mist disactivated")) COMMAND.mist(LINUXCNC.MIST_OFF) else: printInfo(_("Button mist clicked, mist activated")) COMMAND.mist(LINUXCNC.MIST_ON)
def add_tool(self, state=None): tool_num = None for i in range(1, 9999): skip = False for instr in self.tablemodel.arraydata: if instr[1] == i: skip = True break if not skip: tool_num = i break printDebug(_('Add tool request: {}', tool_num)) if tool_num: data = [ QCheckBox(), tool_num, tool_num, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'No Comment' ] self.tablemodel.arraydata.append(data) else: printDebug(_('Failed to find new tool number')) self.save_tool_file( self.convert_to_standard_type(self.tablemodel.arraydata)) self.reload_tools() for n, instr in enumerate(self.tablemodel.arraydata): if instr[1] == i: self.set_row(self.model().index(n, 0)) break
def __init__(self,parent,parameters): QWidget.__init__(self) lay = QVBoxLayout() caption = QLabel(parameters[0]) text = QLabel(parameters[1]) self.p = parameters self.parser = parent.config self.page = parent.page self.parent = parent self.edit = QLineEdit() buttonYes = QPushButton() buttonYes.setText(_("Yes")) buttonYes.clicked.connect(self.yes_clicked) buttonNo = QPushButton() buttonNo .setText(_("No")) buttonNo.clicked.connect(self.no_clicked) buttonNext = QPushButton() buttonNext .setText(_("Next")) buttonNext.clicked.connect(self.next_clicked) lay.addWidget(caption) if parameters[2]: lay.addWidget(self.edit) lay.addWidget(text) lay.addStretch() if not parameters[2]: lay.addWidget(buttonNo) lay.addWidget(buttonYes) lay.addWidget(buttonNext) self.setLayout(lay)
def execute(self): printVerbose(_("Button save log clicked")) dirs = [] files = [] dirs.append("/var/log") dirs.append(os.path.dirname(os.environ['INI_FILE_NAME'])) for dir in dirs: contents = os.listdir(dir) name = "{}.tar.gz".format(dir[1:].replace('/','_')[-20:]) tar = tarfile.open(name, "w:gz") files.append(name) for item in contents: try: tar.add(os.path.join(dir,item)) except Exception as e: printError(_("Open log failed: {}", e)) continue tar.close() dest = QFileDialog.getExistingDirectory(None, _("Open directory"), ".", QFileDialog.ShowDirsOnly) for file in files: try: shutil.copyfile(file, os.path.join(dest, file)) except Exception as e: printError(_("Save log '{}' failed: {}", file, e)) continue
def new_section(self,section): scroll = QScrollArea() scroll.setWidgetResizable(True) widget = QWidget() scroll.setWidget(widget) vlay = QVBoxLayout() vlay.setContentsMargins(20,20,20,20) hlay1 = QHBoxLayout() hlay2 = QHBoxLayout() del_section_button = QPushButton() del_section_button.setText(_("Delete section")) del_section_button.clicked.connect(partial(self.delete_tab_clicked, scroll,section)) hlay1.addWidget(del_section_button) add_button = QPushButton() add_button.setText(_("New option")) add_button.clicked.connect(partial(self.new_line_clicked,vlay,section)) hlay2.addWidget(add_button) hlay1.addStretch() hlay2.addStretch() vlay.addLayout(hlay1) vlay.addLayout(hlay2) widget.setLayout(vlay) return scroll,vlay
def execute(self): if UPDATER.jog_continuous: printVerbose(_("Button JOG incremental clicked")) UPDATER.emit("jog_continuous", False) else: printVerbose(_("Button JOG continuous clicked")) UPDATER.emit("jog_continuous", True)
def execute(self): if not UPDATER.jog_activate and STAT.task_state == LINUXCNC.STATE_ON: printVerbose(_("Button JOG activate clicked")) UPDATER.emit("jog_activate", True) else: printVerbose(_("Button JOG disactivate clicked")) UPDATER.emit("jog_activate", False)
def execute(self): if UPDATER.jog_encoder: printVerbose(_("Button JOG joystick clicked")) UPDATER.emit("jog_encoder", False) else: printVerbose(_("Button JOG encoder clicked")) UPDATER.emit("jog_encoder", True)
def report_gcode_error(self, result, seq, filename): error_str = GCODE.strerror(result) Notify.Error( _("3D plot, Error in {} line {}\n{}", os.path.basename(filename), str(seq), error_str)) printError( _("3D plot, Error in {} line {}\n{}", os.path.basename(filename), str(seq), error_str))
def __frameworkError(msg): printError(_("alterx ERROR: {}", msg)) try: if osIsWindows: input(_("Press enter to exit.")) except (KeyboardInterrupt, Exception) as e: pass sys.exit(1)
def on_tool_changed(self, data): if data == 0: self.tool_number.setText(_("No tool")) self.tool_comment.setText(_("No comment")) else: tool = INFO.get_tool_info(data) self.tool_number.setText("#{}".format(data)) self.tool_comment.setText("{}".format(tool[19]))
def reloadfile(self, w): printDebug(_("PathViewer reload: {}", self._reload_filename)) try: self.load(self._reload_filename) #STATUS.emit('graphics-gcode-properties',self.gcode_properties) except Exception as e: printError( _("PathViewer reload {} error: {}", self._reload_filename, e)) pass
def unlock_clicked(self): if self.pw.text() == self.password: self.parent.blocked = False Notify.Info(_("Access granted")) else: Notify.Info(_("Access denied")) self.parent.blocked = True self.change_pw_widget.setEnabled(not self.parent.blocked)
def save_file(self, path): if type(path) is not bool: self.editor.filepath = path try: self.editor.save_text() except Exception as e: printError(_('File save failed: {}', path)) Notify.Warning(_("Not saved")) else: Notify.Info(_("Saved"))
def __init__(self, parent, title, text, verboseText=None, icon=QMessageBox.Critical, okButton=True, continueButton=False, cancelButton=False): QDialog.__init__(self, parent) self.setLayout(QGridLayout()) self.setWindowTitle(title) self.text = "<pre>" + saxutils.escape(text) + "\n</pre>" self.verboseText = None if verboseText and verboseText.strip() != text.strip(): self.verboseText = "<pre>" + \ saxutils.escape(verboseText) + "\n</pre>" self.textBox = QLabel(self) self.textBox.setTextInteractionFlags(Qt.TextSelectableByMouse | Qt.TextSelectableByKeyboard | Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard) self.layout().addWidget(self.textBox, 0, 0, 1, 3) if self.verboseText: self.verboseCheckBox = QCheckBox(_("Show verbose information"), self) self.layout().addWidget(self.verboseCheckBox, 1, 0, 1, 3) else: self.verboseCheckBox = None buttonsLayout = QHBoxLayout() if okButton: self.okButton = QPushButton(_("&Ok"), self) buttonsLayout.addWidget(self.okButton) if continueButton: self.continueButton = QPushButton(_("C&ontinue"), self) buttonsLayout.addWidget(self.continueButton) if cancelButton: self.cancelButton = QPushButton(_("&Cancel"), self) buttonsLayout.addWidget(self.cancelButton) self.layout().addLayout(buttonsLayout, 2, 1) self.__updateText() if okButton: self.okButton.released.connect(self.accept) if continueButton: self.continueButton.released.connect(self.accept) if cancelButton: self.cancelButton.released.connect(self.reject) if self.verboseCheckBox: self.verboseCheckBox.stateChanged.connect(self.__updateText)
def load_clicked(self,default_file=None,only_update=False): self.wizard = False self.run_wizard.setText(_("Run wizard")) if self.page.count() > 0: for i in reversed(range(self.page.count())): try: self.page.widget(i).deleteLater() self.page.removeTab(i) except Exception as e: printDebug(_("Delete tab exception: {}",e)) widget = QWidget() layout = QVBoxLayout() edit = QLineEdit() edit.setObjectName("edit_config_editor_{}_{}".format("new","new")) button = QPushButton() button.setText(_("Add new section")) button.clicked.connect(partial(self.new_section_clicked,edit)) layout.addWidget(edit,2) layout.addWidget(button,7) layout.addStretch() widget.setLayout(layout) if default_file: ini = default_file else: ini = os.environ['INI_FILE_NAME'] if ini: if not only_update: self.config = ConfigParser.ConfigParser( dict_type=MultiOrderedDict,allow_no_value=True) self.config.optionxform = str self.config.read(ini) else: printWarning(_("INI-file arg is not found.")) return self.page.addTab(widget,"+") for s in sorted(self.config.sections()): widget,layout = self.new_section(s) for o in sorted(self.config.options(s)): lay = QHBoxLayout() self.new_line(lay,s,o) layout.addLayout(lay) layout.addStretch() self.page.addTab(widget,s) if self.page.count()>1: self.page.setCurrentIndex(1)
def execute(self): if self.edit.isVisible(): self.edit.setVisible(False) printVerbose(_("Run program from line: {}", self.edit.text())) if self.edit.text() != "": COMMAND.auto(LINUXCNC.AUTO_RUN, int(self.edit.text())) COMMAND.auto(LINUXCNC.AUTO_PAUSE) else: printVerbose(_("Button Run from line clicked")) self.edit.setVisible(True) self.edit.setFocus()
def __unhandledExceptionHook(etype, value, tb): text = _("AlterX: ABORTING due to unhandled exception:") print(text, file=sys.stderr) __orig_excepthook(etype, value, tb) # Try to show an error message box. with suppressAllExc: import traceback QMessageBox.critical( None, _("AlterX: Unhandled exception"), text + "\n\n\n" + "".join(traceback.format_exception(etype, value, tb)), QMessageBox.Ok, QMessageBox.Ok) # Call QCoreApplication.exit() so that we return from exec_() qapp.exit(ExitCodes.EXIT_ERR_OTHER)
def execute(self): if self.edit.isVisible(): self.edit.setVisible(False) printVerbose(_("Button macro command {}: {}", 1, self.edit.text())) if self.edit.text() != "": COMMAND.mdi("G0 Z{}".format(self.edit.text())) else: printVerbose(_("Button macro command {} clicked", 1)) self.edit_lifetime = 5 self.edit.setText("") self.edit.setVisible(True) self.edit.setFocus()
def handleFatalException(parentWidget=None): text = str(traceback.format_exc()) print(_("Fatal exception:\n"), text) text = saxutils.escape(text) QMessageBox.critical( parentWidget, _("A fatal exception occurred"), _( "<pre>" "A fatal exception occurred:\n\n" "{}\n\n" "AlterX will be terminated." "</pre>", text)) sys.exit(1)
def execute(self): if self.edit.isVisible(): self.edit.setVisible(False) if self.edit.text() != "": printVerbose( _("Button save as clicked, path: {}", os.path.join(self.path, self.edit.text()))) UPDATER.emit("geditor_save", os.path.join(self.path, self.edit.text())) else: printVerbose(_("Button save as clicked")) self.edit.setVisible(True) self.edit.setFocus()
def execute(self): printVerbose(_("Button filemanager delete clicked")) if self.delete_confirm: self.delete_confirm = False self.update_image() UPDATER.emit("fileman_delete") else: self.button.setFocus() self.button.setIcon(QIcon()) self.button.setStyleSheet("color:black") self.button.setText(_("Are you sure?\nClick to delete.")) self.delete_confirm = True
def dataChanged(self, new, old, x): row = new.row() col = new.column() data = self.tabledata[row][col] printDebug("Offset changed - Row: {} Col: {} Data: {}".format(row,col,data)) # Hack to not edit any rotational offset but Z axis if row == 1 and not col == 3: return # TODO: Save system name if col == 10: return if row == 1: if col == 3: self.tabledata[row][col] = self.degree_tmpl.format(data) else: self.tabledata[row][col] = " " else: self.tabledata[row][col] = self.linear_tmpl.format(data) # make sure we switch to correct units for machine and rotational, row 2, does not get converted try: qualified = float(data) #qualified = float(locale.atof(data)) except Exception as e: printError(_("Offset data changed error {}", e)) # now update linuxcnc to the change try: if STAT.task_mode == LINUXCNC.MODE_MDI: if row == 0: # current Origin COMMAND.mdi("G10 L2 P0 %s %10.4f" % (self.axisletters[col-1], qualified)) elif row == 1: # rotational if col == 2: # Z axis only COMMAND.mdi("G10 L2 P0 R %10.4f" % (qualified)) elif row == 2: # G92 offset COMMAND.mdi("G92 %s %10.4f" % (self.axisletters[col-1], qualified)) elif row == 3: # Tool if not self.current_tool == 0: COMMAND.mdi("G10 L1 P%d %s %10.4f" % ( self.current_tool, self.axisletters[col-1], qualified)) COMMAND.mdi("G43") else: COMMAND.mdi("G10 L2 P%d %s %10.4f" % (row-3, self.axisletters[col-1], qualified)) except Exception as e: printError(_("Offsetpage widget error: MDI call error, {}", e)) self.reload_offsets()
def execute(self): if self.edit.isVisible(): self.edit.setVisible(False) printVerbose(_("Offset viewer edit Z: {}", self.edit.text())) if self.edit.text() != "": UPDATER.emit("offsetviewer_edit", (2, float(self.edit.text()))) else: UPDATER.emit("offsetviewer_edit", (2, 0.0)) else: printVerbose(_("Offset viewer edit Z clicked")) self.edit_lifetime = 5 self.edit.setText(str(STAT.actual_position[2])) self.edit.setVisible(True) self.edit.setFocus()
def __init__(self, parent=None): QGroupBox.__init__(self, parent) self.setTitle(_("Tool")) h1 = QHBoxLayout() self.tool_number = QLabel(_("No tool")) self.tool_number.setObjectName("lbl_main_screen_toolnum") self.tool_comment = QLabel(_("No comment")) self.tool_comment.setObjectName("lbl_main_screen_toolcomment") self.tool_comment.setAlignment(Qt.AlignRight | Qt.AlignVCenter) h1.addWidget(self.tool_number, 1) h1.addWidget(self.tool_comment, 7) self.setLayout(h1) UPDATER.signal("tool_in_spindle", self.on_tool_changed)
def execute(self): if self.edit.isVisible(): self.edit.setVisible(False) printVerbose(_("Tool viewer edit: {}", self.edit.text())) if self.edit.text() != "": UPDATER.emit("toolviewer_edit", self.edit.text()) else: UPDATER.emit("toolviewer_edit", 0) else: printVerbose(_("Tool viewer edit clicked")) self.edit_lifetime = 5 self.edit.setText("") self.edit.setVisible(True) self.edit.setFocus()
def save_clicked(self,default_file=None): if default_file: ini = default_file else: ini = os.environ['INI_FILE_NAME'] if not os.path.isfile(ini): ini = None if not ini: Notify.Warning(_("INI-file arg is not found.")) printWarning(_("INI-file arg is not found.")) return default_hal = os.path.join(os.path.dirname(ini),"default.hal") if not os.path.isfile(default_hal): copyfile(os.path.join(self.config_dir,"default_hal.cfg"),default_hal) with open(ini, "w") as fp: if self.config._defaults: fp.write("[%s]\n" % DEFAULTSECT) for (key, value) in self.config._defaults.items(): value = toUnicode(value) key = toUnicode(key) if '\n' in value: value = value.split('\n') else: value = [value] for v in value: if (v is not None) or (self.config._optcre == self.config.OPTCRE): data = "{} = {}\n".format(key, v) fp.write(data.encode('utf-8')) fp.write("\n") for section in self.config._sections: fp.write("[%s]\n" % section) for (key, value) in self.config._sections[section].items(): value = toUnicode(value) key = toUnicode(key) if key == "__name__": continue if '\n' in value: value = value.split('\n') else: value = [value] for v in value: if (v is not None) or (self.config._optcre == self.config.OPTCRE): data = "{} = {}\n".format(key, v) fp.write(data.encode('utf-8')) fp.write("\n") Notify.Info(_("Config file saved."))
def run_axis_wizard(self): if self.page.count() > 0: for i in reversed(range(self.page.count())): try: self.page.widget(i).deleteLater() self.page.removeTab(i) except Exception as e: printDebug(_("Delete tab exception: {}",e)) version = self.config.get("EMC","CORE") if float(version[:3]) <= '2.7': default_wizard = os.path.join(self.config_dir,"axis_wizard.cfg") else: default_wizard = os.path.join(self.config_dir,"joint_wizard.cfg") coordinates = self.config.get("TRAJ","COORDINATES") with open(default_wizard, "r") as fp: for line in fp: if line.startswith('#') or len(line) < 8 or not line: continue for i,axis in enumerate(coordinates.split(' ')): try: c,t,e,nYes,nNo,aYes,aNo = line.split(';')[:-1] except Exception as e: printDebug(_("Broken wizard line: {}\n{}",e,line)) continue if float(version[:3]) <= '2.7': num = {'X':0,'Y':1,'Z':2,'A':3,'B':4,'C':5,'U':6,'V':7,'W':8}[axis] else: num = i c = c.replace("_('",'') c = c.replace("')",'') t = t.replace("_('",'') t = t.replace("')",'') caption = c text = t try: caption = _(c).format(num,axis) text = _(t).format(num,axis) except: caption = c.format(num,axis) text = t.format(num,axis) p = (caption,text,e,nYes,nNo,aYes,aNo) self.page.addTab(WizardWidget(self,p),caption)
def task_mode_handler(self, data): if data == LINUXCNC.MODE_MANUAL: mode = _("MANUAL") UPDATER.emit("screen_manual") elif data == LINUXCNC.MODE_MDI: mode = _("MDI") UPDATER.emit("screen_mdi") elif data == LINUXCNC.MODE_AUTO: mode = _("AUTO") UPDATER.emit("screen_auto") else: mode = _("None") printVerbose(_("LinuxCNC mode {}", mode))