def on_save_atlas_clicked(self): """Save function as same as type synthesis widget.""" count = self.collection_list.count() if not count: return lateral, ok = QInputDialog.getInt(self, "Atlas", "The number of lateral:", 5, 1, 10) if not ok: return fileName = self.outputTo("Atlas image", Qt_images) if not fileName: return icon_size = self.collection_list.iconSize() width = icon_size.width() image_main = QImage( QSize(lateral * width if count > lateral else count * width, ((count // lateral) + bool(count % lateral)) * width), self.collection_list.item(0).icon().pixmap( icon_size).toImage().format()) image_main.fill(QColor(Qt.white).rgb()) painter = QPainter(image_main) for row in range(count): image = self.collection_list.item(row).icon().pixmap( icon_size).toImage() painter.drawImage( QPointF(row % lateral * width, row // lateral * width), image) painter.end() pixmap = QPixmap() pixmap.convertFromImage(image_main) pixmap.save(fileName, format=QFileInfo(fileName).suffix()) self.saveReplyBox("Atlas", fileName)
def __save_atlas(self): """Save function as same as type synthesis widget.""" count = self.collection_list.count() if not count: return lateral, ok = QInputDialog.getInt(self, "Atlas", "The number of lateral:", 5, 1) if not ok: return file_name = self.output_to("Atlas image", qt_image_format) if not file_name: return icon_size = self.collection_list.iconSize() width = icon_size.width() image_main = QImage( QSize(lateral * width if count > lateral else count * width, ((count // lateral) + bool(count % lateral)) * width), self.collection_list.item(0).icon().pixmap( icon_size).toImage().format()) image_main.fill(Qt.transparent) painter = QPainter(image_main) for row in range(count): image = self.collection_list.item(row).icon().pixmap( icon_size).toImage() painter.drawImage( QPointF(row % lateral * width, row // lateral * width), image) painter.end() pixmap = QPixmap() pixmap.convertFromImage(image_main) pixmap.save(file_name) self.save_reply_box("Atlas", file_name)
def __typeCombine(self, row: int) -> List[Graph]: """Combine and show progress dialog.""" item = self.Expression_number.item(row) progdlg = QProgressDialog("Analysis of the topology...", "Cancel", 0, 100, self) progdlg.setAttribute(Qt.WA_DeleteOnClose, True) progdlg.setWindowTitle("Type synthesis - ({})".format(item.text())) progdlg.setMinimumSize(QSize(500, 120)) progdlg.setModal(True) progdlg.show() def stopFunc(): """If stop by GUI.""" QCoreApplication.processEvents() progdlg.setValue(progdlg.value() + 1) return progdlg.wasCanceled() def setjobFunc(job: str, maximum: float): """New job.""" progdlg.setLabelText(job) progdlg.setValue(0) progdlg.setMaximum(maximum + 1) answer, time = topo(item.links, not self.graph_degenerate.isChecked(), setjobFunc, stopFunc) self.time_label.setText("{}[min] {:.2f}[s]".format( int(time // 60), time % 60)) progdlg.setValue(progdlg.maximum()) if answer: return [Graph(G.edges) for G in answer]
def graph(G: Graph, width: int, engine: [str, Dict[int, Tuple[float, float]]], node_mode: bool = False, except_node: int = None) -> QIcon: """Draw a linkage graph.""" try: pos = engine_picker(G, engine, node_mode) except EngineError as e: raise e width_ = -inf for x, y in pos.values(): if abs(x) > width_: width_ = x if abs(y) > width_: width_ = y width_ *= 2 * 1.2 image = QImage(QSize(width_, width_), QImage.Format_ARGB32_Premultiplied) image.fill(Qt.transparent) painter = QPainter(image) painter.translate(image.width() / 2, image.height() / 2) pen = QPen() r = width_ / 50 pen.setWidth(r) painter.setPen(pen) if node_mode: for l1, l2 in G.edges: painter.drawLine(QPointF(pos[l1][0], -pos[l1][1]), QPointF(pos[l2][0], -pos[l2][1])) else: painter.setBrush(QBrush(QColor(226, 219, 190, 150))) for link in G.nodes: if link == except_node: continue #Distance sorted function from canvas painter.drawPolygon(*convex_hull([(pos[n][0], -pos[n][1]) for n, edge in edges_view(G) if link in edge])) for k, (x, y) in pos.items(): if node_mode: color = colorNum(len(list(G.neighbors(k))) - 1) else: if except_node in tuple(G.edges)[k]: color = colorQt('Green') else: color = colorQt('Blue') pen.setColor(color) painter.setPen(pen) painter.setBrush(QBrush(color)) painter.drawEllipse(QPointF(x, -y), r, r) painter.end() icon = QIcon(QPixmap.fromImage(image).scaledToWidth(width)) return icon
def __save_atlas(self): """Saving all the atlas to image file. We should turn transparent background to white first. Then using QImage class to merge into one image. """ file_name = "" lateral = 0 if self.save_edges_auto.isChecked(): lateral, ok = QInputDialog.getInt(self, "Atlas", "The number of lateral:", 5, 1, 10) if not ok: return file_name = self.outputTo("Atlas image", qt_image_format) if file_name: reply = QMessageBox.question( self, "Type synthesis", "Do you want to Re-synthesis?", (QMessageBox.Yes | QMessageBox.YesToAll | QMessageBox.Cancel), QMessageBox.Yes) if reply == QMessageBox.Yes: self.__structure_synthesis() elif reply == QMessageBox.YesToAll: self.__structure_synthesis_all() count = self.structure_list.count() if not count: return if not lateral: lateral, ok = QInputDialog.getInt(self, "Atlas", "The number of lateral:", 5, 1, 10) if not ok: return if not file_name: file_name = self.outputTo("Atlas image", qt_image_format) if not file_name: return width = self.structure_list.iconSize().width() image_main = QImage( QSize(lateral * width if count > lateral else count * width, ((count // lateral) + bool(count % lateral)) * width), self.__atlas_image(0).format()) image_main.fill(QColor(Qt.white).rgb()) painter = QPainter(image_main) for row in range(count): image = self.__atlas_image(row) painter.drawImage( QPointF(row % lateral * width, row // lateral * width), image) painter.end() pixmap = QPixmap() pixmap.convertFromImage(image_main) pixmap.save(file_name, format=QFileInfo(file_name).suffix()) self.saveReplyBox("Atlas", file_name)
def __init__(self, Title, mechanism_data=[], parent=None): super(ChartDialog, self).__init__(parent) self.setWindowTitle("Chart") self.setWindowFlags(self.windowFlags() | Qt.WindowMaximizeButtonHint) self.setSizeGripEnabled(True) self.setModal(True) self.setMinimumSize(QSize(800, 600)) self.Title = Title self.mechanism_data = mechanism_data #Widgets main_layout = QVBoxLayout(self) main_layout.setContentsMargins(6, 6, 6, 6) self.tabWidget = QTabWidget(self) self.setChart("Fitness / Generation Chart", 0, 1) self.setChart("Generation / Time Chart", 2, 0) self.setChart("Fitness / Time Chart", 2, 1) main_layout.addWidget(self.tabWidget)
def __init__(self, title, algorithm_data, parent: QWidget): """Add three tabs of chart.""" super(ChartDialog, self).__init__(parent) self.setWindowTitle("Chart") self.setWindowFlags(self.windowFlags() | Qt.WindowMaximizeButtonHint) self.setSizeGripEnabled(True) self.setModal(True) self.setMinimumSize(QSize(800, 600)) self.__title = title self.__algorithm_data = algorithm_data # Widgets main_layout = QVBoxLayout(self) main_layout.setContentsMargins(6, 6, 6, 6) self.tabWidget = QTabWidget(self) self.__set_chart("Fitness / Generation Chart", 0, 1) self.__set_chart("Generation / Time Chart", 2, 0) self.__set_chart("Fitness / Time Chart", 2, 1) main_layout.addWidget(self.tabWidget)
def __init__(self, item): QGraphicsView.__init__(self) scene = QGraphicsScene(self) self.setScene(scene) item.setMinimumSize(QSize(150, 150)) item.setMaximum(36000) item.setSingleStep(100) item.setPageStep(100) item.setInvertedAppearance(True) item.setWrapping(True) item.setNotchTarget(.1) item.setNotchesVisible(True) graphics_item = scene.addWidget(item) graphics_item.setRotation(-90) #make the QGraphicsView invisible. self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setFixedHeight(item.height()) self.setFixedWidth(item.width()) self.setStyleSheet("border: 0px;")
def to_graph(graph: Graph, width: int, engine: Union[str, Dict[int, Tuple[float, float]]], node_mode: bool = False, except_node: int = None) -> QIcon: """Draw a generalized chain graph.""" pos: Pos = engine_picker(graph, engine, node_mode) width_bound = -float('inf') for x, y in pos.values(): if abs(x) > width_bound: width_bound = x if abs(y) > width_bound: width_bound = y width_bound *= 2.2 image = QImage(QSize(int(width_bound), int(width_bound)), QImage.Format_ARGB32_Premultiplied) image.fill(Qt.transparent) painter = QPainter(image) painter.translate(image.width() / 2, image.height() / 2) pen = QPen() r = width_bound / 50 pen.setWidth(int(r)) painter.setPen(pen) # Draw edges. if node_mode: for l1, l2 in graph.edges: if except_node in {l1, l2}: pen.setColor(color_qt('Gray')) else: pen.setColor(color_qt('Black')) painter.setPen(pen) painter.drawLine(QPointF(pos[l1][0], -pos[l1][1]), QPointF(pos[l2][0], -pos[l2][1])) else: painter.setBrush(QBrush(QColor(226, 219, 190, 150))) for link in graph.nodes: if link == except_node: pen.setColor(color_qt('Gray')) else: pen.setColor(color_qt('Black')) painter.setPen(pen) painter.drawPolygon(*convex_hull([(pos[n][0], -pos[n][1]) for n, edge in edges_view(graph) if link in edge], as_qpoint=True)) # Draw nodes. for k, (x, y) in pos.items(): if node_mode: color = color_num(len(list(graph.neighbors(k))) - 1) if k == except_node: color.setAlpha(150) else: if except_node in dict(edges_view(graph))[k]: color = color_qt('Green') else: color = color_qt('Blue') pen.setColor(color) painter.setPen(pen) painter.setBrush(QBrush(color)) painter.drawEllipse(QPointF(x, -y), r, r) painter.end() icon = QIcon(QPixmap.fromImage(image).scaledToWidth(width)) return icon
def colorIcons(name: str, size: int = 20) -> QIcon: """Get color block as QIcon by name.""" colorBlock = QPixmap(QSize(size, size)) colorBlock.fill(colorQt(name)) return QIcon(colorBlock)
def to_graph( g: Graph, width: int, engine: Union[str, Pos], node_mode: bool, show_label: bool, monochrome: bool, *, except_node: Optional[int] = None ) -> QIcon: """Draw a generalized chain graph.""" pos: Pos = engine_picker(g, engine, node_mode) if not pos: pixmap = QPixmap(width, width) pixmap.fill(Qt.transparent) return QIcon(pixmap) width_bound = -float('inf') for x, y in pos.values(): if abs(x) > width_bound: width_bound = x if abs(y) > width_bound: width_bound = y width_bound *= 2.5 image = QImage( QSize(int(width_bound), int(width_bound)), QImage.Format_ARGB32_Premultiplied ) image.fill(Qt.transparent) painter = QPainter(image) painter.translate(image.width() / 2, image.height() / 2) pen = QPen() r = int(width_bound / 50) pen.setWidth(r) painter.setPen(pen) _font.setPixelSize(r * 6) painter.setFont(_font) # Draw edges. if node_mode: for l1, l2 in g.edges: if except_node in {l1, l2}: pen.setColor(Qt.gray) else: pen.setColor(Qt.black) painter.setPen(pen) painter.drawLine( QPointF(pos[l1][0], -pos[l1][1]), QPointF(pos[l2][0], -pos[l2][1]) ) else: if monochrome: color = QColor(Qt.darkGray) else: color = QColor(226, 219, 190) color.setAlpha(150) painter.setBrush(QBrush(color)) for link in g.nodes: if link == except_node: pen.setColor(Qt.gray) else: pen.setColor(Qt.black) painter.setPen(pen) painter.drawPolygon(*convex_hull([ (pos[n][0], -pos[n][1]) for n, edge in edges_view(g) if link in edge ], as_qpoint=True)) # Draw nodes. for k, (x, y) in pos.items(): if node_mode: color = color_num(len(list(g.neighbors(k))) - 1) if k == except_node: color.setAlpha(150) else: if monochrome: color = Qt.black elif except_node in dict(edges_view(g))[k]: color = color_qt('Green') else: color = color_qt('Blue') pen.setColor(color) painter.setPen(pen) painter.setBrush(QBrush(color)) point = QPointF(x, -y) painter.drawEllipse(point, r, r) if show_label: pen.setColor(Qt.darkMagenta) painter.setPen(pen) painter.drawText(point, str(k)) painter.end() return QIcon(QPixmap.fromImage(image).scaledToWidth(width))