Example #1
0
    def __init__(self, verify, prompt, window_title, default_text):
        qtw.QDialog.__init__(
            self, None, qtc.Qt.WindowCloseButtonHint | qtc.Qt.WindowTitleHint)

        self.setObjectName(window_title)

        self.verify_function = verify

        layout = qtw.QGridLayout()
        layout.addWidget(qtw.QLabel(prompt), 0, 0, 1, 2)

        self.input_field = qtw.QLineEdit()
        self.input_field.setText(default_text)
        self.input_field.selectAll()
        layout.addWidget(self.input_field, 1, 0, 1, 2)

        buttons = qtw.QDialogButtonBox(qtw.QDialogButtonBox.Ok
                                       | qtw.QDialogButtonBox.Cancel)
        buttons.accepted.connect(self.verify_response)
        buttons.rejected.connect(self.reject)
        layout.addWidget(buttons, 2, 1, 1, 1)

        self.error_label = qtw.QLabel("")
        self.error_label.setMinimumWidth(
            qtg.QFontMetrics(qtg.QFont()).horizontalAdvance("Verify Failed"))
        layout.addWidget(self.error_label, 2, 0, 1, 1)

        layout.setSizeConstraint(qtw.QLayout.SetFixedSize)

        self.setLayout(layout)

        self.show()
Example #2
0
 def __init__(self,
              parent,
              command,
              number,
              name="",
              enabled=True,
              height=None):
     super(Command, self).__init__(parent)
     self.command = command
     self.widget = QtWidgets.QTextBrowser()
     self.widget.setReadOnly(True)
     if not height:
         font_height = QtGui.QFontMetrics(
             self.widget.document().defaultFont()).height()
         lines = math.ceil(len(command) / 200)
         self.setMinimumHeight(
             int(font_height + ((lines + 2) * (font_height * 1.25))))
     else:
         self.setMinimumHeight(height)
     self.number = number
     self.name = name
     self.label = QtWidgets.QLabel(
         f"{t('Command')} {self.number}" if not self.name else self.name)
     self.update_grid()
     self.widget.setDisabled(not enabled)
Example #3
0
    def draw_annotation(self, opts):
        x1 = self.image_generator.sec2pixels(opts.get("start", 0))
        x2 = self.image_generator.sec2pixels(opts.get("end", 0))
        y1 = self.freq2pixels(opts.get("max_freq", 0))
        y2 = self.freq2pixels(opts.get("min_freq", 0))
        text = opts.get("text", "")
        buffer = opts.get("vertical_buffer", 1)
        top_offset = opts.get("top_offset", 0)
        bottom_offset = opts.get("bottom_offset", 0)

        if y2 - y1 <= 0:
            y1 = 0
            y2 = self.spectrogram_scene.height() - 2
            if buffer:
                v_offset = buffer * y2 / 100
                y1 += v_offset + top_offset
                y2 -= v_offset - bottom_offset
                if text:
                    font = QtGui.QFont(opts.get("text_font", ""),
                                       opts.get("text_fontsize", 12))
                    font_height = QtGui.QFontMetrics(font).height()
                    y1 += font_height

        coords = (x1, y1, x2 - x1, y2 - y1)

        opts["coords"] = coords

        rect = AnnotatedRectItem(opts)

        self.spectrogram_scene.addItem(rect)
Example #4
0
    def __init__(self, parent, scene):
        super(Port, self).__init__(parent)

        self.radius_ = 5
        self.margin = 2

        path = QtGui.QPainterPath()
        path.addEllipse(-self.radius_, -self.radius_, 2 * self.radius_,
                        2 * self.radius_)
        self.setPath(path)

        self.setFlag(QtWidgets.QGraphicsPathItem.ItemSendsScenePositionChanges)
        self.font = QtGui.QFont()
        self.font_metrics = QtGui.QFontMetrics(self.font)

        self.port_text_height = self.font_metrics.height()

        self._is_output = False
        self._name = None
        self.margin = 2

        self.m_node = None
        self.connection = None

        self.text_path = QtGui.QPainterPath()
Example #5
0
    def __init__(self, parent=None):
        super(RichTextLineEdit, self).__init__(parent)

        self.monofamily = "courier"
        self.sansfamily = "helvetica"
        self.seriffamily = "times"
        self.setLineWrapMode(QtWidgets.QTextEdit.NoWrap)
        self.setTabChangesFocus(True)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        fm = QtGui.QFontMetrics(self.font())
        h = int(fm.height() * (1.4 if platform.system() == "Windows" else 1.2))
        self.setMinimumHeight(h)
        self.setMaximumHeight(int(h * 1.2))
        self.setToolTip("Press <b>Ctrl+M</b> for the text effects "
                        "menu and <b>Ctrl+K</b> for the color menu")
Example #6
0
	def paintEvent(self, arg__1: QtGui.QPaintEvent) -> None:
		p = QtGui.QPainter(self)
		font = p.font()
		fontsize = font.pointSizeF()

		p.setBackgroundMode(QtCore.Qt.TransparentMode)
		pointColor = QtGui.QColor(p.pen().color())
		bgColor = QtGui.QColor(p.background().color())

		# draw outer rect for dbg
		# p.drawRect(QtCore.QRectF(0, 0, self.width()-1, self.height()-1))

		# font.setPointSizeF()

		metrics = QtGui.QFontMetrics(font)

		rect = metrics.boundingRect(self.text())

		center = QtCore.QPoint(int(self.width()/2), int(self.height()/2)+1)

		padding = self.padding * fontsize

		text_rect = QtCore.QRectF(center.x() - rect.width()/2 - padding,
		                          center.y() - rect.height()/2,rect.width() + 2 * padding, rect.height())

		p.setBrush(QtGui.QBrush(pointColor))
		p.drawRect(text_rect)
		text_rect.setX(text_rect.x() + padding)
		p.setPen(QtGui.QColor(bgColor))
		# p.setPen(QtGui.QColor("red"))
		# print("label text = ", type(text))
		p.drawText(text_rect, self.text())


		p.setPen(self._barsColor)
		p.drawLine(QtCore.QPointF(center.x() + rect.width()/2 + padding*4, center.y()),
		           QtCore.QPointF(self.width(), center.y()))
		p.drawLine(QtCore.QPointF(center.x() - rect.width() / 2 - padding * 4, center.y()),
		           QtCore.QPointF(0, center.y()))
Example #7
0
    def build(self):
        """ Build the node
        """

        self.title_path = QtGui.QPainterPath()  # reset
        self.type_path = QtGui.QPainterPath()  # The path for the type
        self.misc_path = QtGui.QPainterPath()  # a bunch of other stuff

        total_width = 0
        total_height = 0
        path = QtGui.QPainterPath()  # The main path

        # The fonts what will be used
        title_font = QtGui.QFont("Lucida Sans Unicode", pointSize=16)
        title_type_font = QtGui.QFont("Lucida Sans Unicode", pointSize=8)
        port_font = QtGui.QFont("Lucida Sans Unicode")

        # Get the dimentions of the title and type
        title_dim = {
            "w":
            QtGui.QFontMetrics(title_font).horizontalAdvance(self._title_text),
            "h": QtGui.QFontMetrics(title_font).height(),
        }

        title_type_dim = {
            "w":
            QtGui.QFontMetrics(title_type_font).horizontalAdvance(
                "(" + self._type_text + ")"),
            "h":
            QtGui.QFontMetrics(title_type_font).height(),
        }

        # Get the max width
        for dim in [title_dim["w"], title_type_dim["w"]]:
            if dim > total_width:
                total_width = dim

        # Add both the title and type height together for the total height
        for dim in [title_dim["h"], title_type_dim["h"]]:
            total_height += dim

        # Add the heigth for each of the ports
        for port in self._ports:
            port_dim = {
                "w":
                QtGui.QFontMetrics(port_font).horizontalAdvance(port.name()),
                "h": QtGui.QFontMetrics(port_font).height(),
            }

            if port_dim["w"] > total_width:
                total_width = port_dim["w"]

            total_height += port_dim["h"]

        # Add the margin to the total_width
        total_width += self.horizontal_margin
        total_height += self.vertical_margin

        # Draw the background rectangle
        path.addRoundedRect(-total_width / 2, -total_height / 2, total_width,
                            total_height, 5, 5)

        # Draw the title
        self.title_path.addText(
            -title_dim["w"] / 2,
            (-total_height / 2) + title_dim["h"],
            title_font,
            self._title_text,
        )

        # Draw the type
        self.type_path.addText(
            -title_type_dim["w"] / 2,
            (-total_height / 2) + title_dim["h"] + title_type_dim["h"],
            title_type_font,
            "(" + self._type_text + ")",
        )

        y = (-total_height /
             2) + title_dim["h"] + title_type_dim["h"] + port_dim["h"]

        for port in self._ports:
            if port.is_output():
                port.setPos(total_width / 2 - 10, y)
            else:
                port.setPos(-total_width / 2 + 10, y)
            y += port_dim["h"]

        self.setPath(path)

        self._width = total_width
        self._height = total_height
Example #8
0
 def setRect(self, *args, **kwargs):
     super().setRect(*args, **kwargs)
     if self.infoTextItem:
         font_height = QtGui.QFontMetrics(self.infoTextFont).height()
         self.infoTextItem.setPos(self.rect().x(), self.rect().y() - font_height)
Example #9
0
 def minimumSizeHint(self):
     fm = QtGui.QFontMetrics(self.font())
     return QtCore.QSize(fm.horizontalAdvance("WWWW"), self.minimumHeight())