Пример #1
0
    def printFile(self): # Needs some work...
        printDialog = QPrintDialog(self.printer, py_de)
        if printDialog.exec_() == QDialog.Accepted:
            margin = 10
            pageNum = 1
            yPos = 0
            printJob = QPainter()
            printJob.begin(self.printer)
            printJob.setFont(self.font)
            fm = printJob.fontMetrics()

            for i in range(self.textEdit.lines()):
                if margin + yPos > self.printer.height() - margin:
                    pageNum += 1
                    self.printer.newPage()
                    yPos = 0
                printJob.drawText(margin,               # X
                                  margin + yPos,        # Y
                                  self.printer.width(), # Width
                                  self.printer.height(),# Height
                                  QtCore.Qt.AlignTop,       # Alignment
                                  self.textEdit.text(i - 1)# The text to print
                                  )
                yPos += fm.lineSpacing()
            printJob.end
Пример #2
0
    def paintEvent(self, event):
        # the original code tried to be clever about painting an caching. it
        # only painted the screen if it was dirty. for the redraws when the
        # dirty flag was not set it relyed on the OS not the clear the cash.
        # but this does not work (at least on Mac OS X). instead of caching in
        # the OS cache the screen in a pixmap to have full control over it
        if self._pixmap == None or self.size() != self._pixmap.size():
            self._pixmap = QPixmap(self.size())
            self._dirty = True

        if self._dirty:
            self._dirty = False

            pixmap_painter = QPainter(self._pixmap)
            pixmap_painter.setFont(self.font())

            self._paint_screen(pixmap_painter)

        painter = QPainter(self)
        painter.drawPixmap(0, 0, self._pixmap)

        # We don't use the blinky cursor for now
        #        if self._cursor_rect is not None and self._selection is None:
        #            self._paint_cursor(painter)
        if self._selection:
            self._paint_selection(painter)
            self._dirty = True
Пример #3
0
def splash_screen():
    """
    """
    pm = QPixmap(
        pkg_resources.resource_filename(
            __name__, "icons/orange-splash-screen.png")
    )

    version = QCoreApplication.applicationVersion()
    size = 21 if len(version) < 5 else 16
    font = QFont("Helvetica")
    font.setPixelSize(size)
    font.setBold(True)
    font.setItalic(True)
    font.setLetterSpacing(QFont.AbsoluteSpacing, 2)
    metrics = QFontMetrics(font)
    br = metrics.boundingRect(version).adjusted(-5, 0, 5, 0)
    br.moveCenter(QPoint(436, 224))

    p = QPainter(pm)
    p.setRenderHint(QPainter.Antialiasing)
    p.setRenderHint(QPainter.TextAntialiasing)
    p.setFont(font)
    p.setPen(QColor("#231F20"))
    p.drawText(br, Qt.AlignCenter, version)
    p.end()
    return pm, QRect(88, 193, 200, 20)
Пример #4
0
        def paintEvent(self, event):
            painter = QPainter(self)
            painter.fillRect(event.rect(), self.numberBarColor)

            block = self.editor.firstVisibleBlock()

            # Iterate over all visible text blocks in the document.
            while block.isValid():
                blockNumber = block.blockNumber()
                block_top = self.editor.blockBoundingGeometry(block).translated(self.editor.contentOffset()).top()

                # Check if the position of the block is outside of the visible area.
                if not block.isVisible() or block_top >= event.rect().bottom():
                    break

                # We want the line number for the selected line to be bold.
                if blockNumber == self.editor.textCursor().blockNumber():
                    self.font.setBold(True)
                    painter.setPen(QColor("#000000"))
                else:
                    self.font.setBold(False)
                    painter.setPen(QColor("#717171"))
                painter.setFont(self.font)

                # Draw the line number right justified at the position of the line.
                paint_rect = QRect(0, block_top, self.width(), self.editor.fontMetrics().height())
                painter.drawText(paint_rect, Qt.AlignRight, str(blockNumber + 1))

                block = block.next()

            painter.end()

            QWidget.paintEvent(self, event)
Пример #5
0
    def _drawMonthFrame(self):
        self.initMonthInfo()
        wi = self.month_info
        painter = QPainter(self)

        pen = painter.pen()
        pen.setWidth(Var.line_width)
        painter.setPen(pen)

        for coord in wi.paint_base_lines:
            painter.drawLine(*coord)

        # Draw selections
        for selection in wi.selections():
            painter.fillRect(*selection)


        # Draw dates
        font = painter.font()
        font.setPointSize(wi.cell_height/8)
        painter.setFont(font)

        for cell_id in range(42):
            x, y = wi.getCoordinate(cell_id)
            x += wi.cell_width * 74/100
            y += wi.cell_height/7
            
            day = wi.getDay(cell_id)

            painter.drawText(QPointF(x, y), QString(str(day)))
    def drawROIBoxes(self, image):
        #print(self.frame_data)
        if not isinstance(self.frame_data, pd.DataFrame) or len(self.frame_data) == 0 \
        or not self.label_type in self.frame_data:
            return

        self.img_h_ratio = image.height() / self.image_height
        self.img_w_ratio = image.width() / self.image_width

        painter = QPainter()
        painter.begin(image)
        for row_id, row_data in self.frame_data.iterrows():
            x = row_data['coord_x'] * self.img_h_ratio
            y = row_data['coord_y'] * self.img_w_ratio
            #check if the coordinates are nan
            if not (x == x) or not (y == y):
                continue

            x = int(x)
            y = int(y)
            c = self.wlabC[int(row_data[self.label_type])]

            painter.setPen(c)
            painter.setFont(QFont('Decorative', 10))

            painter.drawText(x, y, str(int(row_data[self.worm_index_type])))

            bb = row_data['roi_size'] * self.img_w_ratio
            painter.drawRect(x - bb / 2, y - bb / 2, bb, bb)
        painter.end()
Пример #7
0
 def paintEvent(self, e):
     painter = QPainter()
     reactantside = ""
     productside = ""
     reactantside += self._CurrentReaction.GetReactants()[0].GetFormula()
     for x in range(1, len(self._CurrentReaction.GetReactants())):
         reactant = self._CurrentReaction.GetReactants()[x]
         formula = reactant.GetFormula()
         moles = reactant.GetInitialMoles()
         if moles > 0:
             reactantside += " + "+formula
     productside += self._CurrentReaction.GetProducts()[0].GetFormula()
     for x in range(1, len(self._CurrentReaction.GetProducts())):
         product = self._CurrentReaction.GetProducts()[x]
         formula = product.GetFormula()
         moles = product.GetInitialMoles()
         if moles > 0:
             productside += " + "+formula
     painter.begin(self)
     painter.setFont(QFont("Arial", 20, 50, False))
     painter.setPen(QPen(Qt.red, 2, Qt.SolidLine))
     painter.drawText(376 - (len(reactantside) * 15), 40, reactantside)
     target = QRectF(378, 20, 44, 32)
     arrows = QPixmap("assets/double arrow.png")
     portion = QRectF(10, 0, 44, 32)
     painter.drawPixmap(target, arrows, portion)
     painter.setPen(QPen(Qt.blue, 2, Qt.SolidLine))
     painter.drawText(425, 40, productside)
     painter.end()
Пример #8
0
 def paintEvent(self, e):
     painter = QPainter()
     reactantside = ""
     productside = ""
     reactantside += self._CurrentReaction.GetReactants()[0].GetFormula()
     for x in range(1, len(self._CurrentReaction.GetReactants())):
         reactant = self._CurrentReaction.GetReactants()[x]
         formula = reactant.GetFormula()
         moles = reactant.GetInitialMoles()
         if moles > 0:
             reactantside += " + " + formula
     productside += self._CurrentReaction.GetProducts()[0].GetFormula()
     for x in range(1, len(self._CurrentReaction.GetProducts())):
         product = self._CurrentReaction.GetProducts()[x]
         formula = product.GetFormula()
         moles = product.GetInitialMoles()
         if moles > 0:
             productside += " + " + formula
     painter.begin(self)
     painter.setFont(QFont("Arial", 20, 50, False))
     painter.setPen(QPen(Qt.red, 2, Qt.SolidLine))
     painter.drawText(376 - (len(reactantside) * 15), 40, reactantside)
     target = QRectF(378, 20, 44, 32)
     arrows = QPixmap("assets/double arrow.png")
     portion = QRectF(10, 0, 44, 32)
     painter.drawPixmap(target, arrows, portion)
     painter.setPen(QPen(Qt.blue, 2, Qt.SolidLine))
     painter.drawText(425, 40, productside)
     painter.end()
Пример #9
0
def draw_image(name, q):
  image = QSvgGenerator()
  image.setSize(QSize(IMAGE_SIZE, IMAGE_SIZE))
  image.setFileName(name + ".svg")

  painter = QPainter()
  painter.begin(image)
  painter.setBrush(Qt.white)
  painter.setPen(Qt.NoPen)
  painter.drawEllipse(QPointF(IMAGE_SIZE/2, IMAGE_SIZE/2), IMAGE_SIZE/2, IMAGE_SIZE/2)
  painter.setBrush(QBrush())
  painter.setPen(QPen())
  
  draw_defect(painter, q)
  draw_circle(painter, q)
  
  pen = QPen()
  pen.setWidth(7)
  pen.setColor(Qt.red)
  painter.setPen(pen)
  
  painter.drawLine(IMAGE_SIZE/2 - ARROW_SIZE, IMAGE_SIZE/2, IMAGE_SIZE/2 + ARROW_SIZE, IMAGE_SIZE/2)
  painter.drawLine(IMAGE_SIZE/2 + ARROW_SIZE, IMAGE_SIZE/2, IMAGE_SIZE/2 + ARROW_SIZE - 30, IMAGE_SIZE/2 + 20)
  painter.drawLine(IMAGE_SIZE/2 + ARROW_SIZE, IMAGE_SIZE/2, IMAGE_SIZE/2 + ARROW_SIZE - 30, IMAGE_SIZE/2 - 20)
  
  font = painter.font()
  font.setPixelSize(40)
  font.setBold(True)
  painter.setFont(font)
  painter.drawText(QPointF(IMAGE_SIZE/2 + ARROW_SIZE - 30, IMAGE_SIZE/2 - 30), "E")
  
  painter.end()
Пример #10
0
 def paintEvent(self, event):
     painter = QPainter(self)
     painter.setRenderHint(QPainter.TextAntialiasing)
     painter.setFont(self.__parent.getDefaultFont())
     painter.setPen(QColor(250, 250, 250, 250))
     painter.drawText(0, 0, self.width(), self.height(), Qt.AlignVCenter | Qt.AlignHCenter,
                      self.__parent.getText())
	def drawROIBoxes(self, image):
		#print(self.frame_data)
		if not isinstance(self.frame_data, pd.DataFrame) or len(self.frame_data) == 0 \
		or not self.label_type in self.frame_data:
			return 
		 			
		self.img_h_ratio = image.height()/self.image_height;
		self.img_w_ratio = image.width()/self.image_width;

		painter = QPainter()
		painter.begin(image)
		for row_id, row_data in self.frame_data.iterrows():
			x = row_data['coord_x']*self.img_h_ratio
			y = row_data['coord_y']*self.img_w_ratio
			#check if the coordinates are nan
			if not (x == x) or  not (y == y): 
				continue

			x = int(x)
			y = int(y)
			c = self.wlabC[int(row_data[self.label_type])]
			
			painter.setPen(c)
			painter.setFont(QFont('Decorative', 10))
			
			painter.drawText(x, y, str(int(row_data[self.worm_index_type])))

			bb = row_data['roi_size']*self.img_w_ratio
			painter.drawRect(x-bb/2, y-bb/2, bb, bb);
		painter.end()
Пример #12
0
    def paintEvent(self, event=None):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)
        xOffset = self.width() / SIZE
        yOffset = self.height() / SIZE
        for x in range(SIZE):
            for y in range(SIZE):
                cell = self.grid[x][y]
                rect = (QRectF(x * xOffset, y * yOffset, xOffset,
                               yOffset).adjusted(0.5, 0.5, -0.5, -0.5))
                great_rect = QRectF(x * xOffset, y * yOffset, xOffset, yOffset)

                if cell != BLANK:
                    painter.save()
                    painter.setPen(Qt.black)
                    font = QFont()
                    font.setPointSize(20)
                    painter.setFont(font)
                    painter.drawText(rect, Qt.AlignCenter, cell)
                    painter.restore()
                if [x, y] == self.selected:
                    painter.setPen(QPen(Qt.blue, SIZE))
                else:
                    painter.setPen(Qt.black)
                painter.drawRect(rect)
Пример #13
0
    def paintEvent(self, event=None):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)
        xOffset = self.width() / SIZE
        yOffset = self.height() / SIZE
        for x in range(SIZE):
            for y in range(SIZE):
                cell = self.grid[x][y]
                rect = (QRectF(x * xOffset, y * yOffset,
                        xOffset, yOffset).adjusted(0.5, 0.5, -0.5, -0.5))
		great_rect = QRectF(x * xOffset, y * yOffset,
                        xOffset, yOffset)
                
                if cell != BLANK:
                    painter.save()
                    painter.setPen(Qt.black)
		    font = QFont()
		    font.setPointSize(20)
		    painter.setFont(font)
		    painter.drawText(rect, Qt.AlignCenter, cell)
                    painter.restore()
                if [x, y] == self.selected:
                    painter.setPen(QPen(Qt.blue, SIZE))
                else:
                    painter.setPen(Qt.black)
                painter.drawRect(rect)
Пример #14
0
    def drawBaseImage(self, backgroundImage, titleText, titleFont):

        if self._image == None or not self.lastBackgroundImage == backgroundImage:
            self.lastBackgroundImage = backgroundImage

            if backgroundImage == "":
                im = Image.new("RGB", (1280, 720), "black")
            else:
                im = Image.open(backgroundImage)

            # resize if necessary
            if not im.size == (1280, 720):
                im = im.resize((1280, 720), Image.ANTIALIAS)

            self._image = ImageQt(im)

        self._image1 = QtGui.QImage(self._image)
        painter = QPainter(self._image1)
        font = titleFont
        font.setPointSizeF(35)
        painter.setFont(font)
        painter.setPen(QColor(255, 255, 255))

        painter.drawText(70, 375, titleText)
        painter.end()

        buffer = QtCore.QBuffer()
        buffer.open(QtCore.QIODevice.ReadWrite)
        self._image1.save(buffer, "PNG")

        strio = io.BytesIO()
        strio.write(buffer.data())
        buffer.close()
        strio.seek(0)
        return Image.open(strio)
Пример #15
0
 def _paint_title(self, p: QPainter):
     dpi = Info.dpi
     p.drawLine(OIBlock.padding * dpi, 0.35 * dpi + OIBlock.padding * dpi,
                self.width() - (0.01 + OIBlock.padding) * dpi,
                0.35 * dpi + OIBlock.padding * dpi)
     p.setPen(self._fg_color)
     f = p.font()
     f.setPointSize(10)
     f.setBold(True)
     p.setFont(f)
     p.drawText(
         QRectF((0.04 + OIBlock.padding) * dpi,
                (OIBlock.padding + .01) * dpi,
                self.width() - .12 * dpi, .25 * dpi),
         str(self.__block.name()))
     f.setBold(False)
     f.setPointSize(8)
     p.setPen(
         QColor(self._fg_color.red(), self._fg_color.green(),
                self._fg_color.blue(), 100))
     p.setFont(f)
     p.drawText(
         QRectF((.04 + OIBlock.padding) * dpi,
                (.17 + OIBlock.padding) * dpi,
                self.width() - .12 * dpi, .15 * dpi),
         str(self.__block.type_name()))
Пример #16
0
 def __write(self, text, font, pen):
     width = QFontMetrics(font).width(text+' ')
     painter = QPainter(self)
     painter.setFont(font)
     painter.setPen(pen)
     painter.drawText(self.spaceLeft, Qt.AlignBottom, text)
     self.spaceLeft.setLeft(self.spaceLeft.left() + width ) # move the left edge to the end of what we just painted.
Пример #17
0
    def create_scale_marker_values_text(self):
        painter = QPainter(self)
        # painter.setRenderHint(QPainter.HighQualityAntialiasing)
        painter.setRenderHint(QPainter.Antialiasing)

        # Koordinatenursprung in die Mitte der Flaeche legen
        painter.translate(self.width() / 2, self.height() / 2)
        # painter.save()
        font = QFont(self.scale_fontname, self.scale_fontsize)
        fm = QFontMetrics(font)

        pen_shadow = QPen()

        pen_shadow.setBrush(self.ScaleValueColor)
        painter.setPen(pen_shadow)

        text_radius_factor = 0.8
        text_radius = self.widget_diameter/2 * text_radius_factor

        scale_per_div = int((self.value_max - self.value_min) / self.scala_main_count)

        angle_distance = (float(self.scale_angle_size) / float(self.scala_main_count))
        for i in range(self.scala_main_count + 1):
            # text = str(int((self.value_max - self.value_min) / self.scala_main_count * i))
            text = str(int(self.value_min + scale_per_div * i))
            w = fm.width(text) + 1
            h = fm.height()
            painter.setFont(QFont(self.scale_fontname, self.scale_fontsize))
            angle = angle_distance * i + float(self.scale_angle_start_value - self.angle_offset)
            x = text_radius * math.cos(math.radians(angle))
            y = text_radius * math.sin(math.radians(angle))
            # print(w, h, x, y, text)
            text = [x - int(w/2), y - int(h/2), int(w), int(h), Qt.AlignCenter, text]
            painter.drawText(text[0], text[1], text[2], text[3], text[4], text[5])
 def paintEvent(self, event):
     'Paint semi-transparent background, animated pattern, background text'
     QWidget.paintEvent(self, event)
     # make a painter
     p = QPainter(self)
     p.setRenderHint(QPainter.TextAntialiasing)
     p.setRenderHint(QPainter.HighQualityAntialiasing)
     # fill a rectangle with transparent painting
     p.fillRect(event.rect(), Qt.transparent)
     # animated random dots background pattern
     for i in range(4096):
         x = randint(9, self.size().width() - 9)
         y = randint(9, self.size().height() - 9)
         p.setPen(QPen(QColor(randint(200, 255), randint(200, 255), 255), 1))
         p.drawPoint(x, y)
     # set pen to use white color
     p.setPen(QPen(QColor(randint(9, 255), randint(9, 255), 255), 1))
     # Rotate painter 45 Degree
     p.rotate(35)
     # Set painter Font for text
     p.setFont(QFont('Ubuntu', 300))
     # draw the background text, with antialiasing
     p.drawText(99, 199, "Radio")
     # Rotate -45 the QPen back !
     p.rotate(-35)
     # set the pen to no pen
     p.setPen(Qt.NoPen)
     # Background Color
     p.setBrush(QColor(0, 0, 0))
     # Background Opacity
     p.setOpacity(0.75)
     # Background Rounded Borders
     p.drawRoundedRect(self.rect(), 50, 50)
     # finalize the painter
     p.end()
Пример #19
0
    def paintEvent(self, event):
        # the original code tried to be clever about painting an caching. it
        # only painted the screen if it was dirty. for the redraws when the
        # dirty flag was not set it relyed on the OS not the clear the cash.
        # but this does not work (at least on Mac OS X). instead of caching in
        # the OS cache the screen in a pixmap to have full control over it
        if self._pixmap == None or self.size() != self._pixmap.size():
            self._pixmap = QPixmap(self.size())
            self._dirty = True

        if self._dirty:
            self._dirty = False

            pixmap_painter = QPainter(self._pixmap)
            pixmap_painter.setFont(self.font())

            self._paint_screen(pixmap_painter)

        painter = QPainter(self)
        painter.drawPixmap(0, 0, self._pixmap)

        # We don't use the blinky cursor for now
#        if self._cursor_rect is not None and self._selection is None:
#            self._paint_cursor(painter)
        if self._selection:
            self._paint_selection(painter)
            self._dirty = True
Пример #20
0
	def paintEvent(self, event):
		"""
		Reimplements the :meth:`QWidget.paintEvent` method.
		
		:param event: Event.
		:type event: QEvent
		"""

		def __setBold(state):
			"""
			Sets the current painter font bold state.

			:return: Definiton success.
			:rtype: bool
			"""

			font = painter.font()
			font.setBold(state)
			painter.setFont(font)
			return True

		painter = QPainter(self)
		painter.fillRect(event.rect(), self.__backgroundColor)

		pen = QPen(QBrush(), self.__separatorWidth)
		pen.setColor(self.__separatorColor)
		painter.setPen(pen)
		topRightCorner = event.rect().topRight()
		bottomRightCorner = event.rect().bottomRight()
		painter.drawLine(topRightCorner.x(), topRightCorner.y(), bottomRightCorner.x(), bottomRightCorner.y())
		painter.setPen(self.__color)

		viewportHeight = self.__editor.viewport().height()
		metrics = QFontMetrics(self.__editor.document().defaultFont())
		currentBlock = self.__editor.document().findBlock(
			self.__editor.textCursor().position())

		block = self.__editor.firstVisibleBlock()
		blockNumber = block.blockNumber()
		painter.setFont(self.__editor.document().defaultFont())

		while block.isValid():
			blockNumber += 1
			position = self.__editor.blockBoundingGeometry(block).topLeft() + self.__editor.contentOffset()
			if position.y() > viewportHeight:
				break

			if not block.isVisible():
				continue

			block == currentBlock and __setBold(True) or __setBold(False)
			painter.drawText(self.width() - metrics.width(foundations.strings.toString(blockNumber)) - self.__margin / 3,
							round(position.y() + metrics.ascent() + metrics.descent() - \
							(self.__editor.blockBoundingRect(block).height() * 8.0 / 100)),
							foundations.strings.toString(blockNumber))
			block = block.next()

		painter.end()
		QWidget.paintEvent(self, event)
Пример #21
0
 def _paint_title(self, p: QPainter):
     f = p.font()
     f.setBold(True)
     f.setPointSize(8)
     p.setPen(QColor(self._fg_color.red(), self._fg_color.green(), self._fg_color.blue(), 180))
     p.setFont(f)
     title = str(self.name()) + ' : ' + self.type_name()
     p.drawText(QRectF(6 + Block.padding, 25 + Block.padding, self.width() - 12, 15), title)
Пример #22
0
 def paintEvent(self, evt):
     QLabel.paintEvent(self, evt)
     p = QPainter(self)
     p.setFont(self.font())
     x = self._movieWidth + 6
     y = (self.height() + p.fontMetrics().xHeight()) / 2
     p.drawText(x, y, self._text)
     p.end()
    def paintEvent(self,event):
        titleHeight = 40
        bottomHeight = 50
        
        #画标题背景
        painter = QPainter(self)
        painter.save()
        linearGradient = QLinearGradient(0, 0,0,titleHeight)
        linearGradient.setColorAt(0, QColor(60,150,255))
        linearGradient.setColorAt(0.1, QColor(6,88,200)) 
        linearGradient.setColorAt(1, QColor(80,150,255))
        painter.setBrush(QBrush(linearGradient))
        contenRect = QRect(0, 0, self.width(), titleHeight)
        painter.fillRect(contenRect, QBrush(linearGradient))
        painter.restore()
        
        #画标题内容
        painter.save()
        painter.setPen(QPen(QColor(255, 255, 255),1))
        font = painter.font()
        font.setPointSize(12)
        painter.setFont(font)
        painter.drawText(QPoint(10,25), self.title)
        painter.restore()
        
        #画中间白色背景
        painter.save()
        painter.setPen(QPen(QColor(255, 255, 255),1))
        brush = QBrush(QColor(242,242,242))
        painter.setBrush(brush)
        contenRect = QRect(0, titleHeight, self.width()-1, self.height() - titleHeight - bottomHeight)
#         painter.fillRect(contenRect, brush)
        painter.drawRect(contenRect)
        painter.restore()
        
        #画提示信息内容
        painter.save()
        painter.setPen(QPen(QColor(1, 1, 1),1))
        font = painter.font()
        font.setPointSize(15)
        painter.setFont(font)
        fm = QFontMetrics(font)
        infoWidth = fm.width(self.hintInfo)
        painter.drawText(QPoint((self.width() - infoWidth - 10)/2, 150), self.hintInfo)
        painter.restore()
        
        #画底层背景
        painter.save()
        brush = QBrush(QColor(219,234,255))
        painter.setBrush(brush)
        contenRect = QRect(0, self.height() - bottomHeight, self.width(), bottomHeight)
        painter.fillRect(contenRect, brush)
        painter.restore()
        
        
        
        
        
Пример #24
0
 def __write(self, text, font, pen):
     width = QFontMetrics(font).width(text + ' ')
     painter = QPainter(self)
     painter.setFont(font)
     painter.setPen(pen)
     painter.drawText(self.spaceLeft, Qt.AlignBottom, text)
     self.spaceLeft.setLeft(
         self.spaceLeft.left() +
         width)  # move the left edge to the end of what we just painted.
Пример #25
0
def drawDay(xy, txt):
    painter = QPainter()

    painter.begin(qt_im)
    painter.setFont(QtGui.QFont('Helvetica', 50))
    painter.setPen(QPen(QtCore.Qt.gray))
    x0, y0 = xy
    painter.drawText(x0, y0, txt)
    painter.end()
Пример #26
0
    def paintEvent(self, event):
        if not self.program:
            return
        # TODO: get rid of this call
        #self.ResizeCanvas()
        paint = QPainter(self)
        paint.setPen(self.colors["line"])
        paint.setFont(QtGui.QFont('Decorative', 10))
        for e in self.program.edges:
            if e != self.selectedEdge:
                self.drawArrow(
                    paint, self.vertices[e.source].x() + self.size / 2,
                    self.vertices[e.source].y() + self.size / 2,
                    self.vertices[e.destination].x() + self.size / 2,
                    self.vertices[e.destination].y() + self.size / 2)
            else:
                paint.setPen(self.colors["selected"])
                paint.setBrush(self.colors["selected"])
                self.drawArrow(
                    paint, self.vertices[e.source].x() + self.size / 2,
                    self.vertices[e.source].y() + self.size / 2,
                    self.vertices[e.destination].x() + self.size / 2,
                    self.vertices[e.destination].y() + self.size / 2)
                paint.setPen(self.colors["line"])
                paint.setBrush(self.colors["line"])

        paint.setPen(self.colors["vertex"])
        paint.setBrush(self.colors["vertex"])
        for task in self.vertices.values():
            if task == self.selectedVertex:
                paint.setPen(self.colors["selected"])
                paint.setBrush(self.colors["selected"])
                paint.drawEllipse(task)
                paint.setPen(self.colors["vertex"])
                paint.setBrush(self.colors["vertex"])
            else:
                paint.drawEllipse(task)

        paint.setPen(self.colors["text"])
        for v in self.vertices.keys():
            task = self.vertices[v]
            paint.drawText(task.center().x() - 2,
                           task.center().y() + 5, str(v.number))
            paint.drawText(task.topRight().x(),
                           task.topRight().y() + 5, str(v.name))

        paint.setPen(self.colors["line"])
        if self.edgeDraw:
            self.drawArrow(
                paint, self.curEdge[0].x() + self.size / 2,
                self.curEdge[0].y() + self.size / 2,
                QCursor.pos().x() -
                self.mapToGlobal(self.geometry().topLeft()).x(),
                QCursor.pos().y() -
                self.mapToGlobal(self.geometry().topLeft()).y())
        paint.end()
Пример #27
0
def drawLabel(start, end, txt):
    painter = QPainter()

    painter.begin(qt_im)
    painter.setFont(QtGui.QFont('Helvetica', 30))
    painter.setPen(QPen(QtCore.Qt.blue))
    x0, y0 = start
    x1, y1 = end
    painter.drawText((x0 + x1)/2, y0 - 20, txt)
    painter.end()
Пример #28
0
 def paintEvent(self, event):
     QGraphicsView.paintEvent(self, event)
     if getattr(self, "_userMessage", None):
         painter = QPainter(self.viewport())
         font = QFont(self.font())
         font.setPointSize(15)
         painter.setFont(font)
         painter.drawText(self.viewport().geometry(), Qt.AlignCenter,
                          self._userMessage)
         painter.end()
Пример #29
0
        def paintEvent(self, event):
            """
            Paint the widget event
            """
            contents_y = self.edit.verticalScrollBar().value()
            page_bottom = contents_y + self.edit.viewport().height()
            font_metrics = self.fontMetrics()
            current_block = self.edit.document().findBlock(
                self.edit.textCursor().position())

            painter = QPainter(self)

            line_count = 0
            # Iterate over all text blocks in the document.
            block = self.edit.document().begin()
            while block.isValid():
                line_count += 1

                # The top left position of the block in the document
                position = self.edit.document().documentLayout(
                ).blockBoundingRect(block).topLeft()

                # Check if the position of the block is out side of the visible
                # area.
                if position.y() > page_bottom:
                    break

                # We want the line number for the selected line to be bold.
                bold = False
                if block == current_block:
                    bold = True
                    font = painter.font()
                    font.setBold(True)
                    painter.setFont(font)

                # Draw the line number right justified at the y position of the
                # line. 3 is a magic padding number. drawText(x, y, text).
                x = self.width() - font_metrics.width(str(line_count)) - 3
                y = round(position.y()) - contents_y + font_metrics.ascent()
                t = str(line_count)

                painter.drawText(x, y, t)

                # Remove the bold style if it was set previously.
                if bold:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)

                block = block.next()

            self.highest_line = line_count
            painter.end()

            QWidget.paintEvent(self, event)
Пример #30
0
    def paintEvent(self, event):

        w, h, cx, cy, r = self.clockFaceDetails()

        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing)

        painter.fillRect(event.rect(), self.background)

        painter.setBrush(QBrush(Qt.NoBrush))
        painter.setPen(QPen(Qt.black))
        painter.drawEllipse(cx - r * 1.1, cy - r * 1.1, 2.2 * r, 2.2 * r)

        painter.setBrush(QBrush(Qt.NoBrush))
        painter.setPen(QPen(Qt.black, 3))

        for i in range(12):
            angle = 2 * i * math.pi / 12
            painter.drawLine(cx + (0.9 * r * math.cos(angle)),
                             cy + (0.9 * r * math.sin(angle)),
                             cx + (r * math.cos(angle)),
                             cy + (r * math.sin(angle)))

        painter.setPen(QPen(Qt.black, 2))

        for i in range(60):
            angle = 2 * i * math.pi / 60
            painter.drawLine(cx + (0.95 * r * math.cos(angle)),
                             cy + (0.95 * r * math.sin(angle)),
                             cx + (r * math.cos(angle)),
                             cy + (r * math.sin(angle)))

        hour, minute = self.displayTime
        hour = hour % 12

        angle = (-math.pi / 2) + (2 * hour * math.pi /
                                  12) + (2 * math.pi / 12 * minute / 60.0)

        painter.setPen(QPen(Qt.black, 8, Qt.SolidLine, Qt.RoundCap))
        painter.drawLine(cx, cy, cx + (0.55 * r * math.cos(angle)),
                         cy + (0.55 * r * math.sin(angle)))

        angle = (-math.pi / 2) + (2 * minute * math.pi / 60)

        painter.drawLine(cx, cy, cx + (0.8 * r * math.cos(angle)),
                         cy + (0.8 * r * math.sin(angle)))

        painter.setPen(QPen(self.foreground))
        painter.setFont(self.font())
        rect = QRect(0, self.height() * 0.75, self.width(), self.maxHeight)
        painter.drawText(rect, Qt.AlignCenter, "%02i:%02i" % self.displayTime)
        painter.end()
Пример #31
0
 def paintEvent(self, *args, **kwargs):
     painter = QPainter(self)
     painter.drawPixmap(0, 0, 12, self.WIDTH_BORDER_TOP, self.__pic_bg, 0,
                        0, 12, self.WIDTH_BORDER_TOP)
     painter.drawPixmap(
         self.WIDTH_BORDER_LEFT, 0,
         self.width() - self.WIDTH_BORDER_RIGHT - self.WIDTH_BORDER_LEFT,
         self.WIDTH_BORDER_TOP, self.__pic_bg, 12, 0, 1,
         self.WIDTH_BORDER_TOP)
     painter.drawPixmap(self.width() - self.WIDTH_BORDER_RIGHT, 0,
                        self.__pic_bg, 13, 0, 12, self.WIDTH_BORDER_TOP)
     painter.drawPixmap(0,
                        self.height() - self.WIDTH_BORDER_BOTTOM,
                        self.__pic_bg, 0, 90, 12, 14)
     painter.drawPixmap(
         0, self.WIDTH_BORDER_TOP, self.WIDTH_BORDER_LEFT,
         self.height() - self.WIDTH_BORDER_BOTTOM - self.WIDTH_BORDER_TOP,
         self.__pic_bg, 0, 89, 12, 1)
     painter.drawPixmap(
         self.width() - self.WIDTH_BORDER_RIGHT, self.WIDTH_BORDER_TOP,
         self.WIDTH_BORDER_LEFT,
         self.height() - self.WIDTH_BORDER_BOTTOM - self.WIDTH_BORDER_TOP,
         self.__pic_bg, 13, 89, 12, 1)
     painter.drawPixmap(
         self.WIDTH_BORDER_LEFT,
         self.height() - self.WIDTH_BORDER_BOTTOM,
         self.width() - self.WIDTH_BORDER_RIGHT - self.WIDTH_BORDER_LEFT,
         self.WIDTH_BORDER_BOTTOM, self.__pic_bg, 12, 90, 1, 14)
     painter.drawPixmap(self.width() - self.WIDTH_BORDER_RIGHT,
                        self.height() - self.WIDTH_BORDER_BOTTOM,
                        self.__pic_bg, 13, 90, 12, 14)
     painter.fillRect(
         self.WIDTH_BORDER_LEFT - 4, self.WIDTH_BORDER_TOP,
         self.width() - self.WIDTH_BORDER_LEFT - self.WIDTH_BORDER_RIGHT +
         8,
         self.height() - self.WIDTH_BORDER_BOTTOM - self.WIDTH_BORDER_TOP,
         QBrush(QColor(255, 255, 255)))
     painter.setFont(QFont('Microsoft Yahei', 8, QFont.Bold))
     painter.setPen(QColor(250, 250, 250, 220))
     painter.drawText(1, 5, self.width(), 27,
                      Qt.AlignHCenter | Qt.AlignVCenter, self.windowTitle())
     painter.setPen(QColor(50, 50, 50, 255))
     painter.drawText(0, 4, self.width(), 27,
                      Qt.AlignHCenter | Qt.AlignVCenter, self.windowTitle())
     painter.setPen(QColor(142, 142, 142, 255))
     if self.width() > 380:
         painter.drawLine(self.WIDTH_FRAME_LEFT + self.OFFSET_BORDER_LEFT,
                          self.OFFSET_BORDER_TOP + 22,
                          self.WIDTH_FRAME_LEFT + self.OFFSET_BORDER_LEFT,
                          self.height() - self.OFFSET_BORDER_BOTTOM - 1)
Пример #32
0
 def _paint_title(self, p: QPainter):
     p.drawLine(Block.padding, 35 + Block.padding, self.width() - Block.padding, 35 + Block.padding)
     p.setPen(self._fg_color)
     f = p.font()
     f.setPointSize(10)
     f.setBold(True)
     p.setFont(f)
     p.drawText(QRectF(4 + Block.padding, Block.padding + 2, self.width() - 12, 25),
                str(self.settings["Name"].value()))
     f.setBold(False)
     f.setPointSize(8)
     p.setPen(QColor(self._fg_color.red(), self._fg_color.green(), self._fg_color.blue(), 100))
     p.setFont(f)
     p.drawText(QRectF(4 + Block.padding, 18 + Block.padding, self.width() - 12, 15), str(self.__type_name))
Пример #33
0
        def paintEvent(self, event):
            contents_y = self.edit.verticalScrollBar().value()
            page_bottom = contents_y + self.edit.viewport().height()
            font_metrics = self.fontMetrics()
            current_block = self.edit.document().findBlock(self.edit.textCursor().position())

            painter = QPainter(self)

            line_count = 0
            # Iterate over all text blocks in the document.
            block = self.edit.document().begin()
            while block.isValid():
                line_count += 1

                # The top left position of the block in the document
                position = self.edit.document().documentLayout().blockBoundingRect(block).topLeft()

                # Check if the position of the block is out side of the visible
                # area.
                if position.y() > page_bottom:
                    break

                # We want the line number for the selected line to be bold.
                bold = False
                if block == current_block:
                    bold = True
                    font = painter.font()
                    font.setBold(True)
                    painter.setFont(font)

                # Draw the line number right justified at the y position of the
                # line. 3 is a magic padding number. drawText(x, y, text).
                painter.drawText(
                    self.width() - font_metrics.width(str(line_count)) - 3,
                    round(position.y()) - contents_y + font_metrics.ascent(),
                    str(line_count),
                )

                # Remove the bold style if it was set previously.
                if bold:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)

                block = block.next()

            self.highest_line = line_count
            painter.end()

            QWidget.paintEvent(self, event)
Пример #34
0
 def paintEvent(self, event):
     """
     Draw the QImage on screen.
     """
     textPosX,textPosY = 10,200
     painter = QPainter(self)
     painter.drawImage(painter.viewport(), self._image)
     innerFont = QFont()
     innerFont.setPointSize(12)
     painter.setFont(innerFont)
     painter.setPen(QColor(QtCore.Qt.white))
     painter.drawText(10,180,'Current Action:')
     painter.drawText(10,200,self._currentMovement)
     self.drawMoreText(painter,10,300,['Control Buttons:',
     'w,s - Walking Forwards/Backwards',
     'q,e - Walking Left/Right',
     'a,d - Turning Left/Right',
     'x - stopping',
     'Space - standing up',
     'Ctrl - crouch',
     'Escape,Enter - restMode, wakeUp',
     '1 - Grabbing small',
     '2 - Grabbing large',
     '3 - Grabbing Kuscheltier',
     '4 - Grabbing bottle'])
     self.drawMoreText(painter,self.width()-300-25,300,['Dialog Control:({})'.format(self._attitude),
     'u - Introduction',
     'i - Ask for object',
     'h - Object is Somat',
     'j - Object is Muesli',
     'k - Object is Bottle',
     'l - Object is Kuscheltier',
     'n - Wertstoff',
     'm - Altpapier', 
     'o - Ask for help',
     'z - Ask proband to repeat sentence',
     'p - Repeat task',
     '0(Null) - construct initial state',
     't - Goodbye',
     'b - thanks',
     '# - Start free Speech(PopUp)'])
     self.drawMoreText(painter,100,50,['Movement Speeds','Forward: {}'.format(self._currentSpeeds['Forward']),'Leftward: {}'.format(self._currentSpeeds['Leftward']),'CounterClockwise: {}'.format(self._currentSpeeds['CounterClockwise'])])
     pen = QPen()
     pen.setColor(QColor(QtCore.Qt.red))
     pen.setWidth(5)
     painter.setPen(pen)
     painter.drawEllipse(20,15,60,30)
     pen.setColor(QColor(QtCore.Qt.blue))
     painter.setPen(pen)
     painter.drawPolygon(self.rotatePolygon(arrowPolygon,math.degrees(self._motionProxy.getAngles('HeadYaw',True)[0]),[30,20]))
Пример #35
0
    def __init__( self ):

        self.labelAlignment = \
            Qt.Alignment( Qt.AlignBottom | Qt.AlignRight | Qt.AlignAbsolute )

        splashPixmap = PixmapCache().getPixmap( 'splash.png' )
        painter = QPainter( splashPixmap )
        font = QFont( "Arial" )
        font.setPointSize( 12 )
        painter.setFont( font )
        painter.drawText( QPoint( 20, 130 ), "CODIMENSION v" + str( cdmverspec.__version__ ) )
        QSplashScreen.__init__( self, None, splashPixmap )

        self.show()
        QApplication.flush()
        return
Пример #36
0
    def _paint_content(self, p: QPainter):
        t = self.settings["Value"].type()
        p.setPen(self._fg_color)
        f = self.font()
        f.setPointSize(9)
        p.setFont(f)
        p.drawText(QRectF(Block.padding + 5, self.height() / 2 + 10, self.width() - Block.padding * 2 - 10,
                          30), Qt.AlignCenter, str(t))

        f.setPointSize(12)
        p.setFont(f)
        s = 'None'
        if self.settings["Value"].data() is not None:
            s = str(self.settings["Value"].data())
        p.drawText(QRectF(Block.padding + 5, self.height() / 2 - 5, self.width() - Block.padding * 2 - 10,
                          30), Qt.AlignCenter, s)
Пример #37
0
 def pixmap(self):
     if self._pixmap is None:
         if not self.upsideDown:
             if self.abbreviation == "tokens":
                 path = os.path.join(settingsManager.settings['imagesDir'],
                                     'tokens',
                                     self.index)
             else:
                 path = os.path.join(settingsManager.settings['cardsDir'],
                                     self.abbreviation,
                                     "%s.jpg"%(self.index))
                 pngPath = os.path.join(settingsManager.settings['cardsDir'],
                                     self.abbreviation,
                                     "%s.png"%(self.index))
                 print "Opening path {}".format(path)
                 if not os.path.isfile(path):
                     if os.path.isfile(pngPath):
                         print "Opening path {}".format(pngPath)
                         path = pngPath
                     else:
                         cardCrawler.crawlCardAndInfo(self.abbreviation, self.index)
         else: # Card is upside down
             if self.isFlipCard:
                 path = os.path.join(settingsManager.settings['cardsDir'],
                                     self.abbreviation,
                                     "%s000.jpg"%(self.index))
             else:
                 if not self.abbreviation.startswith('ygo'): # Is a Magic card
                     path = os.path.join(settingsManager.settings['imagesDir'],'back.jpg')
                 else: # Is a Yu-Gi-Oh card
                     path = os.path.join(settingsManager.settings['imagesDir'],'yugiohBack.jpg')
         # Resize card in case it is not already the correct height
         self._pixmap = QPixmap(path).scaledToHeight(445,Qt.SmoothTransformation)
         print "%s" % QPixmap(path).isNull()
     if self.plusOneCounter is not 0:
         painter = QPainter(self._pixmap)
         painter.setBrush(QBrush(Qt.darkBlue))
         painter.drawRect(0,60,130,45)
         painter.setPen(QPen(Qt.white))
         painter.setFont(QFont("Helvetica", 30, weight=QFont.Bold))
         text = "+%s/+%s" % (self.plusOneCounter,self.plusOneCounter)
         if (self.plusOneCounter < 0):
             text = "%s/%s" % (self.plusOneCounter,self.plusOneCounter)
         painter.drawText(5,97,text)
     # if self._pixmap is None or self._pixmap.isNull() and self.abbreviation == 'M15':
         # Get debug info from Dan. Currently, can not reproduce.
     return self._pixmap
Пример #38
0
    def paintEvent(self, e):
        qp = QPainter()
        qp.begin(self)

        if self.step == 'waiting_to_start':
            qp.setPen(QPen(Qt.red, 20, Qt.SolidLine))
            qp.setFont(QFont('Decorative', 20))

        if self.step == 'calibration_started':
            qp.setPen(QPen(Qt.red, 35, Qt.SolidLine))
            qp.drawEllipse(self.x, self.y, 40, 40)

        if self.step == 'show_gaze':
            qp.setPen(QPen(Qt.red, 10, Qt.SolidLine))
            qp.drawEllipse(self.x, self.y, 10, 10)

        qp.end()
Пример #39
0
    def create_digital_indicator(self):
        """ Main value indicator inside the Gauge """
        painter = QPainter(self)
        # painter.setRenderHint(QPainter.HighQualityAntialiasing)
        painter.setRenderHint(QPainter.Antialiasing)

        # Koordinatenursprung in die Mitte der Flaeche legen
        # Place the coordinate origin in the center
        painter.translate(*self.center_p())
        # painter.save()
        # xShadow = 3.0
        # yShadow = 3.0
        font = QFont(self.value_fontname, self.value_fontsize)
        fm = QFontMetrics(font)

        pen_shadow = QPen()

        pen_shadow.setBrush(self.DisplayValueColor)
        painter.setPen(pen_shadow)

        text_radius = self.widget_diameter / 2 * self.text_radius_factor

        # angle_distance = (float(self.scale_angle_size) / float(self.scala_main_count))
        # for i in range(self.scala_main_count + 1):
        text = str(int(self.value))
        w = fm.width(text) + 1
        h = fm.height()
        painter.setFont(QFont(self.value_fontname, self.value_fontsize))

        # Mitte zwischen Skalenstart und Skalenende:
        # Skalenende = Skalenanfang - 360 + Skalenlaenge
        # Skalenmitte = (Skalenende - Skalenanfang) / 2 + Skalenanfang
        angle_end = float(self.scale_angle_start_value +
                          self.scale_angle_size - 360)
        angle = (angle_end - self.scale_angle_start_value
                 ) / 2 + self.scale_angle_start_value

        x = text_radius * math.cos(math.radians(angle))
        y = text_radius * math.sin(math.radians(angle))
        # print(w, h, x, y, text)
        text = [
            x - int(w / 2), y - int(h / 2),
            int(w),
            int(h), Qt.AlignCenter, text
        ]
        painter.drawText(text[0], text[1], text[2], text[3], text[4], text[5])
Пример #40
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.fillRect(self.contentsRect(), Qt.lightGray)

        self.paint_tiles(painter)
        self.paint_pieces(painter)
        self.paint_names(painter)
        self.paint_buttons(painter)

        painter.setPen(QPen(Qt.black, 8))
        font = QFont()
        font.setPointSize(20)
        painter.setFont(font)
        if get_player() == "W":
            painter.setPen(QPen(Qt.white, 8))
        painter.drawText(QRectF(10, 10, 60, 60), Qt.AlignCenter, get_player())
Пример #41
0
 def createAxisLabelPixmap(self):
     pixmap = QPixmap(250, 250)
     pixmap.fill(self.backgroundColor)
     painter = QPainter()
     painter.begin(pixmap)
     font = QFont()
     font.setBold(True)
     font.setPixelSize(250 - 30)
     path = QPainterPath()
     path.addText(QPointF(50, 250 - 50), font, self.axis)
     brush = QBrush(self.foregroundColor)
     painter.setBrush(brush)
     painter.drawPath(path)
     painter.setFont(font)
     painter.end()
     pixmap = pixmap.scaled(QSize(self.labelsWidth, self.labelsheight), Qt.KeepAspectRatio, Qt.SmoothTransformation)
     return pixmap
Пример #42
0
 def paintEvent(self, event):
     QWidget.paintEvent(self, event)
     p = QPainter(self)
     p.setFont(self.font)
     if self.pixmap:
         p.drawPixmap(QPoint(0,0), self.pixmap)
     r = QRect(self.rect().topLeft() + QPoint(0, 180), QSize(self.rect().size().width(), p.fontMetrics().height()))
     p.fillRect(r, self.palette().midlight())
     if self.progress:
         pr = QRect(r)
         pr.setWidth( (r.width() * self.progress) / 100 )
         p.fillRect(pr, self.palette().dark())
     p.setBrush(Qt.NoBrush)
     p.setPen(QPen(self.palette().text(), 1))
     p.drawText(QRectF(r), self.title, QTextOption(Qt.AlignHCenter))
     p.setPen(QPen(self.palette().shadow(), 1))
     p.drawRect(self.rect().adjusted(0,0,-1,-1))
Пример #43
0
    def drawBaseImage(self, backgroundImage, titleText, titleFont, fontSize,
                      alignment, xOffset, yOffset):

        if self._image == None or not self.lastBackgroundImage == backgroundImage:
            self.lastBackgroundImage = backgroundImage

            if backgroundImage == "":
                im = Image.new("RGB", (1280, 720), "black")
            else:
                im = Image.open(backgroundImage)

            # resize if necessary
            if not im.size == (1280, 720):
                im = im.resize((1280, 720), Image.ANTIALIAS)

            self._image = ImageQt(im)

        self._image1 = QtGui.QImage(self._image)
        painter = QPainter(self._image1)
        font = titleFont
        font.setPointSizeF(fontSize)
        painter.setFont(font)
        painter.setPen(QColor(255, 255, 255))

        yPosition = yOffset

        fm = QtGui.QFontMetrics(font)
        if alignment == 0:  #Left
            xPosition = xOffset
        if alignment == 1:  #Middle
            xPosition = xOffset - fm.width(titleText) / 2
        if alignment == 2:  #Right
            xPosition = xOffset - fm.width(titleText)
        painter.drawText(xPosition, yPosition, titleText)
        painter.end()

        buffer = QtCore.QBuffer()
        buffer.open(QtCore.QIODevice.ReadWrite)
        self._image1.save(buffer, "PNG")

        strio = io.BytesIO()
        strio.write(buffer.data())
        buffer.close()
        strio.seek(0)
        return Image.open(strio)
Пример #44
0
def run_script(iface):
    canvas = iface.mapCanvas()

    img = QImage(QSize(1920, 1080), QImage.Format_ARGB32_Premultiplied)
    color = QColor(255, 255, 255)
    p = QPainter(img)

    for path in paths:
        #accessibilityLayer.setDataProvider(path)

        # http://www.qgisworkshop.org/html/workshop/python_in_qgis_tutorial2.html
        rlayer = iface.addRasterLayer(path)
        # http://gis.stackexchange.com/questions/26846
        rlayer.loadNamedStyle(
            '/home/matthewc/microaccessibility/times/colors.qml')

        # add the vector layers
        poly = iface.addVectorLayer(
            'dbname=\'matthewc\' host=localhost port=5432 user=\'matthewc\' password=\'password\' sslmode=disable key=\'tid\' srid=4326 type=POLYGON table="public"."ucsb_final_polygon" (way) sql=',
            'poly', 'postgres')
        poly.loadNamedStyle('/home/matthewc/microaccessibility/times/poly.qml')

        line = iface.addVectorLayer(
            'dbname=\'matthewc\' host=localhost port=5432 user=\'matthewc\' password=\'password\' sslmode=disable key=\'tid\' srid=4326 type=LINESTRING table="public"."ucsb_final_line" (way) sql=',
            'line', 'postgres')
        line.loadNamedStyle('/home/matthewc/microaccessibility/times/line.qml')

        renderer = canvas.mapRenderer()

        img.fill(color.rgb())
        p.begin(img)
        p.setRenderHint(QPainter.Antialiasing)
        renderer.setOutputSize(img.size(), img.logicalDpiX())
        renderer.render(p)

        p.setFont(QFont("Ubuntu", 48, QFont.Bold))
        p.setPen(QColor(0, 0, 0))
        p.drawText(10, 58, parseToTime(path))

        p.end()
        img.save(path + ".png", "png")

        QgsMapLayerRegistry.instance().removeMapLayer(rlayer.id())
        QgsMapLayerRegistry.instance().removeMapLayer(poly.id())
        QgsMapLayerRegistry.instance().removeMapLayer(line.id())
Пример #45
0
 def createAxisLabelPixmap(self):
     pixmap = QPixmap(250, 250)
     pixmap.fill(self.backgroundColor)
     painter = QPainter()
     painter.begin(pixmap)
     font = QFont()
     font.setBold(True)
     font.setPixelSize(250 - 30)
     path = QPainterPath()
     path.addText(QPointF(50, 250 - 50), font, self.axis)
     brush = QBrush(self.foregroundColor)
     painter.setBrush(brush)
     painter.drawPath(path)
     painter.setFont(font)
     painter.end()
     pixmap = pixmap.scaled(QSize(self.labelsWidth, self.labelsheight),
                            Qt.KeepAspectRatio, Qt.SmoothTransformation)
     return pixmap
Пример #46
0
 def paintEvent(self, ev):
     edit = self._textedit
     if not edit:
         return
     painter = QPainter(self)
     painter.setFont(edit.font())
     rect = QRect(0, 0, self.width() - 2, QFontMetrics(edit.font()).height())
     block = edit.firstVisibleBlock()
     while block.isValid():
         geom = edit.blockBoundingGeometry(block)
         geom.translate(edit.contentOffset())
         if geom.top() >= ev.rect().bottom():
             break
         if block.isVisible() and geom.bottom() > ev.rect().top() + 1:
             rect.moveTop(geom.top())
             text = format(block.blockNumber() + 1, 'd')
             painter.drawText(rect, Qt.AlignRight, text)
         block = block.next()
Пример #47
0
    def number_bar_paint(self, number_bar, event):
        font_metrics = self.fontMetrics()
        current_line = self.document().findBlock(self.textCursor().position()).blockNumber() + 1

        block = self.firstVisibleBlock()
        line_count = block.blockNumber()
        painter = QPainter(number_bar)
        # painter.fillRect(event.rect(), Qt.lightGray)#self.palette().base())
        painter.fillRect(event.rect(), QColor(230, 230, 230))
        painter.setPen(QPen(QColor(180, 180, 180)))
        painter.drawLine(event.rect().width() - 1, 0, event.rect().width() - 1, event.rect().height() - 1)

        # Iterate over all visible text blocks in the document.
        while block.isValid():
            line_count += 1
            block_top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top()

            # Check if the position of the block is out side of the visible
            # area.
            if not block.isVisible() or block_top >= event.rect().bottom():
                break

            # We want the line number for the selected line to be bold.
            if line_count == current_line:
                font = painter.font()
                font.setBold(True)
                painter.setFont(font)
                painter.setPen(QColor(160, 100, 160))
            else:
                font = painter.font()
                font.setBold(False)
                painter.setFont(font)
                painter.setPen(QColor(160, 160, 160))

            # Draw the line number right justified at the position of the line.
            # left, top, right, bottom = super(WithLineNumbers, self).get_viewport_margins()
            left = number_bar.width()
            super(WithLineNumbers, self).set_viewport_margins("line_number", (left, 0, 0, 0))
            paint_rect = QRect(0, block_top, number_bar.width() - 3, font_metrics.height())
            painter.drawText(paint_rect, Qt.AlignRight, str(line_count))

            block = block.next()

        painter.end()
Пример #48
0
        def numberbarPaint(self, number_bar, event):
            font_metrics = self.fontMetrics()
            current_line = self.document().findBlock(self.textCursor().position()).blockNumber() + 1

            block = self.firstVisibleBlock()
            line_count = block.blockNumber()
            painter = QPainter(number_bar)
            painter.fillRect(event.rect(), self.palette().base())

            # Iterate over all visible text blocks in the document.
            while block.isValid():
                line_count += 1
                block_top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top()

                # Check if the position of the block is out side of the visible
                # area.
                if not block.isVisible() or block_top >= event.rect().bottom():
                    break

                # We want the line number for the selected line to be bold.
                if line_count == current_line:
                    font = painter.font()
                    font.setBold(True)
                    painter.setPen(Qt.black)
                    painter.setFont(font)
                else:
                    font = painter.font()
                    font.setBold(False)
                    painter.setPen(Qt.darkGray)
                    painter.setFont(font)

                if self.instLine is not None and line_count == self.instLine:
                    painter.drawImage(QRect(0, block_top, 16, 16), self.instPtrImage)

                if line_count in self.breakpoints:
                    painter.drawImage(QRect(0, block_top, 16, 16), self.brkpObjImage)

                # Draw the line number right justified at the position of the line.
                paint_rect = QRect(0, block_top, number_bar.width(), font_metrics.height())
                painter.drawText(paint_rect, Qt.AlignRight, unicode(line_count))

                block = block.next()

            painter.end()
Пример #49
0
    def create_font_array(self, char_height=62, pixel_margin=1, font_family='Courier', font_weight=50):
        # Load font and get the dimensions of one character (assuming monospaced font)
        f = QFont(font_family)
        f.setPixelSize(char_height)
        f.setWeight(font_weight)
        fm = QFontMetrics(f, QImage())

        char_width = char_height = 0
        char_y = 999

        for i in range(32, 127):
            bb = fm.boundingRect(chr(i))
            char_width = max(char_width, bb.width())
            char_height = max(char_height, bb.height())
            char_y = min(char_y, bb.y())

        imgsize = (char_width + 2 * pixel_margin, char_height + 2 * pixel_margin)
        self.char_ar = float(imgsize[1]) / imgsize[0]

        # init the image and the painter that will draw the characters to each image
        img = QImage(imgsize[0], imgsize[1], QImage.Format_ARGB32)
        ptr = c_void_p(int(img.constBits()))
        painter = QPainter(img)
        painter.setFont(f)
        painter.setPen(QColor(255, 255, 255, 255))

        # Set-up the texture array
        self.tex_id = gl.glGenTextures(1)
        gl.glBindTexture(gl.GL_TEXTURE_2D_ARRAY, self.tex_id)
        gl.glTexImage3D(gl.GL_TEXTURE_2D_ARRAY, 0, gl.GL_RGBA8, imgsize[0], imgsize[1], 127 - 32, 0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, None)
        gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
        gl.glTexParameteri(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
        gl.glTexParameterf(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_BORDER)
        gl.glTexParameterf(gl.GL_TEXTURE_2D_ARRAY, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_BORDER)
        # We're using the ASCII range 32-126; space, uppercase, lower case, numbers, brackets, punctuation marks
        for i in range(32, 127):
            img.fill(0)
            painter.drawText(pixel_margin, pixel_margin - char_y, chr(i))
            gl.glTexSubImage3D(gl.GL_TEXTURE_2D_ARRAY, 0, 0, 0, i - 32, imgsize[0], imgsize[1], 1, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, ptr)

        # We're done, close the painter, and return the texture ID, char width and char height
        painter.end()
Пример #50
0
 def paintEvent(self, event):
     bgcol = QColor('#111')
     if self.panic:
         fgcol = QColor('#e11')
     else:
         fgcol = QColor('#ddd')
     # Size and shit
     w, h = self.width(), self.height()
     minsize = min(w,h)*self.scale
     arcwidth = minsize*0.1
     minsize *= 0.86
     marginx = (w-minsize)/2
     marginy = (h-minsize)/2
     # Start drawing shit
     painter = QPainter(self)
     painter.setRenderHints(QPainter.Antialiasing | QPainter.TextAntialiasing)
     painter.setPen(QPen(fgcol, arcwidth, cap=Qt.FlatCap))
     #font = QFont('sv basic manual')
     font = QFont('bank gothic')
     font.setPointSize(get_font_size(font, minsize-2*arcwidth))
     smallfont = QFont(font)
     smallfont.setPointSizeF(font.pointSize()/2)
     painter.fillRect(QRectF(0,0,w,h), bgcol)
     # Timer dial thingy
     painter.setOpacity(0.05)
     painter.drawArc(marginx,marginy, minsize,minsize, 0, 5760)
     painter.setOpacity(1)
     arclength = min(1, self.totalseconds/self.panictime) * 5760
     painter.drawArc(marginx,marginy, minsize,minsize, 90*16, -arclength)
     # Timer text
     painter.setFont(font)
     textoptions = QtGui.QTextOption(Qt.AlignCenter)
     painter.drawText(QRectF(marginx, marginy, minsize, minsize),
                      self.get_text(0), textoptions)
     painter.setFont(smallfont)
     painter.setOpacity(0.5)
     painter.drawText(QRectF(marginx, marginy+minsize*0.4, minsize, minsize/2),
                      self.get_text(1), textoptions)
     #painter.setOpacity(0.15)
     #painter.drawText(QRectF(marginx, marginy+minsize*0.05, minsize, minsize/2),
     #                 self.get_text(2), textoptions)
     painter.end()
Пример #51
0
 def _paint_title(self, p: QPainter):
     dpi = Info.dpi
     p.drawLine(OIBlock.padding * dpi, 0.35 * dpi + OIBlock.padding * dpi,
                self.width() - (0.01 + OIBlock.padding) * dpi,
                0.35 * dpi + OIBlock.padding * dpi)
     p.setPen(self._fg_color)
     f = p.font()
     f.setPointSize(10)
     f.setBold(True)
     p.setFont(f)
     p.drawText(
         QRectF((0.04 + OIBlock.padding) * dpi, (OIBlock.padding + .01) * dpi, self.width() - .12 * dpi, .25 * dpi),
         str(self.__block.name()))
     f.setBold(False)
     f.setPointSize(8)
     p.setPen(QColor(self._fg_color.red(), self._fg_color.green(), self._fg_color.blue(), 100))
     p.setFont(f)
     p.drawText(
         QRectF((.04 + OIBlock.padding) * dpi, (.17 + OIBlock.padding) * dpi, self.width() - .12 * dpi, .15 * dpi),
         str(self.__block.type_name()))
Пример #52
0
def _get_pos_widget(name, backgroundColor, foregroundColor):
    label = QLabel()
    label.setAttribute(Qt.WA_TransparentForMouseEvents, True)

    pixmap = QPixmap(25*10, 25*10)
    pixmap.fill(backgroundColor)
    painter = QPainter()
    painter.begin(pixmap)
    pen = QPen(foregroundColor)
    painter.setPen(pen)
    painter.setRenderHint(QPainter.Antialiasing)
    font = QFont()
    font.setBold(True)
    font.setPixelSize(25*10-30)
    path = QPainterPath()
    path.addText(QPointF(50, 25*10-50), font, name)
    brush = QBrush(foregroundColor)
    painter.setBrush(brush)
    painter.drawPath(path)
    painter.setFont(font)
    painter.end()
    pixmap = pixmap.scaled(QSize(20,20),
                           Qt.KeepAspectRatio,
                           Qt.SmoothTransformation)
    label.setPixmap(pixmap)

    spinbox = QSpinBox()
    spinbox.setAttribute(Qt.WA_TransparentForMouseEvents, True)
    spinbox.setEnabled(False)
    spinbox.setAlignment(Qt.AlignCenter)
    spinbox.setToolTip("{0} Spin Box".format(name))
    spinbox.setButtonSymbols(QAbstractSpinBox.NoButtons)
    spinbox.setMaximumHeight(20)
    spinbox.setMaximum(9999)
    font = spinbox.font()
    font.setPixelSize(14)
    spinbox.setFont(font)
    sheet = TEMPLATE.format(foregroundColor.name(),
                            backgroundColor.name())
    spinbox.setStyleSheet(sheet)
    return label, spinbox
Пример #53
0
 def paintEvent(self, ev):
     rect = ev.rect()
     s = self._square
     rows = range(rect.top() // s, rect.bottom() // s + 1)
     cols = range(rect.left() // s, rect.right() // s + 1)
     
     painter = QPainter(self)
     painter.setPen(QPen(self.palette().color(QPalette.Window)))
     painter.setFont(self._font)
     metrics = QFontMetrics(self._font)
     
     # draw characters on white tiles
     tile = self.palette().color(QPalette.Base)
     selected_tile = self.palette().color(QPalette.Highlight)
     selected_tile.setAlpha(96)
     selected_box = self.palette().color(QPalette.Highlight)
     
     text_pen = QPen(self.palette().text())
     disabled_pen = QPen(self.palette().color(QPalette.Disabled, QPalette.Text))
     selection_pen = QPen(selected_box)
     for row in rows:
         for col in cols:
             char = row * self._column_count + col + self._range[0]
             if char > self._range[1]:
                 break
             printable = self.isprint(char)
             painter.setClipRect(col * s, row * s, s, s)
             if char == self._selected:
                 painter.fillRect(col * s + 1, row * s + 1, s - 2, s - 2, selected_tile)
                 painter.setPen(selection_pen)
                 painter.drawRect(col * s, row * s, s - 1, s - 1)
             elif printable:
                 painter.fillRect(col * s + 1, row * s + 1, s - 2, s - 2, tile)
             painter.setPen(text_pen if printable else disabled_pen)
             t = chr(char)
             x = col * s + s // 2 - metrics.width(t) // 2
             y = row * s + 4 + metrics.ascent()
             painter.drawText(x, y, t)
         else:
             continue
         break
Пример #54
0
    def paintEvent(self, event):
        """This method draws a left sidebar

        :param event: QEvent
        """

        bottom = self.editor.viewport().height()
        font_metrics = QFontMetrics(self.editor.document().defaultFont())
        current_line = self.editor.document().findBlock(
            self.editor.textCursor().position()).blockNumber() + 1
        painter = QPainter(self)
        painter.fillRect(self.rect(), QColor("#D0D0D0"))
        block = self.editor.firstVisibleBlock()
        vpoffset = self.editor.contentOffset()
        line = block.blockNumber()
        painter.setFont(self.editor.document().defaultFont())

        while block.isValid():
            line += 1
            pos = self.editor.blockBoundingGeometry(block).topLeft() + vpoffset
            if pos.y() > bottom:
                break

            # Text bold
            font = painter.font()
            if current_line == line:
                font.setBold(True)
            else:
                font.setBold(False)
            painter.setFont(font)

            if block.isVisible():
                fm_ascent = font_metrics.ascent()
                fm_descent = font_metrics.descent()
                painter.drawText(self.width() -
                                 font_metrics.width(str(line)) + 1,
                                 pos.y() + fm_ascent + fm_descent, str(line))

            block = block.next()
        painter.end()
        QFrame.paintEvent(self, event)