예제 #1
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)
예제 #2
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)
예제 #3
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()
예제 #4
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()