예제 #1
0
 def __draw_atlas(self, i: int, g: Graph) -> bool:
     """Draw atlas and return True if done."""
     item = QListWidgetItem(f"No. {i + 1}")
     item.setIcon(
         to_graph(g,
                  self.structure_list.iconSize().width(),
                  self.graph_engine.currentText(),
                  self.graph_link_as_node.isChecked()))
     item.setToolTip(f"Edge Set: {list(g.edges)}\n"
                     f"Link Assortments: {l_a(g)}\n"
                     f"Contracted Link Assortments: {c_l_a(g)}")
     self.structure_list.addItem(item)
     return True
예제 #2
0
class AddVariable(QUndoCommand):
    """Add a variable to list widget."""
    def __init__(self, text: str, widget: QListWidget):
        super(AddVariable, self).__init__()
        self.item = QListWidgetItem(text)
        self.item.setToolTip(text)
        self.widget = widget

    def redo(self):
        """Add to widget."""
        self.widget.addItem(self.item)

    def undo(self):
        """Take out the item."""
        self.widget.takeItem(self.widget.row(self.item))
예제 #3
0
 def find_in_nodes(node: QTreeWidgetItem, last_name: str = ''):
     """Find the word in all nodes."""
     last_name += node.text(0)
     if node.childCount():
         last_name += '->'
     code = int(node.text(2))
     doc = self.data[code]
     pattern = re.compile(text.encode('utf-8'), flags)
     for m in pattern.finditer(doc.encode('utf-8')):
         start, end = m.span()
         item = QListWidgetItem(last_name)
         item.setToolTip(f"{code}:{start}:{end}")
         self.find_list_node[code] = node
         self.find_list.addItem(item)
     for i in range(node.childCount()):
         find_in_nodes(node.child(i), last_name)
예제 #4
0
 def __addResult(self, result: Dict[str, Any]):
     """Add result items, except add to the list."""
     item = QListWidgetItem(result['Algorithm'])
     interrupt = result['interrupted']
     if interrupt == 'False':
         item.setIcon(QIcon(QPixmap(":/icons/task-completed.png")))
     elif interrupt == 'N/A':
         item.setIcon(QIcon(QPixmap(":/icons/question-mark.png")))
     else:
         item.setIcon(QIcon(QPixmap(":/icons/interrupted.png")))
     text = "{} ({})".format(
         result['Algorithm'], "No interrupt."
         if interrupt == 'False' else "Interrupt at {}".format(interrupt))
     if interrupt == 'N/A':
         text += "\n※Completeness is not clear."
     item.setToolTip(text)
     self.Result_list.addItem(item)
예제 #5
0
 def __drawAtlas(self, i: int, G: Graph) -> bool:
     """Draw atlas and return True if done."""
     item = QListWidgetItem("No. {}".format(i + 1))
     try:
         item.setIcon(
             graph(G,
                   self.Topologic_result.iconSize().width(), self.engine,
                   self.graph_link_as_node.isChecked()))
     except EngineError as e:
         QMessageBox.warning(
             self, str(e),
             "Please install and make sure Graphviz is working.")
         return False
     else:
         item.setToolTip(str(G.edges))
         self.Topologic_result.addItem(item)
         return True
예제 #6
0
 def __add_result(self, result: Dict[str, Any]):
     """Add result items, except add to the list."""
     item = QListWidgetItem(result['Algorithm'])
     interrupt = result['interrupted']
     if interrupt == 'False':
         interrupt_icon = "task_completed.png"
     elif interrupt == 'N/A':
         interrupt_icon = "question.png"
     else:
         interrupt_icon = "interrupted.png"
     item.setIcon(QIcon(QPixmap(f":/icons/{interrupt_icon}")))
     if interrupt == 'False':
         interrupt_text = "No interrupt."
     else:
         interrupt_text = f"Interrupt at: {interrupt}"
     text = f"{result['Algorithm']} ({interrupt_text})"
     if interrupt == 'N/A':
         text += "\n※Completeness is unknown."
     item.setToolTip(text)
     self.result_list.addItem(item)
예제 #7
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)
예제 #8
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)
예제 #9
0
 def __init__(self, parent: QWidget, commit, decompress: Callable[[str],
                                                                  Any]):
     """Data come from commit."""
     super(WorkbookOverview, self).__init__(parent)
     self.setupUi(self)
     """Window title"""
     self.setWindowTitle("{} - commit #{}".format(commit.branch.name,
                                                  commit.id))
     """Expression of main canvas."""
     expr = decompress(commit.mechanism)
     if len(expr) > 3:
         item = QListWidgetItem("[Main canvas]")
         item.setToolTip("{}...".format(expr[:30]))
         self.storage_list.addItem(item)
     """Expression of storage data."""
     storage = decompress(commit.storage)
     for name, expr in storage:
         item = QListWidgetItem("[Storage] - {}".format(name))
         item.setToolTip(expr)
         self.storage_list.addItem(item)
     self.__setItemText(0, int(len(expr) > 3) + len(storage))
     """Expression of inputs variable data."""
     inputsdata = decompress(commit.inputsdata)
     for expr in inputsdata:
         self.variables_list.addItem("Point{}->{}->{}".format(*expr))
     """Path data."""
     pathdata = decompress(commit.pathdata)
     for name, paths in pathdata.items():
         item = QListWidgetItem(name)
         item.setToolTip(", ".join('[{}]'.format(i)
                                   for i, path in enumerate(paths) if path))
         self.records_list.addItem(item)
     self.__setItemText(1, len(inputsdata), len(pathdata))
     """Structure collections."""
     collectiondata = decompress(commit.collectiondata)
     for edges in collectiondata:
         self.structures_list.addItem(str(edges))
     """Triangle collections."""
     triangledata = decompress(commit.triangledata)
     for name, data in triangledata.items():
         item = QListWidgetItem(name)
         item.setToolTip(data['Expression'])
         self.triangular_iteration_list.addItem(item)
     self.__setItemText(2, len(collectiondata), len(triangledata))
     """Dimensional synthesis."""
     algorithmdata = decompress(commit.algorithmdata)
     for data in algorithmdata:
         self.results_list.addItem(data['Algorithm'])
     self.__setItemText(3, len(algorithmdata))
예제 #10
0
    def __init__(
        self,
        parent: QWidget,
        title: str,
        storage_data: List[Tuple[str, str]],
        input_data: Sequence[Tuple[int, int]],
        path_data: Dict[str, Sequence[Tuple[float, float]]],
        collection_data: List[Tuple[Tuple[int, int], ...]],
        config_data: Dict[str, Dict[str, Any]],
        algorithm_data: List[Dict[str, Any]]
    ):
        """Data come from commit."""
        super(OverviewDialog, self).__init__(parent)
        self.setupUi(self)

        # Window title
        self.setWindowTitle(title)

        # Expression of storage data.
        for name, expr in storage_data:
            item = QListWidgetItem(f"[Storage] - {name}")
            item.setToolTip(expr)
            self.storage_list.addItem(item)
        self.__set_item_text(0, len(storage_data))

        # Expression of inputs variable data and Path data.
        for a, b in input_data:
            self.variables_list.addItem(f"Point{a}->Point{b}")
        for name, paths in path_data.items():
            item = QListWidgetItem(name)
            item.setToolTip(", ".join(
                f'[{i}]' for i, path in enumerate(paths) if path
            ))
            self.records_list.addItem(item)
        self.__set_item_text(1, len(input_data), len(path_data))

        # Structure collections and Triangle collections.
        for edges in collection_data:
            self.structures_list.addItem(str(edges))
        for name, data in config_data.items():
            item = QListWidgetItem(name)
            item.setToolTip(data['Expression'])
            self.triangular_iteration_list.addItem(item)
        self.__set_item_text(2, len(collection_data), len(config_data))

        # Dimensional synthesis.
        for data in algorithm_data:
            self.results_list.addItem(data['Algorithm'])
        self.__set_item_text(3, len(algorithm_data))
예제 #11
0
 def add_find_result(code: int, last_name: str, start: int, end: int):
     """Add result to list."""
     item = QListWidgetItem("{}: [{}, {}]".format(code, start, end))
     item.setToolTip(last_name)
     self.find_list.addItem(item)