Esempio n. 1
0
    def __read_slvs(self, file_name: str):
        """Read slvs format.

        + Choose a group.
        + Read the entities of the group.
        """
        parser = SlvsParser(file_name)
        if not parser.isValid():
            QMessageBox.warning(self, "Format error",
                                "The format is not support.")
            return
        groups = parser.getGroups()
        if not groups:
            QMessageBox.warning(self, "Format error",
                                "The model file is empty.")
            return
        group, ok = QInputDialog.getItem(
            self, "Solvespace groups", "Choose a group:\n"
            "(Please know that the group must contain a sketch only.)",
            ["@".join(g) for g in groups], 0, False)
        if not ok:
            return
        self.clear()
        self.DatabaseWidget.reset()
        print(f"Read from group: {group}")
        self.parseExpression(parser.parse(group.split('@')[0]))
Esempio n. 2
0
 def loadExample(self, isImport=False) -> bool:
     """Load example to new workbook."""
     if not self.checkSaved():
         return False
     #load example by expression.
     example_name, ok = QInputDialog.getItem(
         self, "Examples", "Select a example to load:",
         sorted(k for k in example_list), 0, False)
     if not ok:
         return False
     if not isImport:
         self.reset()
         self.clearFunc()
     self.parseFunc(example_list[example_name])
     self.fileName = QFileInfo(example_name)
     self.isSavedFunc()
     print("Example \"{}\" has been loaded.".format(example_name))
     return True
Esempio n. 3
0
 def on_merge_btn_clicked(self):
     tmp = []
     for i in range(self.tabWidget.count()):
         if i == self.tabWidget.currentIndex():
             continue
         tmp.append(str(i) + ":" + self.tabWidget.tabText(i))
     item, ok = QInputDialog.getItem(self, "Merge", "Select figure", tmp, 0,
                                     False)
     if not ok: return
     tabcunt = int(item.split(":")[0])
     view = self.tabWidget.widget(self.tabWidget.currentIndex())
     mer = self.tabWidget.widget(tabcunt)
     for seri in mer.m_chart.series():
         spline = QSplineSeries()
         spline.append(seri.pointsVector())
         view.m_chart.addSeries(spline)
     self.on_tabWidget_tabCloseRequested(tabcunt)
     mer.close()
Esempio n. 4
0
    def __spell_correction(self):
        """Refactor words."""
        pos = self.positionFromLineIndex(*self.getCursorPosition())
        start, end, words = self.__word_at_pos(pos)
        if not words:
            return

        # Camel case.
        word = words
        for m in re.finditer(r'[A-Za-z][a-z]+', words):
            if m.start() < pos - start < m.end():
                word = m.group(0)
                break

        answer, ok = QInputDialog.getItem(self, "Spell correction",
                                          f"Refactor word: \"{word}\"",
                                          _spell.candidates(word))
        if ok:
            self.__replace_all(words, words.replace(word, answer))
Esempio n. 5
0
 def loadExample(self, is_import: bool = False) -> bool:
     """Load example to new workbook."""
     if self.__check_file_changed():
         return False
     # load example by expression.
     example_name, ok = QInputDialog.getItem(self, "Examples",
                                             "Select an example to load:",
                                             sorted(example_list), 0, False)
     if not ok:
         return False
     expr, inputs = example_list[example_name]
     if not is_import:
         self.reset()
         self.__clear_func()
     self.__parse_func(expr)
     if not is_import:
         # Import without input data.
         self.__load_inputs_func(inputs)
     self.file_name = QFileInfo(example_name)
     self.__workbook_saved()
     print(f"Example \"{example_name}\" has been loaded.")
     return True
Esempio n. 6
0
 def importMechanism(self, fileName: str):
     """Pick and import the latest mechanism from a branch."""
     self.connectDatabase(fileName)
     commit_all = CommitModel.select().join(BranchModel)
     branch_all = BranchModel.select().order_by(BranchModel.name)
     if self.history_commit != None:
         self.connectDatabase(self.fileName.absoluteFilePath())
     else:
         self.colseDatabase()
     branch_name, ok = QInputDialog.getItem(
         self, "Branch", "Select the latest commit in the branch to load.",
         [branch.name for branch in branch_all], 0, False)
     if not ok:
         return
     try:
         commit = (commit_all.where(
             BranchModel.name == branch_name).order_by(
                 CommitModel.date).get())
     except CommitModel.DoesNotExist:
         QMessageBox.warning(self, "Warning",
                             "This file is a non-committed database.")
     else:
         self.importCommit(commit)