示例#1
0
    def __init__(self, iface, zoneOrd, parentDiag):

        self.plugin_dir = os.path.dirname(__file__)
        self.iface = iface
        self.zoneOrd = zoneOrd
        self.parentDlg = parentDiag

        self.dlg = zoneSeqDiag()
        self.setTable()

        upPix = QPixmap(os.path.join(self.plugin_dir,
                                     'if_arrow-up.svg'))
        upIcon = QIcon(upPix)
        self.dlg.upBtn.setIcon(upIcon)
        self.dlg.upBtn.setIconSize(0.02*upPix.rect().size())

        downPix = QPixmap(os.path.join(self.plugin_dir,
                                       'if_arrow-down.svg'))
        downIcon = QIcon(downPix)
        self.dlg.downBtn.setIcon(downIcon)
        self.dlg.downBtn.setIconSize(0.02*downPix.rect().size())

        self.dlg.upBtn.clicked.connect(self.ordUp)
        self.dlg.upBtn.setToolTip(u'¶¶§Ç¤W²¾')
        self.dlg.downBtn.clicked.connect(self.ordDown)
        self.dlg.downBtn.setToolTip(u'¶¶§Ç¤U²¾')
示例#2
0
    def loadIcon(self):
        pixMap = QPixmap(
            os.path.join(os.path.dirname(__file__), 'georeference.svg'))
        geoIcon = QIcon(pixMap)
        self.geoRefBtn.setIcon(geoIcon)
        self.geoRefBtn.setIconSize(0.7 * pixMap.rect().size())

        pixMap = QPixmap(
            os.path.join(os.path.dirname(__file__), 'settings.svg'))
        settingIcon = QIcon(pixMap)
        self.callSettingsBtn.setIcon(settingIcon)
        self.callSettingsBtn.setIconSize(0.1 * pixMap.rect().size())
示例#3
0
    def data(self, index, role):
        if not index.isValid():
            return None

        item = index.internalPointer()
        ret = None
        if role == Qt.DisplayRole:
            if index.column() == 0:
                ret = item.exp
            elif index.column() == 1:
                ret = item.type
            elif index.column() == 2:
                ret = item.value

        elif role == Qt.EditRole:
            if index.column() == 2:
                ret = item.value

        elif role == Qt.DecorationRole:
            if index.column() == 0:
                if item.access in ['private', 'protected']:
                    iconprefix = item.access + "_"
                else:
                    iconprefix = ""

                icon = None
                if not item.inScope:
                    return QPixmap(":/icons/images/outofscope.png")
                elif not isinstance(item, StdVariable):
                    icon = QPixmap(":/icons/images/" + iconprefix +
                                   "struct.png")
                else:  # leave item
                    icon = QPixmap(":/icons/images/" + iconprefix + "var.png")

                # overlay for arguments
                if icon and item.arg:
                    ol = QPixmap(":/icons/images/overlay_arg.png")
                    p = QPainter(icon)
                    p.drawPixmap(ol.rect(), ol)
                elif icon and item.exp == "Return value":
                    ol = QPixmap(":/icons/images/overlay_ret.png")
                    p = QPainter(icon)
                    p.drawPixmap(ol.rect(), ol)
                return icon

        elif role == Qt.BackgroundRole:
            if not item.inScope:
                ret = QBrush(Qt.gray)
            elif index.column() == 2:
                if item.marked and item.inScope:
                    ret = QBrush(Qt.yellow)

        return ret
示例#4
0
    def data(self, index, role):
        if not index.isValid():
            return None

        item = index.internalPointer()
        ret = None
        if role == Qt.DisplayRole:
            if index.column() == 0:
                ret = item.exp
            elif index.column() == 1:
                ret = item.type
            elif index.column() == 2:
                ret = item.value

        elif role == Qt.EditRole:
            if index.column() == 2:
                ret = item.value

        elif role == Qt.DecorationRole:
            if index.column() == 0:
                if item.access in ['private', 'protected']:
                    iconprefix = item.access + "_"
                else:
                    iconprefix = ""

                icon = None
                if not item.inScope:
                    return QPixmap(":/icons/images/outofscope.png")
                elif not isinstance(item, StdVariable):
                    icon = QPixmap(":/icons/images/" + iconprefix + "struct.png")
                else:  # leave item
                    icon = QPixmap(":/icons/images/" + iconprefix + "var.png")

                # overlay for arguments
                if icon and item.arg:
                    ol = QPixmap(":/icons/images/overlay_arg.png")
                    p = QPainter(icon)
                    p.drawPixmap(ol.rect(), ol)
                elif icon and item.exp == "Return value":
                    ol = QPixmap(":/icons/images/overlay_ret.png")
                    p = QPainter(icon)
                    p.drawPixmap(ol.rect(), ol)
                return icon

        elif role == Qt.BackgroundRole:
            if not item.inScope:
                ret = QBrush(Qt.gray)
            elif index.column() == 2:
                if item.marked and item.inScope:
                    ret = QBrush(Qt.yellow)

        return ret
示例#5
0
class WeatherWidget(QWidget):
    def __init__(self, parent):
        QWidget.__init__(self, parent)
        http = QNetworkAccessManager()
        self.weatherText = self.trUtf8("正在查询天气情况...")
        self.pixmap = QPixmap()
        self.setContextMenuPolicy(Qt.ActionsContextMenu)
        #        self.actionConfigure=QAction(QIcon(":/images/configure.png"), self.trUtf8("配置(&C)..."), None)
        #        self.actionConfigure.triggered.connect(self.configure)
        #        self.addAction(self.actionConfigure)
        self.provider = LiqweiProvider(http)
        self.provider.gotResult.connect(self.setResult)

    def paintEvent(self, event):
        QWidget.paintEvent(self, event)
        painter = QPainter(self)
        painter.drawText(self.rect(), Qt.AlignLeft | Qt.AlignVCenter,
                         self.weatherText)
        if not self.pixmap.isNull():
            r = self.pixmap.rect()
            r.moveTop(5)
            r.moveRight(self.width() - 5)
            painter.drawPixmap(r, self.pixmap)

    def setResult(self, text, pixmapPath):
        self.weatherText = text
        self.pixmap = QPixmap(pixmapPath)
        self.update()
示例#6
0
class WeatherWidget(QWidget):
    def __init__(self, parent):
        QWidget.__init__(self, parent)
        http = QNetworkAccessManager()
        self.weatherText = self.trUtf8("正在查询天气情况...")
        self.pixmap = QPixmap()
        self.setContextMenuPolicy(Qt.ActionsContextMenu)
#        self.actionConfigure=QAction(QIcon(":/images/configure.png"), self.trUtf8("配置(&C)..."), None)
#        self.actionConfigure.triggered.connect(self.configure)
#        self.addAction(self.actionConfigure)
        self.provider = LiqweiProvider(http)
        self.provider.gotResult.connect(self.setResult)

    def paintEvent(self, event):
        QWidget.paintEvent(self, event)
        painter = QPainter(self)
        painter.drawText(self.rect(), Qt.AlignLeft | Qt.AlignVCenter, self.weatherText)
        if not self.pixmap.isNull():
            r = self.pixmap.rect()
            r.moveTop(5)
            r.moveRight(self.width() - 5)
            painter.drawPixmap(r, self.pixmap)

    def setResult(self, text, pixmapPath):
        self.weatherText = text
        self.pixmap = QPixmap(pixmapPath)
        self.update()
示例#7
0
class QtPngCompassGauge(QWidget):
    def __init__(self, parent, skin, tachoImage):
        QWidget.__init__(self, parent)
        self.m_value = 0
        self.m_skin = skin
        self.tachoImage = tachoImage
        self.backgroundPic = QPixmap("images/" + self.m_skin + "/" +
                                     self.tachoImage)

        self.init()

    def init(self):
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.updateGeometry()
#        self.update()

    def setValue(self, value):
        self.m_value = value
        self.update()

    def value(self):
        return self.m_value

    def paintEvent(self, event):
        painter = QPainter(self)

        minSize = min(self.rect().width(), self.rect().height())
        myRect = QRect(self.rect().x(), self.rect().y(), minSize, minSize)

        painter.drawPixmap(myRect, self.backgroundPic,
                           self.backgroundPic.rect())

        pen = QPen()
        pen.setCapStyle(Qt.RoundCap)
        pen.setWidthF(4.0)
        pen.setColor(Qt.red)
        pen.setJoinStyle(Qt.RoundJoin)
        painter.setPen(pen)
        spacing = 30
        contentRect = myRect.adjusted(spacing, spacing, -spacing, -spacing)

        math_pi = 3.14159265358979323846
        degree = self.m_value - 90
        degree = degree * math_pi / 180
        radius = (contentRect.width() - spacing * 0.5) * 0.5
        vec = QPoint(radius * math.cos(degree), radius * math.sin(degree))
        painter.drawLine(contentRect.center(), contentRect.center() + vec)

    def minimumSizeHint(self):
        return QSize(200, 200)


#    def sizeHint(self):
#        return QSize(400, 400)

    def setShowOverlay(self, show):
        self.m_showOverlay = show
        self.update()
示例#8
0
 def _makePixmap(self, width, height):
     pixmap = QPixmap(width, height)
     style = self.brushComboBox.itemData(
         self.brushComboBox.currentIndex()).toInt()[0]
     brush = QBrush(self.color, Qt.BrushStyle(style))
     painter = QPainter(pixmap)
     painter.fillRect(pixmap.rect(), Qt.white)
     painter.fillRect(pixmap.rect(), brush)
     return pixmap
 def _makePixmap(self, width, height):
     pixmap = QPixmap(width, height)
     style = self.brushComboBox.itemData(
                     self.brushComboBox.currentIndex()).toInt()[0]
     brush = QBrush(self.color, Qt.BrushStyle(style))
     painter = QPainter(pixmap)
     painter.fillRect(pixmap.rect(), Qt.white)
     painter.fillRect(pixmap.rect(), brush)
     return pixmap
示例#10
0
	def __init__(self,*args, **kwargs):
		super(RefreshButton,self).__init__(*args, **kwargs)
		button_style = """
		QPushButton {
            color: white;
            font: 8pt;
		}
		QPushButton:hover {
			background-color: white;
            color: #008080;
            font: 04pt;
		}"""
		refresh_image_path = os.path.join("Images","refresh.png")
		if "OINKModules" in os.getcwd():
			refresh_image_path = os.path.join("..",refresh_image_path)
		refresh_pixmap = QPixmap(refresh_image_path)
		refresh_icon = QIcon(refresh_pixmap)
		#self.setStyleSheet(button_style)
		self.setIcon(refresh_icon)
		icon_size = refresh_pixmap.rect().size()
		button_size = QSize(icon_size.width()*1.5,icon_size.height()*1.5)
		self.setIconSize(refresh_pixmap.rect().size())
		self.setFixedSize(button_size)
示例#11
0
    def __init__(self, *args, **kwargs):
        super(RefreshButton, self).__init__(*args, **kwargs)
        button_style = """
		QPushButton {
            color: white;
            font: 8pt;
		}
		QPushButton:hover {
			background-color: white;
            color: #008080;
            font: 04pt;
		}"""
        refresh_image_path = os.path.join("Images", "refresh.png")
        if "OINKModules" in os.getcwd():
            refresh_image_path = os.path.join("..", refresh_image_path)
        refresh_pixmap = QPixmap(refresh_image_path)
        refresh_icon = QIcon(refresh_pixmap)
        #self.setStyleSheet(button_style)
        self.setIcon(refresh_icon)
        icon_size = refresh_pixmap.rect().size()
        button_size = QSize(icon_size.width() * 1.5, icon_size.height() * 1.5)
        self.setIconSize(refresh_pixmap.rect().size())
        self.setFixedSize(button_size)
示例#12
0
class IconButton(QPushButton):
    def __init__(self,icon_path=None,*args,**kwargs):
        super(IconButton,self).__init__(*args,**kwargs)
        self.icon_path = icon_path
        self.icon_pixmap = QPixmap(icon_path)
        self.icon = QIcon(self.icon_pixmap)
        self.setIcon(self.icon)
        self.icon_size = self.icon_pixmap.rect().size()
        self.button_size = QSize(self.icon_size.width()*1.2,self.icon_size.height()*1.2)

        self.setIconSize(self.icon_size)
        self.setFixedSize(self.button_size)
    def setSize(self,width, height):
        self.setIconSize(QSize(width,height))
        self.setFixedSize(QSize(width*1.2,height*1.2))


        
示例#13
0
 def createUI(self):
     self.label = QLabel(self.name + ":")
     self.line_edit = QLineEdit()
     self.line_edit.setReadOnly(True)
     self.line_edit.setMinimumWidth(150)
     self.browse_button = QPushButton()
     browse_icon_path = os.path.join("essentials", "folder.png")
     browse_icon_pixmap = QPixmap(browse_icon_path)
     browse_icon = QIcon(browse_icon_pixmap)
     self.browse_button.setIcon(browse_icon)
     self.browse_button.setToolTip("Click to select a new output folder.")
     icon_size = browse_icon_pixmap.rect().size()
     button_size = QSize(icon_size.width(), icon_size.height())
     self.browse_button.setIconSize(icon_size)
     self.browse_button.setFixedSize(button_size)
     self.browse_button.setToolTip("Click this to change the location")
     layout = QGridLayout()
     layout.addWidget(self.label, 0, 0, 1, 1, Qt.AlignLeft)
     layout.addWidget(self.line_edit, 0, 1, 1, 2, Qt.AlignLeft)
     layout.addWidget(self.browse_button, 0, 3, 1, 1, Qt.AlignHCenter)
     self.setLayout(layout)
示例#14
0
    def __init__(self, *args, **kwargs):
        super(QColorButton, self).__init__(*args, **kwargs)

        self.color_button = QPushButton()
        self._color = None
        self.color_as_rgb = (0, 0, 0)

        #self.setMaximumWidth(32)
        icon_path = os.path.join("Images","eyedropper.png")
        icon_pixmap = QPixmap(icon_path)
        icon = QIcon(icon_pixmap)
        
        icon_size = icon_pixmap.rect().size()
        button_size = QSize(icon_size.width()*1.2,icon_size.height()*1.1)
        self.color_button.setFixedSize(20,20)
        self.color_button.setIcon(icon)
        self.color_button.pressed.connect(self.onColorPicker)
        layout = QHBoxLayout()
        layout.addWidget(self.color_button, 0, Qt.AlignTop)
        #self.setMaximumHeight(self.color_button.height()*1.5)
        
        self.setLayout(layout)
示例#15
0
    def __init__(self, *args, **kwargs):
        super(QColorButton, self).__init__(*args, **kwargs)

        self.color_button = QPushButton()
        self._color = None
        self.color_as_rgb = (0, 0, 0)

        # self.setMaximumWidth(32)
        icon_path = os.path.join("essentials", "eyedropper.png")
        icon_pixmap = QPixmap(icon_path)
        icon = QIcon(icon_pixmap)

        icon_size = icon_pixmap.rect().size()
        button_size = QSize(icon_size.width() * 1.2, icon_size.height() * 1.1)
        self.color_button.setFixedSize(20, 20)
        self.color_button.setIcon(icon)
        self.color_button.pressed.connect(self.onColorPicker)
        layout = QHBoxLayout()
        layout.addWidget(self.color_button, 0, Qt.AlignTop)
        # self.setMaximumHeight(self.color_button.height()*1.5)

        self.setLayout(layout)
示例#16
0
    def __init__(self, parent=None):
        """Constructor."""
        super(habitatDialog, self).__init__(parent)
        # Set up the user interface from Designer.
        # After setupUI you can access any designer object by doing
        # self.<objectname>, and you can use autoconnect slots - see
        # http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
        # #widgets-and-dialogs-with-auto-connect
        self.setupUi(self)
        self.settings = QSettings('ManySplendid', 'HabitatFitness')
        self.settingDiag = settings()
        self.projFolderEdit.setText(
            toUnicode(self.settings.value('projFolder')))

        self.projFolderSelectBtn.clicked.connect(self.selectProjectFolder)
        self.xlsSelectBtn.clicked.connect(self.selectXlsFiles)
        self.specieListWidget.currentItemChanged.connect(self.showAttribute)
        self.callSettingsBtn.clicked.connect(self.settingDiag.run)

        pixMap = QPixmap(os.path.join(os.path.dirname(__file__),
                                      'settings.svg'))
        settingIcon = QIcon(pixMap)
        self.callSettingsBtn.setIcon(settingIcon)
        self.callSettingsBtn.setIconSize(0.1*pixMap.rect().size())
示例#17
0
文件: __init__.py 项目: nerdocs/MedUX
    def drawIconWithShadow(cls, icon, rect, painter, iconMode,
                           dipRadius=3, color=QColor(0, 0, 0, 130),
                           dipOffset=QPoint(1, -2)):
        """
        :type icon: QIcon
        :type rect: QRect
        :type painter: QPainter
        :type iconMode:  QIcon.Mode
        :type dipRadius: int
        :type color: QColor
        :type dipOffset: QPoint
        """
        cache = QPixmap()
        pixmapName = "icon {0} {1} {2}".format(icon.cacheKey(), iconMode, rect.height())

        if not QPixmapCache.find(pixmapName, cache):
            # High-dpi support: The in parameters (rect, radius, offset) are in
            # device-independent pixels. The call to QIcon.pixmap() below might
            # return a high-dpi pixmap, which will in that case have a devicePixelRatio
            # different than 1. The shadow drawing calculations are done in device
            # pixels.
            from math import ceil

            px = icon.pixmap(rect.size())
            devicePixelRatio = int(ceil(cls.pixmapDevicePixelRatio(px)))
            radius = dipRadius * devicePixelRatio
            offset = dipOffset * devicePixelRatio # result = QPoint, like dipOffset
            cache = QPixmap(px.size() + QSize(radius * 2, radius * 2))
            cache.fill(Qt.transparent)

            cachePainter = QPainter(cache)
            if iconMode == QIcon.Disabled:
                im = px.toImage().convertToFormat(QImage.Format_ARGB32)
                for y in range(0, im.height()):
                    scanLine = abs(im.scanLine(y))
                    for x in range(0, im.width()):
                        pixel = scanLine
                        intensity = qGray(pixel)
                        scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel))
                        scanLine += 1

                px = QPixmap.fromImage(im)

            # Draw shadow
            tmp = QImage(px.size() + QSize(radius * 2, radius * 2 + 1), QImage.Format_ARGB32_Premultiplied)
            tmp.fill(Qt.transparent)

            tmpPainter = QPainter(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_Source)
            tmpPainter.drawPixmap(QRect(radius, radius, px.width(), px.height()), px)
            tmpPainter.end()

            # blur the alpha channel
            blurred = QImage(tmp.size(), QImage.Format_ARGB32_Premultiplied)
            blurred.fill(Qt.transparent)
            blurPainter = QPainter(blurred)
            # qt_blurImage is not available in PyQt4, skip it
            # qt_blurImage(&blurPainter, tmp, radius, false, true)
            blurPainter.end()

            tmp = blurred

            # blacken the image...
            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            tmpPainter.begin(tmp)
            tmpPainter.setCompositionMode(QPainter.CompositionMode_SourceIn)
            tmpPainter.fillRect(tmp.rect(), color)
            tmpPainter.end()

            # draw the blurred drop shadow...
            cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp)

            # Draw the actual pixmap...
            cachePainter.drawPixmap(QRect(QPoint(radius, radius) + offset, QSize(px.width(), px.height())), px)
            import PyQt4

            if StrictVersion(PyQt4.QtCore.__version__).version[0] == 5:
                cache.setDevicePixelRatio(devicePixelRatio)
            QPixmapCache.insert(pixmapName, cache)

        targetRect = cache.rect()
        targetRect.setSize(targetRect.size() / cls.pixmapDevicePixelRatio(cache))
        targetRect.moveCenter(rect.center() - dipOffset)
        painter.drawPixmap(targetRect, cache)
示例#18
0
    def __init__(self, *args, **kwargs):
        super(QColorPanel, self).__init__(*args, **kwargs)

        self.black_color = None
        self.white_color = None
        #self.setMaximumWidth(32)
        self.black_button = QPushButton()
        self.grey_1_button = QPushButton()
        self.grey_2_button = QPushButton()
        self.grey_3_button = QPushButton()
        self.white_button = QPushButton()
        self.current_black = (0,0,0)
        self.current_grey_1 = (55,55,55)
        self.current_grey_2 = (123,123,123)
        self.current_grey_3 = (200,200,200)
        self.current_white = (255,255,255)

        self.black_button.pressed.connect(self.onBlackColorPicker)
        self.white_button.pressed.connect(self.onWhiteColorPicker)

        icon_path = os.path.join("essentials","eyedropper.png")
        icon_pixmap = QPixmap(icon_path)
        icon = QIcon(icon_pixmap)
        
        icon_size = icon_pixmap.rect().size()
        button_size = QSize(icon_size.width()*1.2,icon_size.height()*1.2)
        
        self.black_button.setIcon(icon)
        self.white_button.setIcon(icon)
        self.black_button.setIconSize(icon_size)
        self.white_button.setIconSize(icon_size)

        self.black_button.setToolTip("Left click to select the icon border color.")
        self.white_button.setToolTip("Left click to select the icon background color.")


        layout = QHBoxLayout()
        self.buttons_list = [
                        self.black_button,
                        self.grey_1_button,
                        self.grey_2_button, 
                        self.grey_3_button, 
                        self.white_button
                    ]

        self.color_list = [
                    self.current_black, 
                    self.current_grey_1, 
                    self.current_grey_2, 
                    self.current_grey_3, 
                    self.current_white
                ]
        #Loop and set the colors and add to the layout.
        counter = 0
        for button in self.buttons_list:
            button.setFixedSize(20,20)
            layout.addWidget(button, 0)
            button_style_sheet = """QPushButton {
                                background-color: rgb(%d,%d,%d);
                            }"""%(
                                self.color_list[counter][0], 
                                self.color_list[counter][1], 
                                self.color_list[counter][2]
                                )
            button.setStyleSheet(button_style_sheet)
            counter += 1

        #self.setMaximumHeight(button_size.height()*1.5)
        self.setLayout(layout)
示例#19
0
class QtPngDialGauge(QWidget):
    def __init__(self, parent, skin, tachoImage):
        QWidget.__init__(self, parent)
        self.m_minimum = 0
        self.m_maximum = 100
        self.m_value = 0
        self.m_startAngle = 0
        self.m_skin = skin
        self.tachoImage = tachoImage
        self.backgroundPic = QPixmap("images/" + self.m_skin + "/" +
                                     self.tachoImage)

        self.init()

    def init(self):
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.updateGeometry()


#        self.update()

    def setValue(self, value):
        if value < self.m_minimum:
            value = self.m_minimum
        elif value > self.m_maximum:
            value = self.m_maximum

        self.m_value = value
        self.update()

    def setMinimum(self, minimum):
        self.m_minimum = minimum
        if self.m_value < self.m_minimum:
            self.m_value = self.m_minimum

        self.update()

    def setMaximum(self, maximum):
        self.m_maximum = maximum
        if self.m_value > self.m_maximum:
            self.m_value = self.m_maximum

        self.update()

    def setStartAngle(self, angle):
        self.m_startAngle = angle

    def value(self):
        return self.m_value

    def minimum(self):
        return self.m_minimum

    def maximum(self):
        return self.m_maximum

    def startAngle(self):
        return self.m_startAngle

    def paintEvent(self, event):
        painter = QPainter(self)

        minSize = min(self.rect().width(), self.rect().height())
        myRect = QRect(self.rect().x(), self.rect().y(), minSize, minSize)
        painter.drawPixmap(myRect, self.backgroundPic,
                           self.backgroundPic.rect())

        pen = QPen()
        pen.setCapStyle(Qt.RoundCap)
        pen.setWidthF(4.0)
        pen.setColor(Qt.red)
        pen.setJoinStyle(Qt.RoundJoin)
        painter.setPen(pen)
        spacing = 40
        contentRect = myRect.adjusted(spacing, spacing, -spacing, -spacing)

        valueInPercent = (self.m_value - self.m_minimum) / (self.m_maximum -
                                                            self.m_minimum)
        math_pi = 3.14159265358979323846
        degree = (self.m_startAngle +
                  90) - valueInPercent * 2.0 * self.m_startAngle
        degree = degree * math_pi / 180.0
        radius = (contentRect.width() - spacing * 0.5) * 0.5
        vec = QPoint(radius * math.cos(degree), radius * -math.sin(degree))
        painter.drawLine(contentRect.center(), contentRect.center() + vec)

    def minimumSizeHint(self):
        return QSize(200, 200)

    def setShowOverlay(self, show):
        self.m_showOverlay = show
        self.update()
示例#20
0
文件: main.py 项目: cgomez4/Selekti
    def __init__(self, parent=None):
        super(Ui_Train, self).__init__(parent)

        self.setWindowTitle(("Train"))   
        self.setWindowState(QtCore.Qt.WindowMaximized)
        self.isTrainWindowShown = True
        self.importedFiles = ImageData(self.imgs, self.isTrainWindowShown)

        # Random images will be taken from imgs_unscored
        for imgPath in self.importedFiles.images:
            self.imgs_unscored.append({'imgPath': imgPath})
        
        # print("[INFO] imgs_unscored:")
        # print(json.dumps(self.imgs_unscored, indent=2))

        self.mainMenu = self.menuBar()

        # Actions which can be seen from the drop-down of each menu selection	
        self.instructionsAction = QtGui.QAction("&Instructions", self)	
        self.instructionsAction.triggered.connect(self.instructions_Button_clicked)	

        # Menu selections that show on the menubar on the Selekti screen	
        self.helpMenu = self.mainMenu.addMenu('&Help')	
        self.helpMenu.addAction(self.instructionsAction)

        self.rate_label = QtGui.QLabel(self)
        self.rate_label.setText("What do you think of this photo?")
        self.rate_label.setStyleSheet("QLabel { color: white; font: 18px; }")
        self.rate_label.setAlignment(Qt.AlignCenter | Qt.AlignVCenter)

        star_empty = QPixmap("star_empty.png")
        star_filled = QPixmap("star_filled.png")
        star_size = star_empty.rect().size()

        stars = []

        # Make the stars
        self.star_1 = StarButton('', self)
        self.star_2 = StarButton('', self)
        self.star_3 = StarButton('', self)
        self.star_4 = StarButton('', self)
        self.star_5 = StarButton('', self)

        stars.append(self.star_1)
        stars.append(self.star_2)
        stars.append(self.star_3)
        stars.append(self.star_4)
        stars.append(self.star_5)

        # Ideally all this stuff would go into StarButton's constructor but I couldn't find out how to override it properly
        for btn in stars:
            btn.initStarList()
            btn.setIcon(QIcon(star_empty))
            btn.setDefaultIcon(QIcon(star_empty))
            btn.setOnHoverIcon(QIcon(star_filled))
            btn.setFixedSize(star_size)
            btn.setIconSize(QSize(50,50))
            btn.setStyleSheet("QPushButton { border: none; }")
            btn.setEnabled(True)

        # Clicking a star will rate the image with the level of the star
        self.star_1.clicked.connect(lambda: self.rate_Button_clicked(1))
        self.star_2.clicked.connect(lambda: self.rate_Button_clicked(2))
        self.star_3.clicked.connect(lambda: self.rate_Button_clicked(3))
        self.star_4.clicked.connect(lambda: self.rate_Button_clicked(4))
        self.star_5.clicked.connect(lambda: self.rate_Button_clicked(5))

        # when the current star is hovered over, all the stars to its left
        # should also be highlighted 
        self.star_2.addDependentStar(self.star_1)

        self.star_3.addDependentStar(self.star_1)
        self.star_3.addDependentStar(self.star_2)

        self.star_4.addDependentStar(self.star_1)
        self.star_4.addDependentStar(self.star_2)
        self.star_4.addDependentStar(self.star_3)

        self.star_5.addDependentStar(self.star_1)
        self.star_5.addDependentStar(self.star_2)
        self.star_5.addDependentStar(self.star_3)
        self.star_5.addDependentStar(self.star_4)


        self.finish_Button = QtGui.QPushButton('Finish', self)
        self.finish_Button.clicked.connect(self.finish_Button_clicked)

        self.train_imageLabel = QtGui.QLabel(self)
        self.train_imageLabel.setAlignment(QtCore.Qt.AlignCenter)

        # need to show the win before trying to access its size below
        self.show()

        # prevent window minimization
        self.setFixedSize(self.width(), self.height())

        self.rate_label.setGeometry(QtCore.QRect((self.width()*0.40), (self.height()*0.065), 400, 30))
        self.finish_Button.setGeometry(QtCore.QRect((self.width()*0.70), (self.height()*0.95), 100, 30))

        self.star_1.setGeometry(QtCore.QRect((self.width()*0.40), (self.height()*0.88), 97, 27))
        self.star_2.setGeometry(QtCore.QRect((self.width()*0.45), (self.height()*0.88), 97, 27))
        self.star_3.setGeometry(QtCore.QRect((self.width()*0.50), (self.height()*0.88), 97, 27))
        self.star_4.setGeometry(QtCore.QRect((self.width()*0.55), (self.height()*0.88), 97, 27))
        self.star_5.setGeometry(QtCore.QRect((self.width()*0.60), (self.height()*0.88), 97, 27))


        self.current_img = self.get_next_image(self.imgs_unscored)
        if  self.current_img == None:
            print("[INFO] No images to score.")
        else:
            # click on the train image
            pixmap = QPixmap(self.current_img['imgPath'])

            # sometimes the pixmap is null
            if pixmap.width() == 0 or pixmap.width() > self.width() or pixmap.height() > self.height():
                QMessageBox.critical(self, "Uh oh!", "Could not display:\n {}\n\nYou can still rate it by clicking on a star.".format(self.current_img['imgPath']))

            else:
                print("[INFO] displaying a pixmap")
                self.train_imageLabel.setPixmap(pixmap)
                self.train_imageLabel.setGeometry(QtCore.QRect((self.width()/2) - (pixmap.width()/2), (self.height()/2) - (pixmap.height()/2), pixmap.width(), pixmap.height()))

            self.train_imageLabel.setObjectName('train_imageLabel')
            self.train_imageLabel.mousePressEvent = self.train_image_clicked
            print("[INFO] Starting image was set.")

        # Feedback consists of the user's score for an image along with that image's feature vector
        # It's stored in a dictionary where the feat vectors are the keys and the scores are the values
        self.feedback_path = "feedback.cpickle"
        if os.path.isfile(self.feedback_path):
            feedback_file = open(self.feedback_path, "rb")
            self.feedback = pickle.load(feedback_file)
            # print("[INFO] feedback on OPEN: {}".format(self.feedback))
            feedback_file.close()
        else:
            self.feedback = {}