Python PyQt5.QtGui.QPen() Examples

The following are code examples for showing how to use PyQt5.QtGui.QPen(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: echolocation   Author: hgross   File: radar.py    MIT License 7 votes vote down vote up
def _add_crosshair(self):
        """
        Adds vertical, horizontal and diagonal crosshairs to the graphic scene
        """
        pen = QPen(self.crosshair_line_color)
        pen.setWidth(self.line_width)
        pen.setStyle(Qt.DotLine)
        width, height = self.width(), self.height()
        mx, my = self._get_middle()

        # horizontal
        self.scene.addLine(0, my, width, my, pen=pen)
        # vertical
        self.scene.addLine(mx, 0, mx, height, pen=pen)
        # 45°
        self.scene.addLine(0, 0, width, height, pen=pen)
        self.scene.addLine(width, 0, 0, height, pen=pen) 
Example 2
Project: dcc   Author: amimo   File: DisasmViewMode.py    Apache License 2.0 6 votes vote down vote up
def _write_instruction2(self, asm, qp, cemu):
        s = asm.operands
        idx = 0
        qp.setPen(QtGui.QPen(QtGui.QColor(192, 192, 192), 1, QtCore.Qt.SolidLine))

        for tok in asm.lexer:
            if tok.lexpos > idx:
                cemu.write(s[idx:tok.lexpos])
                idx = tok.lexpos

            qp.save()
            if tok.type == 'REGISTER':
                qp.setPen(QtGui.QPen(QtGui.QColor('white')))

            if tok.type == 'NUMBER':
                qp.setPen(QtGui.QPen(QtGui.QColor('green')))

            cemu.write(tok.value)

            qp.restore()
            idx = tok.lexpos + len(tok.value)

        if idx < len(s):
            cemu.write(s[idx:]) 
Example 3
Project: dcc   Author: amimo   File: Banners.py    Apache License 2.0 6 votes vote down vote up
def __init__(self, themes, dataModel, viewMode):
        self.width = 0
        self.height = 0
        self.dataModel = dataModel
        self.viewMode = viewMode
        self.qpix = self._getNewPixmap(self.width, self.height)
        self.backgroundBrush = QtGui.QBrush(themes['background'])

        # text font
        self.font = themes['font']

        # font metrics. assume font is monospaced
        self.font.setKerning(False)
        self.font.setFixedPitch(True)
        fm = QtGui.QFontMetrics(self.font)
        self.fontWidth = fm.width('a')
        self.fontHeight = fm.height()

        self.textPen = QtGui.QPen(QtGui.QColor(192, 192, 192), 0, QtCore.Qt.SolidLine) 
Example 4
Project: dcc   Author: amimo   File: Banners.py    Apache License 2.0 6 votes vote down vote up
def __init__(self, themes, dataModel, viewMode):
        self.width = 0
        self.height = 0
        self.dataModel = dataModel
        self.viewMode = viewMode
        self.backgroundBrush = QtGui.QBrush(themes['background'])

        self.qpix = self._getNewPixmap(self.width, self.height)

        # text font
        self.font = themes['font']

        # font metrics. assume font is monospaced
        self.font.setKerning(False)
        self.font.setFixedPitch(True)
        fm = QtGui.QFontMetrics(self.font)
        self.fontWidth = fm.width('a')
        self.fontHeight = fm.height()

        self.textPen = QtGui.QPen(themes['pen'], 0, QtCore.Qt.SolidLine) 
Example 5
Project: dcc   Author: amimo   File: Banners.py    Apache License 2.0 6 votes vote down vote up
def __init__(self, themes, dataModel, viewMode):
        self.width = 0
        self.height = 0
        self.dataModel = dataModel
        self.viewMode = viewMode

        self.qpix = self._getNewPixmap(self.width, self.height)
        self.backgroundBrush = QtGui.QBrush(themes['background'])

        # text font
        self.font = themes['font']

        # font metrics. assume font is monospaced
        self.font.setKerning(False)
        self.font.setFixedPitch(True)
        fm = QtGui.QFontMetrics(self.font)
        self.fontWidth = fm.width('a')
        self.fontHeight = fm.height()

        self.textPen = QtGui.QPen(themes['pen'], 0, QtCore.Qt.SolidLine) 
Example 6
Project: dcc   Author: amimo   File: BinViewMode.py    Apache License 2.0 6 votes vote down vote up
def handleEditMode(self, modifiers, key, event):
        if key in range(0, 256):
            offs = self.getCursorOffsetInPage()

            self.dataModel.setData_b(self.dataModel.getOffset() + offs, str(event.text()))

            z = self.dataModel.getOffset() + offs
            # TODO: sa nu se repete, tre original_transformengine
            self.transformationEngine = RangePen(self.original_textdecorator, z, z + 0,
                                                 QtGui.QPen(QtGui.QColor(218, 94, 242), 0, QtCore.Qt.SolidLine),
                                                 ignoreHighlights=True)

            self.moveCursor(Directions.Right)

            x, y = self.cursor.getPosition()

            self.draw(refresh=True, row=y, howMany=1) 
Example 7
Project: musaic   Author: al165   File: sliders.py    GNU General Public License v3.0 6 votes vote down vote up
def paintEvent(self, e):
        painter = QtGui.QPainter(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        rect = painter.device().rect()

        radius = min(rect.width(), rect.height())/2

        pc = (self.value - self.minimum) / (self.maximum - self.minimum)

        a = 4.18879 - pc*5.23599
        x = math.cos(a) * (radius-1) + radius
        y = -math.sin(a) * (radius-1) + radius

        pen = QtGui.QPen()
        pen.setWidth(2)
        pen.setColor(self._color)
        painter.setPen(pen)
        painter.drawArc(1, 1, 2*radius-1, 2*radius-1, -120*16, -300*16)
        pen.setColor(QtGui.QColor('#DDDDDD'))
        painter.setPen(pen)
        painter.drawLine(radius, radius, x, y) 
Example 8
Project: PyQt-multifunctional-uart-helper   Author: IronSublimate   File: widgetpainter.py    MIT License 6 votes vote down vote up
def paintEvent(self, a0: QPaintEvent):
        # print("paint")
        painter = QPainter(self)

        # painter.begin(self)
        painter.drawPixmap(0, 0, self.width(), self.height(), self.qpix)
        if self.enable_extra_14_bytes and self.extra_data:
            pix_width = self.width() / self.imgWidth
            pix_height = self.height() / self.imgHeight
            # painter.setPen(QPen(Qt.red, -14))
            painter.setBrush(QBrush(Qt.red))
            painter.drawEllipse(self.extra_data[1] * pix_width, self.extra_data[0] * pix_height, pix_width, pix_height)
            painter.drawEllipse(self.extra_data[2] * pix_width, self.extra_data[0] * pix_height, pix_width, pix_height)
            painter.drawEllipse(self.extra_data[3] * pix_width, self.extra_data[0] * pix_height, pix_width, pix_height)
            painter.drawEllipse(self.extra_data[4] * pix_width, self.extra_data[0] * pix_height, pix_width, pix_height)

        if self.enable_grid:
            painter.setPen(Qt.darkBlue)
            painter.drawLines(self.grid_points)
        # painter.end() 
Example 9
Project: SpriteMator   Author: rafaelvasco   File: canvas_overlay_object.py    Apache License 2.0 6 votes vote down vote up
def _draw_grid(self, painter):
        pen = QPen()
        pen.setWidth(0)
        pen.setColor(Qt.white)
        painter.setPen(pen)
        painter.setOpacity(0.2)

        painter.setCompositionMode(QPainter.CompositionMode_Difference)

        scene_rect = self._canvas.sceneRect()

        grid_delta = self._canvas.pixel_size

        for x in range(int(scene_rect.left()), int(scene_rect.right()), grid_delta):

            painter.drawLine(x, scene_rect.top(), x, scene_rect.bottom())

        for y in range(int(scene_rect.top()), int(scene_rect.bottom()), grid_delta):

            painter.drawLine(scene_rect.left(), y, scene_rect.right(), y)

        painter.setOpacity(1.0) 
Example 10
Project: SpriteMator   Author: rafaelvasco   File: color_picker_widget.py    Apache License 2.0 6 votes vote down vote up
def _generate_picker(self):

        image = QImage(8, 18, QImage.Format_ARGB32_Premultiplied)

        image.fill(Qt.transparent)

        p = QPainter()

        p.begin(image)

        pen = QPen(Qt.black)
        pen.setWidth(2)

        p.setPen(pen)

        p.setBrush(Qt.white)

        rect = QRect(0, 0, 8, 18)

        p.drawRect(rect)

        p.end()

        self._pickerPixmap = QPixmap.fromImage(image) 
Example 11
Project: eddy   Author: obdasystems   File: view.py    GNU General Public License v3.0 6 votes vote down vote up
def setGridSize(self, size):
        """
        Sets the grid size.
        """
        action = self.session.action('toggle_grid')
        size = clamp(size, 0)
        if size <= 0 or not action.isChecked():
            brush = QtGui.QBrush(QtCore.Qt.NoBrush)
        else:
            image = QtGui.QImage(size, size, QtGui.QImage.Format_RGB32)
            image.fill(QtCore.Qt.white)
            painter = QtGui.QPainter(image)
            painter.setPen(QtGui.QPen(QtGui.QBrush(QtGui.QColor(80, 80, 80, 255)), 1, QtCore.Qt.SolidLine))
            painter.drawPoint(QtCore.QPointF(0, 0))
            painter.end()
            brush = QtGui.QBrush(image)
        self.setBackgroundBrush(brush) 
Example 12
Project: eddy   Author: obdasystems   File: qt.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, width, height, color, border=None):
        """
        Initialize the icon.
        :type width: T <= int | float
        :type height: T <= int | float
        :type color: str
        :type border: str
        """
        pixmap = QtGui.QPixmap(width, height)
        painter = QtGui.QPainter(pixmap)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        path = QtGui.QPainterPath()
        path.addRect(QtCore.QRectF(QtCore.QPointF(0, 0), QtCore.QPointF(width, height)))
        painter.fillPath(path, QtGui.QBrush(QtGui.QColor(color)))
        if border:
            painter.setPen(QtGui.QPen(QtGui.QColor(border), 0, QtCore.Qt.SolidLine))
            painter.drawPath(path)
        painter.end()
        super().__init__(pixmap) 
Example 13
Project: eddy   Author: obdasystems   File: common.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, geometry=QtGui.QPolygonF(),
         brush=QtGui.QBrush(QtCore.Qt.NoBrush),
         pen=QtGui.QPen(QtCore.Qt.NoPen)):
        """
        Initialize the polygon.
        :type geometry: T <= QRectF|QtGui.QPolygonF|QPainterPath
        :type brush: QBrush
        :type pen: QPen
        """
        self._geometry = geometry
        self._brush = brush
        self._pen = pen

    #############################################
    #   INTERFACE
    ################################# 
Example 14
Project: BBoxEE   Author: persts   File: annotation_graphicsview.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, parent=None):
        """Class init function."""
        QtWidgets.QGraphicsView.__init__(self, parent)
        self.mode = Mode.PAN
        self.points = []
        self.point_graphics_items = []
        self.bbox = QtCore.QRectF()
        self.selected_bbox = None
        self.quad = Quad.TL
        self.setViewportUpdateMode(QtWidgets.QGraphicsView.FullViewportUpdate)
        self.brushes = [QtGui.QBrush(QtCore.Qt.blue, QtCore.Qt.SolidPattern),
                        QtGui.QBrush(QtCore.Qt.green, QtCore.Qt.SolidPattern),
                        QtGui.QBrush(QtCore.Qt.yellow, QtCore.Qt.SolidPattern),
                        QtGui.QBrush(QtCore.Qt.red, QtCore.Qt.SolidPattern)]
        self.pens = [QtGui.QPen(self.brushes[0], 2),
                     QtGui.QPen(self.brushes[1], 2),
                     QtGui.QPen(self.brushes[2], 2),
                     QtGui.QPen(self.brushes[3], 2)] 
Example 15
Project: hexutil   Author: stephanh42   File: example.py    MIT License 6 votes vote down vote up
def __init__(self, *args, **kws):
        super().__init__(*args, **kws)
        self.setMouseTracking(True) # we want to receive mouseMoveEvents

        self.level = Level(500)
        self.player = hexutil.origin
        self.hexgrid = hexutil.HexGrid(24)

        # initialize GUI objects needed for painting
        self.font = QtGui.QFont("Helvetica", 20)
        self.font.setStyleHint(QtGui.QFont.SansSerif)
        self.pen = QtGui.QPen()
        self.pen.setWidth(2)
        self.select_brush = QtGui.QBrush(QtGui.QColor(127, 127, 255, 127))
        self.unseen_brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 127))

        self.update_fov() 
Example 16
Project: plexdesktop   Author: coryo   File: delegates.py    GNU General Public License v3.0 6 votes vote down vote up
def draw_unwatched_indicator(plex_item, pixmap, size=0.20):
    """draw a triangle on the top right of pixmap"""
    if not hasattr(plex_item, 'watched') and not hasattr(plex_item, 'in_progress'):
        return
    if plex_item.watched or plex_item.in_progress:
        return
    p = QtGui.QPainter(pixmap)
    rect = p.window()
    top_right = rect.topRight()
    size = pixmap.height() * size
    color = QtGui.QColor(204, 123, 25)
    triangle = QtGui.QPolygon([top_right, top_right - QtCore.QPoint(size, 0),
                               top_right + QtCore.QPoint(0, size)])
    p.setPen(QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 120)), 6))
    p.drawLine(triangle.point(1), triangle.point(2))
    p.setBrush(QtGui.QBrush(color))
    p.setPen(color)
    p.drawPolygon(triangle) 
Example 17
Project: interSubs   Author: oltodosel   File: interSubs.py    MIT License 6 votes vote down vote up
def highligting(self, color, underline_width):
		color = QColor(color)
		color = QColor(color.red(), color.green(), color.blue(), 200)
		painter = QPainter(self)

		if config.hover_underline:
			font_metrics = QFontMetrics(self.font())
			text_width = font_metrics.width(self.word)
			text_height = font_metrics.height()

			brush = QBrush(color)
			pen = QPen(brush, underline_width, Qt.SolidLine, Qt.RoundCap)
			painter.setPen(pen)
			if not self.skip:
				painter.drawLine(0, text_height - underline_width, text_width, text_height - underline_width)

		if config.hover_hightlight:
			x = y = 0
			y += self.fontMetrics().ascent()

			painter.setPen(color)
			painter.drawText(x, y + config.outline_top_padding - config.outline_bottom_padding, self.word) 
Example 18
Project: echolocation   Author: hgross   File: radar.py    MIT License 6 votes vote down vote up
def _add_latest_input_line(self, angle):
        """Adds a line to the graphic scene that visualizes a scanned angle"""
        mx, my = self._get_middle()
        angle_rad = deg2rad(angle)
        angle_1_rad = deg2rad(angle - self.measurement_angle/2.0)
        angle_2_rad = deg2rad(angle + self.measurement_angle/2.0)
        length = max(self.width(), self.height())

        start_point = (mx, my)
        p1 = (mx + length * math.cos(angle_1_rad), my + length * math.sin(angle_1_rad))
        p2 = (mx + length * math.cos(angle_2_rad), my + length * math.sin(angle_2_rad))

        gradient_start_point, gradient_end_point = (mx, my), (mx + length * math.cos(angle_rad), my + length * math.sin(angle_rad))
        gradient = QLinearGradient(*gradient_start_point, *gradient_end_point)
        gradient.setColorAt(0, Qt.transparent)
        gradient.setColorAt(0.8, Qt.red)
        gradient.setColorAt(1, Qt.darkRed)

        triangle = QPolygonF()
        triangle.append(QPointF(*start_point))
        triangle.append(QPointF(*p1))
        triangle.append(QPointF(*p2))
        triangle.append(QPointF(*start_point))

        self.scene.addPolygon(triangle, pen=QPen(Qt.transparent), brush=QBrush(gradient)) 
Example 19
Project: echolocation   Author: hgross   File: radar.py    MIT License 6 votes vote down vote up
def _add_measurement(self, length, angle, added_time):
        """
        Adds a visualization for a measured distance to the scene
        :param length: length in cm
        :param angle: the angle
        """
        mx, my = self._get_middle()
        angle_rad = deg2rad(angle)
        ex, ey = mx + length * math.cos(angle_rad), my + length * math.sin(angle_rad)

        age = time.time() - added_time
        age = age if age < self.fade_out_time else self.fade_out_time
        alpha_channel_value = scale((0, self.fade_out_time), (255, 0), age)
        assert 0 <= alpha_channel_value <= 255

        brush_color = QColor(self.measured_distances_color)
        brush_color.setAlpha(alpha_channel_value)
        brush = QBrush(brush_color)
        tpen = QPen(brush_color)

        self.scene.addLine(mx, my, ex, ey, pen=tpen)
        self.scene.addEllipse(ex-self.dot_width/2, ey-self.dot_width/2, self.dot_width, self.dot_width, pen=tpen, brush=brush) 
Example 20
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab6.py    MIT License 6 votes vote down vote up
def __init__(self):
        QtWidgets.QWidget.__init__(self)
        uic.loadUi("window.ui", self)
        self.scene = myScene(0, 0, 561, 581)
        self.scene.win = self
        self.view.setScene(self.scene)
        self.image = QImage(561, 581, QImage.Format_ARGB32_Premultiplied)
        self.image.fill(col_zero)
        self.lock.clicked.connect(lambda: lock(self))
        self.erase.clicked.connect(lambda: clean_all(self))
        self.paint.clicked.connect(lambda: fill_with_seed(self))
        self.addpoint.clicked.connect(lambda: add_point_by_btn(self))
        self.pixel.clicked.connect(lambda: set_flag_zat(self))
        self.addcircle.clicked.connect(lambda: set_flag_cir(self))
        self.edges = []
        self.point_now = None
        self.point_lock = None

        self.pen = QPen(col_one)
        self.delay.setChecked(False) 
Example 21
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab7.py    MIT License 6 votes vote down vote up
def __init__(self):
        QtWidgets.QWidget.__init__(self)
        uic.loadUi("window.ui", self)
        self.scene = Scene(0, 0, 561, 581)
        self.scene.win = self
        self.view.setScene(self.scene)
        self.image = QImage(561, 581, QImage.Format_ARGB32_Premultiplied)
        self.image.fill(Qt.white)
        self.bars.clicked.connect(lambda : set_bars(self))
        self.erase.clicked.connect(lambda: clean_all(self))
        self.paint.clicked.connect(lambda: clipping(self))
        self.rect.clicked.connect(lambda: set_rect(self))
        self.ect.clicked.connect(lambda: add_bars(self))
        self.lines = []
        self.clip = None
        self.point_now = None
        self.input_bars = False
        self.input_rect = False
        self.pen = QPen(red) 
Example 22
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab5.py    MIT License 6 votes vote down vote up
def __init__(self):
        QtWidgets.QWidget.__init__(self)
        uic.loadUi("window.ui", self)
        self.scene = myScene(0, 0, 561, 581)
        self.scene.win = self
        self.view.setScene(self.scene)
        self.image = QImage(561, 581, QImage.Format_ARGB32_Premultiplied)
        self.image.fill(col_zero)
        self.lock.clicked.connect(lambda: lock(self))
        self.erase.clicked.connect(lambda: clean_all(self))
        self.paint.clicked.connect(lambda: fill_xor(self))
        self.addpoint.clicked.connect(lambda: add_point_by_btn(self))
        self.edges = []
        self.point_now = None
        self.point_lock = None
        self.pen = QPen(col_one)
        self.delay.setChecked(False) 
Example 23
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab8.py    MIT License 6 votes vote down vote up
def __init__(self):
        QtWidgets.QWidget.__init__(self)
        uic.loadUi("window.ui", self)
        self.scene = Scene(0, 0, 561, 581)
        self.scene.win = self
        self.view.setScene(self.scene)
        self.image = QImage(561, 581, QImage.Format_ARGB32_Premultiplied)
        self.image.fill(Qt.white)
        self.bars.clicked.connect(lambda : set_bars(self))
        self.erase.clicked.connect(lambda: clean_all(self))
        self.paint.clicked.connect(lambda: clipping(self))
        self.rect.clicked.connect(lambda: set_rect(self))
        self.ect.clicked.connect(lambda: add_bars(self))
        self.lock.clicked.connect(lambda: lock(self))
        self.lines = []
        self.edges = []
        self.clip = None
        self.point_now_rect = None
        self.point_now_bars = None
        self.point_lock = None
        self.input_bars = False
        self.input_rect = False
        self.pen = QPen(black) 
Example 24
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab4.py    MIT License 6 votes vote down vote up
def __init__(self):
        QtWidgets.QWidget.__init__(self)
        uic.loadUi("window.ui", self)
        self.scene = QtWidgets.QGraphicsScene(0, 0, 511, 511)
        self.mainview.setScene(self.scene)
        self.image = QImage(511, 511, QImage.Format_ARGB32_Premultiplied)
        self.pen = QPen()
        self.color_line = QColor(Qt.black)
        self.color_bground = QColor(Qt.white)
        self.draw_once.clicked.connect(lambda: draw_once(self))
        self.clean_all.clicked.connect(lambda: clear_all(self))
        self.btn_bground.clicked.connect(lambda: get_color_bground(self))
        self.btn_line.clicked.connect(lambda: get_color_line(self))
        self.draw_centr.clicked.connect(lambda: draw_centr(self))
        layout = QtWidgets.QHBoxLayout()
        layout.addWidget(self.what)
        layout.addWidget(self.other)
        self.setLayout(layout)
        self.circle.setChecked(True)
        self.canon.setChecked(True)
        #self.circle.toggled.connect(lambda : change_text(self)) 
Example 25
Project: PyRHEED   Author: yux1991   File: kikuchi.py    MIT License 6 votes vote down vote up
def add_curve(self,list,list_x,list_y,color='red',width=2,label='kikuchi_line'):
        pen = QtGui.QPen(QtCore.Qt.SolidLine)
        pen.setColor(QtGui.QColor(color))
        pen.setWidth(width)
        series = QtChart.QLineSeries()
        series.setPen(pen)
        for x,y in zip(list_x,list_y):
            series.append(x,y)
        self.plot.profileChart.addSeries(series)
        for ax in self.plot.profileChart.axes():
            series.attachAxis(ax)
        if label == 'kikuchi_line':
            self.kikuchi_line_series[list] = series
        elif label == 'kikuchi_envelope':
            self.kikuchi_envelope_series[list] = series
        self.plot.profileChart.axisY().setRange(-0.5,self.plot_range.value()) 
Example 26
Project: PyRHEED   Author: yux1991   File: canvas.py    MIT License 6 votes vote down vote up
def draw_line(self,start,end,EnablePlot = True):
        self.clear_canvas()
        if QtGui.QGuiApplication.queryKeyboardModifiers().__eq__(QtCore.Qt.ShiftModifier):
            if end.x() == start.x():
                slope = 10
            else:
                slope = (end.y()-start.y())/(end.x()-start.x())
            if slope > np.tan(np.pi/3):
                end.setX(start.x())
            elif slope < np.tan(np.pi/6):
                end.setY(start.y())
            else:
                end.setY(end.x()-start.x()+start.y())
        self._lineItem = self._scene.addLine(QtCore.QLineF(start,end),QtGui.QPen(QtCore.Qt.yellow,1))
        self._lineItem.show()
        self.canvasObject = "line"
        self.saveStart,self.saveEnd = start,end
        if EnablePlot:
            self.PLOT_LINE_SCAN.emit(start,end) 
Example 27
Project: PyRHEED   Author: yux1991   File: canvas.py    MIT License 6 votes vote down vote up
def draw_rect(self,start,end,width,EnablePlot = True):
        self.clear_canvas()
        rect = QtGui.QPolygonF()
        if QtGui.QGuiApplication.queryKeyboardModifiers().__eq__(QtCore.Qt.ShiftModifier):
            if end.x() == start.x():
                slope = 10
            else:
                slope = (end.y()-start.y())/(end.x()-start.x())
            if slope > np.tan(np.pi/3):
                end.setX(start.x())
            elif slope < np.tan(np.pi/6):
                end.setY(start.y())
            else:
                end.setY(end.x()-start.x()+start.y())
        p1,p2,p3,p4 = self.get_rectangle_position(start,end,width)
        rect.append(p1)
        rect.append(p2)
        rect.append(p3)
        rect.append(p4)
        self._rectItem = self._scene.addPolygon(rect,QtGui.QPen(QtCore.Qt.yellow,1))
        self._rectItem.show()
        self.canvasObject = "rectangle"
        self.saveStart,self.saveEnd,self.saveWidth = start,end,width
        if EnablePlot:
            self.PLOT_INTEGRAL.emit(self.saveStart,self.saveEnd,self.saveWidth) 
Example 28
Project: PointlessMaker   Author: aboood40091   File: items.py    GNU General Public License v3.0 6 votes vote down vote up
def paint(self, painter, option, widget):
        painter.setClipRect(option.exposedRect)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)

        if self.isSelected():
            painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 92, 196, 240)))
            painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255), 1))

        else:
            painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 92, 196, 120)))
            painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0), 1))

        painter.drawRoundedRect(self.itemRect, 4 * (globals.TileWidth / 16), 4 * (globals.TileWidth / 16))

        painter.setFont(self.font)
        painter.drawText(self.itemRect, Qt.AlignCenter, str(self.objType)) 
Example 29
Project: PLEASE   Author: mgrady3   File: please.py    GNU General Public License v3.0 6 votes vote down vote up
def clearLEEDIV(self):
        """Triggered by menu action to clear all LEED selections."""
        self.LEEDivplotwidget.clear()
        if self.LEEDrects:
            # items stored as (QRectF, QPen)
            for tup in self.LEEDrects:
                self.LEEDimagewidget.scene().removeItem(tup[0])
        if self.LEEDBackgroundrects:
            for tup in self.LEEDBackgroundrects:
                self.LEEDimagewidget.scene().removeItem(tup[0])
        self.LEEDrects = []
        self.LEEDBackgroundrects = []
        self.LEEDclickpos = []
        self.LEEDBackgroundcenters = []
        self.LEEDclicks = 0
        self.LEEDAverageIV = [] 
Example 30
Project: dcc   Author: amimo   File: DisasmViewMode.py    Apache License 2.0 5 votes vote down vote up
def _drawRow(self, qp, cemu, row, asm, offset=-1):
        log.debug('DRAW AN INSTRUCTION %s %s %s %s %s', asm, row, asm.get_name(), len(asm.get_operands(offset)), hex(self.getPageOffset()))

        qp.setPen(QtGui.QPen(QtGui.QColor(192, 192, 192), 1, QtCore.Qt.SolidLine))

        hex_data = asm.get_hex()

        # write hexdump
        cemu.writeAt(0, row, hex_data)

        # fill with spaces
        cemu.write((MNEMONIC_COLUMN - len(hex_data)) * ' ')

        # let's color some branch instr
        # if asm.isBranch():
        #    qp.setPen(QtGui.QPen(QtGui.QColor(255, 80, 0)))
        # else:
        qp.setPen(QtGui.QPen(QtGui.QColor(192, 192, 192), 1, QtCore.Qt.SolidLine))

        mnemonic = asm.get_name()
        cemu.write(mnemonic)

        # leave some spaces
        cemu.write((MNEMONIC_WIDTH - len(mnemonic)) * ' ')

        if asm.get_symbol():
            qp.setPen(QtGui.QPen(QtGui.QColor(192, 192, 192), 1, QtCore.Qt.SolidLine))
            cemu.write_c('[')

            qp.setPen(QtGui.QPen(QtGui.QColor('yellow'), 1, QtCore.Qt.SolidLine))
            cemu.write(asm.get_symbol())

            qp.setPen(QtGui.QPen(QtGui.QColor(192, 192, 192), 1, QtCore.Qt.SolidLine))
            cemu.write_c(']')

        self._write_operands(asm, qp, cemu, offset)
        self._write_comments(asm, qp, cemu, offset) 
Example 31
Project: dcc   Author: amimo   File: DisasmViewMode.py    Apache License 2.0 5 votes vote down vote up
def _write_comments(self, asm, qp, cemu, offset):
        comments = asm.get_comments()
        if comments:
            cemu.write(30 * ' ')

            qp.setPen(QtGui.QPen(QtGui.QColor(82, 192, 192), 1, QtCore.Qt.SolidLine))
            cemu.write('; "{0}"'.format(' '.join(comments))) 
Example 32
Project: dcc   Author: amimo   File: SourceViewMode.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, themes, width, height, data, cursor, widget=None):
        super(SourceViewMode, self).__init__()

        self.themes = themes

        self.dataModel = data
        self.addHandler(self.dataModel)

        self.width = width
        self.height = height

        self.cursor = cursor
        self.widget = widget

        self.refresh = True

        # background brush
        self.backgroundBrush = QtGui.QBrush(self.themes['background'])

        # text font
        self.font = self.themes['font']

        # font metrics. assume font is monospaced
        self.font.setKerning(False)
        self.font.setFixedPitch(True)
        fm = QtGui.QFontMetrics(self.font)
        self._fontWidth = fm.width('a')
        self._fontHeight = fm.height()

        self.textPen = QtGui.QPen(self.themes['pen'], 0, QtCore.Qt.SolidLine)
        self.resize(width, height)

        self.Paints = {}
        self.Ops = []
        self.newPix = None

        self.selector = TextSelection.DefaultSelection(themes, self)

        self.LINES = self.dataModel.current_class.get_source().split('\n') 
Example 33
Project: dcc   Author: amimo   File: TextDecorators.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, viewmode):
        self.operations = []
        self.dataModel = viewmode.getDataModel()
        self.viewmode = viewmode
        self.penMap = {}
        self.brushMap = {}
        self.PenInterval = []

        self.normalPen = QtGui.QPen(QtGui.QColor(192, 192, 192), 1, QtCore.Qt.SolidLine)

        # if we want to generate T/F table
        self.Special = string.ascii_letters + string.digits + ' .;\':;=\"?-!()/\\_'
        self.Special = [False, False, False, False, False, False, False, False, False, False, False, False, False,
                        False, False, False, False, False, False, False,
                        False, False, False, False, False, False, False, False, False, False, False, False, True, True,
                        True, False, False, False, False, True, True,
                        True, False, False, False, True, True, True, True, True, True, True, True, True, True, True,
                        True, True, True, True, False, True, False, True,
                        False, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True,
                        True, True, True, True, True, True, True, True,
                        True, True, True, False, True, False, False, True, False, True, True, True, True, True, True,
                        True, True, True, True, True, True, True, True, True,
                        True, True, True, True, True, True, True, True, True, True, True, False, False, False, False,
                        False, False, False, False, False, False, False,
                        False, False, False, False, False, False, False, False, False, False, False, False, False,
                        False, False, False, False, False, False, False, False,
                        False, False, False, False, False, False, False, False, False, False, False, False, False,
                        False, False, False, False, False, False, False, False,
                        False, False, False, False, False, False, False, False, False, False, False, False, False,
                        False, False, False, False, False, False, False, False,
                        False, False, False, False, False, False, False, False, False, False, False, False, False,
                        False, False, False, False, False, False, False, False,
                        False, False, False, False, False, False, False, False, False, False, False, False, False,
                        False, False, False, False, False, False, False, False,
                        False, False, False, False, False, False, False, False, False, False, False, False, False,
                        False, False, False, False] 
Example 34
Project: dcc   Author: amimo   File: TextDecorators.py    Apache License 2.0 5 votes vote down vote up
def highliteWidechar2(self, page):

        pageStart = self.dataModel.getOffset()
        pageEnd = pageStart + len(page)

        touched = False
        # for s, e in self.Intervals:
        #    touched = True

        if not touched:
            # expand
            Match = [(m.start(), m.end()) for m in re.finditer(r'([a-zA-Z0-9\-\\.%*:/? ]\x00){4,}', page)]
            for s, e in Match:
                for i in range(e - s):
                    self.penMap[pageStart + s + i] = QtGui.QPen(QtGui.QColor(255, 255, 0))

                # get rid of '\x00'
                string = page[s:e:2]
                l = len(string)
                # copy string that has no zeros
                page[s:s + l] = string
                # fill with zeros the remaining space
                page[s + l: s + 2 * l] = '\x00' * l

        return page

    ### todo: other way to highlight widechar, should test and see which one is faster 
Example 35
Project: SpriteMator   Author: rafaelvasco   File: animation_manager_widget.py    Apache License 2.0 5 votes vote down vote up
def __init__(self):

        super(FrameStrip, self).__init__()

        self._sprite = None

        self._frameList = None

        self._frameSize = 70

        self._maxFramesOnView = 6

        self._framePadding = 4

        self._horizontalShift = 0

        self._pen = QPen(QColor(0, 179, 255))
        self._pen.setCapStyle(Qt.SquareCap)
        self._pen.setJoinStyle(Qt.MiterJoin)
        self._pen.setWidth(4.0)

        self.setContentsMargins(0, 0, 0, 0)

        self.setMinimumSize(self._frameSize + self._framePadding * 2,
                            self._frameSize + self._framePadding * 2)
        self.setMaximumHeight(self._frameSize + self._framePadding * 2)

        self._checkerTile = ResourcesCache.get("CheckerTileLight") 
Example 36
Project: SpriteMator   Author: rafaelvasco   File: tools.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, canvas):
        super(Manipulator, self).__init__(canvas)

        self._name = 'Manipulator'
        self._load_icon(":/icons/ico_sel_move", ":/icons/ico_sel_move_hover")
        self._cursor = QPixmap(":/images/mover_cursor")

        self._pressMousePos = QPoint()
        self._lastMousePos = QPoint()
        self._curMousePos = QPoint()
        self._selectionRectangle = QRect()
        self._selectionRectColor = QColor(255, 255, 255, 50)
        self._selectionRectDashOffset = 0
        self._selectionImage = None
        self._cutOnSelection = True
        self._doEraseOnSelectionMove = False

        self._selectionBorderPen = QPen()
        self._selectionBorderPen.setWidth(0)
        self._selectionBorderPen.setStyle(Qt.DashLine)
        self._selectionBorderPen.setColor(Qt.white)

        self._selectionRectNodesPen = QPen()
        self._selectionRectNodesPen.setWidth(0)
        self._selectionRectNodesPen.setColor(Qt.white)

        self._state = ManipulatorState.Idle 
Example 37
Project: eddy   Author: obdasystems   File: splash.py    GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, paintEvent):
        """
        Executed when the splashscreen needs to be painted.
        :type paintEvent: QPaintEvent
        """
        painter = QtGui.QPainter(self)
        # APPNAME
        painter.setFont(self.font1)
        painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255), 1.0, QtCore.Qt.SolidLine))
        painter.drawText(QtCore.QRect(31 + self.__spaceX, 138 + self.__spaceY, 380, 400), QtCore.Qt.AlignTop|QtCore.Qt.AlignLeft, APPNAME)
        # VERSION
        painter.setFont(self.font2)
        painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255), 1.0, QtCore.Qt.SolidLine))
        painter.drawText(QtCore.QRect(34 + self.__spaceX, 185 + self.__spaceY, 380, 400), QtCore.Qt.AlignTop|QtCore.Qt.AlignLeft, 'Version {0}'.format(VERSION))
        # COPYRIGHT
        painter.setFont(self.font3)
        painter.setPen(QtGui.QPen(QtGui.QColor(122, 101, 104), 1.0, QtCore.Qt.SolidLine))
        painter.drawText(QtCore.QRect(0 + self.__spaceX, 220 + self.__spaceY, 360, 40), QtCore.Qt.AlignTop|QtCore.Qt.AlignHCenter, COPYRIGHT)
        # CREDITS
        painter.setFont(self.font3)
        painter.setPen(QtGui.QPen(QtGui.QColor(122, 101, 104), 1.0, QtCore.Qt.SolidLine))
        painter.drawText(QtCore.QRect(0 + self.__spaceX, 273 + self.__spaceY, 360, 80), QtCore.Qt.AlignTop|QtCore.Qt.AlignHCenter, CREDITS)
        # LICENSE
        painter.setFont(self.font3)
        painter.setPen(QtGui.QPen(QtGui.QColor(122, 101, 104), 1.0, QtCore.Qt.SolidLine))
        painter.drawText(QtCore.QRect(0 + self.__spaceX, 286 + self.__spaceY, 360, 40), QtCore.Qt.AlignTop|QtCore.Qt.AlignHCenter, LICENSE) 
Example 38
Project: eddy   Author: obdasystems   File: attribute.py    GNU General Public License v3.0 5 votes vote down vote up
def updateNode(self, functional=None, **kwargs):
        """
        Update the current node.
        :type functional: bool
        """
        if functional is None:
            functional = self.isFunctional()

        # FUNCTIONAL POLYGON (SHAPE)
        path1 = QtGui.QPainterPath()
        path1.addEllipse(self.polygon.geometry())
        path2 = QtGui.QPainterPath()
        path2.addEllipse(QtCore.QRectF(-7, -7, 14, 14))
        self.fpolygon.setGeometry(path1.subtracted(path2))

        # FUNCTIONAL POLYGON (PEN & BRUSH)
        pen = QtGui.QPen(QtCore.Qt.NoPen)
        brush = QtGui.QBrush(QtCore.Qt.NoBrush)
        if functional:
            pen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)
            brush = QtGui.QBrush(QtGui.QColor(252, 252, 252, 255))
        self.fpolygon.setPen(pen)
        self.fpolygon.setBrush(brush)

        # SELECTION + BACKGROUND + CACHE REFRESH
        super().updateNode(**kwargs) 
Example 39
Project: eddy   Author: obdasystems   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def penA(self):
        """
        Returns the pen used to paint the shape A of this node.
        :rtype: QtGui.QPen
        """
        return self.polygonA.pen() 
Example 40
Project: eddy   Author: obdasystems   File: base.py    GNU General Public License v3.0 5 votes vote down vote up
def pen(self):
        """
        Returns the pen used to paint the shape of this node.
        :rtype: QtGui.QPen
        """
        return self.polygon.pen() 
Example 41
Project: eddy   Author: obdasystems   File: base.py    GNU General Public License v3.0 5 votes vote down vote up
def setPen(self, pen):
        """
        Set the pen used to paint the shape of this node.
        :type pen: QtGui.QPen
        """
        self.polygon.setPen(pen) 
Example 42
Project: eddy   Author: obdasystems   File: common.py    GNU General Public License v3.0 5 votes vote down vote up
def pen(self):
        """
        Returns the pen used to draw the shape.
        :rtype: QPen
        """
        return self._pen 
Example 43
Project: eddy   Author: obdasystems   File: common.py    GNU General Public License v3.0 5 votes vote down vote up
def setPen(self, pen):
        """
        Set the brush used to draw the shape.
        :type pen: QPen
        """
        self._pen = pen 
Example 44
Project: pyqt5-widgets   Author: mfitzp   File: gradient.py    MIT License 5 votes vote down vote up
def paintEvent(self, e):
        painter = QtGui.QPainter(self)
        width = painter.device().width()
        height = painter.device().height()

        # Draw the linear horizontal gradient.
        gradient = QtGui.QLinearGradient(0, 0, width, 0)
        for stop, color in self._gradient:
            gradient.setColorAt(stop, QtGui.QColor(color))

        rect = QtCore.QRect(0, 0, width, height)
        painter.fillRect(rect, gradient)

        pen = QtGui.QPen()

        y = painter.device().height() / 2


        # Draw the stop handles.
        for stop, _ in self._gradient:
            pen.setColor(QtGui.QColor('white'))
            painter.setPen(pen)

            painter.drawLine(stop * width, y - self._handle_h, stop * width, y + self._handle_h)

            pen.setColor(QtGui.QColor('red'))
            painter.setPen(pen)

            rect = QtCore.QRect(
                stop * width - self._handle_w/2,
                y - self._handle_h/2,
                self._handle_w,
                self._handle_h
            )
            painter.drawRect(rect)

        painter.end() 
Example 45
Project: pyqt5-widgets   Author: mfitzp   File: paint.py    MIT License 5 votes vote down vote up
def _flood_fill_from_event(self, e):

        image = self.pixmap().toImage()
        w, h = image.width(), image.height()
        x, y = e.x(), e.y()

        # Get our target color from origin.
        target_color = image.pixel(x, y)

        have_seen = set()
        queue = [(x, y)]

        def get_cardinal_points(have_seen, center_pos):
            points = []
            cx, cy = center_pos
            for x, y in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
                xx, yy = cx + x, cy + y
                if (xx >= 0 and xx < w and
                            yy >= 0 and yy < h and
                            (xx, yy) not in have_seen):
                    points.append((xx, yy))
                    have_seen.add((xx, yy))

            return points

        # Now perform the search and fill.
        p = QtGui.QPainter(self.pixmap())
        p.setPen(QtGui.QPen(self._pen_color))

        while queue:
            x, y = queue.pop()
            if image.pixel(x, y) == target_color:
                p.drawPoint(QtCore.QPoint(x, y))
                queue.extend(get_cardinal_points(have_seen, (x, y)))

        self.update() 
Example 46
Project: PaintsTensorFlow   Author: seekerzz   File: Painter.py    MIT License 5 votes vote down vote up
def setpen(self, pen_size=2, color=Qt.black):

        self.pen = QPen(color,
                        pen_size,
                        Qt.SolidLine,
                        Qt.FlatCap,
                        Qt.RoundJoin)

        self.pen_size = pen_size
        self.pen_color = color 
Example 47
Project: interSubs   Author: oltodosel   File: interSubs.py    MIT License 5 votes vote down vote up
def draw_text_n_outline(self, painter: QPainter, x, y, outline_width, outline_blur, text):
		outline_color = QColor(config.outline_color)

		font = self.font()
		text_path = QPainterPath()
		if config.R2L_from_B:
			text_path.addText(x, y, font, ' ' + r2l(text.strip()) + ' ')
		else:
			text_path.addText(x, y, font, text)

		# draw blur
		range_width = range(outline_width, outline_width + outline_blur)
		# ~range_width = range(outline_width + outline_blur, outline_width, -1)

		for width in range_width:
			if width == min(range_width):
				alpha = 200
			else:
				alpha = (max(range_width) - width) / max(range_width) * 200

			blur_color = QColor(outline_color.red(), outline_color.green(), outline_color.blue(), alpha)
			blur_brush = QBrush(blur_color, Qt.SolidPattern)
			blur_pen = QPen(blur_brush, width, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)

			painter.setPen(blur_pen)
			painter.drawPath(text_path)

		# draw outline
		outline_color = QColor(outline_color.red(), outline_color.green(), outline_color.blue(), 255)
		outline_brush = QBrush(outline_color, Qt.SolidPattern)
		outline_pen = QPen(outline_brush, outline_width, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)

		painter.setPen(outline_pen)
		painter.drawPath(text_path)

		# draw text
		color = self.palette().color(QPalette.Text)
		painter.setPen(color)
		painter.drawText(x, y, text) 
Example 48
Project: echolocation   Author: hgross   File: radar.py    MIT License 5 votes vote down vote up
def _add_circles(self, n, add_text_labels=True):
        """
        Adds n circles to the graphic scene.
        :param n: the number of circles
        """
        pen = QPen(self.circle_line_color)
        pen.setStyle(Qt.DotLine)
        pen.setWidth(self.line_width)
        width, height = self.width(), self.height()
        stepw, steph = width/n, height/n
        mx, my = self._get_middle()

        for i in range(1, n+1):
            w, h = width - i * stepw, height - i * steph
            self.scene.addEllipse((width-w)/2, (height-h)/2, w, h, pen)

            if add_text_labels:
                text = QGraphicsTextItem()
                text.setDefaultTextColor(self.text_label_color)
                text.setPlainText(str(int(w/2)))
                text.setPos(mx+w/2.0, my)

                text2 = QGraphicsTextItem()
                text2.setDefaultTextColor(self.text_label_color)
                text2.setPlainText(str(int(-w / 2)))
                text2.setPos(mx - w / 2.0, my)

                self.scene.addItem(text)
                self.scene.addItem(text2) 
Example 49
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab3.py    MIT License 5 votes vote down vote up
def __init__(self):
        QtWidgets.QWidget.__init__(self)
        uic.loadUi("window.ui", self)
        self.scene = QtWidgets.QGraphicsScene(0, 0, 511, 511)
        self.mainview.setScene(self.scene)
        self.image = QImage(511, 511, QImage.Format_ARGB32_Premultiplied)
        self.pen = QPen()
        self.color_line = QColor(Qt.black)
        self.color_bground = QColor(Qt.white)
        self.draw_line.clicked.connect(lambda: draw_line(self))
        self.clean_all.clicked.connect(lambda : clear_all(self))
        self.btn_bground.clicked.connect(lambda: get_color_bground(self))
        self.btn_line.clicked.connect(lambda: get_color_line(self))
        self.draw_sun.clicked.connect(lambda: draw_sun(self))
        self.cda.setChecked(True) 
Example 50
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab6.py    MIT License 5 votes vote down vote up
def draw_edges(image, edges):
    p = QPainter()
    p.begin(image)
    p.setPen(QPen(QColor(0, 0, 255)))
    for ed in edges:
        p.drawLine(ed[0], ed[1], ed[2], ed[3])
    p.end()