Esempio n. 1
0
 def render_emblems(item, emblems):
     emblems = tuple(emblems)
     if not emblems:
         return
     icon = self.rendered_emblem_cache.get(emblems, None)
     if icon is None:
         pixmaps = []
         for emblem in emblems:
             pm = self.emblem_cache.get(emblem, None)
             if pm is None:
                 pm = self.emblem_cache[emblem] = QPixmap(
                     I(emblem)).scaled(self.iconSize(), transformMode=Qt.SmoothTransformation)
             pixmaps.append(pm)
         num = len(pixmaps)
         w, h = pixmaps[0].width(), pixmaps[0].height()
         if num == 1:
             icon = self.rendered_emblem_cache[emblems] = QIcon(pixmaps[0])
         else:
             canvas = QPixmap((num * w) + ((num-1)*2), h)
             canvas.fill(Qt.transparent)
             painter = QPainter(canvas)
             for i, pm in enumerate(pixmaps):
                 painter.drawPixmap(i * (w + 2), 0, pm)
             painter.end()
             icon = self.rendered_emblem_cache[emblems] = canvas
     item.setData(0, Qt.DecorationRole, icon)
Esempio n. 2
0
 def render_emblems(item, emblems):
     emblems = tuple(emblems)
     if not emblems:
         return
     icon = self.rendered_emblem_cache.get(emblems, None)
     if icon is None:
         pixmaps = []
         for emblem in emblems:
             pm = self.emblem_cache.get(emblem, None)
             if pm is None:
                 pm = self.emblem_cache[emblem] = QPixmap(
                     I(emblem)).scaled(
                         self.iconSize(),
                         transformMode=Qt.SmoothTransformation)
             pixmaps.append(pm)
         num = len(pixmaps)
         w, h = pixmaps[0].width(), pixmaps[0].height()
         if num == 1:
             icon = self.rendered_emblem_cache[emblems] = QIcon(
                 pixmaps[0])
         else:
             canvas = QPixmap((num * w) + ((num - 1) * 2), h)
             canvas.fill(Qt.transparent)
             painter = QPainter(canvas)
             for i, pm in enumerate(pixmaps):
                 painter.drawPixmap(i * (w + 2), 0, pm)
             painter.end()
             icon = self.rendered_emblem_cache[emblems] = canvas
     item.setData(0, Qt.DecorationRole, icon)
 def updateCustomColorItemIcon(self, qcolor):
     """
     Update the custom color item icon in the background color combobox
     with I{qcolor}.
     """
     pixmap = QPixmap(16, 16)
     pixmap.fill(qcolor)
     self.backgroundColorComboBox.setItemIcon(bg_CUSTOM, QIcon(pixmap))
     return
Esempio n. 4
0
def pixmap_from_color_and_size(color, size):
    """
    #doc; size can be int or (int,int)
    """
    if type(size) == type(1):
        size = size, size
    w,h = size
    qcolor = qcolor_from_anything(color)
    from PyQt4.Qt import QPixmap
    qp = QPixmap(w,h)
    qp.fill(qcolor)
    return qp
    def add_tab(self, name, widget, removeable = True):
        if name is None:
            name = widget.get_name()

        if widget is None:
            raise ProjectTabManagerException("Error Widget is None!")

        pm = QPixmap(QSize(16, 16))
        pm.fill()
        icon = QIcon(pm)
        self.tab_view.addTab(widget, icon, name)
        self.tabs.append([name, widget])
Esempio n. 6
0
def pixmap_from_color_and_size(color, size):
    """
    #doc; size can be int or (int,int)
    """
    if type(size) == type(1):
        size = size, size
    w, h = size
    qcolor = qcolor_from_anything(color)
    from PyQt4.Qt import QPixmap
    qp = QPixmap(w, h)
    qp.fill(qcolor)
    return qp
Esempio n. 7
0
 def fset(self, val):
     val = unicode(val or '')
     col = QColor(val)
     orig = self._color
     if col.isValid():
         self._color = val
         self.setText(val)
         p = QPixmap(self.iconSize())
         p.fill(col)
         self.setIcon(QIcon(p))
     else:
         self._color = None
         self.setText(self.choose_text)
         self.setIcon(QIcon())
     if orig != col:
         self.color_changed.emit(self._color)
Esempio n. 8
0
 def fset(self, val):
     val = unicode(val or '')
     col = QColor(val)
     orig = self._color
     if col.isValid():
         self._color = val
         self.setText(val)
         p = QPixmap(self.iconSize())
         p.fill(col)
         self.setIcon(QIcon(p))
     else:
         self._color = None
         self.setText(self.choose_text)
         self.setIcon(QIcon())
     if orig != col:
         self.color_changed.emit(self._color)
Esempio n. 9
0
    def add_tab(self, name = None, nysa_id = None, widget = None, removeable = True):
        if name is None:
            name = widget.get_name()

        if widget is None:
            raise TabManagerException("Error Widget is None!")

        if nysa_id is None:
            pm = QPixmap(QSize(16, 16))
            pm.fill(QColor('white'))
            icon = QIcon(pm)
            self.tab_view.addTab(widget, icon, name)

        else: 
            color = get_color_from_id(nysa_id)
            pm = QPixmap(QSize(16, 16))
            pm.fill(color)
            icon = QIcon(pm)
            self.tab_view.addTab(widget, icon, name)

        self.tabs.append([nysa_id, widget])
Esempio n. 10
0
class ColorButton(QPushButton):

    changed = pyqtSignal()

    def __init__(self, data, name, text, parent):
        QPushButton.__init__(self, text, parent)
        self.ic = QPixmap(self.iconSize())
        color = data[name]
        self.data, self.name = data, name
        if color is not None:
            self.current_color = read_color(color).color()
            self.ic.fill(self.current_color)
        else:
            self.ic.fill(Qt.transparent)
            self.current_color = color
        self.update_tooltip()
        self.setIcon(QIcon(self.ic))
        self.clicked.connect(self.choose_color)

    def clear(self):
        self.current_color = None
        self.update_tooltip()
        self.ic.fill(Qt.transparent)
        self.setIcon(QIcon(self.ic))
        self.data[self.name] = self.value
        self.changed.emit()

    def choose_color(self):
        col = QColorDialog.getColor(self.current_color or Qt.black, self,
                                    _('Choose color'))
        if col.isValid():
            self.current_color = col
            self.update_tooltip()
            self.ic.fill(col)
            self.setIcon(QIcon(self.ic))
            self.data[self.name] = self.value
            self.changed.emit()

    def update_tooltip(self):
        self.setToolTip(
            _('Red: {0} Green: {1} Blue: {2}').format(
                *self.current_color.getRgb()[:3]) if self.
            current_color else _('No color'))

    @property
    def value(self):
        if self.current_color is None:
            return None
        return col_to_string(self.current_color)
Esempio n. 11
0
 def setColor(self, color, default = False):
     """
     Set the color.
     
     @param color: The color.
     @type  color: tuple of 3 floats (r, g, b)
     
     @param default: If True, make I{color} the default color. Default is
                     False.
     @type  default: boolean
     """
     
     if color == self.color:
         return
     
     if default:
         self.defaultColor = color
         self.setAsDefault = default
     self.color = color
     
     try:
         # Try to set the current item to a color in the combobox.
         self.setCurrentIndex(self.colorList.index(color))
     except:
         # color was not in the combobox, so set current index to the last
         # item which is "Other color...". Also update the color icon to.
         otherColorIndex = len(self.colorList) - 1
         self.otherColor = color
         self.colorList[otherColorIndex] = color
         pixmap = QPixmap(16, 16)
         qcolor = RGBf_to_QColor(color)
         pixmap.fill(qcolor)
         self.setItemIcon(otherColorIndex, QIcon(pixmap))
         self.setCurrentIndex(self.colorList.index(self.otherColor))
     
     # Finally, emit a signal so the parent knows the color has changed.
     self.emit(SIGNAL("editingFinished()")) 
     return
    def setColor(self, color, default=False):
        """
        Set the color.
        
        @param color: The color.
        @type  color: tuple of 3 floats (r, g, b)
        
        @param default: If True, make I{color} the default color. Default is
                        False.
        @type  default: boolean
        """

        if color == self.color:
            return

        if default:
            self.defaultColor = color
            self.setAsDefault = default
        self.color = color

        try:
            # Try to set the current item to a color in the combobox.
            self.setCurrentIndex(self.colorList.index(color))
        except:
            # color was not in the combobox, so set current index to the last
            # item which is "Other color...". Also update the color icon to.
            otherColorIndex = len(self.colorList) - 1
            self.otherColor = color
            self.colorList[otherColorIndex] = color
            pixmap = QPixmap(16, 16)
            qcolor = RGBf_to_QColor(color)
            pixmap.fill(qcolor)
            self.setItemIcon(otherColorIndex, QIcon(pixmap))
            self.setCurrentIndex(self.colorList.index(self.otherColor))

        # Finally, emit a signal so the parent knows the color has changed.
        self.emit(SIGNAL("editingFinished()"))
        return
Esempio n. 13
0
class ColorButton(QPushButton):

    changed = pyqtSignal()

    def __init__(self, data, name, text, parent):
        QPushButton.__init__(self, text, parent)
        self.ic = QPixmap(self.iconSize())
        color = data[name]
        self.data, self.name = data, name
        if color is not None:
            self.current_color = read_color(color).color()
            self.ic.fill(self.current_color)
        else:
            self.ic.fill(Qt.transparent)
            self.current_color = color
        self.update_tooltip()
        self.setIcon(QIcon(self.ic))
        self.clicked.connect(self.choose_color)

    def clear(self):
        self.current_color = None
        self.update_tooltip()
        self.ic.fill(Qt.transparent)
        self.setIcon(QIcon(self.ic))
        self.data[self.name] = self.value
        self.changed.emit()

    def choose_color(self):
        col = QColorDialog.getColor(self.current_color or Qt.black, self, _('Choose color'))
        if col.isValid():
            self.current_color = col
            self.update_tooltip()
            self.ic.fill(col)
            self.setIcon(QIcon(self.ic))
            self.data[self.name] = self.value
            self.changed.emit()

    def update_tooltip(self):
        self.setToolTip(_('Red: {0} Green: {1} Blue: {2}').format(*self.current_color.getRgb()[:3]) if self.current_color else _('No color'))

    @property
    def value(self):
        if self.current_color is None:
            return None
        return col_to_string(self.current_color)
Esempio n. 14
0
class PaintBoard(QWidget):

    # Define virtual panel coordinates for different shapes/regions
    VPCoord_Start = [316, 332]  #LeftTopX, Y
    VPCoord_Circle = [316, 332, 336, 363]  #LeftTopX, Y, RightBotX, Y
    VPCoord_Rect = [336, 332, 356, 363]  #LeftTopX, Y, RightBotX, Y
    VPCoord_Tri = [316, 363, 336, 395]  #LeftTopX, Y, RightBotX, Y
    VPCoord_Line = [336, 363, 356, 395]  #LeftTopX, Y, RightBotX, Y

    # A flag to check if the user is currently using the virtual panel
    usingVP = False

    def __init__(self, sizeX, sizeY, Parent=None):
        '''
        Constructor
        '''
        super(PaintBoard, self).__init__(Parent)

        self.__InitData(sizeX,
                        sizeY)  #Initialize Data first, then interface/view
        self.__InitView()
        print("Init PaintBoard")

    def __InitView(self):

        self.setFixedSize(self.__size)

    def __InitData(self, sizeX, sizeY):
        self.__size = QSize(sizeX, sizeY)

        self.__board = QPixmap(
            self.__size)  # Make a new QPixmap as paint board,350px * 250px
        self.__board.fill(Qt.white)  #Fill the paint board with white

        self.__IsEmpty = True  #board is empty by default
        self.EraserMode = False  #eraser mode is disabled by default

        self.__lastPos = None
        self.__currentPos = QPoint(0, 0)

        self.__painter = QPainter()

        self.__thickness = 1  #default pen thickness is 1
        self.__penColor = QColor("black")  #default color is black
        self.__colorList = QColor.colorNames()  #get the list of colors

    def Clear(self):
        #Clear the board
        self.__board.fill(Qt.white)
        self.update()
        self.__IsEmpty = True

    def ChangePenColor(self, color="black"):
        self.__penColor = QColor(color)

    def ChangePenThickness(self, thickness=1):
        self.__thickness = thickness

    def IsEmpty(self):
        #Is the board empty
        return self.__IsEmpty

    def GetContentAsQImage(self):
        #return the content of the board (return QImage)
        image = self.__board.toImage()
        return image

    def paintEvent(self, paintEvent):

        self.__painter.begin(self)
        self.__painter.drawPixmap(0, 0, self.__board)
        self.__painter.end()

        # print("inside paintEvent")

    def penPressEvent(self, pos):

        self.__currentPos = QPoint(pos[0], pos[1])
        self.__lastPos = self.__currentPos

    def penMoveEvent(self, pos, pressure):
        pen_x = pos[0]
        pen_y = pos[1]
        pen_pressure = pressure

        if self.__lastPos is None:
            self.__lastPos = QPoint(pen_x, pen_y)
        elif (abs(pen_x - self.__lastPos.x()) > 21
              or abs(pen_y - self.__lastPos.y()) > 21):
            self.__lastPos = QPoint(pen_x, pen_y)

        self.__currentPos = QPoint(pen_x, pen_y)
        self.__painter.begin(self.__board)

        if self.EraserMode == False:
            #Non-Eraser mode
            self.__painter.setPen(QPen(
                self.__penColor, self.__thickness))  #Set pen color, thickness
        else:
            #Eraser mode: pen color is white, thickness is 6
            self.__painter.setPen(QPen(Qt.white, 6))

        self.__painter.drawLine(self.__lastPos, self.__currentPos)
        self.__painter.end()
        self.__lastPos = self.__currentPos

        self.update()  #Show updates

    # Virtual Panel event
    def penVPEvent(self, pos, pressure):
        pass

    '''    
        # Check if the pressure is over 500
        if(pen_pressure > 400):
            # Check which region the pen is in and prepare to draw shape accordingly
            if(pen_x < self.VPCoord_Circle[2] and pen_y < self.VPCoord_Circle[3]):
                print("A")        
            elif(pen_x < self.VPCoord_Rect[2] and pen_y < self.VPCoord_Rect[3]):
                print("B")
            elif(pen_x < self.VPCoord_Tri[2] and pen_y < self.VPCoord_Tri[3]):
                print("C")
            elif(pen_x < self.VPCoord_Line[2] and pen_y < self.VPCoord_Line[3]):
                print("D")
    '''

    def penReleaseEvent(self, pos):
        self.__IsEmpty = False  #board is not empty

    def paintEllipse(self, center_x, center_y, radias1, radias2):
        self.__painter.begin(self.__board)

        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawEllipse(QPoint(center_x, center_y), radias1,
                                   radias2)

        self.__painter.end()

        self.update()  #Show updates

    def paintRect(self, center_x, center_y, upper_left_x, upper_left_y):
        width = abs(2 * (center_x - upper_left_x))
        height = abs(2 * (center_y - upper_left_y))

        self.__painter.begin(self.__board)

        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawRect(upper_left_x, upper_left_y, width, height)

        self.__painter.end()

        self.update()  #Show updates

    def paintTriangle(self, points):
        self.__painter.begin(self.__board)

        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawPolygon(points)

        self.__painter.end()

        self.update()  #Show updates

    def paintLine(self, P1_x, P1_y, P2_x, P2_y):
        P1 = QPoint(P1_x, P1_y)
        P2 = QPoint(P2_x, P2_y)

        self.__painter.begin(self.__board)
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawLine(P1, P2)
        self.__painter.end()

        self.update()  #Show updates

    def paintArc(self, center_x, center_y, start_x, start_y, end_x, end_y):
        radius = math.sqrt(
            math.pow(center_x - start_x, 2) + math.pow(center_y - start_y, 2))
        rect = QRectF(center_x - radius, center_y - radius, radius * 2,
                      radius * 2)
        startAngle = 16 * math.atan2(start_x - center_y,
                                     start_x - center_x) * 180.0 / math.pi
        endAngle = 16 * math.atan2(end_y - center_y,
                                   end_x - center_x) * 180.0 / math.pi
        spanAngle = endAngle - startAngle

        self.__painter.begin(self.__board)
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawArc(rect, startAngle, spanAngle)
        self.__painter.end()

        self.update()  #Show updates

    def paintBezierSpline(self, pointListX, pointListY):
        P1 = QPoint(int(pointListX[0]), int(pointListY[0]))
        path = QtGui.QPainterPath()
        path.moveTo(P1)

        self.__painter.begin(self.__board)
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))

        i = 0
        while i < len(pointListX) - 3:
            P2 = QPoint(int(pointListX[i + 1]), int(pointListY[i + 1]))
            P3 = QPoint(int(pointListX[i + 2]), int(pointListY[i + 2]))
            P4 = QPoint(int(pointListX[i + 3]), int(pointListY[i + 3]))
            path.cubicTo(P2, P3, P4)
            self.__painter.drawPath(path)
            i += 3

        self.__painter.end()

        self.update()  #Show updates
    def __init__(
        self,
        parentWidget,
        label='Color:',
        labelColumn=0,
        colorList=[],
        colorNames=[],
        color=white,
        setAsDefault=True,
        spanWidth=False,
    ):
        """
        Appends a color chooser widget to <parentWidget>, a property manager 
        group box.
        
        @param parentWidget: the parent group box containing this widget.
        @type  parentWidget: PM_GroupBox
        
        @param label: The label that appears to the left or right of the 
                      color frame (and "Browse" button). 
                      
                      If spanWidth is True, the label will be displayed on
                      its own row directly above the lineedit (and button).
                      
                      To suppress the label, set I{label} to an 
                      empty string.
        @type  label: str
        
        @param labelColumn: The column number of the label in the group box
                            grid layout. The only valid values are 0 (left 
                            column) and 1 (right column). The default is 0 
                            (left column).
        @type  labelColumn: int
        
        @param colorList: List of colors.
        @type  colorList: List where each item contains 3 floats (r, g, b)
        
        @param colorNames: List of color names.
        @type  colorNames: List of strings
        
        @param color: The initial color. White is the default. If I{color}
                      is not in I{colorList}, then the initial color will be
                      set to the last color item (i.e. "Other color...").
        @type  color: tuple of 3 floats (r, g, b)
        
        @param setAsDefault: if True, will restore L{color} when the
                    "Restore Defaults" button is clicked.
        @type  setAsDefault: boolean
        
        @param spanWidth: if True, the widget and its label will span the width
                      of the group box. Its label will appear directly above
                      the widget (unless the label is empty) and is left
                      justified.
        @type  spanWidth: boolean
        """

        if len(colorNames) and len(colorList):
            assert len(colorNames) == len(colorList)
            self.colorNames = colorNames
            self.colorList = colorList

        self.colorDict = dict(zip(self.colorNames, self.colorList))

        PM_ComboBox.__init__(
            self,
            parentWidget,
            label=label,
            labelColumn=labelColumn,
            choices=self.colorNames,
            index=0,  # Gets (re)set by setColor()
            setAsDefault=setAsDefault,
            spanWidth=spanWidth)

        # Load QComboBox widget choices and set initial choice (index).
        idx = 0
        for colorName in self.colorNames:
            pixmap = QPixmap(12, 12)
            qcolor = RGBf_to_QColor(self.colorDict[str(colorName)])
            pixmap.fill(qcolor)
            self.setItemIcon(idx, QIcon(pixmap))
            idx += 1

        self.setIconSize(QSize(12, 12))  # Default is 16x16.
        self.setColor(color)  # Sets current index.

        self.connect(self, SIGNAL("activated(QString)"),
                     self._setColorFromIndex)

        return
Esempio n. 16
0
 def initSystray(self):
     self.s = SystemTrayIcon(self.name, self.interval)
     p = QPixmap(22,22)
     p.fill(self.s.bgColor)
     self.s.setIcon(QIcon(p))
     self.s.show()
Esempio n. 17
0
class PaintBoard(QWidget):

    # Define virtual panel coordinates for different shapes/regions
    VPCoord_Start = [316, 332]  #LeftTopX, Y
    VPCoord_Circle = [316, 332, 336, 363]  #LeftTopX, Y, RightBotX, Y
    VPCoord_Rect = [336, 332, 356, 363]  #LeftTopX, Y, RightBotX, Y
    VPCoord_Tri = [316, 363, 336, 395]  #LeftTopX, Y, RightBotX, Y
    VPCoord_Line = [336, 363, 356, 395]  #LeftTopX, Y, RightBotX, Y

    # A flag to check if the user is currently using the virtual panel
    usingVP = False

    def __init__(self, sizeX, sizeY, Parent=None):
        '''
        Constructor
        '''
        super(PaintBoard, self).__init__(Parent)

        self.__InitData(sizeX,
                        sizeY)  #Initialize Data first, then interface/view
        self.__InitView()
        print("Init PaintBoard")

    def __InitView(self):

        self.setFixedSize(self.__size)

    def __InitData(self, sizeX, sizeY):
        self.__size = QSize(sizeX, sizeY)

        self.__board = QPixmap(
            self.__size)  # Make a new QPixmap as paint board,350px * 250px
        self.__board.fill(Qt.white)  #Fill the paint board with white

        self.__IsEmpty = True  #board is empty by default
        self.EraserMode = False  #eraser mode is disabled by default

        self.__lastPos = None
        self.__currentPos = QPoint(0, 0)

        self.__painter = QPainter()

        self.__thickness = 1  #default pen thickness is 1
        self.__penColor = QColor("black")  #default color is black
        self.__colorList = QColor.colorNames()  #get the list of colors

    def Clear(self):
        #Clear the board
        self.__board.fill(Qt.white)
        self.update()
        self.__IsEmpty = True

    def ChangePenColor(self, color="black"):
        self.__penColor = QColor(color)

    def ChangePenThickness(self, thickness=1):
        self.__thickness = thickness

    def IsEmpty(self):
        #Is the board empty
        return self.__IsEmpty

    def GetContentAsQImage(self):
        #return the content of the board (return QImage)
        image = self.__board.toImage()
        return image

    def paintEvent(self, paintEvent):

        self.__painter.begin(self)
        self.__painter.drawPixmap(0, 0, self.__board)
        self.__painter.end()

        # print("inside paintEvent")

    def penPressEvent(self, pos):

        self.__currentPos = QPoint(pos[0], pos[1])
        self.__lastPos = self.__currentPos

    def penMoveEvent(self, pos, pressure, liftedDeque):
        pen_x = pos[0]
        pen_y = pos[1]
        pen_pressure = pressure

        # print(liftedDeque)
        # print(self.__lastPos)

        if self.__lastPos is None:
            self.__lastPos = QPoint(pen_x, pen_y)

        self.__currentPos = QPoint(pen_x, pen_y)
        self.__painter.begin(self.__board)

        if self.EraserMode == False:
            #Non-Eraser mode
            self.__penColor = QColor("blue")
            self.__painter.setPen(QPen(
                self.__penColor, self.__thickness))  #Set pen color, thickness
        else:
            #Eraser mode: pen color is white, thickness is 6
            self.__painter.setPen(QPen(Qt.white, 6))

        self.__painter.drawLine(self.__lastPos, self.__currentPos)
        self.__painter.end()
        self.__lastPos = self.__currentPos

        self.update()  #Show updates

        # If ever detected the pen is lifted, reset the __lastPos variable in order to reposition the pen
        if (True in liftedDeque):
            self.__lastPos = None

    # Virtual Panel event
    def penVPEvent(self, pos, pressure):
        pass

    '''    
        # Check if the pressure is over 500
        if(pen_pressure > 400):
            # Check which region the pen is in and prepare to draw shape accordingly
            if(pen_x < self.VPCoord_Circle[2] and pen_y < self.VPCoord_Circle[3]):
                print("A")        
            elif(pen_x < self.VPCoord_Rect[2] and pen_y < self.VPCoord_Rect[3]):
                print("B")
            elif(pen_x < self.VPCoord_Tri[2] and pen_y < self.VPCoord_Tri[3]):
                print("C")
            elif(pen_x < self.VPCoord_Line[2] and pen_y < self.VPCoord_Line[3]):
                print("D")
    '''

    def penReleaseEvent(self, pos):
        self.__IsEmpty = False  #board is not empty

    def paintEllipse(self, center_x, center_y, radias1, radias2):
        self.__painter.begin(self.__board)
        self.__penColor = QColor("black")
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawEllipse(QPoint(center_x, center_y), radias1,
                                   radias2)

        self.__painter.end()

        self.update()  #Show updates

    def paintRect(self, center_x, center_y, upper_left_x, upper_left_y):
        width = abs(2 * (center_x - upper_left_x))
        height = abs(2 * (center_y - upper_left_y))

        self.__painter.begin(self.__board)
        self.__penColor = QColor("black")
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawRect(upper_left_x, upper_left_y, width, height)

        self.__painter.end()

        self.update()  #Show updates

    def paintTriangle(self, points):
        self.__painter.begin(self.__board)
        self.__penColor = QColor("black")
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawPolygon(points)

        self.__painter.end()

        self.update()  #Show updates

    def paintPolyg(self, x1, y1, x2, y2, x3, y3, x4, y4):
        self.__painter.begin(self.__board)
        self.__penColor = QColor("black")
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawPolygon(QPoint(x1, y1), QPoint(x2, y2),
                                   QPoint(x3, y3), QPoint(x4, y4))
        self.__painter.end()

        self.update()  #Show updates

    def paintLine(self, P1_x, P1_y, P2_x, P2_y):
        P1 = QPoint(P1_x, P1_y)
        P2 = QPoint(P2_x, P2_y)

        self.__painter.begin(self.__board)
        self.__penColor = QColor("black")
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawLine(P1, P2)
        self.__painter.end()

        self.update()  #Show updates

    def paintAuxLine(self, P1_x, P1_y, P2_x, P2_y):
        P1 = QPoint(P1_x, P1_y)
        P2 = QPoint(P2_x, P2_y)

        self.__painter.begin(self.__board)
        self.__penColor = QColor("red")
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawLine(P1, P2)
        self.__painter.end()

        self.update()  #Show updates

    def PointsInCircum(self, r, n, phi):
        return [(math.cos(2 * pi / n * x + phi) * r,
                 math.sin(2 * pi / n * x + phi) * r) for x in range(0, n + 1)
                ]  # defining the points on the Circum of a circle

    def paintPCircle(self, center_x, center_y, start_x, start_y, pers_x,
                     pers_y):
        point = [start_x, start_y]
        center = [center_x, center_y]
        distance = [(point[0] - center[0]), (point[1] - center[1])]
        phi = math.atan2(distance[1], distance[0])
        r = math.sqrt(distance[0] * distance[0] + distance[1] * distance[1])
        points = self.PointsInCircum(r, 300, phi)
        #Drawing the circle in perspective
        dist_x = center_x - pers_x
        print("dist_x", dist_x, pers_x, pers_y, center_x, center_y)
        points = [(j[0], (j[1] + center_x - pers_y) *
                   ((j[0] + center_x) / dist_x) + pers_y - center_y)
                  for j in points]

        self.__painter.begin(self.__board)
        self.__penColor = QColor("blue")
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        for x in points:
            self.__painter.drawPoint(round(x[0] + center[0], 3),
                                     round(x[1] / 1.00 + center[1], 3))

        self.__painter.end()

    # returns true if given angle is in the second quadrant;
    # requires angle in degree and in range -180 to 180
    def _isAngleInSecondQuadrant(self, angle):
        if angle > 90 and angle < 180:
            return True
        else:
            return False

    # returns true if given angle is in the third quadrant;
    # requires angle in degree and in range -180 to 180
    def _isAngleInThirdQuadrant(self, angle):
        if angle < -90 and angle > -180:
            return True
        else:
            return False

    def paintArc(self, center_x, center_y, start_x, start_y, end_x, end_y):
        radius = math.sqrt(
            math.pow(center_x - start_x, 2) + math.pow(center_y - start_y, 2))
        rect = QRectF(center_x - radius, center_y - radius, radius * 2,
                      radius * 2)
        # start angle calculation
        startAngle = math.degrees(
            math.atan2(center_y - start_y, start_x - center_x))
        # end angle calculation
        endAngle = math.degrees(math.atan2(center_y - end_y, end_x - center_x))

        # span angle calculation
        spanAngle = endAngle - startAngle
        # assume user always wants to draw clock-wise
        if spanAngle > 0:
            spanAngle = -1 * (360 - spanAngle)
        #print("start angle is " + str(startAngle))
        #print("span angle is " + str(spanAngle))

        self.__painter.begin(self.__board)
        self.__penColor = QColor("black")
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawArc(rect, 16 * startAngle, 16 * spanAngle)
        self.__painter.end()

        self.update()  #Show updates

    def paintAuxArc(self, center_x, center_y, start_x, start_y, end_x, end_y):
        radius = math.sqrt(
            math.pow(center_x - start_x, 2) + math.pow(center_y - start_y, 2))
        rect = QRectF(center_x - radius, center_y - radius, radius * 2,
                      radius * 2)
        # start angle calculation
        startAngle = math.degrees(
            math.atan2(center_y - start_y, start_x - center_x))
        # end angle calculation
        endAngle = math.degrees(math.atan2(center_y - end_y, end_x - center_x))

        # span angle calculation
        spanAngle = 0
        if (self._isAngleInThirdQuadrant(startAngle)
                and self._isAngleInSecondQuadrant(endAngle)
            ) or (self._isAngleInThirdQuadrant(endAngle)
                  and self._isAngleInSecondQuadrant(startAngle)) or (
                      startAngle == 180
                      and self._isAngleInThirdQuadrant(endAngle)
                  ) or (startAngle == -180
                        and self._isAngleInSecondQuadrant(endAngle)) or (
                            endAngle == 180
                            and self._isAngleInThirdQuadrant(startAngle)) or (
                                endAngle == -180
                                and self._isAngleInSecondQuadrant(startAngle)):
            if startAngle == 180 or self._isAngleInThirdQuadrant(startAngle):
                spanAngle = endAngle - (startAngle + 360)
            else:
                spanAngle = (endAngle + 360) - startAngle
        else:
            spanAngle = endAngle - startAngle
        #print("start angle is " + str(startAngle))
        #print("span angle is " + str(spanAngle))

        self.__painter.begin(self.__board)
        self.__penColor = QColor("red")
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))
        self.__painter.drawArc(rect, 16 * startAngle, 16 * spanAngle)
        self.__painter.end()

        self.update()  #Show updates

    def paintBezierSpline(self, pointListX, pointListY):
        P1 = QPoint(int(pointListX[0]), int(pointListY[0]))
        path = QtGui.QPainterPath()
        path.moveTo(P1)

        self.__painter.begin(self.__board)
        self.__penColor = QColor("black")
        self.__painter.setPen(QPen(self.__penColor, self.__thickness))

        i = 0
        while i < len(pointListX) - 3:
            P2 = QPoint(int(pointListX[i + 1]), int(pointListY[i + 1]))
            P3 = QPoint(int(pointListX[i + 2]), int(pointListY[i + 2]))
            P4 = QPoint(int(pointListX[i + 3]), int(pointListY[i + 3]))
            path.cubicTo(P2, P3, P4)
            self.__painter.drawPath(path)
            i += 3

        self.__painter.end()

        self.update()  #Show updates
Esempio n. 18
0
 def set_tab_color (self, widget, color):
     index = self.tab_view.indexOf(widget)
     pm = QPixmap(QSize(16, 16))
     pm.fill(color)
     icon = QIcon(pm)
     self.tab_view.setTabIcon(index, icon)
Esempio n. 19
0
 def __init__(self, 
              parentWidget, 
              label        = 'Color:', 
              labelColumn  = 0,
              colorList    = [],
              colorNames   = [],
              color        = white, 
              setAsDefault = True,
              spanWidth    = False,
              ):
     """
     Appends a color chooser widget to <parentWidget>, a property manager 
     group box.
     
     @param parentWidget: the parent group box containing this widget.
     @type  parentWidget: PM_GroupBox
     
     @param label: The label that appears to the left or right of the 
                   color frame (and "Browse" button). 
                   
                   If spanWidth is True, the label will be displayed on
                   its own row directly above the lineedit (and button).
                   
                   To suppress the label, set I{label} to an 
                   empty string.
     @type  label: str
     
     @param labelColumn: The column number of the label in the group box
                         grid layout. The only valid values are 0 (left 
                         column) and 1 (right column). The default is 0 
                         (left column).
     @type  labelColumn: int
     
     @param colorList: List of colors.
     @type  colorList: List where each item contains 3 floats (r, g, b)
     
     @param colorNames: List of color names.
     @type  colorNames: List of strings
     
     @param color: The initial color. White is the default. If I{color}
                   is not in I{colorList}, then the initial color will be
                   set to the last color item (i.e. "Other color...").
     @type  color: tuple of 3 floats (r, g, b)
     
     @param setAsDefault: if True, will restore L{color} when the
                 "Restore Defaults" button is clicked.
     @type  setAsDefault: boolean
     
     @param spanWidth: if True, the widget and its label will span the width
                   of the group box. Its label will appear directly above
                   the widget (unless the label is empty) and is left
                   justified.
     @type  spanWidth: boolean
     """
     
     if len(colorNames) and len(colorList):
         assert len(colorNames) == len(colorList)
         self.colorNames = colorNames
         self.colorList  = colorList
     
     self.colorDict = dict(zip(self.colorNames, self.colorList))
     
     PM_ComboBox.__init__(self, 
              parentWidget, 
              label        = label, 
              labelColumn  = labelColumn,
              choices      = self.colorNames,
              index        = 0, # Gets (re)set by setColor()
              setAsDefault = setAsDefault,
              spanWidth    = spanWidth
              )
     
     # Load QComboBox widget choices and set initial choice (index).
     idx = 0
     for colorName in self.colorNames:
         pixmap = QPixmap(12, 12)
         qcolor = RGBf_to_QColor(self.colorDict[str(colorName)])
         pixmap.fill(qcolor)
         self.setItemIcon(idx, QIcon(pixmap))
         idx += 1
         
     self.setIconSize(QSize(12, 12)) # Default is 16x16.
     self.setColor(color) # Sets current index.
     
     self.connect(self, SIGNAL("activated(QString)"), self._setColorFromName)
     
     return