Ejemplo n.º 1
0
def check_update(dlg: QProgressDialog) -> str:
    """Check for update."""
    ver_list = [int(v) for v in __version__.split('.') if v.isdigit()]
    m = len(ver_list)
    for i in range(m):
        if i == 0:
            text = "major"
        elif i == 1:
            text = "minor"
        else:
            text = "build"
        dlg.setLabelText(f"Checking for {text}...")
        QCoreApplication.processEvents()
        if dlg.wasCanceled():
            return ""
        next_ver = ver_list[:m]
        next_ver[i] += 1
        url = ("https://github.com/KmolYuan/Pyslvs-UI/releases/tag/"
               f"v{next_ver[0]}.{next_ver[1]:02}.{next_ver[2]}")
        request = requests.get(url)
        dlg.setValue(i + 1)
        if request.status_code == 200:
            dlg.setValue(m)
            return url
    return ""
Ejemplo n.º 2
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()
Ejemplo n.º 3
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()