Exemplo n.º 1
0
	def __init__( self, cornerWidget=None, **kw ) :

		GafferUI.ContainerWidget.__init__( self, _TabWidget(), **kw )

		# Tab bar
		# -------

		self.__tabBar = GafferUI.Widget( QtWidgets.QTabBar() )
		self.__tabBar._qtWidget().setDrawBase( False )
		self.__tabBar._qtWidget().tabMoved.connect( Gaffer.WeakMethod( self.__moveWidget ) )
		self.__tabBar.dragEnterSignal().connect( Gaffer.WeakMethod( self.__tabBarDragEnter ), scoped = False )
		self.__tabBar.dragMoveSignal().connect( Gaffer.WeakMethod( self.__tabBarDragMove ), scoped = False )
		self.__tabBar.dragLeaveSignal().connect( Gaffer.WeakMethod( self.__tabBarDragLeave ), scoped = False )
		self.__tabBarDragState = self.__DragState.None_

		# See comments in Button.py
		if TabbedContainer.__palette is None :
			TabbedContainer.__palette = QtGui.QPalette( QtWidgets.QApplication.instance().palette( self.__tabBar._qtWidget() ) )
			TabbedContainer.__palette.setColor( QtGui.QPalette.Disabled, QtGui.QPalette.Light, QtGui.QColor( 0, 0, 0, 0 ) )

		self.__tabBar._qtWidget().setPalette( TabbedContainer.__palette )

		self._qtWidget().setTabBar( self.__tabBar._qtWidget() )
		self._qtWidget().setElideMode( QtCore.Qt.ElideNone )

		# Corner widget and scrolling
		# ---------------------------
		#
		# QTabBar does provide scroll buttons for use when there is not enough
		# horizontal space to show all tabs. But these are really awkward to use
		# : you may not know which way to scroll, it may take several clicks to
		# find the thing you want, and it's hard to track the jumpy movement of
		# the tabs. Instead we provide a dropdown menu which provides an
		# overview of all tabs and allows you to jump to the right one with a
		# single click. This is stored in `self.__cornerContainer[0]`, alongside
		# an optional user-provided corner widget which is stored in
		# `self.__cornerContainer[1]`.

		self.__cornerContainer = GafferUI.ListContainer( GafferUI.ListContainer.Orientation.Horizontal )
		with self.__cornerContainer :
			GafferUI.MenuButton(
				image = "tabScrollMenu.png", hasFrame = False,
				menu = GafferUI.Menu( Gaffer.WeakMethod( self.__scrollMenuDefinition ) )
			)
		self._qtWidget().setCornerWidget( self.__cornerContainer._qtWidget() )
		self.setCornerWidget( cornerWidget )

		# When there's not enough horizontal space, we need QTabWidget to scroll
		# to show the current tab. But `QTabBarPrivate::makeVisible()` refuses
		# to do this unless the scroll buttons are visible. So we have to
		# pretend to be using them and then use the stylesheet to set their size to
		# 0. One benefit of this hack is that we can track the show/hide events
		# for the buttons so that we only show our menu button when scrolling
		# is necessary. This is a bit more reliable than trying to do it ourselves
		# using resize events and size queries.

		self._qtWidget().setUsesScrollButtons( True )
		assert( len( self._qtWidget().tabBar().children() ) == 2 ) # We expect a left and a right button
		_VisibilityLink(
			self._qtWidget().tabBar().children()[0],
			self.__cornerContainer[0]._qtWidget()
		)

		# Child storage and signals
		# -------------------------

		self.__widgets = []
		self.__currentChangedSignal = GafferUI.WidgetEventSignal()
		self._qtWidget().currentChanged.connect( Gaffer.WeakMethod( self.__currentChanged ) )
Exemplo n.º 2
0
        return str(self.saveState())

    def matrix(self):
        return np.array([[self.m11(), self.m12(),
                          self.m13()], [self.m21(),
                                        self.m22(),
                                        self.m23()],
                         [self.m31(), self.m32(),
                          self.m33()]])


if __name__ == '__main__':
    import widgets
    import GraphicsView
    from functions import *
    app = QtGui.QApplication([])
    win = QtGui.QMainWindow()
    win.show()
    cw = GraphicsView.GraphicsView()
    #cw.enableMouse()
    win.setCentralWidget(cw)
    s = QtGui.QGraphicsScene()
    cw.setScene(s)
    win.resize(600, 600)
    cw.enableMouse()
    cw.setRange(QtCore.QRectF(-100., -100., 200., 200.))

    class Item(QtGui.QGraphicsItem):
        def __init__(self):
            QtGui.QGraphicsItem.__init__(self)
            self.b = QtGui.QGraphicsRectItem(20, 20, 20, 20, self)
Exemplo n.º 3
0
    def paint(self, painter, option, index):
        """Paint checkbox and text.
         _
        |_|  My label    >
        """

        body_rect = QtCore.QRectF(option.rect)

        check_rect = QtCore.QRectF(body_rect)
        check_rect.setWidth(check_rect.height())
        offset = (check_rect.height() / 4) + 1
        check_rect.adjust(offset, offset, -(offset), -(offset))

        check_color = colors["idle"]

        perspective_icon = icons["angle-right"]
        perspective_rect = QtCore.QRectF(body_rect)
        perspective_rect.setWidth(perspective_rect.height())
        perspective_rect.adjust(0, 3, 0, 0)
        perspective_rect.translate(
            body_rect.width() - (perspective_rect.width() / 2 + 2), 0)

        publish_states = index.data(Roles.PublishFlagsRole)
        if publish_states & InstanceStates.InProgress:
            check_color = colors["active"]

        elif publish_states & InstanceStates.HasError:
            check_color = colors["error"]

        elif publish_states & InstanceStates.HasWarning:
            check_color = colors["warning"]

        elif publish_states & InstanceStates.HasFinished:
            check_color = colors["ok"]

        elif not index.data(Roles.IsEnabledRole):
            check_color = colors["inactive"]

        offset = (body_rect.height() - font_metrics["h4"].height()) / 2
        label_rect = QtCore.QRectF(
            body_rect.adjusted(check_rect.width() + 12, offset - 1, 0, 0))

        assert label_rect.width() > 0

        label = index.data(QtCore.Qt.DisplayRole)
        label = font_metrics["h4"].elidedText(label, QtCore.Qt.ElideRight,
                                              label_rect.width() - 20)

        font_color = colors["idle"]
        if not index.data(QtCore.Qt.CheckStateRole):
            font_color = colors["inactive"]

        # Maintain reference to state, so we can restore it once we're done
        painter.save()

        # Draw perspective icon
        painter.setFont(fonts["awesome10"])
        painter.setPen(QtGui.QPen(font_color))
        painter.drawText(perspective_rect, perspective_icon)

        # Draw label
        painter.setFont(fonts["h4"])
        painter.setPen(QtGui.QPen(font_color))
        painter.drawText(label_rect, label)

        # Draw checkbox
        pen = QtGui.QPen(check_color, 1)
        painter.setPen(pen)

        if index.data(Roles.IsOptionalRole):
            painter.drawRect(check_rect)

            if index.data(QtCore.Qt.CheckStateRole):
                optional_check_rect = QtCore.QRectF(check_rect)
                optional_check_rect.adjust(2, 2, -1, -1)
                painter.fillRect(optional_check_rect, check_color)

        else:
            painter.fillRect(check_rect, check_color)

        if option.state & QtWidgets.QStyle.State_MouseOver:
            painter.fillRect(body_rect, colors["hover"])

        if option.state & QtWidgets.QStyle.State_Selected:
            painter.fillRect(body_rect, colors["selected"])

        # Ok, we're done, tidy up.
        painter.restore()
Exemplo n.º 4
0
 def change_background_color(self, color):
     pal = self.palette()
     pal.setColor(QtGui.QPalette.Button, QtGui.QColor(color).darker(200))
     self.setPalette(pal)
Exemplo n.º 5
0
 def clear(self):
     self.pFilterModel.setSourceModel( QtGui.QStandardItemModel() )
     super(ExtendedCombo,self).clear()
Exemplo n.º 6
0
 def modify(self):
     # self.mIconPixmap = QtGui.QPixmap(os.path.join(self.manager.getIconsDir(), "iconMax.png"))
     self.mIconPixmap = QtGui.QPixmap(":/icons/CSS/rc/iconMax.png")
     self.managerIcon_label.setPixmap(self.mIconPixmap)
Exemplo n.º 7
0
 def shape(self):
     qp = QtGui.QPainterPathStroker()
     qp.setWidth(10.0)
     qp.setCapStyle(QtCore.Qt.SquareCap)
     return qp.createStroke(self.path())
Exemplo n.º 8
0
    def __init__(self, parent=None):
        QtWidgets.QSystemTrayIcon.__init__(self, parent)
        # self.activated.connect(self.showMainWidget)
        self.setIcon(QtGui.QIcon(libData.get_img_path('software/default')))

        self.parent = parent

        Tank().init_os()
        self.data = Tank().data
        self.user = Tank().user
        self.project_data = Tank().data['project']

        menu = QtWidgets.QMenu()
        menu.setStyleSheet(self.data['script'][TITLE]['style'])

        # ADMIN UI
        if True:  # self.user.is_admin:
            adminMenu = QtWidgets.QMenu('Admin')
            adminMenu.setStyleSheet(self.data['script'][TITLE]['style'])
            menu.addMenu(adminMenu)

            menuItem = adminMenu.addAction(
                QtGui.QIcon(libData.get_img_path('btn/btnFolder48')),
                'Open Project Data')
            menuItem.triggered.connect(self.press_btnOpenProjectLog)
            menuItem = adminMenu.addAction(
                QtGui.QIcon(libData.get_img_path('btn/btnFolder48')),
                'Open User Data')
            menuItem.triggered.connect(self.press_btnOpenLocalLog)

            menu.addSeparator()

        menuItem = menu.addAction(
            QtGui.QIcon(libData.get_img_path('user/' + self.user.id)),
            self.user.id)
        menuItem.triggered.connect(self.press_btnShowUserData)

        menuItem = menu.addAction(
            QtGui.QIcon(libData.get_img_path('project/default')),
            self.data['project']['name'])
        menuItem.triggered.connect(self.press_btnOpenProjectPath)

        menu.addSeparator()

        subMenu = QtWidgets.QMenu('Software')
        subMenu.setStyleSheet(self.data['script'][TITLE]['style'])
        menu.addMenu(subMenu)

        for soft, soft_func in self.data['script'][TITLE]['SOFTWARE'].items():
            menuItem = subMenu.addAction(
                QtGui.QIcon(libData.get_img_path('software/' + soft)),
                soft.title())
            menuItem.triggered.connect(eval(soft_func))

        menu.addSeparator()

        menuItem = menu.addAction(
            QtGui.QIcon(libData.get_img_path('btn/btnFolderSearchGet48')),
            'Load')
        menuItem.triggered.connect(self.press_btnLoad)

        menu.addSeparator()

        menuItem = menu.addAction(
            QtGui.QIcon(libData.get_img_path('btn/btnReport48')), 'Report')
        menuItem.triggered.connect(self.press_btnReport)

        menuItem = menu.addAction(
            QtGui.QIcon(libData.get_img_path('btn/btnHelp48')), 'Help')
        menuItem.triggered.connect(self.press_btnHelp)

        menu.addSeparator()

        menuItem = menu.addAction(
            QtGui.QIcon(libData.get_img_path('btn/btnDenial48')), 'Quit')
        menuItem.triggered.connect(self.press_closeStartup)

        self.setContextMenu(menu)
Exemplo n.º 9
0
 def iconColor(self):
     setIconPath = '/dexter/Cache_DATA/CRT/riggingTeamShelf/bumbleBee/icon/'
     self.ui.zeroOut_BTN.setIcon(QtGui.QIcon('%szeroOut.jpg' % setIconPath))
     self.ui.mirrorJoints_BTN.setIcon(
         QtGui.QIcon('%smirrorJoints.jpg' % setIconPath))
     self.ui.biped_build_BTN.setIcon(
         QtGui.QIcon('%sbuild2.jpg' % setIconPath))
     self.ui.biped_temp_BTN.setIcon(
         QtGui.QIcon('%simportBipedTemp.jpg' % setIconPath))
     self.ui.biped_ex_build_BTN.setIcon(
         QtGui.QIcon('%sbuild3.jpg' % setIconPath))
     self.ui.biped_ex_neck_BTN.setIcon(
         QtGui.QIcon('%sex_neck.jpg' % setIconPath))
     self.ui.biped_ex_finger_BTN.setIcon(
         QtGui.QIcon('%sex_finger.jpg' % setIconPath))
     self.ui.biped_ex_leg_BTN.setIcon(
         QtGui.QIcon('%sex_leg.jpg' % setIconPath))
     self.ui.biped_ex_arm_BTN.setIcon(
         QtGui.QIcon('%sex_arm.jpg' % setIconPath))
     self.ui.biped_ex_shoulder_BTN.setIcon(
         QtGui.QIcon('%sex_shoulder.jpg' % setIconPath))
     self.ui.quad_temp_BTN.setIcon(
         QtGui.QIcon('%squad_importTemp.jpg' % setIconPath))
     self.ui.quad_neck_BTN.setIcon(
         QtGui.QIcon('%squad_neck.jpg' % setIconPath))
     self.ui.quad_spine_BTN.setIcon(
         QtGui.QIcon('%squad_spine.jpg' % setIconPath))
     self.ui.quad_forelegL_BTN.setIcon(
         QtGui.QIcon('%squad_foreLeg_L.jpg' % setIconPath))
     self.ui.quad_forelegR_BTN.setIcon(
         QtGui.QIcon('%squad_foreLeg_L.jpg' % setIconPath))
     self.ui.quad_hindlegL_BTN.setIcon(
         QtGui.QIcon('%squad_hindLeg_L.jpg' % setIconPath))
     self.ui.quad_hindlegR_BTN.setIcon(
         QtGui.QIcon('%squad_hindLeg_L.jpg' % setIconPath))
     self.ui.quad_tail_BTN.setIcon(
         QtGui.QIcon('%squad_tail.jpg' % setIconPath))
     self.ui.quad_setup_BTN.setIcon(
         QtGui.QIcon('%squad_setup.jpg' % setIconPath))
     self.ui.interacteFoot_BTN.setIcon(
         QtGui.QIcon('%sinteracteFoot.jpg' % setIconPath))
     self.ui.createPathTempJoints_BTN.setIcon(
         QtGui.QIcon('%screatePathTempJoints.jpg' % setIconPath))
     self.ui.setBodyDivJoints_BTN.setIcon(
         QtGui.QIcon('%ssetBodyDivJoints.jpg' % setIconPath))
     self.ui.setRig_BTN.setIcon(QtGui.QIcon('%ssetRig.jpg' % setIconPath))
     self.ui.pathCurveSet_BTN.setIcon(
         QtGui.QIcon('%spathCurveSet.jpg' % setIconPath))
     self.ui.makeLocOnCurve_BTN.setIcon(
         QtGui.QIcon('%smakeLocOnCurve.jpg' % setIconPath))
Exemplo n.º 10
0
    def shape(self):

        path = QtGui.QPainterPath()
        path.addRegion(self.widget().childrenRegion())
        return path
Exemplo n.º 11
0
    def populateUi(self):
        config = get_config()
        self._file_info = None

        w, h = lib.get_default_image_resolution()
        self.imageRes_label.setEnabled(False)
        self.imageResWidth_label.setEnabled(False)
        self.imageResWidth_spinBox.setValue(w)
        self.imageResWidth_spinBox.setEnabled(False)
        self.imageResHeight_label.setEnabled(False)
        self.imageResHeight_spinBox.setValue(h)
        self.imageResHeight_spinBox.setEnabled(False)

        self.fileInfo_plainTextEdit.setReadOnly(True)

        value = get_config_value(
            config,
            'data/load_bundle_position',
            const.LOAD_BUNDLE_POS_DEFAULT_VALUE)
        self.loadBndPositions_checkBox.setChecked(value)

        value = get_config_value(
            config,
            'data/use_overscan',
            const.USE_OVERSCAN_DEFAULT_VALUE)
        self.overscan_checkBox.setChecked(value)

        # Get the file path from the clipboard.
        try:
            clippy = QtGui.QClipboard()
            text = str(clippy.text()).strip()
            if lib.is_valid_file_path(text):
                self.setFilePath(text)
        except Exception as e:
            msg = 'Could not get file path from clipboard.'
            LOG.warning(msg)
            LOG.info(str(e))

        all_camera_nodes = lib.get_cameras()
        selected_cameras = lib.get_selected_cameras()
        active_camera = lib.get_active_viewport_camera()
        self.updateCameraList(
            self.camera_comboBox,
            self.camera_model,
            all_camera_nodes,
            selected_cameras,
            active_camera
        )
        active_camera = self.getCameraData()
        mkr_grp_nodes = lib.get_marker_groups(active_camera)
        active_mkr_grp = None
        self.updateMarkerGroupList(
            self.markerGroup_comboBox,
            self.markerGroup_model,
            active_mkr_grp,
            mkr_grp_nodes
        )

        value = get_config_value(
            config,
            "data/load_mode",
            const.LOAD_MODE_DEFAULT_VALUE
        )
        self.populateLoadModeModel(self.loadMode_model)
        index = self.loadMode_model.stringList().index(value)
        self.loadMode_comboBox.setCurrentIndex(index)

        value = get_config_value(
            config,
            "data/distortion_mode",
            const.DISTORTION_MODE_DEFAULT_VALUE
        )
        self.populateDistortionModeModel(self.distortionMode_model)
        index = self.distortionMode_model.stringList().index(value)
        self.distortionMode_comboBox.setCurrentIndex(index)
        return
Exemplo n.º 12
0
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(281, 96)
        self.horizontalLayout = QtWidgets.QHBoxLayout(Form)
        self.horizontalLayout.setSpacing(7)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setSpacing(2)
        self.gridLayout.setObjectName("gridLayout")
        self.dsbm22 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm22.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm22.setSingleStep(0.1)
        self.dsbm22.setObjectName("dsbm22")
        self.gridLayout.addWidget(self.dsbm22, 1, 1, 1, 1)
        self.dsbm21 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm21.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm21.setSingleStep(0.1)
        self.dsbm21.setObjectName("dsbm21")
        self.gridLayout.addWidget(self.dsbm21, 1, 0, 1, 1)
        self.dsbm31 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm31.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm31.setSingleStep(0.1)
        self.dsbm31.setObjectName("dsbm31")
        self.gridLayout.addWidget(self.dsbm31, 2, 0, 1, 1)
        self.dsbm32 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm32.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm32.setSingleStep(0.1)
        self.dsbm32.setObjectName("dsbm32")
        self.gridLayout.addWidget(self.dsbm32, 2, 1, 1, 1)
        self.dsbm23 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm23.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm23.setSingleStep(0.1)
        self.dsbm23.setObjectName("dsbm23")
        self.gridLayout.addWidget(self.dsbm23, 1, 2, 1, 1)
        self.dsbm33 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm33.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm33.setSingleStep(0.1)
        self.dsbm33.setObjectName("dsbm33")
        self.gridLayout.addWidget(self.dsbm33, 2, 2, 1, 1)
        self.dsbm12 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm12.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm12.setSingleStep(0.1)
        self.dsbm12.setObjectName("dsbm12")
        self.gridLayout.addWidget(self.dsbm12, 0, 1, 1, 1)
        self.dsbm11 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm11.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm11.setSingleStep(0.1)
        self.dsbm11.setObjectName("dsbm11")
        self.gridLayout.addWidget(self.dsbm11, 0, 0, 1, 1)
        self.dsbm13 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm13.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm13.setSingleStep(0.1)
        self.dsbm13.setObjectName("dsbm13")
        self.gridLayout.addWidget(self.dsbm13, 0, 2, 1, 1)
        self.dsbm24 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm24.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm24.setObjectName("dsbm24")
        self.gridLayout.addWidget(self.dsbm24, 1, 3, 1, 1)
        self.dsbm34 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm34.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm34.setObjectName("dsbm34")
        self.gridLayout.addWidget(self.dsbm34, 2, 3, 1, 1)
        self.dsbm14 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm14.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm14.setObjectName("dsbm14")
        self.gridLayout.addWidget(self.dsbm14, 0, 3, 1, 1)
        self.dsbm44 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm44.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm44.setObjectName("dsbm44")
        self.gridLayout.addWidget(self.dsbm44, 3, 3, 1, 1)
        self.dsbm41 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm41.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm41.setObjectName("dsbm41")
        self.gridLayout.addWidget(self.dsbm41, 3, 0, 1, 1)
        self.dsbm42 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm42.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm42.setObjectName("dsbm42")
        self.gridLayout.addWidget(self.dsbm42, 3, 1, 1, 1)
        self.dsbm43 = QtWidgets.QDoubleSpinBox(Form)
        self.dsbm43.setMaximumSize(QtCore.QSize(80, 16777215))
        self.dsbm43.setObjectName("dsbm43")
        self.gridLayout.addWidget(self.dsbm43, 3, 2, 1, 1)
        self.horizontalLayout.addLayout(self.gridLayout)
        spacerItem = QtWidgets.QSpacerItem(40, 20,
                                           QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setObjectName("verticalLayout")
        self.pbReset = QtWidgets.QPushButton(Form)
        self.pbReset.setMaximumSize(QtCore.QSize(25, 25))
        self.pbReset.setText("")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/icons/resources/reset.png"),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.pbReset.setIcon(icon)
        self.pbReset.setObjectName("pbReset")
        self.verticalLayout.addWidget(self.pbReset)
        spacerItem1 = QtWidgets.QSpacerItem(20, 40,
                                            QtWidgets.QSizePolicy.Minimum,
                                            QtWidgets.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem1)
        self.horizontalLayout.addLayout(self.verticalLayout)

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)
Exemplo n.º 13
0
    def setType(self, porttype=None):
        pp, cc = None, None  # polygon/circle coordinates
        if porttype:
            self.porttype = porttype
            
        if self.porttype is None:
            return
            
        if   self.porttype == 'input': # block input
            pp = ((PW/2,0), (-PW/2,PW/2), (-PW/2,-PW/2))
            self.label_side = 'right'

        elif self.porttype == 'output': # block output
            pp = ((-PW/2,-PW/2), (PW/2,-PW/2), (PW/2,PW/2), (-PW/2,PW/2))
            self.label_side = 'left'

        elif self.porttype == 'inout':  # block inout
            pp = ((-PW/2,0), (0,PW/2), (PW/2,0), (0,-PW/2))
            self.label_side = 'left'

        elif self.porttype == 'ipin': # input terminal
            pp = ((PW/2,0), (0,PW/2), (-PW,PW/2), (-PW,-PW/2), (0,-PW/2))
            self.label_side = 'left'

        elif self.porttype == 'opin': # output terminal
            pp = ((PW/2,0), (0,PW/2), (-PW,PW/2), (-PW/2,0), (-PW,-PW/2), (0,-PW/2))
            self.label_side = 'right'

        elif self.porttype == 'iopin':  # inout terminal
            pp = ((-PW,0), (-PW/2,PW/2), (PW/2,PW/2), (PW,0), (PW/2,-PW/2), (-PW/2,-PW/2))
            self.label_side = 'right'

        elif self.porttype.startswith('node'):  # node, nodeT, nodeB, nodeL, nodeR
            s = self.porttype[-1].upper()
            self.porttype = 'node'
            d = dict(T='top', B='bottom', L='left', R='right')
            if s in 'TBLR':
                self.label_side = d[s]
            else:
                self.label_side = 'top'
            cc = (-NW/2, -NW/2, NW, NW)

        for k in [self.porttype, 'port_'+self.porttype, self.porttype[:-1]]:
            if k in colors:
                self.lineColor, self.fillColor = colors[k]
                pen = QtGui.QPen(self.lineColor)
                pen.setWidth(1)
                self.setPen(pen)
                self.setBrush(self.fillColor)
                break

        self.p.swap(QtGui.QPainterPath()) # new painterpath
        if pp:
            polygon = QtGui.QPolygonF()
            for (x, y) in pp:
                polygon.append(QtCore.QPointF(x, y))
            polygon.append(QtCore.QPointF(pp[0][0], pp[0][1])) # close polygon
            self.p.addPolygon(polygon)
        elif cc:
            bb = QtCore.QRectF(*cc)
            self.p.addEllipse(bb)

        else:
            error('unknown Port type: {}'.format(self.porttype))
Exemplo n.º 14
0
    def paintEvent(self, event):
        painter = qg.QPainter(self)
        option = qw.QStyleOption()
        option.initFrom(self)

        x = option.rect.x() + 1
        y = option.rect.y() + 2
        height = option.rect.height() - 5
        width = option.rect.width() - 2

        painter.setRenderHint(qg.QPainter.Antialiasing)

        #################################
        # draw TEXT
        #
        alignment = (qc.Qt.AlignHCenter | qc.Qt.AlignVCenter)
        text = self.text()
        font = self.font()

        text_width = self.fontMetrics.width(text)
        text_height = font.pointSize()

        textPath = qg.QPainterPath()
        textPath.addText(x, y, font, text)

        penHover = self._pen_textHover
        penText = self._pen_text
        penpress = self._pen_pressed

        path = qg.QPainterPath()
        path.addRoundedRect(qc.QRectF(x, y, width, height), self.radius,
                            self.radius)

        painter.fillPath(path, self.BRUSHPRESS)
        painter.setPen(self._penBorder)
        painter.drawPath(path)

        painter.fillRect(x, y, width, height, self._brushClear)

        penText.setCapStyle(qc.Qt.RoundCap)
        penText.setStyle(qc.Qt.SolidLine)
        painter.setPen(penText)
        painter.drawText(x + 1, y, width + 2, height, alignment, text)

        if self.isDown():
            painter.fillPath(path, self.BRUSHPRESS)
            painter.setPen(penpress)
            penpress.setCapStyle(qc.Qt.RoundCap)
            penpress.setStyle(qc.Qt.SolidLine)
            painter.drawText(x + 1, y, width + 2, height, alignment, text)

        elif self.underMouse():
            painter.setPen(penHover)
            penHover.setCapStyle(qc.Qt.RoundCap)
            penHover.setStyle(qc.Qt.SolidLine)
            painter.fillPath(path, self.BRUSHHOVER)
            painter.drawText(x + 1, y, width + 2, height, alignment, text)

        if not self.isEnabled():
            painter.setPen(self._penDisabled)
            self._penDisabled.setCapStyle(qc.Qt.RoundCap)
            self._penDisabled.setStyle(qc.Qt.SolidLine)
            painter.drawRoundedRect(qc.QRectF(x, y, width, height),
                                    self.radius, self.radius)
            painter.setPen(self._penDisabled)

            painter.fillPath(path, self.BRUSHDISABLED)
            painter.drawText(x + 1, y, width + 2, height, alignment, text)

        painter.end()
Exemplo n.º 15
0
class Colors:
    AbsoluteBlack = QtGui.QColor(0, 0, 0, 255)
    DarkGray = QtGui.QColor(60, 60, 60)
    DirtyPen = QtGui.QColor(250, 250, 250, 200)
    Gray = QtGui.QColor(110, 110, 110)
    Green = QtGui.QColor(96, 169, 23, 255)
    NodeBackgrounds = QtGui.QColor(40, 40, 40, 200)
    NodeNameRectBlue = QtGui.QColor(28, 74, 149, 200)
    NodeNameRectGreen = QtGui.QColor(74, 124, 39, 200)
    NodeNameRectOrange = QtGui.QColor(124, 94, 39, 200)
    NodeSelectedPenColor = QtGui.QColor(200, 200, 200, 150)
    Red = QtGui.QColor(255, 0, 0, 255)
    White = QtGui.QColor(255, 255, 255, 200)
    Yellow = QtGui.QColor(255, 211, 25)
    Orange = QtGui.QColor(209, 84, 0)
Exemplo n.º 16
0
    def populate(self):
        # first page
        self.p1 = QWidget()
        self.p1Layout = QHBoxLayout(self.p1)
        self.lePkgName = QLineEdit("DemoPackage")
        # allow only letters without spaces
        self.lePkgName.setValidator(
            QtGui.QRegExpValidator(QtCore.QRegExp("^[A-Za-z]+$")))

        self.lePkgName.setAlignment(QtCore.Qt.AlignCenter)
        self.p1Layout.addWidget(self.lePkgName)
        self.addPageWidget(self.p1, "Choose a name for your new package!")

        # second page
        self.p2 = QWidget()
        self.p2Layout = QVBoxLayout(self.p2)
        self.goToDocsWidget = QWidget()
        self.goToDocsLayout = QHBoxLayout(self.goToDocsWidget)
        spacer = QSpacerItem(40, 20, QSizePolicy.Expanding,
                             QSizePolicy.Maximum)
        self.goToDocsLayout.addItem(spacer)
        self.bpGotoComponentsDocs = QPushButton("?")
        self.bpGotoComponentsDocs.setToolTip("Go to docs")
        self.bpGotoComponentsDocs.clicked.connect(self.onGotoComponentsDocs)
        self.goToDocsLayout.addWidget(self.bpGotoComponentsDocs)
        self.p2Layout.addWidget(self.goToDocsWidget)
        self.cbIncludeClassNode = QCheckBox("Class node")
        self.cbIncludeClassNode.stateChanged.connect(
            self.checkIncludeUINodeFactory)
        self.cbIncludeFooLib = QCheckBox("Function library")
        self.cbIncludePin = QCheckBox("Pin")
        self.cbIncludePin.stateChanged.connect(self.checkUIPinFactories)
        self.cbIncludeTool = QCheckBox("Tool")
        self.cbIncludeExporter = QCheckBox("Exporter")

        self.classNodeLayout = QHBoxLayout()
        self.classNodeLayout.setSpacing(1)
        self.classNodeLayout.setContentsMargins(0, 0, 0, 0)
        self.cbIncludeUINodeFactory = QCheckBox("Include ui node factory")
        self.cbIncludeUINodeFactory.setEnabled(False)
        self.classNodeLayout.addWidget(self.cbIncludeClassNode)
        self.classNodeLayout.addWidget(self.cbIncludeUINodeFactory)
        self.p2Layout.addLayout(self.classNodeLayout)
        self.p2Layout.addWidget(self.cbIncludeFooLib)

        self.pinLayout = QHBoxLayout()
        self.pinLayout.setSpacing(1)
        self.pinLayout.setContentsMargins(0, 0, 0, 0)
        self.cbUIPinFactory = QCheckBox("Include ui pin factory")
        self.cbUIPinFactory.setEnabled(False)
        self.pinLayout.addWidget(self.cbIncludePin)
        self.pinLayout.addWidget(self.cbUIPinFactory)
        self.p2Layout.addLayout(self.pinLayout)

        self.toolLayout = QHBoxLayout()
        self.toolLayout.setSpacing(1)
        self.toolLayout.setContentsMargins(0, 0, 0, 0)
        self.cbPinInputWidgetFactory = QCheckBox(
            "Include pin input widget factory")
        self.cbPinInputWidgetFactory.setEnabled(False)
        self.toolLayout.addWidget(self.cbIncludeTool)
        self.toolLayout.addWidget(self.cbPinInputWidgetFactory)
        self.p2Layout.addLayout(self.toolLayout)

        self.p2Layout.addWidget(self.cbIncludeExporter)
        self.addPageWidget(
            self.p2, "What components should be included?",
            "Please select at least one component to include to package!",
            self.isPackaeModuleSelected)

        # third page
        self.p3 = QWidget()
        self.p3Layout = QHBoxLayout(self.p3)
        self.pbOutPathSelect = QPushButton("...")
        self.p3Layout.addWidget(self.pbOutPathSelect)
        self.pbOutPathSelect.clicked.connect(self.onSelectPackageDirectory)
        self.addPageWidget(
            self.p3,
            "Select output directory for your new package!" +
            "\n\n**Note**: Output directory should be writable.",
            pageEnterCallback=self.onSelectPackageRootEntered)
Exemplo n.º 17
0
    def __init__(self, appInstance=None):

        self.appInstance = appInstance

        self.TextColor = QtGui.QColor(228, 228, 228)

        self.MainColor = QtGui.QColor(215, 128, 26)

        self.BgColor = QtGui.QColor(53, 53, 53)
        self.BgColorDarker = QtGui.QColor(50, 50, 50)
        self.BgColorBright = QtGui.QColor(82, 82, 82)
        self.BorderColor = QtGui.QColor(10, 10, 10)

        self.LoggerBgColor = QtGui.QColor(35, 35, 35)

        self.InputFieldColor = QtGui.QColor(32, 32, 32)
        self.TextSelectedColor = QtGui.QColor(255, 255, 255)

        self.ButtonsColor = QtGui.QColor(60, 60, 60)

        self.CanvasBgColor = QtGui.QColor(35, 35, 35)
        self.CanvasGridColor = QtGui.QColor(20, 20, 20, 100)
        self.CanvasGridColorDarker = QtGui.QColor(20, 20, 20)
        self.DrawGrid = [1]
        self.GridSizeFine = [10]
        self.GridSizeHuge = [100]
        self.DrawNumbers = [0]
        self.SetAppStyleSheet = [1]

        self.LOD_Number = [4]
        self.NodeSwitch = [3]
        self.ConnectionSwitch = [3]
        self.PinSwitch = [3]
        self.CanvasSwitch = [3]

        self.ConnectionMode = [ConnectionTypes.Circuit]
        self.ConnectionRoundness = [5]
        self.ConnectionOffset = [20]

        self.storeDeffaults()
        self.presets = {}
        self.loadPresets(THEMES_PATH)
        try:
            themeName = ConfigManager().getPrefsValue("PREFS",
                                                      "Theme/Theme_Name")
            if themeName:
                self.loadFromData(self.presets[themeName])
            else:
                if len(self.presets) > 0:
                    self.loadFromData(self.presets[list(
                        self.presets.keys())[0]])
        except:
            pass
Exemplo n.º 18
0
    def paint(self, painter, option, index):
        """Paint checkbox and text

         _______________________________________________
        |       |  label              | duration  |arrow|
        |toggle |_____________________|           | to  |
        |       |  families           |           |persp|
        |_______|_____________________|___________|_____|

        """

        # Layout
        spacing = 10

        body_rect = QtCore.QRectF(option.rect).adjusted(2, 2, -8, -2)
        content_rect = body_rect.adjusted(5, 5, -5, -5)

        perspective_rect = QtCore.QRectF(body_rect)
        perspective_rect.setWidth(35)
        perspective_rect.setHeight(35)
        perspective_rect.translate(
            content_rect.width() - (perspective_rect.width() / 2) + 10,
            (content_rect.height() / 2) - (perspective_rect.height() / 2))

        toggle_rect = QtCore.QRectF(body_rect)
        toggle_rect.setWidth(7)
        toggle_rect.adjust(1, 1, 0, -1)

        icon_rect = QtCore.QRectF(content_rect)
        icon_rect.translate(toggle_rect.width() + spacing, 3)
        icon_rect.setWidth(35)
        icon_rect.setHeight(35)

        duration_rect = QtCore.QRectF(content_rect)
        duration_rect.translate(content_rect.width() - 50, 0)

        # Colors
        check_color = colors["idle"]

        publish_states = index.data(Roles.PublishFlagsRole)
        if publish_states is None:
            return
        if publish_states & InstanceStates.InProgress:
            check_color = colors["active"]

        elif publish_states & InstanceStates.HasError:
            check_color = colors["error"]

        elif publish_states & InstanceStates.HasWarning:
            check_color = colors["warning"]

        elif publish_states & InstanceStates.HasFinished:
            check_color = colors["ok"]

        elif not index.data(Roles.IsEnabledRole):
            check_color = colors["inactive"]

        perspective_icon = icons["angle-right"]

        if not index.data(QtCore.Qt.CheckStateRole):
            font_color = colors["inactive"]
        else:
            font_color = colors["idle"]

        if (option.state
                & (QtWidgets.QStyle.State_MouseOver
                   or QtWidgets.QStyle.State_Selected)):
            perspective_color = colors["idle"]
        else:
            perspective_color = colors["inactive"]
        # Maintan reference to state, so we can restore it once we're done
        painter.save()

        # Draw background
        painter.fillRect(body_rect, colors["hover"])

        # Draw icon
        icon = index.data(QtCore.Qt.DecorationRole)

        painter.setFont(fonts["largeAwesome"])
        painter.setPen(QtGui.QPen(font_color))
        painter.drawText(icon_rect, icon)

        # Draw label
        painter.setFont(fonts["h3"])
        label_rect = QtCore.QRectF(content_rect)
        label_x_offset = icon_rect.width() + spacing
        label_rect.translate(label_x_offset, 0)
        metrics = painter.fontMetrics()
        label_rect.setHeight(metrics.lineSpacing())
        label_rect.setWidth(content_rect.width() - label_x_offset -
                            perspective_rect.width())
        # Elide label
        label = index.data(QtCore.Qt.DisplayRole)
        label = metrics.elidedText(label, QtCore.Qt.ElideRight,
                                   label_rect.width())
        painter.drawText(label_rect, label)

        # Draw families
        painter.setFont(fonts["h5"])
        painter.setPen(QtGui.QPen(colors["inactive"]))

        families = ", ".join(index.data(Roles.FamiliesRole))
        families = painter.fontMetrics().elidedText(families,
                                                    QtCore.Qt.ElideRight,
                                                    label_rect.width())

        families_rect = QtCore.QRectF(label_rect)
        families_rect.translate(0, label_rect.height() + spacing)

        painter.drawText(families_rect, families)

        painter.setFont(fonts["largeAwesome"])
        painter.setPen(QtGui.QPen(perspective_color))
        painter.drawText(perspective_rect, perspective_icon)

        # Draw checkbox
        pen = QtGui.QPen(check_color, 1)
        painter.setPen(pen)

        if index.data(Roles.IsOptionalRole):
            painter.drawRect(toggle_rect)

            if index.data(QtCore.Qt.CheckStateRole):
                painter.fillRect(toggle_rect, check_color)

        elif (index.data(QtCore.Qt.CheckStateRole)):
            painter.fillRect(toggle_rect, check_color)

        if option.state & QtWidgets.QStyle.State_MouseOver:
            painter.fillRect(body_rect, colors["hover"])

        if option.state & QtWidgets.QStyle.State_Selected:
            painter.fillRect(body_rect, colors["selected"])

        painter.setPen(colors["outline"])
        painter.drawRect(body_rect)

        # Ok, we're done, tidy up.
        painter.restore()
Exemplo n.º 19
0
    def __buildAction(self, item, name, parent):

        label = name
        with IECore.IgnoredExceptions(AttributeError):
            label = item.label

        qtAction = QtWidgets.QAction(label, parent)
        qtAction.__item = item

        if item.checkBox is not None:
            qtAction.setCheckable(True)
            checked = self.__evaluateItemValue(item.checkBox)
            qtAction.setChecked(checked)

        if item.divider:
            qtAction.setSeparator(True)

        if item.command:

            if item.checkBox:
                signal = qtAction.toggled[bool]
            else:
                signal = qtAction.triggered[bool]

            if self.__searchable:
                signal.connect(
                    IECore.curry(Gaffer.WeakMethod(self.__menuActionTriggered),
                                 qtAction))

            signal.connect(
                IECore.curry(Gaffer.WeakMethod(self.__actionTriggered),
                             weakref.ref(qtAction)))

        active = self.__evaluateItemValue(item.active)
        qtAction.setEnabled(active)

        shortCut = getattr(item, "shortCut", None)
        if shortCut is not None:
            qtAction.setShortcuts(
                [QtGui.QKeySequence(s.strip()) for s in shortCut.split(",")])
            # If we allow shortcuts to be created at the window level (the default),
            # then we can easily get into a situation where our shortcuts conflict
            # with those of the host when embedding our MenuBars in an application like Maya.
            # Here we're limiting the scope so that conflicts don't occur, deferring
            # to the code in MenuBar to manage triggering of the action with manual
            # shortcut processing.
            qtAction.setShortcutContext(QtCore.Qt.WidgetShortcut)

        # when an icon file path is defined in the menu definition
        icon = getattr(item, "icon", None)
        if icon is not None:
            if isinstance(icon, basestring):
                image = GafferUI.Image(icon)
            else:
                assert (isinstance(icon, GafferUI.Image))
                image = icon
            qtAction.setIcon(QtGui.QIcon(image._qtPixmap()))

        if item.description:
            qtAction.setStatusTip(item.description)

        return qtAction
Exemplo n.º 20
0
        Parameters
        ----------
        button : QPushButton
            Icon Button
        color : QColor, optional
            set the Icon color, by default QtGui.QColor("red")
        """
        self.color = color
        self._setColor()

    def _setColor(self):
        if not self.color:
            return
        icon = self.bar.icon()
        pixmap = icon.pixmap(35)
        image = pixmap.toImage()
        pcolor = image.pixelColor(8, 35)
        for x in range(image.width()):
            for y in range(image.height()):
                pcolor = image.pixelColor(x, y)
                if pcolor.alpha() > 0:
                    self.color.setAlpha(pcolor.alpha())
                    image.setPixelColor(x, y, self.color)
        self.bar.setIcon(QtGui.QIcon(QtGui.QPixmap.fromImage(image)))


if __name__ == "__main__":
    widget = CollapsibleSperator()
    widget.show()
    widget.setButtonColor(QtGui.QColor("rgb(0,255,0)"))
Exemplo n.º 21
0
 def add_items(self):
     for row, task_status in enumerate(self.list_task_status):
         self.addItem(str(task_status["short_name"]).upper(),
                      userData=task_status)
         color = QtGui.QColor(task_status["color"]).darker(180)
         self.model().item(row).setBackground(color)
Exemplo n.º 22
0
 def getIcon():
     return QtGui.QIcon(
         str((Path(__file__).parent /
              Path('res/export.png')).resolve().absolute()))
Exemplo n.º 23
0
        super(ExtendedCombo, self).setModelColumn( column )


    def view( self ):
        return self.completer.popup()

    def index( self ):
        return self.currentIndex()

    def setTextIfCompleterIsClicked(self, text):
      if text:
        index = self.findText(text)
        self.setCurrentIndex(index)

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)

    model = QtGui.QStandardItemModel()

    for i,word in enumerate( ['hola', 'adios', 'hello', 'good bye'] ):
        item = QtGui.QStandardItem(word)
        model.setItem(i, item)

    combo = ExtendedCombo()
    combo.setModel(model)
    combo.setModelColumn(0)

    combo.show()

    sys.exit(app.exec_())
 def getIcon():
     return QtGui.QIcon(":brick.png")
Exemplo n.º 25
0
 def changeLockIcon(self, checked):
     if checked:
         self.lockCheckBox.setIcon(QtGui.QIcon(':/locked.png'))
     else:
         self.lockCheckBox.setIcon(QtGui.QIcon(':/unlocked.png'))
Exemplo n.º 26
0
    def draw_title(self, painter):
        """Draw title of the node. Called exclusively in paint.

        :param painter: painter from paint.
        :type painter: QtGui.QPainter
        """
        # draw bg
        painter.setPen(QtCore.Qt.NoPen)
        bg = painter.background()
        bgm = painter.backgroundMode()
        if self.is_real:
            painter.setBackgroundMode(QtCore.Qt.OpaqueMode)
        else:
            painter.setBackgroundMode(QtCore.Qt.TransparentMode)
            [c.setAlphaF(self.color_alpha) for c in self.colors]
        color_count = len(self.colors)
        color_band_width = 10
        for i in range(color_count):
            color = self.colors[i]
            if self.is_proxy:
                painter.setBackground(color.darker(self.dim_factor))
                brush = QtGui.QBrush(color.darker(self.dim_factor * 2),
                                     QtCore.Qt.FDiagPattern)
                painter.setBrush(brush)
            else:
                painter.setBrush(color.darker(self.dim_factor))
            # Top Opinion
            if i + 1 == color_count:
                remaining_width = self.max_width - (i * color_band_width)
                painter.drawRect(0, 0, remaining_width, self.title_rect_height)
            # Lower Opinions
            else:
                x_pos = self.max_width - (i + 1) * color_band_width
                painter.drawRect(x_pos, 0, color_band_width,
                                 self.title_rect_height)
        painter.setBackground(bg)
        painter.setBackgroundMode(bgm)
        # draw exec plugs
        exec_attr = nxt_node.INTERNAL_ATTRS.EXECUTE_IN
        exec_in_pos = self.get_attr_in_pos(exec_attr, scene=False)
        exec_radius = self.EXEC_PLUG_RADIUS
        if nxt_path.get_parent_path(self.node_path) == nxt_path.WORLD:
            if self.is_start:
                color = self.start_color
            elif self.is_break:
                color = QtCore.Qt.red
            else:
                color = QtCore.Qt.white
            if not self.exec_in_plug:
                is_break = self.is_break
                if self.is_start:
                    is_break = False
                self.exec_in_plug = NodeGraphicsPlug(pos=exec_in_pos,
                                                     radius=exec_radius,
                                                     color=color,
                                                     is_exec=True,
                                                     is_input=True,
                                                     is_break=is_break,
                                                     is_start=self.is_start)
                self.exec_in_plug.setParentItem(self)
            else:
                self.exec_in_plug.color = QtGui.QColor(color)
                self.exec_in_plug.is_break = self.is_break
                self.exec_in_plug.is_start = self.is_start
                self.exec_in_plug.setPos(exec_in_pos)
                self.exec_in_plug.update()

            out_pos = self.get_attr_out_pos(exec_attr, scene=False)
            if not self.exec_out_plug:
                self.exec_out_plug = NodeGraphicsPlug(pos=out_pos,
                                                      radius=exec_radius,
                                                      color=QtCore.Qt.white,
                                                      is_exec=True,
                                                      is_input=False)
                self.exec_out_plug.setParentItem(self)
            else:
                self.exec_out_plug.setPos(out_pos)
        else:
            if not self.exec_in_plug and self.is_break:
                self.exec_in_plug = NodeGraphicsPlug(pos=exec_in_pos,
                                                     radius=exec_radius,
                                                     color=QtCore.Qt.red,
                                                     is_exec=True,
                                                     is_input=True,
                                                     is_break=self.is_break)
                self.exec_in_plug.setParentItem(self)
            elif self.exec_in_plug and not self.is_break:
                self.scene().removeItem(self.exec_in_plug)
                self.exec_in_plug = None

            if self.exec_out_plug:
                self.scene().removeItem(self.exec_out_plug)
                self.exec_out_plug = None

        # draw attr dots
        offset = -6
        for fill in self.attr_dots:
            painter.setBrush(QtCore.Qt.white)
            if fill:
                painter.setBrush(QtCore.Qt.white)
            else:
                painter.setBrush(QtCore.Qt.NoBrush)
            dots_color = QtGui.QColor(QtCore.Qt.white).darker(self.dim_factor)
            painter.setPen(QtGui.QPen(dots_color, 0.5))
            dot_x = self.max_width - 15
            dot_y = (self.title_rect_height / 2) + offset
            painter.drawEllipse(QtCore.QPointF(dot_x, dot_y), 2, 2)
            offset += 6

        # draw title
        painter.setPen(QtGui.QColor(QtCore.Qt.white).darker(self.dim_factor))
        if not self.node_enabled:
            painter.setPen(QtGui.QColor(QtCore.Qt.white).darker(150))
        painter.setFont(self.title_font)
        title_str = nxt_path.node_name_from_node_path(self.node_path)
        font_metrics = QtGui.QFontMetrics(self.title_font)
        width = self.max_width - 40
        if self.error_list:
            width -= 20
        title = font_metrics.elidedText(title_str, QtCore.Qt.ElideRight, width)
        painter.drawText(15, 0, self.max_width - 15, self.title_rect_height,
                         QtCore.Qt.AlignVCenter, title)

        # draw error
        if self.error_list:
            pos = QtCore.QPointF(self.max_width - 45,
                                 self.title_rect_height / 4)
            error_item = ErrorItem(font=QtGui.QFont('Roboto', 16, 75),
                                   pos=pos,
                                   text='!')
            error_item.setParentItem(self)
            error_item.setZValue(50)
            self.error_item = error_item
        else:
            if self.error_item:
                self.scene().removeItem(self.error_item)
                self.error_item.deleteLater()
            self.error_item = None

        for arrow in self.collapse_arrows:
            self.scene().removeItem(arrow)
        self.collapse_arrows = []
        # TODO calculation needed arrows should be done outside drawing
        # draw collapse state arrow
        if self.collapse_state:
            des_colors = self.model.get_descendant_colors(self.node_path)
            filled = self.model.has_children(self.node_path)
            if not filled:
                des_colors = [QtCore.Qt.white]
            elif not des_colors:
                disp = self.model.comp_layer
                des_colors = [self.model.get_node_color(self.node_path, disp)]
            i = 0
            num = len(des_colors)
            for c in des_colors:
                arrow = CollapseArrow(self, filled=filled, color=c)
                arrow_width = arrow.width * 1.1
                center_offset = (arrow_width * (num * .5) - arrow_width * .5)
                cur_offset = (i * arrow_width)
                pos = ((self.max_width * .5) + center_offset - cur_offset)
                arrow.setPos(pos, self.title_rect_height)
                self.collapse_arrows += [arrow]
                i += 1
Exemplo n.º 27
0
import platform

from Qt import QtWidgets, QtGui, QtCore

from . import model
from .awesome import tags as awesome
from .constants import (PluginStates, InstanceStates, PluginActionStates,
                        Roles, EXPANDER_WIDTH)

colors = {
    "error": QtGui.QColor("#ff4a4a"),
    "warning": QtGui.QColor("#ff9900"),
    "ok": QtGui.QColor("#77AE24"),
    "active": QtGui.QColor("#99CEEE"),
    "idle": QtCore.Qt.white,
    "inactive": QtGui.QColor("#888"),
    "hover": QtGui.QColor(255, 255, 255, 10),
    "selected": QtGui.QColor(255, 255, 255, 20),
    "outline": QtGui.QColor("#333"),
    "group": QtGui.QColor("#333"),
    "group-hover": QtGui.QColor("#3c3c3c"),
    "group-selected-hover": QtGui.QColor("#555555"),
    "expander-bg": QtGui.QColor("#222"),
    "expander-hover": QtGui.QColor("#2d6c9f"),
    "expander-selected-hover": QtGui.QColor("#3784c5")
}

scale_factors = {"darwin": 1.5}
scale_factor = scale_factors.get(platform.system().lower(), 1.0)
fonts = {
    "h3": QtGui.QFont("Open Sans", 10 * scale_factor, QtGui.QFont.Normal),
Exemplo n.º 28
0
    def calculate_attribute_draw_details(self):
        """Calculate position of all known attr names. Details stored in
        self._attribute_draw_details. Public interface to get details is split
        into two functions, get_attr_in_pos and get_attr_out_pos.
        """
        self._attribute_draw_details = OrderedDict()
        index = -1
        comp_layer = self.model.comp_layer
        for attr_name in self.user_attr_names:
            index += 1
            draw_details = {}
            # sizes
            rect_y = self.title_rect_height + index * self.attr_rect_height
            rect_midpoint = rect_y + (self.attr_rect_height / 2)
            draw_details['text_height'] = rect_y
            draw_details['bg_rect'] = QtCore.QRectF(0, rect_y, self.max_width,
                                                    self.attr_rect_height)
            # positions
            draw_details['in_pos'] = QtCore.QPointF(self.attr_plug_side_margin,
                                                    rect_midpoint)
            out_x = self.max_width - self.attr_plug_side_margin
            draw_details['out_pos'] = QtCore.QPointF(out_x, rect_midpoint)
            # background color
            color = self.model.get_node_attr_color(self.node_path, attr_name,
                                                   comp_layer)
            bg_color = QtGui.QColor(color).darker(150).darker(self.dim_factor)
            bg_color.setAlphaF(self.attr_rect_opacity)
            draw_details['bg_color'] = bg_color
            # plug color
            type_ = self.model.get_node_attr_type(self.node_path, attr_name,
                                                  comp_layer)
            draw_details['plug_color'] = colors.ATTR_COLORS.get(
                type_, QtCore.Qt.gray)
            # title color
            attr_is_instance = self.model.node_attr_is_instance(
                self.node_path, attr_name, comp_layer)
            dim_title = 150 if attr_is_instance else self.dim_factor
            white = QtGui.QColor(QtCore.Qt.white)
            draw_details['title_color'] = white.darker(dim_title)
            # font
            font = QtGui.QFont(self.attr_font.family(),
                               self.attr_font.pointSize(),
                               italic=attr_is_instance)
            draw_details['title_font'] = font

            self._attribute_draw_details[attr_name] = draw_details
        # Internal Attrs
        # Exec
        draw_details = {}
        in_pos = QtCore.QPointF(0, self.title_bounding_rect.height() / 3)
        draw_details['in_pos'] = in_pos
        out_pos = QtCore.QPointF(self.max_width,
                                 self.title_bounding_rect.height() / 3)
        draw_details['out_pos'] = out_pos
        draw_details['plug_color'] = QtGui.QColor(QtCore.Qt.white)
        exec_attr = nxt_node.INTERNAL_ATTRS.EXECUTE_IN
        self._attribute_draw_details[exec_attr] = draw_details
        # Inst
        draw_details = {}
        in_pos = QtCore.QPointF(0, (self.title_bounding_rect.height() / 3) * 2)
        draw_details['in_pos'] = in_pos
        out_pos = QtCore.QPointF(self.max_width,
                                 (self.title_bounding_rect.height() / 3) * 2)
        draw_details['out_pos'] = out_pos
        draw_details['plug_color'] = QtGui.QColor(QtCore.Qt.gray)
        inst_attr = nxt_node.INTERNAL_ATTRS.INSTANCE_PATH
        self._attribute_draw_details[inst_attr] = draw_details
Exemplo n.º 29
0
    def group_item_paint(self, painter, option, index):
        """Paint text
         _
        My label
        """
        body_rect = QtCore.QRectF(option.rect)
        bg_rect = QtCore.QRectF(body_rect.left(),
                                body_rect.top() + 1,
                                body_rect.width() - 5,
                                body_rect.height() - 2)

        expander_rect = QtCore.QRectF(bg_rect)
        expander_rect.setWidth(EXPANDER_WIDTH)

        remainder_rect = QtCore.QRectF(
            expander_rect.x() + expander_rect.width(), expander_rect.y(),
            bg_rect.width() - expander_rect.width(), expander_rect.height())

        width = float(expander_rect.width())
        height = float(expander_rect.height())

        x_pos = expander_rect.x()
        y_pos = expander_rect.y()

        x_radius = min(self.radius, width / 2)
        y_radius = min(self.radius, height / 2)
        x_radius2 = x_radius * 2
        y_radius2 = y_radius * 2

        expander_path = QtGui.QPainterPath()
        expander_path.moveTo(x_pos, y_pos + y_radius)
        expander_path.arcTo(x_pos, y_pos, x_radius2, y_radius2, 180.0, -90.0)
        expander_path.lineTo(x_pos + width, y_pos)
        expander_path.lineTo(x_pos + width, y_pos + height)
        expander_path.lineTo(x_pos + x_radius, y_pos + height)
        expander_path.arcTo(x_pos, y_pos + height - y_radius2, x_radius2,
                            y_radius2, 270.0, -90.0)
        expander_path.closeSubpath()

        width = float(remainder_rect.width())
        height = float(remainder_rect.height())
        x_pos = remainder_rect.x()
        y_pos = remainder_rect.y()

        x_radius = min(self.radius, width / 2)
        y_radius = min(self.radius, height / 2)
        x_radius2 = x_radius * 2
        y_radius2 = y_radius * 2

        remainder_path = QtGui.QPainterPath()
        remainder_path.moveTo(x_pos + width, y_pos + height - y_radius)
        remainder_path.arcTo(x_pos + width - x_radius2,
                             y_pos + height - y_radius2, x_radius2, y_radius2,
                             0.0, -90.0)
        remainder_path.lineTo(x_pos, y_pos + height)
        remainder_path.lineTo(x_pos, y_pos)
        remainder_path.lineTo(x_pos + width - x_radius, y_pos)
        remainder_path.arcTo(x_pos + width - x_radius2, y_pos, x_radius2,
                             y_radius2, 90.0, -90.0)
        remainder_path.closeSubpath()

        painter.fillPath(expander_path, colors["expander-bg"])
        painter.fillPath(remainder_path, colors["group"])

        mouse_pos = option.widget.mapFromGlobal(QtGui.QCursor.pos())
        selected = option.state & QtWidgets.QStyle.State_Selected
        hovered = option.state & QtWidgets.QStyle.State_MouseOver

        if selected and hovered:
            if expander_rect.contains(mouse_pos):
                painter.fillPath(expander_path,
                                 colors["expander-selected-hover"])
            else:
                painter.fillPath(remainder_path,
                                 colors["group-selected-hover"])

        elif hovered:
            if expander_rect.contains(mouse_pos):
                painter.fillPath(expander_path, colors["expander-hover"])
            else:
                painter.fillPath(remainder_path, colors["group-hover"])

        text_height = font_metrics["awesome6"].height()
        adjust_value = (expander_rect.height() - text_height) / 2
        expander_rect.adjust(adjust_value + 1.5, adjust_value - 0.5,
                             -adjust_value + 1.5, -adjust_value - 0.5)

        offset = (remainder_rect.height() - font_metrics["h5"].height()) / 2
        label_rect = QtCore.QRectF(remainder_rect.adjusted(
            5, offset - 1, 0, 0))

        expander_icon = icons["plus-sign"]

        expanded = self.parent().isExpanded(index)
        if expanded:
            expander_icon = icons["minus-sign"]
        label = index.data(QtCore.Qt.DisplayRole)
        label = font_metrics["h5"].elidedText(label, QtCore.Qt.ElideRight,
                                              label_rect.width())

        # Maintain reference to state, so we can restore it once we're done
        painter.save()

        painter.setFont(fonts["awesome6"])
        painter.setPen(QtGui.QPen(colors["idle"]))
        painter.drawText(expander_rect, QtCore.Qt.AlignCenter, expander_icon)

        # Draw label
        painter.setFont(fonts["h5"])
        painter.drawText(label_rect, label)

        # Ok, we're done, tidy up.
        painter.restore()
Exemplo n.º 30
0
    def paint_close_button(self):
        """
        Let's draw a tiny little x on the right
        that's our new close button. It's just two little lines! x

        Notes:
        - it's probably faster if we only iterate over visible tabs.
        - How can this be used to write italic text?
        - we could change the x to a o like sublime
        - ANTIALIASING PLEASEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
        """
        #print 1
        #print dir(e)
        #e.accept()
        #paint_rect = e.rect()

        for i in range(self.count()):
            rect = self.tabRect(i)

            if not self.rect().contains(rect):
                continue  # would be nice to optimise

            #print 'tab:    ', rect
            x, y, r, t = rect.getCoords()
            #print rect.getCoords()
            #rqt = QtCore.QRect(x+(r/2),y,r+1,t+1)
            rqt = self.tab_close_button_rect(i)
            #QtCore.QRect.right()

            #QtCore.QRect.adjust()
            #print 'rt side:', rqt
            #print e.region()
            p = QtGui.QPainter()
            #p.setRenderHint(QtGui.QPainter.Antialiasing)
            p.begin(self)
            p.setBrush(self.brush)
            if i == self.over_button and self.mouse_over_rect:
                brush = QtGui.QBrush(QtCore.Qt.gray)
                p.setBrush(brush)
            p.setPen(None)
            p.setRenderHint(QtGui.QPainter.Antialiasing)
            #p.drawEllipse(rqt)

            p.setPen(self.pen)
            self.pen.setWidth(2)
            if i == self.over_button and self.mouse_over_rect:
                pen = QtGui.QPen(QtCore.Qt.white)
                pen.setWidth(2)
                p.setPen(pen)

                #p.save()

            #p.drawText(rect, QtCore.Qt.AlignCenter, 'tab')

            #x,y,r,t = rqt.x, rqt.y, rqt.right(), rqt.top()
            #bl = rqt.bottomLeft()
            #tr = rqt.topRight()
            #p.drawLine(bl, tr)

            a = 2

            rqt.adjust(a, a, -a, -a)
            p.drawLine(rqt.bottomLeft(), rqt.topRight())
            p.drawLine(rqt.topLeft(), rqt.bottomRight())
            #p.restore()
            # print rqt
            p.end()