Exemple #1
0
 def __init__(self, index, **kwds):
     super(GraphicsItemModel, self).__init__()
     self.index = QtCore.QPersistentModelIndex(index)
     self.rect = QtCore.QRectF(0,0,0,0)
     self.shape = QtGui.QPainterPath()
     self.brush = QtGui.QBrush()
     self.pen = QtGui.QPen()
     self.setFlags(self.ItemIsSelectable | self.ItemIsFocusable)
     self.onInit(**kwds)
Exemple #2
0
class GraphicsItemModel(QtGui.QGraphicsItem):
    unselected_color = QtGui.QColor(100,100,100)
    selected_color = QtGui.QColor(100,250,100)
    #------------------------------------------------------------
    def __init__(self, index, **kwds):
        super(GraphicsItemModel, self).__init__()
        self.index = QtCore.QPersistentModelIndex(index)
        self.rect = QtCore.QRectF(0,0,0,0)
        self.shape = QtGui.QPainterPath()
        self.brush = QtGui.QBrush()
        self.pen = QtGui.QPen()
        self.setFlags(self.ItemIsSelectable | self.ItemIsFocusable)
        self.onInit(**kwds)
        
    #------------------------------------------------------------
    def onInit(self, **kwds):      
        pass
    
    #------------------------------------------------------------
    def getIndex(self, column=0):
        if not self.index.isValid() :
            raise Exception('Persistent Model Index is not Valid!')
        return self.scene().model.index(self.index.row(), column, self.index.parent())        
    
    #------------------------------------------------------------
    def boundingRect(self):
        return self.rect
    
    #------------------------------------------------------------
    def shape(self):
        return self.shape
    
    #------------------------------------------------------------
    def paint(self, painter, option, widget):
        if self.isSelected() :
            self.brush.setColor(self.selected_color)
        else:
            self.brush.setColor(self.unselected_color)            
        painter.setBrush(self.brush)
        painter.setPen(self.pen)
        painter.drawPath(self.shape)
    
    #------------------------------------------------------------
    def data(self, column, role=Qt.DisplayRole):
        if self.scene() is None :
            return QtCore.QVariant()
        
        return self.scene().data(self.getIndex(column), role)
    
    #------------------------------------------------------------
    def setData(self, column, value, role=Qt.EditRole):
        if self.scene() is None :
            return False
        
        self.scene().setData(self.getIndex(column), QtCore.QVariant(value), role)
Exemple #3
0
    def fromString(cls, strdata):
        """
        Restores a color set instance from the inputed string data.

        :param      strdata | <str>
        """
        if (not strdata):
            return None

        from xml.etree import ElementTree

        xelem = ElementTree.fromstring(str(strdata))
        output = cls(xelem.get('name'), xelem.get('colorGroups').split(','))

        for xcolor in xelem:
            colorName = xcolor.get('name')

            for xcolorval in xcolor:
                color = QtGui.QColor(int(xcolorval.get('red')),
                                     int(xcolorval.get('green')),
                                     int(xcolorval.get('blue')),
                                     int(xcolorval.get('alpha')))

                output.setColor(colorName, color, xcolorval.get('group'))

        return output
    def __init__(self, model=None, proxyModel=None, **kwds):
        self._qtclass = QtGui.QWidget

        apiUtils.synthesize(self, 'model', model)
        apiUtils.synthesize(self, 'proxyModel', proxyModel)
        apiUtils.synthesize(self, 'dataMapper', QtGui.QDataWidgetMapper())
        #self._dataMapper.setSubmitPolicy(QtGui.QDataWidgetMapper.ManualSubmit)

        BaseGUI.__init__(self, **kwds)
Exemple #5
0
    def color(self, name, colorGroup=None):
        """
        Returns the color for the given name at the inputed group.  If no \
        group is specified, the first group in the list is used.

        :param      name        | <str>
                    colorGroup  | <str> || None

        :return     <QColor>
        """
        if (not colorGroup and self._colorGroups):
            colorGroup = self._colorGroups[0]

        if (not colorGroup):
            return QtGui.QColor()

        return self._colors.get(str(name), {}).get(str(colorGroup),
                                                   QtGui.QColor())
Exemple #6
0
    def getQTApp():
        QtCore.QCoreApplication.setOrganizationName(settings.COMPANY)
        QtCore.QCoreApplication.setApplicationName(settings.PKG_NAME)
        app = QtGui.QApplication.instance()
        if not app:
            app = QtGui.QApplication(sys.argv, apiUtils.isGUIAvailable())
            app.setStyle('Plastique')
            #app.setStyleSheet(Core.getStyleSheet())

        return app
Exemple #7
0
def pauseDialog(msg='', parent=None, func=None):
    msgbox = QtGui.QMessageBox(parent)
    msgbox.setAttribute(Qt.WA_DeleteOnClose)
    msgbox.setWindowTitle('Message')
    msgbox.setText(msg)
    yesbtn = msgbox.addButton(QtGui.QMessageBox.Yes)
    yesbtn.clicked.connect(func)
    msgbox.addButton(QtGui.QMessageBox.No)
    msgbox.setModal(False)
    msgbox.show()
Exemple #8
0
    def colors(self, name):
        """
        Returns all the colors in order for the inputed color name.

        :return     [<QColor>, ..]
        """
        output = []
        colors = self._colors.get(name, {})
        for colorType in self._colorGroups:
            output.append(colors.get(colorType, QtGui.QColor()))
        return output
    def onFinalize(self):
        self.main_splitter = QtGui.QSplitter()

        self.main_splitter.addWidget(self.treeView)
        self.main_splitter.addWidget(self.scrollArea)

        self.mainLayout.addWidget(self.main_splitter)
        self.main_splitter.setSizes([150, 250])
        self.setEditors()
        for key, editor in list(self.editors.items()):
            self.properties_layout.addWidget(editor)
            editor.setVisible(False)
Exemple #10
0
    def palette(self):
        """
        Converts the current color data to a QPalette.

        :return     <QPalette>
        """
        palette = QtGui.QPalette()

        for colorGroup, qColorGroup in list(self.GroupMapping.items()):
            for colorRole, qColorRole in list(self.RoleMapping.items()):
                color = self.color(colorRole, colorGroup)

                palette.setColor(qColorGroup, qColorRole, color)
        return palette
Exemple #11
0
    def loadUi(self, parent=None):
        self.setObjectName("PathWidget")
        self.resize(459, 38)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum,
                                       QtGui.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
        self.setSizePolicy(sizePolicy)
        self.horizontalLayout = QtGui.QHBoxLayout(self)
        self.horizontalLayout.setSpacing(6)
        self.horizontalLayout.setContentsMargins(6, 0, 6, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.ui_Label = QtGui.QLabel(self)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum,
                                       QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.ui_Label.sizePolicy().hasHeightForWidth())
        self.ui_Label.setSizePolicy(sizePolicy)
        self.ui_Label.setText("")
        self.ui_Label.setObjectName("ui_Label")
        self.horizontalLayout.addWidget(self.ui_Label)
        self.ui_Field = QtGui.QLineEdit(self)
        self.ui_Field.setObjectName("ui_Field")
        self.horizontalLayout.addWidget(self.ui_Field)
        self.ui_Picker = QtGui.QToolButton(self)
        self.ui_Picker.setObjectName("ui_Picker")
        self.horizontalLayout.addWidget(self.ui_Picker)
        self.actionShow_in_explorer = QtGui.QAction(self)
        self.actionShow_in_explorer.setObjectName("actionShow_in_explorer")

        self.setWindowTitle(
            QtGui.QApplication.translate("PathWidget", "Path Widget", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.ui_Picker.setText(
            QtGui.QApplication.translate("PathWidget", "...", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.actionShow_in_explorer.setText(
            QtGui.QApplication.translate("PathWidget", "Show in explorer",
                                         None, QtGui.QApplication.UnicodeUTF8))

        QtCore.QMetaObject.connectSlotsByName(self)
Exemple #12
0
 def setupStyle(self):
     self.setWizardStyle(QtGui.QWizard.ModernStyle)
     imgfilepath = Path(settings.PKG_RESOURCE_PATH).join(
         'images', 'Logo_lg.png')
     self.setPixmap(QtGui.QWizard.WatermarkPixmap,
                    QtGui.QPixmap(imgfilepath))
Exemple #13
0
 def getSaveFileFromUser(self, parent=None, ext=[]):
     file_dialog = QtGui.QFileDialog(parent)
     file_dialog.setAcceptMode(QtGui.QFileDialog.AcceptSave)
     file_dialog.setViewMode(QtGui.QFileDialog.Detail)
     return self._return_file(file_dialog)
Exemple #14
0
 def getDirFromUser(self, parent=None):
     file_dialog = QtGui.QFileDialog(parent)
     file_dialog.setFileMode(QtGui.QFileDialog.Directory)
     file_dialog.setOption(QtGui.QFileDialog.ShowDirsOnly)
     file_dialog.setViewMode(QtGui.QFileDialog.Detail)
     return self._return_file(file_dialog)
Exemple #15
0
 def getFileFromUser(self, parent=None, ext=''):
     file_dialog = QtGui.QFileDialog(parent)
     file_dialog.setViewMode(QtGui.QFileDialog.Detail)
     file_dialog.setNameFilter(ext)
     return self._return_file(file_dialog)
Exemple #16
0
 def center(self):
     qr = self._qtclass.frameGeometry(self)
     cp = QtGui.QDesktopWidget().availableGeometry().center()
     qr.moveCenter(cp)
     self.move(qr.topLeft())