Beispiel #1
0
 def on_collection_list_currentItemChanged(self, item, p0):
     """Show the data of collection.
     
     Save the layout position to keep the graphs
     will be in same appearance.
     """
     has_item = bool(item)
     self.delete_button.setEnabled(has_item)
     self.grounded_button.setEnabled(has_item)
     self.triangle_button.setEnabled(has_item)
     if not item:
         return
     self.selection_window.clear()
     item_ = QListWidgetItem(item.text())
     row = self.collection_list.row(item)
     G = self.collections[row]
     self.ground_engine = self.collections_layouts[row]
     item_.setIcon(
         graph(G,
               self.selection_window.iconSize().width(),
               self.ground_engine))
     self.selection_window.addItem(item_)
     self.Expression_edges.setText(str(list(G.edges)))
     self.NL.setText(str(len(G.nodes)))
     self.NJ.setText(str(len(G.edges)))
     self.DOF.setText(
         str(3 * (int(self.NL.text()) - 1) - 2 * int(self.NJ.text())))
Beispiel #2
0
 def on_grounded_button_clicked(self):
     """Grounded combinations."""
     current_item = self.collection_list.currentItem()
     self.collections_grounded.clear()
     self.grounded_list.clear()
     G = self.collections[self.collection_list.row(current_item)]
     item = QListWidgetItem("Released")
     try:
         icon = graph(G,
                      self.grounded_list.iconSize().width(),
                      self.ground_engine)
     except EngineError as e:
         self.engineErrorMsg(e)
         return
     item.setIcon(icon)
     self.collections_grounded.append(G)
     self.grounded_list.addItem(item)
     for node in G.nodes:
         G_ = Graph(G)
         G_.remove_node(node)
         error = False
         for H in self.collections_grounded:
             if is_isomorphic(G_, H):
                 error = True
         if error:
             continue
         item = QListWidgetItem("link_{} constrainted".format(node))
         icon = graph(G,
                      self.grounded_list.iconSize().width(),
                      self.ground_engine,
                      except_node=node)
         item.setIcon(icon)
         self.collections_grounded.append(G_)
         self.grounded_list.addItem(item)
     self.grounded_merge.setEnabled(bool(self.grounded_list.count()))
Beispiel #3
0
    def __grounded(self):
        """Grounded combinations."""
        current_item = self.collection_list.currentItem()
        self.collections_grounded.clear()
        self.grounded_list.clear()
        g = self.collections[self.collection_list.row(current_item)]
        item = QListWidgetItem("Released")
        icon = to_graph(g,
                        self.grounded_list.iconSize().width(),
                        self.ground_engine,
                        self.graph_link_as_node.isChecked(),
                        self.graph_show_label.isChecked(),
                        self.is_monochrome())
        item.setIcon(icon)
        self.collections_grounded.append(g)
        self.grounded_list.addItem(item)

        for node, graph_ in labeled_enumerate(g):
            item = QListWidgetItem(f"link_{node}")
            icon = to_graph(g,
                            self.grounded_list.iconSize().width(),
                            self.ground_engine,
                            self.graph_link_as_node.isChecked(),
                            self.graph_show_label.isChecked(),
                            self.is_monochrome(),
                            except_node=node)
            item.setIcon(icon)
            self.collections_grounded.append(graph_)
            self.grounded_list.addItem(item)
Beispiel #4
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
Beispiel #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
Beispiel #6
0
    def __set_selection(self, row: int):
        """Show the data of collection.

        Save the layout position to keep the graphs
        will be in same appearance.
        """
        item: Optional[QListWidgetItem] = self.collection_list.item(row)
        has_item = item is not None
        self.delete_button.setEnabled(has_item)
        self.configure_button.setEnabled(has_item)
        self.selection_window.clear()
        if item is None:
            return

        # Preview item.
        link_is_node = self.graph_link_as_node.isChecked()
        item_preview = QListWidgetItem(item.text())
        row = self.collection_list.row(item)
        g = self.collections[row]
        self.ground_engine = self.collections_layouts[row]
        item_preview.setIcon(
            to_graph(g,
                     self.selection_window.iconSize().width(),
                     self.ground_engine, link_is_node,
                     self.graph_show_label.isChecked(), self.is_monochrome()))
        self.selection_window.addItem(item_preview)

        # Set attributes.
        self.edges_text.setText(str(list(g.edges)))
        self.nl_label.setText(str(len(g.nodes)))
        self.nj_label.setText(str(len(g.edges)))
        self.dof_label.setText(str(g.dof()))
        self.is_degenerate_label.setText(str(g.is_degenerate()))
        self.link_assortment_label.setText(str(l_a(g)))
        self.contracted_link_assortment_label.setText(str(c_l_a(g)))

        # "Link as node" layout cannot do these action.
        self.configure_button.setEnabled(not link_is_node)
        self.grounded_merge.setEnabled(not link_is_node)

        # Automatic ground.
        self.__grounded()
Beispiel #7
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)
Beispiel #8
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 #9
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 #10
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)
Beispiel #11
0
 def undo(self):
     """Create a new item and recover expression."""
     item = QListWidgetItem(self.name)
     item.expr = self.mechanism
     item.setIcon(QIcon(QPixmap(":/icons/mechanism.png")))
     self.widget.insertItem(self.row, item)
Beispiel #12
0
 def redo(self):
     """Add mechanism expression to 'expr' attribute."""
     item = QListWidgetItem(self.name)
     item.expr = self.mechanism
     item.setIcon(QIcon(QPixmap(":/icons/mechanism.png")))
     self.widget.addItem(item)