コード例 #1
0
 def loadSelectedFile(self):
     """Loads the selected file into LinuxCNC."""
     selection = self.getSelection()
     if selection is not None:
         path = self.model.filePath(selection[0])
         loadProgram(path)
         return True
     return False
コード例 #2
0
 def onItemActivated(self):
     data = self.currentData()
     if data == 'browse_files':
         getDialog('open_file').show()
     elif data is None:
         pass
     else:
         loadProgram(data)
コード例 #3
0
 def onItemActivated(self):
     data = self.currentData()
     if data == 'browse_files':
         self.file_dialog.show()
     elif data is None:
         pass
     else:
         loadProgram(data)
コード例 #4
0
 def openSelected(self):
     try:
         item = self.selectedItems()[0]
         fpath = item.data(Qt.UserRole)
         loadProgram(fpath)
         hideActiveDialog()
     except (IndexError, AttributeError):
         pass
コード例 #5
0
 def copySelectionToGcodeEditor(self):
     fname = '/tmp/mdi_gcode.ngc'
     selection = self.selectedItems()
     with open(fname, 'w') as fh:
         for item in selection:
             cmd = str(item.text()).strip()
             fh.write(cmd + '\n')
         fh.write('M2\n')
     loadProgram(fname)
コード例 #6
0
ファイル: open_file_dialog.py プロジェクト: silopolis/qtpyvcp
 def accept(self):
     path = self.selectedFiles()[0]
     stats = QFileInfo(path)
     if stats.isDir():
         self.setDirectory(path)
         return
     if not stats.exists():
         return
     loadProgram(path)
     self.hide()
コード例 #7
0
    def on_post_to_file(self):
        ok, errors = self.is_valid()
        if ok:
            f = GCodeFile()
            f.ops.append(self.create_op())

            program_path = self._get_next_available_file_name()

            f.write_to_file(program_path)
            if self._confirm_action('Load GCode', 'Would you like to open the file in the viewer?'):
                loadProgram(program_path)
        else:
            self._show_error_msg('GCode Error', '\n'.join(errors))
コード例 #8
0
    def on_post_to_file(self):
        ok, errors = self.is_valid()
        if ok:
            f = GCodeFile()
            f.ops.append(self.create_op())

            program_path = self._get_next_available_file_name()

            f.write_to_file(program_path)

            msg = QMessageBox(QMessageBox.Question,
                              'GCode Generated', 'The file has been created.\n'
                                                 'Would you like to load it into the viewer?',
                              QMessageBox.Yes | QMessageBox.No, self, Qt.FramelessWindowHint)

            if msg.exec_() == QMessageBox.Yes:
                loadProgram(program_path)

        else:
            msg = QMessageBox(QMessageBox.Critical,
                              'GCode Error', '\n'.join(errors),
                              QMessageBox.Ok, self, Qt.FramelessWindowHint)
            msg.exec_()
コード例 #9
0
    def save(self):
        reload_file = True
        self.filename = str(STATUS.file)
        # determine of have a file name
        if self.filename == '':
            reload_file = False
            self.filename = '/tmp/gcode_tmp.ngc'

        # save out the file
        save_file = QFile(self.filename)
        result = save_file.open(QFile.WriteOnly)
        if result:
            save_stream = QTextStream(save_file)
            save_stream << self.text()
            save_file.close()
            # file save worked, now either load fresh or reload
            if reload_file:
                reLoadProgram()
            else:
                loadProgram(self.filename)

        else:
            print("save error")
コード例 #10
0
    def openSelectedItem(self, index=None):
        """If ngc file, opens in LinuxCNC, if dir displays dir."""
        if index is None:
            selection = self.getSelection()
            if selection is None:
                return
            index = selection[0]

        path = self.model.filePath(self.rootIndex())
        name = self.model.filePath(index)

        absolute_path = os.path.join(path, name)

        file_info = QFileInfo(absolute_path)
        if file_info.isDir():
            self.model.setRootPath(absolute_path)
            self.setRootIndex(self.model.index(absolute_path))
            self.rootChanged.emit(absolute_path)

        elif file_info.isFile():
            # if file_info.completeSuffix() not in self.nc_file_exts:
            #     LOG.warn("Unsuported NC program type with extention .%s",
            #              file_info.completeSuffix())
            loadProgram(absolute_path)
コード例 #11
0
    def generateCode(self):
        LOG.debug('generateCode')
        sub_args = [] * MAX_NUMBER_OF_PARAMS
        param_details = [] * MAX_NUMBER_OF_PARAMS

        window = qApp.activeWindow()
        for aSetting in self._setting_args:
            param_name, param_number, default_val, comment = aSetting

            LOG.debug('-----settings param: {}'.format(param_name))

            if param_name == PROBE_MODE_PARAM_NAME:
                val = 0 if self.probe_wcs.isChecked() else 1
            else:
                try:
                    # get the value from the GUI input widget
                    val = getattr(window, param_name).text() or default_val
                except:
                    val = default_val
                    LOG.warning(
                        'No input for red<{}> parameter, using default value blue<{}>'
                        .format(param_name, val))

            if val == '':
                LOG.error(
                    'No value given for parameter red<{}>, and no default specified'
                    .format(param_name))
                return False

            try:
                val = float(val)
            except ValueError:
                LOG.error(
                    'Input value "{}" given for parameter "{}" is not a valid number'
                    .format(val, param_name))
                return False

            index = int(param_number) - 1
            while len(sub_args) <= index:
                sub_args.append("[0.0000]")
                param_details.append("---")

            sub_args[index] = "[{}]".format(val)
            param_details[index] = getCommentFormat().format(param_name, val)

        input_items = (self.verticalLayout.itemAt(i)
                       for i in range(self.verticalLayout.count()))

        input_index = 0
        for anInput in input_items:
            if isinstance(anInput, QWidgetItem):
                entered_value = anInput.widget().get_inputValue()
                LOG.debug('Entered value: <{}>'.format(entered_value))

                param_name, param_number, default_val, comment = self._input_args[
                    input_index]
                LOG.debug('-----input param: {}'.format(param_name))
                input_index += 1

                try:
                    val = entered_value or default_val
                except:
                    val = default_val
                    LOG.warning(
                        'No input for red<{}> parameter, using default value blue<{}>'
                        .format(param_name, val))

                if val == '':
                    LOG.error(
                        'No value given for parameter red<{}>, and no default specified'
                        .format(param_name))
                    return False

                try:
                    val = float(val)
                except ValueError:
                    LOG.error(
                        'Input value "{}" given for parameter "{}" is not a valid number'
                        .format(val, param_name))
                    return False

                index = int(param_number) - 1
                while len(sub_args) <= index:
                    sub_args.append("[0.0000]")
                    param_details.append("---")

                sub_args[index] = "[{}]".format(val)
                param_details[index] = getCommentFormat().format(
                    param_name, val)

        params_list = '\n'.join(param_details)
        arg_str = ' '.join(sub_args)
        sub_name = os.path.splitext(self._routineName)[0]
        program_text = "(Call the probing subroutine with user's entered values)\n" \
                       + params_list + "\n" \
                       "o<{}> call {}\nM2".format(sub_name, arg_str)

        new_file_path = os.path.join(PROGRAM_PREFIX,
                                     "with_vals_" + self._routineName)
        LOG.debug('Writting output file: <%s>', new_file_path)
        outputFile = open(new_file_path, "w")
        outputFile.write(program_text)
        outputFile.close()
        loadProgram(new_file_path)
        self.probingCodeReady.emit(self)
コード例 #12
0
    def parseRoutineAndGenerateCode(self):
        window = qApp.activeWindow()

        subfile = None
        for dir in SUBROUTINE_SEARCH_DIRS:
            subfile = os.path.join(dir, self._filename)
            if os.path.isfile(subfile):
                break

        if subfile is None:
            LOG.error('Subroutine file could not be found: yellow<{}>'.format(self._filename))
            return False

        with open(subfile, 'r') as fh:
            lines = fh.readlines()

        args = []
        for line in lines:
            line = line.strip()
            if not line.startswith('#'):
                continue
            result_list = PARSE_POSITIONAL_ARGS.findall(line)
            if len(result_list) == 0:
                continue

            pname, pnumber, default_val, comment = result_list[0]

            if int(pnumber) > 30:
                # only #1-#30 are passed to the sub
                continue

            try:
                # get the value from the GUI input widget
                val = getattr(window, pname).text() or default_val
            except:
                val = default_val
                LOG.warning('No input for red<{}> parameter, using default value blue<{}>'.format(pname, val))

            if val == '':
                LOG.error('No value given for parameter red<{}>, and no default specified'.format(pname))
                return False

            try:
                val = float(val)
            except ValueError:
                LOG.error('Input value "{}" given for parameter "{}" is not a valid number'.format(val, pname))
                return False

            index = int(pnumber) - 1
            while len(args) <= index:
                args.append("[0.0000]")

            args[index] = "[{}]".format(val)

        arg_str = ' '.join(args)
        sub_name = os.path.splitext(self._filename)[0]
        programText = "(Call the probing subroutine with user's entered values)\n" \
                      "o<{}> call {}\nM2".format(sub_name, arg_str)

        LOG.debug('Program text: <%s>', programText)

        new_file_path = os.path.join(PROGRAM_PREFIX, "with_vals_" + self._filename)
        LOG.debug('Writting output file: <%s>', new_file_path)
        outputFile = open(new_file_path, "w")
        outputFile.write(programText)
        outputFile.close()
        loadProgram(new_file_path)