예제 #1
0
    def save_grid_view(self):
        """
        Saves grid view in png file
        :return: None
        """
        file_types = "PNG (*.png)"
        filename = str(
            QtImport.QFileDialog.getSaveFileName(
                self,
                "Choose a filename to save under",
                os.path.expanduser("~"),
                file_types,
            )
        )

        filename += ".png"
        image = QtImport.QImage(
            self.grid_graphics_view.scene().sceneRect().size().toSize(),
            QtImport.QImage.Format_ARGB32,
        )
        image.fill(QtImport.Qt.white)
        image_painter = QtImport.QPainter(image)
        self.grid_graphics_view.render(image_painter)
        image_painter.end()
        image.save(filename)
예제 #2
0
    def paintEvent(self, event):
        h_main = self.height()
        w_main = self.width()

        h_dial = self.dial.height()
        w_dial = self.dial.width()
        # print(f"h_main - w_main : {h_main} - {w_main}")
        # print(f"h_dial - w_dial : {h_dial} - {w_dial}")

        painter = QtImport.QPainter(self)

        fm = painter.fontMetrics()
        for i, (tag, value) in enumerate(self.tags.items()):
            text_rect = fm.boundingRect(tag)
            text_width = text_rect.width()
            text_height = text_rect.height()
            if i == 0:
                # print(f"h_main - w_main : {h_main} - {w_main}")
                # print(f"h_dial - w_dial : {h_dial} - {w_dial}")
                painter.drawText(w_main / 2 - w_dial / 4 - text_width,
                                 h_main / 2 + h_dial / 2, tag)
            if i == 1:
                painter.drawText(w_main / 2 - w_dial / 2 - text_width,
                                 h_main / 2, tag)
                # painter.drawRect(
                #     w_main / 2 - w_dial / 2 - text_width,
                #     h_main / 2 - text_height / 2,
                #     text_width,
                #     text_height
                #     )
            if i == 2:
                painter.drawText(w_main / 2 - w_dial / 4 - text_width,
                                 h_main / 2 - h_dial / 2 - text_height / 2,
                                 tag)
            if i == 3:
                painter.drawText(w_main / 2 + w_dial / 4,
                                 h_main / 2 - h_dial / 2 - text_height / 2,
                                 tag)
            if i == 4:
                painter.drawText(w_main / 2 + w_dial / 2, h_main / 2, tag)
                # painter.drawRect(
                #     w_main / 2 + w_dial / 2,
                #     h_main / 2,
                #     text_width,
                #     text_height
                # )
            if i == 5:
                painter.drawText(w_main / 2 + w_dial / 4,
                                 h_main / 2 + h_dial / 2, tag)
예제 #3
0
    def paintEvent(self, e):
        painter = QtImport.QPainter(self)

        brush = QtImport.QBrush()
        brush.setColor(self._background_color)
        brush.setStyle(QtImport.Qt.SolidPattern)
        rect = QtImport.QRect(0, 0,
                              painter.device().width(),
                              painter.device().height())
        painter.fillRect(rect, brush)

        # Get current state.
        parent = self.parent()
        vmin, vmax = parent.minimum(), parent.maximum()
        value = parent.value()

        # Define our canvas.
        d_height = painter.device().height() - (self._padding * 2)
        d_width = painter.device().width() - (self._padding * 2)

        # Draw the bars.
        step_size = d_height / self.n_steps
        bar_height = step_size * self._bar_solid_percent
        bar_spacer = step_size * (1 - self._bar_solid_percent) / 2

        # Calculate the y-stop position, from the value in range.
        pc = (value - vmin) / (vmax - vmin)
        n_steps_to_draw = int(pc * self.n_steps)

        for n in range(n_steps_to_draw):
            brush.setColor(QtImport.QColor(self.steps[n]))
            rect = QtImport.QRect(
                self._padding,
                self._padding + d_height - ((1 + n) * step_size) + bar_spacer,
                d_width, bar_height)
            painter.fillRect(rect, brush)

        painter.end()
예제 #4
0
 def paintEvent(self, event):
     if not self.is_running():
         painter = QtImport.QPainter(self)
         painter.setPen(QtImport.QPen(QtImport.Qt.black, 1))
         painter.drawLine(0, 0, self.width(), self.height())
         painter.drawLine(0, self.height(), self.width(), 0)