Beispiel #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())
Beispiel #2
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 ""
Beispiel #3
0
 def stop_func(self) -> bool:
     """Return dialog status."""
     try:
         QCoreApplication.processEvents()
         return self.wasCanceled()
     except RuntimeError:
         return False
Beispiel #4
0
def check_update(progdlg) -> [str, bool]:
    m = progdlg.maximum()
    from core.QtModules import QCoreApplication
    for i in range(m):
        QCoreApplication.processEvents()
        if progdlg.wasCanceled():
            return
        next = list(VERSION[:m])
        next[i] += 1
        url = "https://github.com/KmolYuan/Pyslvs-PyQt5/releases/tag/v{}.{:02}.{}".format(
            *next)
        request = requests.get(url)
        progdlg.setValue(i + 1)
        if request.status_code == 200:
            progdlg.setValue(m)
            return url
    return False
Beispiel #5
0
def check_update(dlg: QProgressDialog) -> str:
    """Check for update."""
    m = dlg.maximum()
    for i in range(m):
        QCoreApplication.processEvents()
        if dlg.wasCanceled():
            return ""
        next_ver = list(__version__[:m])
        next_ver[i] += 1
        url = (
            "https://github.com/KmolYuan/Pyslvs-PyQt5/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 ""
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
0
    def __reload_atlas(self, *_: int):
        """Reload the atlas."""
        scroll_bar: QScrollBar = self.structure_list.verticalScrollBar()
        scroll_pos = scroll_bar.sliderPosition()
        self.structure_list.clear()

        if not self.answer:
            return

        dlg = SynthesisProgressDialog("Type synthesis", "Drawing atlas...",
                                      len(self.answer), self)
        dlg.show()
        for i, G in enumerate(self.answer):
            QCoreApplication.processEvents()
            if dlg.wasCanceled():
                return
            if self.__draw_atlas(i, G):
                dlg.setValue(i + 1)
            else:
                break
        dlg.setValue(dlg.maximum())
        scroll_bar.setSliderPosition(scroll_pos)
Beispiel #9
0
 def stopFunc():
     QCoreApplication.processEvents()
     progdlg.setValue(progdlg.value() + 1)
     return progdlg.wasCanceled()
Beispiel #10
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()