Esempio n. 1
0
 def on_reload_atlas_clicked(self, p0=None):
     """Reload the atlas. Regardless there has any old data."""
     self.engine = self.graph_engine.currentText().split(" - ")[1]
     self.Topologic_result.clear()
     if self.answer:
         progdlg = QProgressDialog(
             "Drawing atlas...",
             "Cancel",
             0,
             len(self.answer),
             self
         )
         progdlg.setWindowTitle("Type synthesis")
         progdlg.resize(400, progdlg.height())
         progdlg.setModal(True)
         progdlg.show()
         for i, G in enumerate(self.answer):
             QCoreApplication.processEvents()
             if progdlg.wasCanceled():
                 return
             if self.drawAtlas(i, G):
                 progdlg.setValue(i+1)
             else:
                 break
         progdlg.setValue(progdlg.maximum())
Esempio n. 2
0
    def __typeCombine(self, row: int) -> List[Graph]:
        """Combine and show progress dialog."""
        item = self.Expression_number.item(row)
        progdlg = QProgressDialog("Analysis of the topology...", "Cancel", 0,
                                  100, self)
        progdlg.setAttribute(Qt.WA_DeleteOnClose, True)
        progdlg.setWindowTitle("Type synthesis - ({})".format(item.text()))
        progdlg.setMinimumSize(QSize(500, 120))
        progdlg.setModal(True)
        progdlg.show()

        def stopFunc():
            """If stop by GUI."""
            QCoreApplication.processEvents()
            progdlg.setValue(progdlg.value() + 1)
            return progdlg.wasCanceled()

        def setjobFunc(job: str, maximum: float):
            """New job."""
            progdlg.setLabelText(job)
            progdlg.setValue(0)
            progdlg.setMaximum(maximum + 1)

        answer, time = topo(item.links, not self.graph_degenerate.isChecked(),
                            setjobFunc, stopFunc)
        self.time_label.setText("{}[min] {:.2f}[s]".format(
            int(time // 60), time % 60))
        progdlg.setValue(progdlg.maximum())
        if answer:
            return [Graph(G.edges) for G in answer]
Esempio n. 3
0
def on_action_Check_update_triggered(self):
    """Check for update."""
    progdlg = QProgressDialog("Checking update ...", "Cancel", 0, 3, self)
    progdlg.setAttribute(Qt.WA_DeleteOnClose, True)
    progdlg.setWindowTitle("Check for update")
    progdlg.resize(400, progdlg.height())
    progdlg.setModal(True)
    progdlg.show()
    url = check_update(progdlg)
    if not url:
        QMessageBox.information(self, "Pyslvs is up to date",
                                "You are using the latest version of Pyslvs.")
        return
    reply = QMessageBox.question(self, "Pyslvs has update",
                                 "Do you want to get it from Github?",
                                 (QMessageBox.Ok | QMessageBox.Cancel),
                                 QMessageBox.Ok)
    if reply == QMessageBox.Ok:
        _openURL(url)
Esempio n. 4
0
    def __reload_atlas(self):
        """Reload atlas with the engine."""
        current_pos = self.collection_list.currentRow()
        self.collections_layouts.clear()
        self.collection_list.clear()
        self.__clear_selection()

        if not self.collections:
            return

        progress_dlg = QProgressDialog("Drawing atlas...", "Cancel", 0,
                                       len(self.collections), self)
        progress_dlg.setAttribute(Qt.WA_DeleteOnClose, True)
        progress_dlg.setWindowTitle("Type synthesis")
        progress_dlg.resize(400, progress_dlg.height())
        progress_dlg.setModal(True)
        progress_dlg.show()
        engine_str = self.graph_engine.currentText()
        for i, g in enumerate(self.collections):
            QCoreApplication.processEvents()
            if progress_dlg.wasCanceled():
                progress_dlg.deleteLater()
                return

            item = QListWidgetItem(f"No. {i + 1}")
            engine = engine_picker(g, engine_str,
                                   self.graph_link_as_node.isChecked())
            item.setIcon(
                to_graph(g,
                         self.collection_list.iconSize().width(), engine,
                         self.graph_link_as_node.isChecked(),
                         self.graph_show_label.isChecked(),
                         self.is_monochrome()))
            self.collections_layouts.append(engine)
            item.setToolTip(f"{g.edges}")
            self.collection_list.addItem(item)
            progress_dlg.setValue(i + 1)

        progress_dlg.deleteLater()
        self.collection_list.setCurrentRow(current_pos)
Esempio n. 5
0
 def on_reload_atlas_clicked(self, p0=None):
     """Reload atlas with the engine."""
     if not self.collections:
         return
     self.collections_layouts.clear()
     self.collection_list.clear()
     self.selection_window.clear()
     self.Expression_edges.clear()
     self.NL.setText('0')
     self.NJ.setText('0')
     self.DOF.setText('0')
     self.grounded_list.clear()
     progdlg = QProgressDialog("Drawing atlas...", "Cancel", 0,
                               len(self.collections), self)
     progdlg.setAttribute(Qt.WA_DeleteOnClose, True)
     progdlg.setWindowTitle("Type synthesis")
     progdlg.resize(400, progdlg.height())
     progdlg.setModal(True)
     progdlg.show()
     engineSTR = self.graph_engine.currentText().split(" - ")[1]
     for i, G in enumerate(self.collections):
         QCoreApplication.processEvents()
         if progdlg.wasCanceled():
             return
         item = QListWidgetItem("No. {}".format(i + 1))
         try:
             engine = engine_picker(G, engineSTR)
             item.setIcon(
                 graph(G,
                       self.collection_list.iconSize().width(), engine))
         except EngineError as e:
             progdlg.setValue(progdlg.maximum())
             self.engineErrorMsg(e)
             break
         else:
             self.collections_layouts.append(engine)
             item.setToolTip(
                 "{}\nUse the right-click menu to operate.".format(G.edges))
             self.collection_list.addItem(item)
             progdlg.setValue(i + 1)
Esempio n. 6
0
    def __check_update(self):
        """Check for update."""
        progress_dlg = QProgressDialog("Checking update ...", "Cancel", 0, 3, self)
        progress_dlg.setAttribute(Qt.WA_DeleteOnClose)
        progress_dlg.setWindowTitle("Check for update")
        progress_dlg.resize(400, progress_dlg.height())
        progress_dlg.setModal(True)
        progress_dlg.show()
        url = check_update(progress_dlg)
        progress_dlg.deleteLater()
        if not url:
            QMessageBox.information(
                self,
                "Pyslvs is up to date",
                "You are using the latest version of Pyslvs."
            )
            return

        if QMessageBox.question(
            self,
            "Pyslvs has update",
            "Do you want to get it from Github?"
        ) == QMessageBox.Yes:
            self.__open_url(url)
Esempio n. 7
0
    def load(self, file_name: str):
        """Load YAML file."""
        if self.__check_file_changed():
            return

        # Clear first
        self.__clear_func()

        # Load file
        dlg = QProgressDialog("Loading project", "Cancel", 0, 8, self.parent())
        dlg.setLabelText("Reading file ...")
        dlg.show()
        with open(file_name, encoding='utf-8') as f:
            yaml_script = f.read()
        data: Dict[str, Any] = yaml.load(yaml_script, Loader=yaml.FullLoader)

        # Links data
        dlg.setValue(1)
        dlg.setLabelText("Loading mechanism ...")
        if dlg.wasCanceled():
            return self.__clear_func()
        links_data: Dict[str, str] = data.get('links', {})
        self.__add_links_func(links_data)

        # Mechanism data
        mechanism_data: List[Dict[str, Any]] = data.get('mechanism', [])
        p_attr = []
        nan = float("nan")
        for point_attr in mechanism_data:
            QCoreApplication.processEvents()
            p_x: float = point_attr.get('x', nan)
            p_y: float = point_attr.get('y', nan)
            p_links: Tuple[str] = point_attr.get('links', ())
            p_type: int = point_attr.get('type', 0)
            p_angle: float = point_attr.get('angle', 0.)
            p_attr.append(
                (p_x, p_y, ','.join(p_links), 'Green', p_type, p_angle))
        self.__add_points_func(p_attr)

        # Input data
        dlg.setValue(2)
        dlg.setLabelText("Loading input data ...")
        if dlg.wasCanceled():
            return self.__clear_func()
        input_data: List[Dict[str, int]] = data.get('input', [])
        i_attr = []
        for input_attr in input_data:
            QCoreApplication.processEvents()
            if ('base' in input_attr) and ('drive' in input_attr):
                i_base = input_attr['base']
                i_drive = input_attr['drive']
                i_attr.append((i_base, i_drive))
        self.__load_inputs_func(i_attr)

        # Storage data
        dlg.setValue(3)
        dlg.setLabelText("Loading storage ...")
        if dlg.wasCanceled():
            return self.__clear_func()
        storage_data: List[Tuple[str, str]] = data.get('storage', [])
        self.__add_storage_func(storage_data)

        # Path data
        dlg.setValue(4)
        dlg.setLabelText("Loading paths ...")
        if dlg.wasCanceled():
            return self.__clear_func()
        path_data: Dict[str, Sequence[Tuple[float,
                                            float]]] = data.get('path', {})
        self.__load_path_func(path_data)

        # Collection data
        dlg.setValue(5)
        dlg.setLabelText("Loading graph collections ...")
        if dlg.wasCanceled():
            return self.__clear_func()
        collection_data: List[Tuple[Tuple[int, int],
                                    ...]] = data.get('collection', [])
        self.__load_collect_func(collection_data)

        # Configuration data
        dlg.setValue(6)
        dlg.setLabelText("Loading synthesis configurations ...")
        if dlg.wasCanceled():
            return self.__clear_func()
        config_data: Dict[str, Dict[str, Any]] = data.get('triangle', {})
        self.__load_triangle_func(config_data)

        # Algorithm data
        dlg.setValue(7)
        dlg.setLabelText("Loading synthesis configurations ...")
        if dlg.wasCanceled():
            return self.__clear_func()
        algorithm_data: List[Dict[str, Any]] = data.get('algorithm', [])
        self.__load_algorithm_func(algorithm_data)

        # Workbook loaded
        dlg.setValue(8)
        dlg.deleteLater()
        self.__set_file_name(file_name)
        self.__workbook_saved()

        # Show overview dialog.
        dlg = OverviewDialog(
            self.parent(), f"YAML project: {QFileInfo(file_name).baseName()}",
            storage_data, i_attr, path_data, collection_data, config_data,
            algorithm_data)
        dlg.show()
        dlg.exec()
        dlg.deleteLater()
Esempio n. 8
0
    def __load_commit(self, commit: CommitModel):
        """Load the commit pointer."""
        if self.__check_file_changed():
            return

        # Clear first
        self.__clear_func()

        # Load the commit to widgets.
        dlg = QProgressDialog(f"Loading commit # {commit.id}.", "Cancel", 0, 8,
                              self)
        dlg.setLabelText(f"Setting commit ...")
        dlg.show()
        self.load_id.emit(commit.id)
        self.commit_current_id.setValue(commit.id)
        self.branch_current.setText(commit.branch.name)

        # Expression
        dlg.setValue(1)
        dlg.setLabelText("Loading mechanism ...")
        self.__add_links_func(_decompress(commit.linkcolor))
        self.__parse_func(_decompress(commit.mechanism))

        # Inputs data
        dlg.setValue(2)
        dlg.setLabelText("Loading input data ...")
        input_data: Sequence[Tuple[int, int]] = _decompress(commit.inputsdata)
        self.__load_inputs_func(input_data)

        # Storage
        dlg.setValue(3)
        dlg.setLabelText("Loading storage ...")
        storage_data: List[Tuple[str, str]] = _decompress(commit.storage)
        self.__add_storage_func(storage_data)

        # Path data
        dlg.setValue(4)
        dlg.setLabelText("Loading paths ...")
        path_data: Dict[str,
                        Sequence[Tuple[float,
                                       float]]] = _decompress(commit.pathdata)
        self.__load_path_func(path_data)

        # Collection data
        dlg.setValue(5)
        dlg.setLabelText("Loading graph collections ...")
        collection_data: List[Tuple[Tuple[int, int],
                                    ...]] = _decompress(commit.collectiondata)
        self.__load_collect_func(collection_data)

        # Configuration data
        dlg.setValue(6)
        dlg.setLabelText("Loading synthesis configurations ...")
        config_data: Dict[str, Dict[str,
                                    Any]] = _decompress(commit.triangledata)
        self.__load_triangle_func(config_data)

        # Algorithm data
        dlg.setValue(7)
        dlg.setLabelText("Loading synthesis configurations ...")
        algorithm_data: List[Dict[str,
                                  Any]] = _decompress(commit.algorithmdata)
        self.__load_algorithm_func(algorithm_data)

        # Workbook loaded
        dlg.setValue(8)
        dlg.deleteLater()
        self.__workbook_saved()

        # Show overview dialog.
        dlg = OverviewDialog(self,
                             f"{commit.branch.name} - commit # {commit.id}",
                             storage_data, input_data, path_data,
                             collection_data, config_data, algorithm_data)
        dlg.show()
        dlg.exec()
        dlg.deleteLater()