Exemplo n.º 1
0
    def __init__(self, parent):
        #
        QtModule.QGraphicsView.__init__(self, parent)
        #
        # Define signals for PyQt5
        #
        if usePySide or usePyQt5:
            #
            self.mouseDoubleClickSignal = Signal()
            #
        self.state = 'idle'
        self.panStartPos = None

        self.pixmap = None

        # set scene
        scene = QtModule.QGraphicsScene(self)

        scene.setSceneRect(0, 0, 256, 256)
        #scene.setItemIndexMethod ( QtGui.QGraphicsScene.NoIndex )
        self.setScene(scene)

        # qt graphics stuff
        #self.setCacheMode ( QtGui.QGraphicsView.CacheBackground )
        self.setRenderHint(QtGui.QPainter.Antialiasing)

        self.setTransformationAnchor(QtModule.QGraphicsView.AnchorUnderMouse)
        self.setResizeAnchor(QtModule.QGraphicsView.AnchorViewCenter)
        self.setDragMode(QtModule.QGraphicsView.RubberBandDrag)

        self.setMouseTracking(False)

        self.BgBrush = QtGui.QBrush(QtGui.QColor(128, 128, 128))
Exemplo n.º 2
0
    def updateNodeParams(self, node):
        #
        self.ui.list_inputs.clear()
        self.ui.list_outputs.clear()

        linkedFont = QtGui.QFont()
        linkedFont.setItalic(True)
        linkedBrush = QtGui.QBrush()
        linkedBrush.setColor(QtCore.Qt.blue)
        # setup input params list
        for param in node.inputParams:
            item = QtModule.QListWidgetItem(param.label)
            item.setData(QtCore.Qt.UserRole + 1, QtCore.QVariant(param))
            item.setData(QtCore.Qt.UserRole + 2, QtCore.QVariant(node))
            if node.isInputParamLinked(param):
                item.setFont(linkedFont)
                item.setForeground(linkedBrush)
            self.ui.list_inputs.addItem(item)
        # setup output params list
        for param in node.outputParams:
            item = QtModule.QListWidgetItem(param.label)
            item.setData(QtCore.Qt.UserRole + 1, QtCore.QVariant(param))
            item.setData(QtCore.Qt.UserRole + 2, QtCore.QVariant(node))
            if node.isOutputParamLinked(param):
                item.setFont(linkedFont)
                item.setForeground(linkedBrush)
            self.ui.list_outputs.addItem(item)
Exemplo n.º 3
0
	def __init__ ( self, link = None, srcConnector = None, dstConnector = None ) :
		#
		QtModule.QGraphicsItem.__init__ ( self )

		from meShaderEd import getDefaultValue
		self.isStraight = getDefaultValue ( app_settings, 'WorkArea', 'straight_links' )

		# qt graphics stuff
		self.brushSelected = QtGui.QBrush ( QtGui.QColor ( 250, 250, 250 ) )
		self.brushNormal = QtGui.QBrush ( QtGui.QColor ( 20, 20, 20 ) )
		self.setFlag ( QtModule.QGraphicsItem.ItemIsSelectable )
		self.setZValue( 0 )

		self.link = link

		self.rect = QtCore.QRectF ()
		self.points = []
		self.path = None
		self.isLinkSelected = False
		self.srcPoint = self.dstPoint = None
		self.srcConnector = self.dstConnector = None

		self.setSrcConnector ( srcConnector )
		self.setDstConnector ( dstConnector)

		if srcConnector != None :
			if srcConnector.isConnectedToInput () and not srcConnector.isConnectedToOutput (): 
				self.swapConnectors ()
Exemplo n.º 4
0
	def setupUi ( self, FloatWidget ) :
		#
		self.widget = FloatWidget
		self.labels = []
		self.controls = []
		
		font = QtGui.QFont ()
		labelFontMetric = QtGui.QFontMetricsF ( font )
		label_wi = 0
		char_wi = labelFontMetric.width ( 'x' )
		array_size = self.widget.param.arraySize
		if array_size > 0 :
			label_wi =  char_wi * ( len ( str ( array_size - 1 ) ) + 2 ) # [0]
		
		for i in range ( self.widget.param.arraySize ) :
			self.labels.append ( QtModule.QLabel ( FloatWidget ) )
			self.labels [ i ].setMinimumSize ( QtCore.QSize ( label_wi, UI.HEIGHT ) )
			self.labels [ i ].setMaximumSize ( QtCore.QSize ( label_wi, UI.HEIGHT ) )
			self.labels [ i ].setAlignment ( QtCore.Qt.AlignRight )
			self.labels [ i ].setText ( '[' + str ( i ) + ']' )
			
			self.controls.append ( QtModule.QLineEdit ( FloatWidget ) )
			self.controls [ i ].setMinimumSize ( QtCore.QSize ( UI.FIELD_WIDTH, UI.HEIGHT ) )
			self.controls [ i ].setMaximumSize ( QtCore.QSize ( UI.FIELD_WIDTH, UI.HEIGHT ) )
			
			sp = QtModule.QSpacerItem ( 0, 0, UI.SP_EXPAND,  UI.SP_MIN )
			
			hl = QtModule.QHBoxLayout ()
			hl.addWidget ( self.labels [ i ] )
			hl.addWidget ( self.controls [ i ] )
			hl.addItem ( sp )
			self.widget.param_vl.addLayout ( hl )
		
		self.connectSignals ( FloatWidget )
		QtCore.QMetaObject.connectSlotsByName ( FloatWidget )
Exemplo n.º 5
0
 def buildRecentProjectsMenu(self):
     #
     print '>> buildRecentProjectsMenu ...'
     if usePyQt4:
         #self.recentProjects = app_settings.value ( 'RecentProjects' ).toStringList ()
         print '>> self.recentProjects:', self.recentProjects
         self.ui.menuRecent_Projects.clear()
         if len(self.recentProjects):
             icon = QtGui.QIcon.fromTheme(
                 'folder', QtGui.QIcon(':/file_icons/resources/open.png'))
             # QtGui.QIcon ( ':/file_icons/resources/recentFile.png' ) 'folder'
             for i, fname in enumerate(self.recentProjects):
                 # QtCore.QFileInfo ( fname ).fileName ()
                 action = QtModule.QAction(icon, '&%d %s' % (i + 1, fname),
                                           self)
                 action.setData(QtCore.QVariant(fname))
                 self.connect(action, QtCore.SIGNAL('triggered()'),
                              self.onOpenRecentProject)
                 self.ui.menuRecent_Projects.addAction(action)
     else:
         #self.recentProjects = app_settings.value ( 'RecentProjects' )
         print '>> self.recentProjects:', self.recentProjects
         self.ui.menuRecent_Projects.clear()
         if len(self.recentProjects):
             icon = QtGui.QIcon.fromTheme(
                 'folder', QtGui.QIcon(':/file_icons/resources/open.png'))
             # QtGui.QIcon ( ':/file_icons/resources/recentFile.png' ) 'folder'
             for i, fname in enumerate(self.recentProjects):
                 # QtCore.QFileInfo ( fname ).fileName ()
                 action = QtModule.QAction(icon, '&%d %s' % (i + 1, fname),
                                           self)
                 action.setData(fname)
                 action.triggered.connect(self.onOpenRecentProject)
                 self.ui.menuRecent_Projects.addAction(action)
Exemplo n.º 6
0
 def buildRecentNetworksMenu(self):
     #
     if usePyQt4:
         #self.recentNetworks = app_settings.value ( 'RecentNetworks' ).toStringList ()
         self.ui.menuRecent_Networks.clear()
         if len(self.recentNetworks):
             for i, fname in enumerate(self.recentNetworks):
                 icon = QtGui.QIcon.fromTheme(
                     'document-new',
                     QtGui.QIcon(':/file_icons/resources/new.png'))
                 # QtCore.QFileInfo ( fname ).fileName ()
                 action = QtModule.QAction(icon, '&%d %s' % (i + 1, fname),
                                           self)
                 action.setData(QtCore.QVariant(fname))
                 self.connect(action, QtCore.SIGNAL('triggered()'),
                              self.onOpenRecentNetwork)
                 self.ui.menuRecent_Networks.addAction(action)
     else:
         #self.recentNetworks = app_settings.value ( 'RecentNetworks' )
         self.ui.menuRecent_Networks.clear()
         if len(self.recentNetworks):
             for i, fname in enumerate(self.recentNetworks):
                 icon = QtGui.QIcon.fromTheme(
                     'document-new',
                     QtGui.QIcon(':/file_icons/resources/new.png'))
                 # QtCore.QFileInfo ( fname ).fileName ()
                 action = QtModule.QAction(icon, '&%d %s' % (i + 1, fname),
                                           self)
                 action.setData(fname)
                 action.triggered.connect(self.onOpenRecentNetwork)
                 self.ui.menuRecent_Networks.addAction(action)
Exemplo n.º 7
0
	def setupUi ( self, NormalWidget ) :
		#
		self.widget = NormalWidget
		self.labels = []
		self.controls = []
		
		font = QtGui.QFont ()
		labelFontMetric = QtGui.QFontMetricsF ( font )
		label_wi = 0
		char_wi = labelFontMetric.width ( 'x' )
		array_size = self.widget.param.arraySize
		if array_size > 0 :
			label_wi =  char_wi * ( len ( str ( array_size - 1 ) ) + 2 ) # [0]
		
		for i in range ( self.widget.param.arraySize ) :
			self.labels.append ( QtModule.QLabel ( NormalWidget ) )
			self.labels [ i ].setMinimumSize ( QtCore.QSize ( label_wi, UI.HEIGHT ) )
			self.labels [ i ].setMaximumSize ( QtCore.QSize ( label_wi, UI.HEIGHT ) )
			self.labels [ i ].setAlignment ( QtCore.Qt.AlignRight )
			self.labels [ i ].setText ( '[' + str ( i ) + ']' )
			
			elem = []
			
			elem.append ( QtModule.QLineEdit( NormalWidget ) )
			elem.append ( QtModule.QLineEdit( NormalWidget ) )
			elem.append ( QtModule.QLineEdit( NormalWidget ) )
			elem.append ( QtModule.QComboBox ( NormalWidget ) )
			
			elem [ 0 ].setMinimumSize ( QtCore.QSize ( UI.FIELD_WIDTH, UI.HEIGHT ) )
			elem [ 1 ].setMinimumSize ( QtCore.QSize ( UI.FIELD_WIDTH, UI.HEIGHT ) )
			elem [ 2 ].setMinimumSize ( QtCore.QSize ( UI.FIELD_WIDTH, UI.HEIGHT ) )
			
			elem [ 0 ].setMaximumSize ( QtCore.QSize ( UI.FIELD_WIDTH, UI.HEIGHT ) )
			elem [ 1 ].setMaximumSize ( QtCore.QSize ( UI.FIELD_WIDTH, UI.HEIGHT ) )
			elem [ 2 ].setMaximumSize ( QtCore.QSize ( UI.FIELD_WIDTH, UI.HEIGHT ) )
			
			elem [ 3 ].setEditable ( False )
			elem [ 3 ].setMaximumSize ( QtCore.QSize( UI.MAX, UI.COMBO_HEIGHT ) )
			
			for label in VALID_RSL_SPACES :
				elem [ 3 ].addItem ( label )
			space = self.widget.param.spaceArray [ i ]
			if space != None :
				elem [ 3 ].setCurrentIndex ( elem [ 3 ].findText ( space ) )

			self.controls.append ( elem )
			
			sp = QtModule.QSpacerItem ( 0, 0, UI.SP_EXPAND, UI.SP_MIN )
			
			hl = QtModule.QHBoxLayout ()
			hl.addWidget ( self.labels [ i ] )
			hl.addWidget ( elem [ 0 ] )
			hl.addWidget ( elem [ 1 ] )
			hl.addWidget ( elem [ 2 ] )
			hl.addWidget ( elem [ 3 ] )
			hl.addItem ( sp )
			self.widget.param_vl.addLayout ( hl )
		
		self.connectSignals ( NormalWidget )
		QtCore.QMetaObject.connectSlotsByName ( NormalWidget )
Exemplo n.º 8
0
    def setupUi(self, StringWidget):
        #
        self.widget = StringWidget
        self.labels = []
        self.controls = []

        font = QtGui.QFont()
        labelFontMetric = QtGui.QFontMetricsF(font)
        label_wi = 0
        char_wi = labelFontMetric.width('x')
        array_size = self.widget.param.arraySize
        if array_size > 0:
            label_wi = char_wi * (len(str(array_size - 1)) + 2)  # [0]

        for i in range(self.widget.param.arraySize):
            self.labels.append(QtModule.QLabel(StringWidget))
            self.labels[i].setMinimumSize(QtCore.QSize(label_wi, UI.HEIGHT))
            self.labels[i].setMaximumSize(QtCore.QSize(label_wi, UI.HEIGHT))
            self.labels[i].setAlignment(QtCore.Qt.AlignRight)
            self.labels[i].setText('[' + str(i) + ']')

            self.controls.append(QtModule.QLineEdit(StringWidget))
            self.controls[i].setMinimumSize(
                QtCore.QSize(UI.LABEL_WIDTH, UI.HEIGHT))
            self.controls[i].setMaximumSize(QtCore.QSize(UI.MAX, UI.HEIGHT))

            hl = QtModule.QHBoxLayout()
            hl.setStretch(0, 0)
            hl.setStretch(1, 1)
            hl.addWidget(self.labels[i])
            hl.addWidget(self.controls[i])
            self.widget.param_vl.addLayout(hl)

        self.connectSignals(StringWidget)
        QtCore.QMetaObject.connectSlotsByName(StringWidget)
Exemplo n.º 9
0
    def scanXmlNodes(self, filename):
        #
        dom = QtXml.QDomDocument('')
        nodeFilename = self.dirName + '/' + self.liblevel + filename

        file = QtCore.QFile(self.libdir.filePath(filename))

        if file.open(QtCore.QIODevice.ReadOnly):
            if dom.setContent(file):
                node = dom.documentElement()
                if node.nodeName() == 'nodenet' or node.nodeName() == 'node':
                    nodeName = node.attributes().namedItem('name').nodeValue()
                    nodeType = node.attributes().namedItem('type').nodeValue()
                    nodeAuthor = node.attributes().namedItem(
                        'author').nodeValue()
                    nodeIcon = node.attributes().namedItem('icon').nodeValue()
                    nodeHelp = ''
                    help_tag = node.namedItem('help')

                    if not help_tag.isNull():
                        nodeHelp = help_tag.toElement().text()

                    item = QtGui.QStandardItem(nodeName)
                    item.setEditable(False)

                    if not usePySide:
                        item.setData(QtCore.QVariant(nodeAuthor),
                                     QtCore.Qt.UserRole + 1)
                        item.setData(QtCore.QVariant(nodeType),
                                     QtCore.Qt.UserRole + 2)
                        item.setData(QtCore.QVariant(nodeHelp),
                                     QtCore.Qt.UserRole + 3)
                        item.setData(QtCore.QVariant(nodeFilename),
                                     QtCore.Qt.UserRole + 4)
                        item.setData(QtCore.QVariant(nodeIcon),
                                     QtCore.Qt.UserRole + 5)
                    else:
                        item.setData(nodeAuthor, QtCore.Qt.UserRole + 1)
                        item.setData(nodeType, QtCore.Qt.UserRole + 2)
                        item.setData(nodeHelp, QtCore.Qt.UserRole + 3)
                        item.setData(nodeFilename, QtCore.Qt.UserRole + 4)
                        item.setData(nodeIcon, QtCore.Qt.UserRole + 5)

                    if node.nodeName() == 'nodenet':
                        # set Blue color for nodenet items
                        brush = QtGui.QBrush()
                        brush.setColor(QtCore.Qt.blue)
                        item.setForeground(brush)
                        item.setWhatsThis('nodenet')
                    else:
                        item.setWhatsThis('node')

                    self.parentItem.appendRow(item)
        file.close()
Exemplo n.º 10
0
    def setupUi(self, ColorWidget):
        #
        print('>> Ui_ColorWidget_array.setupUi (%s)' % ColorWidget.param.label)
        self.widget = ColorWidget
        self.labels = []
        self.controls = []

        font = QtGui.QFont()
        labelFontMetric = QtGui.QFontMetricsF(font)
        label_wi = 0
        char_wi = labelFontMetric.width('x')
        array_size = self.widget.param.arraySize
        if array_size > 0:
            label_wi = char_wi * (len(str(array_size - 1)) + 2)  # [0]

        for i in range(self.widget.param.arraySize):
            self.labels.append(QtModule.QLabel(ColorWidget))
            self.labels[i].setMinimumSize(QtCore.QSize(label_wi, UI.HEIGHT))
            self.labels[i].setMaximumSize(QtCore.QSize(label_wi, UI.HEIGHT))
            self.labels[i].setAlignment(QtCore.Qt.AlignRight)
            self.labels[i].setText('[' + str(i) + ']')

            elem = []

            elem.append(ColorField(ColorWidget, self.widget.param.value[i], i))
            elem.append(QtModule.QComboBox(ColorWidget))

            elem[1].setEditable(False)
            elem[1].setMaximumSize(QtCore.QSize(UI.MAX, UI.COMBO_HEIGHT))

            for label in VALID_RSL_COLOR_SPACES:
                elem[1].addItem(label)
            space = self.widget.param.spaceArray[i]
            if space != None:
                elem[1].setCurrentIndex(elem[1].findText(space))

            self.controls.append(elem)

            sp = QtModule.QSpacerItem(0, 0, UI.SP_EXPAND, UI.SP_MIN)

            hl = QtModule.QHBoxLayout()
            hl.setContentsMargins(UI.SPACING, UI.SPACING, UI.SPACING,
                                  UI.SPACING)
            hl.setSpacing(UI.SPACING)

            hl.addWidget(self.labels[i])
            hl.addWidget(elem[0])
            hl.addWidget(elem[1])
            hl.addItem(sp)
            self.widget.param_vl.addLayout(hl)

        self.connectSignals(ColorWidget)
        QtCore.QMetaObject.connectSlotsByName(ColorWidget)
Exemplo n.º 11
0
    def setupParameters(self):
        #
        if self.node is not None:
            #
            # get known node parametres
            #
            for name in [
                    'text_color', 'bg_color', 'opacity', 'border', 'justify',
                    'text'
            ]:
                param = self.node.getInputParamByName(name)
                if param is not None:
                    if name == 'text':
                        self.text = param.value
                        #print '* text = %s' % self.text
                    elif name == 'border':
                        self.showBorder = param.value
                        #print '* showBorder = %s' % self.showBorder
                    elif name == 'opacity':
                        self.opacity = param.value
                        #print '* opacity = %f' % self.opacity
                    elif name == 'bg_color':
                        r = param.value[0]
                        g = param.value[1]
                        b = param.value[2]
                        self.bgColor = QtGui.QColor(r * 255, g * 255, b * 255)
                    elif name == 'text_color':
                        r = param.value[0]
                        g = param.value[1]
                        b = param.value[2]
                        self.textColor = QtGui.QColor(r * 255, g * 255,
                                                      b * 255)
                        #print '* text_color = %f %f %f' % ( r, g, b )
                    elif name == 'justify':
                        if param.value == 0:
                            self.justify = QtCore.Qt.AlignLeft
                        elif param.value == 1:
                            self.justify = QtCore.Qt.AlignHCenter
                        elif param.value == 2:
                            self.justify = QtCore.Qt.AlignRight

            self.label_widget = GfxNodeLabel(self.node.label, bgFill=False)
            self.label_widget.setBold()
            self.label_widget.setNormalColor(self.textColor)
            if self.isSelected(): self.label_widget.setSelected()

            self.text_widget = GfxNodeLabel(self.text, bgFill=False)
            self.text_widget.setNormalColor(self.textColor)
            self.text_widget.setNormal(True)
            self.text_widget.justify = self.justify

            self.label_widget.setParentItem(self)
            self.text_widget.setParentItem(self)
Exemplo n.º 12
0
    def __init__(self, node):
        #
        QtModule.QGraphicsItem.__init__(self)

        self.label_widget = None
        self.text_widget = None

        self.headerFont = QtGui.QFont()
        self.paramsFont = QtGui.QFont()

        self.x_offset = 10
        self.y_offset = 10
        self.radius = 10

        # node parameters
        self.showBorder = True
        self.justify = QtCore.Qt.AlignLeft  # left:center:right
        self.text = ''
        self.opacity = 0.5
        self.bgColor = QtGui.QColor(128, 128, 128)
        self.textColor = QtGui.QColor(0, 0, 0)
        self.selectedColor = QtGui.QColor(250, 250, 250)

        self.node = node

        if self.node is not None:
            self.updateGfxNode()
            (x, y) = self.node.offset
            self.setPos(x, y)

        self.PenBorderNormal = QtGui.QPen(QtGui.QBrush(self.textColor), 1.0,
                                          QtCore.Qt.SolidLine,
                                          QtCore.Qt.RoundCap,
                                          QtCore.Qt.RoundJoin)

        self.PenBorderSelected = QtGui.QPen(QtGui.QBrush(self.selectedColor),
                                            2.0, QtCore.Qt.SolidLine,
                                            QtCore.Qt.RoundCap,
                                            QtCore.Qt.RoundJoin)

        self.bgColor.setAlphaF(self.opacity)

        self.BrushNodeNormal = QtGui.QBrush(self.bgColor)

        # flag (new from QT 4.6...)
        self.setFlag(QtModule.QGraphicsItem.ItemSendsScenePositionChanges)
        self.setFlag(QtModule.QGraphicsItem.ItemSendsGeometryChanges)
        #self.setFlag ( QtModule.QGraphicsItem.ItemIsFocusable )

        # qt graphics stuff
        self.setFlag(QtModule.QGraphicsItem.ItemIsMovable)
        self.setFlag(QtModule.QGraphicsItem.ItemIsSelectable)
        self.setZValue(1)
Exemplo n.º 13
0
 def shape(self):
     #
     shape = QtGui.QPainterPath()
     shape.addRect(self.boundingRect())
     #shape += self.header['input'].shape()
     #shape += self.header['output'].shape()
     return shape
Exemplo n.º 14
0
 def startDrag(self, dropActions):
     #
     if DEBUG_MODE: print('>> NodeTreeView::startDrag')
     selectedIdx = self.selectedIndexes()
     # for idx in selectedIdx :
     idx = selectedIdx[0]
     item = self.model().itemFromIndex(idx)
     #print "item = %s" % item.text()
     # set custom data
     data = QtCore.QByteArray()
     stream = QtCore.QDataStream(data, QtCore.QIODevice.WriteOnly)
     itemName = item.text()
     if usePyQt4:
         itemFilename = item.data(QtCore.Qt.UserRole + 4).toString()
     else:
         itemFilename = item.data(QtCore.Qt.UserRole + 4)
     if not usePyQt5:
         if usePySide:
             stream.writeString(itemFilename)
         else:
             stream << itemFilename
     else:
         stream.writeBytes(itemFilename)
     if DEBUG_MODE: print('* write itemFilename = %s' % (itemFilename))
     mimeData = QtCore.QMimeData()
     mimeData.setData('application/x-text', data)
     # set drag
     drag = QtGui.QDrag(self)
     drag.setMimeData(mimeData)
     #drag.setPixmap ( QtGui.QPixmap(':/node.png') )
     if not usePyQt5:
         drag.start(QtCore.Qt.CopyAction)
     else:
         drag.exec_(QtCore.Qt.CopyAction)
Exemplo n.º 15
0
    def paint(self, painter, option, widget):
        # print ( ">> GfxSwatchNode.paint" )
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform)

        self.paintShadow(painter)

        pen = self.PenBorderNormal

        if self.isSelected(): pen = self.PenBorderSelected

        painter.setPen(QtCore.Qt.NoPen)
        painter.setBrush(self.brush)  # QtCore.Qt.NoBrush
        painter.drawRoundedRect(self.rect, self.radius, self.radius,
                                QtCore.Qt.AbsoluteSize)

        if self.pixmap is not None:
            if not self.pixmap.isNull():
                #painter.drawPixmap ( 0, 0, self.pixmap.scaled ( self.swatchSize, self.swatchSize,  transformMode = QtCore.Qt.SmoothTransformation ) )
                imageBrush = QtGui.QBrush(
                    self.pixmap.scaled(
                        self.swatchSize,
                        self.swatchSize,
                        transformMode=QtCore.Qt.SmoothTransformation))
                painter.setBrush(imageBrush)

        painter.setPen(pen)
        painter.drawRoundedRect(self.rect, self.radius, self.radius,
                                QtCore.Qt.AbsoluteSize)
Exemplo n.º 16
0
	def createFromLink ( link ):
		#
		gfxLink = GfxLink ()
		gfxLink.link = link
		gfxLink.path = QtGui.QPainterPath ()
		gfxLink.adjust ()

		return gfxLink
Exemplo n.º 17
0
    def onNodeChanged(self):
        #
        if DEBUG_MODE: print '>> ExportShaderDialog.onNodeChanged'
        self.disconnectSignals()
        item = self.ui.list_nodes.currentItem()
        if not usePyQt5:
            node = item.data(QtCore.Qt.UserRole + 1).toPyObject()
        else:
            node = item.data(QtCore.Qt.UserRole + 1)
        print '* (%s) selected' % node.label
        self.ui.node.setNode(node)
        self.ui.prop_tabWidget.setCurrentIndex(0)

        if self.ui.list_nodes.currentRow() != 1:
            self.updateNodeParams(node)
            self.ui.list_inputs.clear()
            self.ui.list_outputs.clear()

            linkedFont = QtGui.QFont()
            linkedFont.setItalic(True)
            linkedBrush = QtGui.QBrush()
            linkedBrush.setColor(QtCore.Qt.blue)
            # setup input params list
            for param in node.inputParams:
                item = QtModule.QListWidgetItem(param.label)
                item.setData(QtCore.Qt.UserRole + 1, QtCore.QVariant(param))
                item.setData(QtCore.Qt.UserRole + 2, QtCore.QVariant(node))
                if node.isInputParamLinked(param):
                    item.setFont(linkedFont)
                    item.setForeground(linkedBrush)
                self.ui.list_inputs.addItem(item)

            # setup output params list
            for param in node.outputParams:
                item = QtModule.QListWidgetItem(param.label)
                item.setData(QtCore.Qt.UserRole + 1, QtCore.QVariant(param))
                item.setData(QtCore.Qt.UserRole + 2, QtCore.QVariant(node))
                if node.isOutputParamLinked(param):
                    item.setFont(linkedFont)
                    item.setForeground(linkedBrush)
                self.ui.list_outputs.addItem(item)
        else:
            self.updateComputedParams()

        self.connectSignals()
Exemplo n.º 18
0
    def drawBackground(self, painter, rect):
        #
        sc_rect = self.sceneRect()
        bbrush = QtGui.QBrush(QtGui.QColor(148, 148,
                                           148))  ## painter.background()
        painter.fillRect(rect, bbrush)

        if self.drawGrid:
            #  print( "grid size = %d" % self.gridSize )
            gr_pen = QtGui.QPen(QtGui.QColor(180, 180, 180))
            gr_pen.setWidth(0)
            painter.setPen(gr_pen)
            for x in range(int(sc_rect.x()), int(sc_rect.right()),
                           self.gridSize):
                painter.drawLine(x, sc_rect.y(), x, sc_rect.bottom())
            for y in range(int(sc_rect.y()), int(sc_rect.bottom()),
                           self.gridSize):
                painter.drawLine(sc_rect.x(), y, sc_rect.right(), y)
Exemplo n.º 19
0
	def adjust ( self ) :
		#
		from meShaderEd import getDefaultValue
		self.isStraight = getDefaultValue ( app_settings, 'WorkArea', 'straight_links' )

		if self.srcConnector is not None : self.srcPoint = self.srcConnector.getCenterPoint ()
		if self.dstConnector is not None : self.dstPoint = self.dstConnector.getCenterPoint ()

		self.prepareGeometryChange ()

		del self.points [ : ]  # clear bezier points
		self.path = None
		if self.srcPoint is not None and self.dstPoint is not None :
			self.path = QtGui.QPainterPath ()
			# first point
			self.points.append ( self.srcPoint )
			self.path.moveTo ( self.points [ 0 ] )

			# draw curved spline if isStraight is False
			if not self.isStraight :
				# hull spline
				hull = QtCore.QRectF ( self.srcPoint, self.dstPoint )
				centerX = hull.center ().x ()
				centerY = hull.center ().y ()
				# second point
				offsetVX = min ( abs ( hull.topRight ().x () - hull.topLeft ().x () ) * 0.1, 40 )
				offsetVY = 0.0

				p1 = self.srcPoint + QtCore.QPointF ( offsetVX, offsetVY )
				self.points.append ( p1 )
				# third point
				p2 =   QtCore.QPointF ( centerX, self.srcPoint.y() )
				self.points.append ( p2 )
				# fourth point
				p3 = QtCore.QPointF ( centerX, centerY )
				self.points.append ( p3 )
				# fifth point (bezier tangent)
				p4 = QtCore.QPointF ( centerX, centerY )
				self.points.append ( p4 )
				# sixth point
				p5 = QtCore.QPointF ( centerX, self.dstPoint.y() )
				self.points.append ( p5 )
				# seventh point
				p6 = self.dstPoint - QtCore.QPointF ( offsetVX, offsetVY )
				self.points.append ( p6 )
			# last point
			self.points.append ( self.dstPoint )
			if self.isStraight :
				#if DEBUG_MODE : print '* GfxLink: Straight mode'
				self.path.lineTo ( self.dstPoint )
			else:
				#if DEBUG_MODE : print '* GfxLink: Curved mode'
				#self.path.cubicTo ( self.points[1], self.points[2], self.points[3] )
				#self.path.cubicTo ( self.points[5], self.points[6], self.points[7] )
				self.path.cubicTo ( p1, p1, p3 )
				self.path.cubicTo ( p6, p6, self.dstPoint )
			self.rect = self.path.boundingRect ()
Exemplo n.º 20
0
 def getLabelSize(self):
     #
     labelFontMetric = QtGui.QFontMetricsF(self.font)
     lines = self.text.split('\n')
     height = 0
     width = 0
     for line in lines:
         height += labelFontMetric.height() + 1
         width = max(width, labelFontMetric.width(line)) + 1
     return (width, height)
Exemplo n.º 21
0
    def updateGui(self, value):
        #
        r = value[0]
        g = value[1]
        b = value[2]

        pixmap = QtGui.QPixmap(UI.COLOR_WIDTH, UI.HEIGHT)
        pixmap.fill(QtCore.Qt.transparent)
        painter = QtGui.QPainter()
        painter.begin(pixmap)
        painter.setRenderHint(QtGui.QPainter.Antialiasing, True)

        color = QtGui.QColor(r * 255, g * 255, b * 255)

        painter.setPen(QtCore.Qt.NoPen)
        painter.setBrush(color)
        painter.drawRect(0.0, 0.0, UI.COLOR_WIDTH, UI.HEIGHT)
        painter.end()

        self.colorEdit.setPixmap(pixmap)
Exemplo n.º 22
0
    def __init__(self, dirName):
        #
        self.dirName = dirName
        self.libdir = QtCore.QDir(dirName)
        self.model = QtGui.QStandardItemModel()
        self.parentItem = self.model.invisibleRootItem()

        print '>> NodeLibrary: libdir = %s' % dirName

        self.liblevel = ''
        self.scanLibDir()
Exemplo n.º 23
0
	def get_bg_color ( self ) :
		#
		bg = QtGui.QColor ( 128, 128, 128 )
		
		if self.node.format == 'rsl' :
			bg = app_colors [ 'rsl_node_bg' ] 
		elif self.node.format == 'rib' :
			bg = app_colors [ 'rib_node_bg' ] 
		elif self.node.format == 'image' :
			bg = app_colors [ 'image_node_bg' ]
		return bg
Exemplo n.º 24
0
    def setImage(self, imageName):
        #
        self.pixmap = QtGui.QPixmap()
        wi = 256
        hi = 256

        if imageName != '':
            print(">> ImageView.setImage name = %s" % imageName)

            imageReader = QtGui.QImageReader(imageName)

            if imageReader.canRead():
                image = imageReader.read()
                if not self.pixmap.convertFromImage(image):
                    print("!! QPixmap can't convert %s" % imageName)
            else:
                print("!! QImageReader can't read %s..." % imageName)
                # print imageReader.supportedImageFormats ()
                print("!! Lets try PIL module ...")
                import Image
                image = Image.open(imageName)
                # image.verify()

                import os
                from global_vars import app_global_vars

                tmpname = app_global_vars['TempPath'] + '/' + os.path.basename(
                    imageName + '.png')
                print("** Save %s ..." % tmpname)
                image.save(tmpname)

                self.pixmap = QtGui.QPixmap(tmpname)

        if not self.pixmap.isNull():
            wi = self.pixmap.width()
            hi = self.pixmap.height()
        else:
            print("!! ImageView: isNull()")

        self.scene().setSceneRect(0, 0, wi, hi)
        self.scene().update()
Exemplo n.º 25
0
 def onClicked(self, colorEdit=None):
     #print ( ">> ColorWidget::onClicked " ), colorEdit
     redValue = int(self.widget.param.value[0] * 255)
     greenValue = int(self.widget.param.value[1] * 255)
     blueValue = int(self.widget.param.value[2] * 255)
     newColor = QtModule.QColorDialog.getColor(
         QtGui.QColor(redValue, greenValue, blueValue), self.widget)
     if newColor.isValid():
         newValue = [newColor.redF(), newColor.greenF(), newColor.blueF()]
         self.widget.param.setValue(newValue)
         #self.widget.param.paramChanged ()
         self.updateGui(self.widget.param.value)
Exemplo n.º 26
0
def setDefaultValue(key, def_value):
    if not app_settings.contains(key):
        app_settings.setValue(key, def_value)
    value = app_settings.value(key)
    if usePyQt4:
        if value.toString() == 'true': value = True
        elif value.toString() == 'false': value = False
        else:
            if isinstance(def_value, QtGui.QColor):
                value = QtGui.QColor(value)
            else:
                value = str(value.toString())
    else:
        if value == 'true': value = True
        elif value == 'false': value = False
        else:
            if isinstance(def_value, QtGui.QColor):
                value = QtGui.QColor(value)
            else:
                value = str(value)
    return value
Exemplo n.º 27
0
def getDefaultValue(settings, group, key, def_value=None):
    if group != '': settings.beginGroup(group)
    value = settings.value(key)
    if group != '': settings.endGroup()
    if usePyQt4:
        if value.toString() == 'true': value = True
        elif value.toString() == 'false': value = False
        else:
            if def_value is not None and isinstance(def_value, QtGui.QColor):
                value = QtGui.QColor(value)
            else:
                value = str(value.toString())
    else:
        if value == 'true' or value is True: value = True
        elif value == 'false' or value is False: value = False
        else:
            if def_value is not None and isinstance(def_value, QtGui.QColor):
                value = QtGui.QColor(value)
            else:
                value = str(value)
    return value
Exemplo n.º 28
0
 def onClicked(self):
     print(">> ColorWidget::onClicked")
     redValue = int(self.widget.param.value[0] * 255)
     greenValue = int(self.widget.param.value[1] * 255)
     blueValue = int(self.widget.param.value[2] * 255)
     colorSelected = QtModule.QColorDialog.getColor(
         QtGui.QColor(redValue, greenValue, blueValue), self.widget)
     if colorSelected.isValid():
         newValue = (colorSelected.redF(), colorSelected.greenF(),
                     colorSelected.blueF())
         self.widget.param.setValue(newValue)
         #self.widget.param.paramChanged ()
         self.updateGui(self.widget.param.value)
Exemplo n.º 29
0
    def setNodeCode(self, editNodeCode, mode='SL', readOnly=False):
        #
        self.editNodeCode = editNodeCode

        if self.editNodeCode is not None:
            code = self.editNodeCode

            doc = QtGui.QTextDocument()

            font = QtGui.QFont('Monospace')
            font.setFixedPitch(True)
            font.setPointSize(UI.FONT_HEIGHT)

            codeSyntax = CodeSyntaxHighlighter(doc, mode)

            self.ui.textEdit.setDocument(doc)
            self.ui.textEdit.setTabStopWidth(UI.TAB_SIZE)
            self.ui.textEdit.setFont(font)
            self.ui.textEdit.setLineWrapMode(QtModule.QTextEdit.NoWrap)
            self.ui.textEdit.setReadOnly(readOnly)
        else:
            code = ''
        self.ui.textEdit.setPlainText(code)
Exemplo n.º 30
0
	def paint ( self, painter, option, widget ) :
		#
		if self.path is not None :
			painter.setRenderHint ( QtGui.QPainter.Antialiasing )
			brush = self.brushNormal
			if self.isLinkSelected : brush = self.brushSelected
			painter.setPen( QtGui.QPen ( brush,
																	1.25,
																	QtCore.Qt.SolidLine,
																	QtCore.Qt.RoundCap,
																	QtCore.Qt.RoundJoin
																)
										)
			painter.drawPath ( self.path )