Пример #1
0
class _ScaleDialog(QDialog):
    """Scale mechanism dialog."""
    def __init__(self, parent: QWidget):
        super(_ScaleDialog, self).__init__(parent)
        self.main_layout = QVBoxLayout(self)
        self.enlarge = QDoubleSpinBox(self)
        self.shrink = QDoubleSpinBox(self)
        self.__add_option("Enlarge", self.enlarge)
        self.__add_option("Shrink", self.shrink)

        button_box = QDialogButtonBox(self)
        button_box.setStandardButtons(QDialogButtonBox.Ok
                                      | QDialogButtonBox.Cancel)
        button_box.accepted.connect(self.accept)
        button_box.rejected.connect(self.reject)
        self.main_layout.addWidget(button_box)

    def __add_option(self, name: str, option: QDoubleSpinBox):
        """Add widgets for option."""
        layout = QHBoxLayout(self)
        label = QLabel(name, self)
        option.setValue(1)
        option.setMaximum(10000)
        option.setMinimum(0.01)
        layout.addWidget(label)
        layout.addWidget(option)
        self.main_layout.addLayout(layout)

    def factor(self) -> float:
        """Return scale value."""
        return self.enlarge.value() / self.shrink.value()
Пример #2
0
    def __init__(self, parent: QWidget):
        super(_ScaleDialog, self).__init__(parent)
        self.main_layout = QVBoxLayout(self)
        self.enlarge = QDoubleSpinBox(self)
        self.shrink = QDoubleSpinBox(self)
        self.__add_option("Enlarge", self.enlarge)
        self.__add_option("Shrink", self.shrink)

        button_box = QDialogButtonBox(self)
        button_box.setStandardButtons(QDialogButtonBox.Ok
                                      | QDialogButtonBox.Cancel)
        button_box.accepted.connect(self.accept)
        button_box.rejected.connect(self.reject)
        self.main_layout.addWidget(button_box)
Пример #3
0
 def __init__(self, parent=None):
     super(Collections, self).__init__(parent)
     layout = QVBoxLayout(self)
     tabWidget = QTabWidget(self)
     layout.addWidget(tabWidget)
     self.setWindowIcon(QIcon(QPixmap(":/icons/collections.png")))
     self.CollectionsStructure = CollectionsStructure(parent)
     self.CollectionsTriangularIteration = CollectionsTriangularIteration(
         parent)
     self.CollectionsTriangularIteration.addToCollection = self.CollectionsStructure.addCollection
     tabWidget.addTab(self.CollectionsStructure,
                      self.CollectionsStructure.windowIcon(), "Structure")
     tabWidget.addTab(self.CollectionsTriangularIteration,
                      self.CollectionsTriangularIteration.windowIcon(),
                      "Triangular iteration")
     self.CollectionsStructure.triangle_button.clicked.connect(
         lambda: tabWidget.setCurrentIndex(1))
     self.CollectionsStructure.layout_sender.connect(
         self.CollectionsTriangularIteration.setGraph)
Пример #4
0
 def __init__(self, parent: QWidget):
     """Create two widget page and using main window to make their parent."""
     super(Collections, self).__init__(parent)
     layout = QVBoxLayout(self)
     tab_widget = QTabWidget(self)
     layout.addWidget(tab_widget)
     self.setWindowIcon(QIcon(QPixmap(":/icons/collections.png")))
     self.StructureWidget = StructureWidget(parent)
     self.TriangularIterationWidget = TriangularIterationWidget(
         self.StructureWidget.addCollection, parent)
     tab_widget.addTab(self.StructureWidget,
                       self.StructureWidget.windowIcon(), "Structures")
     tab_widget.addTab(self.TriangularIterationWidget,
                       self.TriangularIterationWidget.windowIcon(),
                       "Triangular iteration")
     self.StructureWidget.triangle_button.clicked.connect(
         lambda: tab_widget.setCurrentIndex(1))
     self.StructureWidget.layout_sender.connect(
         self.TriangularIterationWidget.setGraph)
Пример #5
0
 def __init__(self, parent: MainWindowBase):
     """Create two widget page and using main window to make their parent."""
     super(Collections, self).__init__(parent)
     layout = QVBoxLayout(self)
     self.tab_widget = QTabWidget(self)
     layout.addWidget(self.tab_widget)
     self.setWindowIcon(QIcon(QPixmap(":/icons/collections.png")))
     self.structure_widget = StructureWidget(parent)
     self.configure_widget = ConfigureWidget(
         self.structure_widget.add_collection, parent)
     self.tab_widget.addTab(self.structure_widget,
                            self.structure_widget.windowIcon(),
                            "Structures")
     self.tab_widget.addTab(self.configure_widget,
                            self.configure_widget.windowIcon(),
                            "Configuration")
     self.structure_widget.configure_button.clicked.connect(
         lambda: self.tab_widget.setCurrentIndex(1))
     self.structure_widget.layout_sender.connect(
         self.configure_widget.set_graph)
Пример #6
0
 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)
Пример #7
0
    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)
Пример #8
0
    def __set_chart(self, tab_name: str, pos_x: int, pos_y: int):
        """Setting charts by data index.

        pos_x / pos_y: [0], [1], [2]
        time_fitness: List[List[Tuple[gen, fitness, time]]]
        """
        axis_x = QCategoryAxis()
        axis_y = QValueAxis()
        axis_x.setLabelsPosition(QCategoryAxis.AxisLabelsPositionOnValue)
        axis_x.setMin(0)
        axis_y.setTickCount(11)

        if self.__algorithm_data:
            # Just copy references from algorithm data.
            plot = [data['time_fitness'] for data in self.__algorithm_data]

            # X max.
            max_x = int(max([max([tnf[pos_x] for tnf in data]) for data in plot]) * 100)
            axis_x.setMax(max_x)
            i10 = int(max_x / 10)
            if i10:
                for i in range(0, max_x + 1, i10):
                    axis_x.append(str(i / 100), i)
            else:
                for i in range(0, 1000, 100):
                    axis_x.append(str(i / 100), i)

            # Y max.
            max_y = max(max([tnf[pos_y] for tnf in data]) for data in plot) + 10
        else:
            plot = None
            # Y max.
            max_y = 100

        max_y -= max_y % 10
        axis_y.setRange(0., max_y)
        chart = DataChart(self.__title, axis_x, axis_y)

        # Append data set.
        for i, data in enumerate(self.__algorithm_data):
            line = QLineSeries()
            scatter = QScatterSeries()
            line.setName(f"{i}: {data['Algorithm']}")
            scatter.setMarkerSize(7)
            scatter.setColor(QColor(110, 190, 30))
            for e in plot[self.__algorithm_data.index(data)]:
                y = e[pos_y]
                x = e[pos_x] * 100
                line.append(QPointF(x, y))
                scatter.append(QPointF(x, y))
            for series in (line, scatter):
                chart.addSeries(series)
                series.attachAxis(axis_x)
                series.attachAxis(axis_y)
            chart.legend().markers(scatter)[0].setVisible(False)

        # Add chart into tab widget
        widget = QWidget()
        self.tabWidget.addTab(widget, QIcon(), tab_name)
        layout = QVBoxLayout(widget)
        layout.setContentsMargins(2, 2, 2, 2)
        chart_view = QChartView(chart)
        chart_view.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        layout.addWidget(chart_view)
Пример #9
0
 def setChart(self, tabName: str, posX: int, posY: int):
     '''Setting charts by data index.
     
     posX / posY: [0] / [1] / [2]
     TimeAndFitness: List[List[Tuple[gen, fitness, time]]]
     '''
     if self.mechanism_data:
         if type(self.mechanism_data[0]['TimeAndFitness'][0]) == float:
             TimeAndFitness = [[
                 (data['lastGen'] * i / len(data['TimeAndFitness']), Tnf, 0)
                 for i, Tnf in enumerate(data['TimeAndFitness'])
             ] for data in self.mechanism_data]
         else:
             #Just copy from mechanism_data
             TimeAndFitness = [[Tnf for Tnf in data['TimeAndFitness']]
                               for data in self.mechanism_data]
     axisX = QCategoryAxis()
     axisY = QValueAxis()
     axisX.setLabelsPosition(QCategoryAxis.AxisLabelsPositionOnValue)
     axisX.setMin(0)
     axisY.setTickCount(11)
     #X maxima
     if self.mechanism_data:
         maximaX = int(
             max([
                 max([Tnf[posX] for Tnf in data]) for data in TimeAndFitness
             ]) * 100)
         axisX.setMax(maximaX)
         i10 = int(maximaX / 10)
         if i10:
             for i in range(0, maximaX + 1, i10):
                 axisX.append(str(i / 100), i)
         else:
             for i in range(0, 1000, 100):
                 axisX.append(str(i / 100), i)
     #Y maxima
     if self.mechanism_data:
         maximaY = max(
             [max([Tnf[posY] for Tnf in data])
              for data in TimeAndFitness]) + 10
     else:
         maximaY = 100
     maximaY -= maximaY % 10
     axisY.setRange(0., maximaY)
     chart = DataChart(self.Title, axisX, axisY)
     #Append datasets
     for data in self.mechanism_data:
         line = QLineSeries()
         scatter = QScatterSeries()
         gen = data['lastGen']
         Tnf = TimeAndFitness[self.mechanism_data.index(data)]
         points = Tnf[:-1] if Tnf[-1] == Tnf[-2] else Tnf
         line.setName("{}({} gen): {}".format(data['Algorithm'], gen,
                                              data['Expression']))
         scatter.setMarkerSize(7)
         scatter.setColor(QColor(110, 190, 30))
         for i, e in enumerate(points):
             y = e[posY]
             x = e[posX] * 100
             line.append(QPointF(x, y))
             scatter.append(QPointF(x, y))
         for series in [line, scatter]:
             chart.addSeries(series)
             series.attachAxis(axisX)
             series.attachAxis(axisY)
         chart.legend().markers(scatter)[0].setVisible(False)
     #Add chart into tab widget
     widget = QWidget()
     self.tabWidget.addTab(widget, QIcon(), tabName)
     layout = QVBoxLayout(widget)
     layout.setContentsMargins(2, 2, 2, 2)
     chartView = QChartView(chart)
     chartView.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
     layout.addWidget(chartView)