示例#1
0
    def paint(self, painter, option, index):
        """ Paint the items in the table.
            
            If the item referred to by <index> is a StarRating, we handle the
            painting ourselves. For the other items, we let the base class
            handle the painting as usual.

            In a polished application, we'd use a better check than the 
            column number to find out if we needed to paint the stars, but
            it works for the purposes of this example.
        """
        if index.column() == 3:
            starRating = StarRating(index.data())

            # If the row is currently selected, we need to make sure we
            # paint the background accordingly.
            if option.state & QStyle.State_Selected:
                # The original C++ example used option.palette.foreground() to
                # get the brush for painting, but there are a couple of
                # problems with that:
                #   - foreground() is obsolete now, use windowText() instead
                #   - more importantly, windowText() just returns a brush
                #     containing a flat color, where sometimes the style
                #     would have a nice subtle gradient or something.
                # Here we just use the brush of the painter object that's
                # passed in to us, which keeps the row highlighting nice
                # and consistent.
                painter.fillRect(option.rect, painter.brush())

            # Now that we've painted the background, call starRating.paint()
            # to paint the stars.
            starRating.paint(painter, option.rect, option.palette)
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
示例#2
0
    def __init__(self, parent):
        """Initialization"""

        QStyledItemDelegate.__init__(self, parent)

        self.bg_color = QColor("#000000")
        self.bg_alternate_color = QColor("#333333")
        self.new_bg_color = QColor("#0044dd")
        self.new_bg_alternate_color = QColor("#223399")
        self.user_color = QColor("#7AB4F5")
        self.time_color = QColor("#7AB4F5")
        self.replyto_color = QColor("#7AB4F5")

        self.text_color = QColor("#FFFFFF")
        self.separator_color = QColor("#000000")
        self.fsize = 1.0
        self.fm = None
        self.minifm = None

        self.normFont = None
        self.miniFont = None

        #        print os.path.join(os.path.dirname(__file__),
        #                                  'icons', 'reply.png')
        self.reply_icon = QPixmap(os.path.join(os.path.dirname(__file__), "icons", "reply.png"))
        #        print dir(self.reply_icon)
        self.retweet_icon = QPixmap(os.path.join(os.path.dirname(__file__), "icons", "retweet.png"))
        self.geoloc_icon = QPixmap(os.path.join(os.path.dirname(__file__), "icons", "geoloc.png"))
示例#3
0
    def __init__(self, parent):
        '''Initialization'''

        QStyledItemDelegate.__init__(self, parent)

        self.bg_color = QColor('#000000')
        self.bg_alternate_color = QColor('#333333')
        self.new_bg_color = QColor('#0044dd')
        self.new_bg_alternate_color = QColor('#223399')
        self.user_color = QColor('#7AB4F5')
        self.time_color = QColor('#7AB4F5')
        self.replyto_color = QColor('#7AB4F5')

        self.text_color = QColor('#FFFFFF')
        self.separator_color = QColor('#000000')
        self.fsize = 1.0
        self.fm = None
        self.minifm = None

        self.normFont = None
        self.miniFont = None

#        print os.path.join(os.path.dirname(__file__),
#                                  'icons', 'reply.png')
        self.reply_icon = QPixmap(os.path.join(os.path.dirname(__file__),
                                  'icons', 'reply.png'))
#        print dir(self.reply_icon)
        self.retweet_icon = QPixmap(os.path.join(os.path.dirname(__file__),
                                    'icons', 'retweet.png'))
        self.geoloc_icon = QPixmap(os.path.join(os.path.dirname(__file__),
                                   'icons', 'geoloc.png'))
示例#4
0
 def setModelData(self, editor, model, index):
     """ Get the data from our custom editor and stuffs it into the model.
     """
     if index.column() == 6:
         model.setData(index, editor.starRating.starCount)
     else:
         QStyledItemDelegate.setModelData(self, editor, model, index)
示例#5
0
    def paint(self, painter, option, index):
        """ Paint the items in the table.
            
            If the item referred to by <index> is a StarRating, we handle the
            painting ourselves. For the other items, we let the base class
            handle the painting as usual.

            In a polished application, we'd use a better check than the 
            column number to find out if we needed to paint the stars, but
            it works for the purposes of this example.
        """
        if index.column() == 3:
            starRating = StarRating(index.data())
            
            # If the row is currently selected, we need to make sure we
            # paint the background accordingly.
            if option.state & QStyle.State_Selected:
                # The original C++ example used option.palette.foreground() to
                # get the brush for painting, but there are a couple of 
                # problems with that:
                #   - foreground() is obsolete now, use windowText() instead
                #   - more importantly, windowText() just returns a brush
                #     containing a flat color, where sometimes the style 
                #     would have a nice subtle gradient or something. 
                # Here we just use the brush of the painter object that's
                # passed in to us, which keeps the row highlighting nice
                # and consistent.
                painter.fillRect(option.rect, painter.brush())
            
            # Now that we've painted the background, call starRating.paint()
            # to paint the stars.
            starRating.paint(painter, option.rect, option.palette)
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
示例#6
0
 def setModelData(self, editor, model, index):
     """ Get the data from our custom editor and stuffs it into the model.
     """
     if index.column() == 3:
         model.setData(index, editor.starRating.starCount)
     else:
         QStyledItemDelegate.setModelData(self, editor, model, index)
示例#7
0
    def __init__(self, parent):
        '''Initialization'''

        QStyledItemDelegate.__init__(self, parent)

        self.bg_color = QColor('#000000')
        self.bg_alternate_color = QColor('#333333')
        self.new_bg_color = QColor('#0044dd')
        self.new_bg_alternate_color = QColor('#223399')
        self.user_color = QColor('#7AB4F5')
        self.time_color = QColor('#7AB4F5')
        self.replyto_color = QColor('#7AB4F5')

        self.text_color = QColor('#FFFFFF')
        self.separator_color = QColor('#000000')
        self.fsize = 1.0
        self.fm = None
        self.minifm = None

        self.normFont = None
        self.miniFont = None

        #        print os.path.join(os.path.dirname(__file__),
        #                                  'icons', 'reply.png')
        self.reply_icon = QPixmap(
            os.path.join(os.path.dirname(__file__), 'icons', 'reply.png'))
        #        print dir(self.reply_icon)
        self.retweet_icon = QPixmap(
            os.path.join(os.path.dirname(__file__), 'icons', 'retweet.png'))
        self.geoloc_icon = QPixmap(
            os.path.join(os.path.dirname(__file__), 'icons', 'geoloc.png'))
示例#8
0
    def paint(self, painter, option, index):
        if not self.draw_focus:
            option.state = option.state & (~QStyle.State_HasFocus)

        if not isinstance(index.data(), GraphRow):
            QStyledItemDelegate.paint(self, painter, option, index)
            return

        row = index.data()

        has_focus = option.state & QStyle.State_HasFocus
        option.state = option.state & (~QStyle.State_HasFocus)
        QStyledItemDelegate.paint(self, painter, option, index)

        lane_size = option.rect.height()

        painter.save()

        painter.setClipRect(option.rect)
        painter.translate(option.rect.x(), option.rect.y())
        painter.scale(lane_size, lane_size)
        painter.setRenderHint(QPainter.Antialiasing, True)

        max_lane = row.commit_node.lane

        if row.prev_row:
            for edge in row.prev_row.edges:
                max_lane = max(max_lane, edge.from_lane, edge.to_lane)
                self.draw_edge(painter, option, edge, -1)
        for edge in row.edges:
            max_lane = max(max_lane, edge.from_lane, edge.to_lane)
            self.draw_edge(painter, option, edge, 0)

        pen = QPen(Qt.black, self.node_thickness)
        painter.setPen(pen)
        painter.setBrush(option.palette.window())
        painter.drawEllipse(
            QPointF(row.commit_node.lane + 0.5, 0.5),
            self.node_radius, self.node_radius)

        if row.log_entry.refs:
            painter.resetTransform()
            painter.translate(
                option.rect.x() + (max_lane + 1) * lane_size,
                option.rect.y())

            ref_x = 0
            for ref in row.log_entry.refs:
                ref_x = self.draw_ref(painter, option, ref, row.repo, ref_x)

        painter.restore()

        if has_focus:
            painter.save()
            focus_option = QStyleOptionFocusRect()
            focus_option.rect = option.rect
            QApplication.style().drawPrimitive(QStyle.PE_FrameFocusRect,
                focus_option, painter)
            painter.restore()
示例#9
0
 def setEditorData(self, editor, index):
     if index.column() == sbml_entitytablemodel.REACTION_ROW.REACTANTS:
         text = index.model().data(index, Qt.DisplayRole).toString()
         i = editor.findText(text)
         if i == -1:
             i = 0
         editor.setCurrentIndex(i)
     else:
         QStyledItemDelegate.setEditorData(self, editor, index)
 def setEditorData(self, editor, index):
     if index.column() == sbml_entitytablemodel.REACTION_ROW.REACTANTS:
         text = index.model().data(index, Qt.DisplayRole).toString()
         i = editor.findText(text)
         if i == -1:
             i = 0
         editor.setCurrentIndex(i)
     else:
         QStyledItemDelegate.setEditorData(self, editor, index)
示例#11
0
    def __init__(self, p_def):

        QStyledItemDelegate.__init__(self)

        self._definition = []

        for _index in range(len(p_def)):

            if p_def[_index]["DISPLAY"]:
                self._definition.append(p_def[_index])
    def setModelData(self, editor, model, index):
#        if index.column() == TEU:
#            model.setData(index, QVariant(editor.value()))
#        elif index.column() in (OWNER, COUNTRY):
#            model.setData(index, QVariant(editor.currentText()))
#        elif index.column() == NAME:
#            model.setData(index, QVariant(editor.text()))
#        elif index.column() == DESCRIPTION:
#            model.setData(index, QVariant(editor.toSimpleHtml()))
        if index.model().dataMode == sbml_entities.TYPE.REACTION:
            self.setModelDataReaction(editor, model, index)
        else:
            QStyledItemDelegate.setModelData(self, editor, model, index)
示例#13
0
 def setModelData(self, editor, model, index):
     #        if index.column() == TEU:
     #            model.setData(index, QVariant(editor.value()))
     #        elif index.column() in (OWNER, COUNTRY):
     #            model.setData(index, QVariant(editor.currentText()))
     #        elif index.column() == NAME:
     #            model.setData(index, QVariant(editor.text()))
     #        elif index.column() == DESCRIPTION:
     #            model.setData(index, QVariant(editor.toSimpleHtml()))
     if index.model().dataMode == sbml_entities.TYPE.REACTION:
         self.setModelDataReaction(editor, model, index)
     else:
         QStyledItemDelegate.setModelData(self, editor, model, index)
示例#14
0
 def setModelData(self, editor, model, index):
     # send modification to model
     if index.column() in (NODE_NAME, NODE_FILE):
         index_str = index.model().data(index, Qt.DisplayRole)
         if index_str != editor.text():
             if index.column() == NODE_FILE \
                     and not MTTSettings.value('showRealAttributeValue'):
                 if not index_str.startswith('\\'):
                     index_str = cmds.workspace(projectPath=index_str)
                 if index_str == editor.text():
                     return
             model.setData(index, editor.text())
     else:
         QStyledItemDelegate.setModelData(self, editor, model, index)
示例#15
0
 def setModelData(self, editor, model, index):
     # send modification to model
     if index.column() in (NODE_NAME, NODE_FILE):
         index_str = index.model().data(index, Qt.DisplayRole)
         if index_str != editor.text():
             if index.column() == NODE_FILE \
                     and not MTTSettings.value('showRealAttributeValue'):
                 if not index_str.startswith('\\'):
                     index_str = cmds.workspace(projectPath=index_str)
                 if index_str == editor.text():
                     return
             model.setData(index, editor.text())
     else:
         QStyledItemDelegate.setModelData(self, editor, model, index)
示例#16
0
 def sizeHint(self, option, index):
     """ Returns the size needed to display the item in a QSize object. """
     if index.column() == 3:
         starRating = StarRating(index.data())
         return starRating.sizeHint()
     else:
         return QStyledItemDelegate.sizeHint(self, option, index)
示例#17
0
 def sizeHint(self, option, index):
     """ Returns the size needed to display the item in a QSize object. """
     if index.column() == 6:
         starRating = StarRating(index.data())
         return starRating.sizeHint()
     else:
         return QStyledItemDelegate.sizeHint(self, option, index)
示例#18
0
 def setEditorData(self, editor, index):
     #        text = index.model().data(index, Qt.DisplayRole).toString()
     #        if index.column() == TEU:
     #            value = text.replace(QRegExp("[., ]"), "").toInt()[0]
     #            editor.setValue(value)
     #        elif index.column() in (OWNER, COUNTRY):
     #            i = editor.findText(text)
     #            if i == -1:
     #                i = 0
     #            editor.setCurrentIndex(i)
     #        elif index.column() == NAME:
     #            editor.setText(text)
     #        elif index.column() == DESCRIPTION:
     #            editor.setHtml(text)
     if index.model().dataMode == sbml_entities.TYPE.REACTION:
         self.setEditorDataReaction(editor, index)
     else:
         QStyledItemDelegate.setEditorData(self, editor, index)
    def setEditorData(self, editor, index):
#        text = index.model().data(index, Qt.DisplayRole).toString()
#        if index.column() == TEU:
#            value = text.replace(QRegExp("[., ]"), "").toInt()[0]
#            editor.setValue(value)
#        elif index.column() in (OWNER, COUNTRY):
#            i = editor.findText(text)
#            if i == -1:
#                i = 0
#            editor.setCurrentIndex(i)
#        elif index.column() == NAME:
#            editor.setText(text)
#        elif index.column() == DESCRIPTION:
#            editor.setHtml(text)
        if index.model().dataMode == sbml_entities.TYPE.REACTION:
            self.setEditorDataReaction(editor, index)
        else:
            QStyledItemDelegate.setEditorData(self, editor, index)
    def sizeHint(self, option, index):

        qSize = QStyledItemDelegate.sizeHint(self, option, index)

        iDecorHeight = option.decorationSize.height()
        if iDecorHeight > qSize.height():
            qSize.setHeight(iDecorHeight)

        return qSize + QSize(0, 2)
    def sizeHint(self, option, index):

        qSize = QStyledItemDelegate.sizeHint(self, option, index)

        iDecorHeight = option.decorationSize.height()
        if iDecorHeight > qSize.height():
            qSize.setHeight(iDecorHeight)

        return qSize + QSize(0, 2)
示例#22
0
 def createEditor(self, parent, option, index):
     """ Creates and returns the custom StarEditor object we'll use to edit 
         the StarRating.
     """
     if index.column() == 6:
         editor = StarEditor(parent)
         editor.editingFinished.connect(self.commitAndCloseEditor)
         return editor
     else:
         return QStyledItemDelegate.createEditor(self, parent, option, index)
示例#23
0
 def createEditor(self, parent, option, index):
     """ Creates and returns the custom StarEditor object we'll use to edit 
         the StarRating.
     """
     if index.column() == 3:
         editor = StarEditor(parent)
         editor.editingFinished.connect(self.commitAndCloseEditor)
         return editor
     else:
         return QStyledItemDelegate.createEditor(self, parent, option,
                                                 index)
示例#24
0
 def createEditor(self, parent, option, index):
     if index.column() == NODE_NAME:
         rename_editor = QLineEdit(parent)
         rename_editor.setValidator(
             QRegExpValidator(QRegExp(r'[a-zA-Z_]+[a-zA-Z0-9_:]*'), self))
         return rename_editor
     elif index.column() == NODE_FILE:
         # filename_editor = QLineEdit(parent)
         filename_editor = PathEditor(parent, index)
         filename_editor.editingFinished.connect(
             self.commit_and_close_editor)
         return filename_editor
     else:
         return QStyledItemDelegate.createEditor(self, parent, option, index)
示例#25
0
 def createEditor(self, parent, option, index):
     if index.column() == NODE_NAME:
         rename_editor = QLineEdit(parent)
         rename_editor.setValidator(
             QRegExpValidator(QRegExp(r'[a-zA-Z_]+[a-zA-Z0-9_:]*'), self))
         return rename_editor
     elif index.column() == NODE_FILE:
         # filename_editor = QLineEdit(parent)
         filename_editor = PathEditor(parent, index)
         filename_editor.editingFinished.connect(
             self.commit_and_close_editor)
         return filename_editor
     else:
         return QStyledItemDelegate.createEditor(self, parent, option,
                                                 index)
示例#26
0
    def sizeHint(self, option, index):
        if not isinstance(index.data(), GraphRow):
            return QStyledItemDelegate.sizeHint(self, option, index)
        row = index.data()
        max_lane = max(row.commit_node.lane, self.max_edge_lane(row.edges))
        if row.prev_row:
            max_lane = max(max_lane, self.max_edge_lane(row.prev_row.edges))

        width = (max_lane + 1) * self.preferred_lane_size
        height = self.preferred_lane_size

        refs_width, refs_height = self.refs_size(option, row.log_entry.refs,
            bool(row.repo.head_ref))
        width += refs_width
        height = max(height, refs_height)

        return QSize(width, height)
示例#27
0
    def sizeHint(self, option, index):
        """

        :param option:
        :type option: QStyleOptionViewItem
        :param index:
        :type index: QModelIndex
        :return:
        :rtype: QSize
        """
        idx = index.model().mapToSource(index)
        size = QStyledItemDelegate.sizeHint(self, option, idx)
        item = idx.model().itemFromIndex(idx)
        row = item.get_parent_row()
        size.setHeight(row.ROW_HEIGHT)

        return size
    def paint(self, painter, option, index):

        icon = index.data(ItemUserRole.IconRole)
        if (not icon) or icon.isNull():
            return QStyledItemDelegate.paint(self, painter, option, index)

        opt = QStyleOptionViewItemV4(option)
        self.initStyleOption(opt, index)

        widget = opt.widget
        style = widget.style() if widget else QApplication.style()
        style.drawControl(QStyle.CE_ItemViewItem, opt, painter, widget)

        optState = opt.state
        mode = QIcon.Normal
        if (not (optState & QStyle.State_Enabled)):
            mode = QIcon.Disabled
        elif (optState & QStyle.State_Selected):
            mode = QIcon.Selected
        state = QIcon.On if (optState & QStyle.State_Open) else QIcon.Off

        decorSize = opt.decorationSize
        iconSize = icon.actualSize(decorSize, mode, state)
        iconHeight = iconSize.height()
        iconWidth = iconSize.width()

        iconRect = style.subElementRect(QStyle.SE_ItemViewItemDecoration, opt,
                                        widget)

        decorHeight = decorSize.height()
        decorWidth = decorSize.width()
        wadj = hadj = 0

        if iconHeight < decorHeight:
            hadj = (decorHeight - iconHeight) * .5

        if iconWidth < decorWidth:
            wadj = (decorWidth - iconWidth) * .5

        if wadj or hadj:
            iconRect.adjust(wadj, hadj, -wadj, -hadj)

        icon.paint(painter, iconRect, opt.decorationAlignment, mode, state)
    def createEditor(self, parent, option, index):
#        if index.model().dataMode == sbml_entities.TYPE.COMPARTMENT:
#            return self.dataCompartment(index, role)
#        elif self.dataMode == sbml_entities.TYPE.SPECIES:
#            return self.dataSpecies(index, role)
        #el
        if index.model().dataMode == sbml_entities.TYPE.REACTION:
            return self.createEditorReaction(parent, option, index)
#        elif self.dataMode == sbml_entities.TYPE.PARAMETER:
#            return self.dataParameter(index, role)
#        elif self.dataMode == sbml_entities.TYPE.RULE:
#            return self.dataRule(index, role)

#        if index.column() == TEU:
#            spinbox = QSpinBox(parent)
#            spinbox.setRange(0, 200000)
#            spinbox.setSingleStep(1000)
#            spinbox.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
#            return spinbox
#        elif index.column() == OWNER:
#            combobox = QComboBox(parent)
#            combobox.addItems(sorted(index.model().owners))
#            combobox.setEditable(True)
#            return combobox
#        elif index.column() == COUNTRY:
#            combobox = QComboBox(parent)
#            combobox.addItems(sorted(index.model().countries))
#            combobox.setEditable(True)
#            return combobox
#        elif index.column() == NAME:
#            editor = QLineEdit(parent)
#            self.connect(editor, SIGNAL("returnPressed()"),
#                         self.commitAndCloseEditor)
#            return editor
#        elif index.column() == DESCRIPTION:
#            editor = richtextlineedit.RichTextLineEdit(parent)
#            self.connect(editor, SIGNAL("returnPressed()"),
#                         self.commitAndCloseEditor)
#            return editor
        else:
            return QStyledItemDelegate.createEditor(self, parent, option,
                                                    index)
示例#30
0
    def createEditor(self, parent, option, index):
        #        if index.model().dataMode == sbml_entities.TYPE.COMPARTMENT:
        #            return self.dataCompartment(index, role)
        #        elif self.dataMode == sbml_entities.TYPE.SPECIES:
        #            return self.dataSpecies(index, role)
        #el
        if index.model().dataMode == sbml_entities.TYPE.REACTION:
            return self.createEditorReaction(parent, option, index)
#        elif self.dataMode == sbml_entities.TYPE.PARAMETER:
#            return self.dataParameter(index, role)
#        elif self.dataMode == sbml_entities.TYPE.RULE:
#            return self.dataRule(index, role)

#        if index.column() == TEU:
#            spinbox = QSpinBox(parent)
#            spinbox.setRange(0, 200000)
#            spinbox.setSingleStep(1000)
#            spinbox.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
#            return spinbox
#        elif index.column() == OWNER:
#            combobox = QComboBox(parent)
#            combobox.addItems(sorted(index.model().owners))
#            combobox.setEditable(True)
#            return combobox
#        elif index.column() == COUNTRY:
#            combobox = QComboBox(parent)
#            combobox.addItems(sorted(index.model().countries))
#            combobox.setEditable(True)
#            return combobox
#        elif index.column() == NAME:
#            editor = QLineEdit(parent)
#            self.connect(editor, SIGNAL("returnPressed()"),
#                         self.commitAndCloseEditor)
#            return editor
#        elif index.column() == DESCRIPTION:
#            editor = richtextlineedit.RichTextLineEdit(parent)
#            self.connect(editor, SIGNAL("returnPressed()"),
#                         self.commitAndCloseEditor)
#            return editor
        else:
            return QStyledItemDelegate.createEditor(self, parent, option,
                                                    index)
    def paint(self, painter, option, index):

        icon = index.data(ItemUserRole.IconRole)
        if (not icon) or icon.isNull():
            return QStyledItemDelegate.paint(self, painter, option, index)

        opt = QStyleOptionViewItemV4(option)
        self.initStyleOption(opt, index)

        widget = opt.widget
        style = widget.style() if widget else QApplication.style()
        style.drawControl(QStyle.CE_ItemViewItem, opt, painter, widget)

        optState = opt.state
        mode = QIcon.Normal
        if (not (optState & QStyle.State_Enabled)):
            mode = QIcon.Disabled
        elif (optState & QStyle.State_Selected):
            mode = QIcon.Selected;
        state = QIcon.On if (optState & QStyle.State_Open) else QIcon.Off

        decorSize = opt.decorationSize
        iconSize = icon.actualSize(decorSize, mode, state)
        iconHeight = iconSize.height()
        iconWidth = iconSize.width()

        iconRect = style.subElementRect(QStyle.SE_ItemViewItemDecoration, opt, widget)

        decorHeight = decorSize.height()
        decorWidth = decorSize.width()
        wadj = hadj = 0

        if iconHeight < decorHeight:
            hadj = (decorHeight - iconHeight) * .5

        if iconWidth < decorWidth:
            wadj = (decorWidth - iconWidth) * .5

        if wadj or hadj:
            iconRect.adjust(wadj, hadj, -wadj, -hadj)

        icon.paint(painter, iconRect, opt.decorationAlignment, mode, state)
    def createEditorReaction(self, parent, option, index):
        '''
        Creates the editor if a Reaction is shown.
        '''
        if index.column() == sbml_entitytablemodel.REACTION_ROW.REACTANTS:
            list = QListView(parent)
            list.setSelectionMode(QAbstractItemView.MultiSelection)

#            combobox = QComboBox(parent)
            speciesIDs = []
            for speciesWrapper in index.model().mainModel.SbmlSpecies:
                speciesIDs.append(speciesWrapper.getId())

            #list. #adding the species...
#

#            combobox.addItems(sorted(speciesIDs))
#            #combobox.setEditable(True)
#            return combobox

        else:
            return QStyledItemDelegate.createEditor(self, parent, option,
                                                    index)
示例#33
0
    def createEditorReaction(self, parent, option, index):
        '''
        Creates the editor if a Reaction is shown.
        '''
        if index.column() == sbml_entitytablemodel.REACTION_ROW.REACTANTS:
            list = QListView(parent)
            list.setSelectionMode(QAbstractItemView.MultiSelection)

            #            combobox = QComboBox(parent)
            speciesIDs = []
            for speciesWrapper in index.model().mainModel.SbmlSpecies:
                speciesIDs.append(speciesWrapper.getId())

            #list. #adding the species...
#

#            combobox.addItems(sorted(speciesIDs))
#            #combobox.setEditable(True)
#            return combobox

        else:
            return QStyledItemDelegate.createEditor(self, parent, option,
                                                    index)
示例#34
0
    def paint(self, painter, option, index):
        # NODE_REFERENCE ---------------------------------------------------
        if index.column() == NODE_REFERENCE:

            # backup painter
            painter.save()

            # paint background
            palette = QApplication.palette()
            if option.state & QStyle.State_Selected:
                bg_color = palette.highlight().color()
            else:
                bg_color = Qt.transparent
            painter.fillRect(option.rect, bg_color)

            # paint
            value = float(index.model().data(index))
            if value == 0.0:
                painter.setPen(
                    Qt.black
                    if option.state & QStyle.State_Selected
                    else Qt.darkGray
                )
                painter.setBrush(Qt.NoBrush)
                mid_size = 3.0
            else:
                painter.setPen(Qt.darkCyan)
                painter.setBrush(Qt.cyan)
                mid_size = 4.0

            h_center = round(option.rect.x() + (option.rect.width() * .5))
            v_center = round(option.rect.y() + (option.rect.height() * .5))
            losange = QPolygonF()
            losange.append(QPointF(h_center, v_center - mid_size))
            losange.append(QPointF(h_center - mid_size, v_center))
            losange.append(QPointF(h_center, v_center + mid_size))
            losange.append(QPointF(h_center + mid_size, v_center))

            painter.drawPolygon(losange)

            # restore painter
            painter.restore()

        # FILE_STATE -------------------------------------------------------
        elif index.column() == FILE_STATE:

            # backup painter
            painter.save()

            # paint background
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            painter.fillRect(option.rect, bg_color)

            # paint circle
            value = index.model().data(index)

            pen_color = [
                Qt.darkRed,
                Qt.black if option.state & QStyle.State_Selected else Qt.gray,
                Qt.darkGreen][value + 1]
            brush_color = [Qt.red, Qt.NoBrush, Qt.green][value + 1]

            painter.setPen(pen_color)
            painter.setBrush(brush_color)

            h_center = round(option.rect.x() + (option.rect.width() * .5))
            v_center = round(option.rect.y() + (option.rect.height() * .5))
            center = QPointF(h_center, v_center)

            painter.drawEllipse(center, 3.0, 3.0)

            # restore painter
            painter.restore()

        # NODE_NAME --------------------------------------------------------
        elif index.column() == NODE_NAME:
            text = index.model().data(index, Qt.DisplayRole)
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            txt_color = palette.highlightedText().color() \
                if option.state & QStyle.State_Selected \
                else palette.text().color()

            if MTTSettings.value('vizWrongNameState') \
                    and not MTTSettings.value('showWrongNameState'):
                file_name = os.path.splitext(os.path.basename(
                    index.model().data(
                        index.sibling(index.row(), NODE_FILE),
                        Qt.DisplayRole
                    )
                ))[0]
                if not re.split('[0-9]*$', text.rsplit(':')[-1])[0] == \
                        re.split('[0-9]*$', file_name)[0]:
                    bg_color = QBrush(
                        Qt.red
                        if option.state & QStyle.State_Selected
                        else Qt.darkRed,
                        Qt.Dense4Pattern
                    )

            if not MTTSettings.value('showNamespaceState'):
                splits = text.split(':')
                text = splits[len(splits) > 1]

            painter.save()
            painter.fillRect(option.rect, bg_color)
            painter.setPen(txt_color)
            rect = option.rect
            rect.setX(4)
            QApplication.style().drawItemText(
                painter, rect, Qt.AlignLeft | Qt.AlignVCenter,
                palette, True, text
            )
            painter.restore()

        # NODE_FILE ------------------------------------------------------------
        elif index.column() == NODE_FILE:
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            txt_color = palette.highlightedText().color() \
                if option.state & QStyle.State_Selected \
                else palette.text().color()

            text = index.model().data(index, Qt.DisplayRole)
            if MTTSettings.value('vizExternalState'):
                if not text.startswith(self.ws_path):
                    bg_color = QBrush(
                        '#ef7900'
                        if option.state & QStyle.State_Selected
                        else '#b05100',
                        Qt.Dense4Pattern)

            if MTTSettings.value('vizWrongPathState'):
                if not re.match(MTTSettings.PATH_PATTERN, text):
                    bg_color = QBrush(
                        Qt.red
                        if option.state & QStyle.State_Selected
                        else Qt.darkRed,
                        Qt.Dense4Pattern)

            if MTTSettings.value('showBasenameState'):
                text = os.path.basename(text)
            elif not MTTSettings.value('showRealAttributeValue'):
                if not text.startswith('\\'):
                    text = os.path.normpath(cmds.workspace(projectPath=text))

            painter.save()
            painter.fillRect(option.rect, bg_color)
            painter.setPen(txt_color)
            QApplication.style().drawItemText(
                painter, option.rect, Qt.AlignLeft | Qt.AlignVCenter,
                palette, True, text)
            painter.restore()
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
示例#35
0
 def __init__(self, draw_focus=False, preferred_lane_size=30, parent=None):
     QStyledItemDelegate.__init__(self, parent)
     self.draw_focus = draw_focus
     self.preferred_lane_size = preferred_lane_size
示例#36
0
    def paint(self, painter, option, index):
        # NODE_REFERENCE ---------------------------------------------------
        if index.column() == NODE_REFERENCE:

            # backup painter
            painter.save()

            # paint background
            palette = QApplication.palette()
            if option.state & QStyle.State_Selected:
                bg_color = palette.highlight().color()
            else:
                bg_color = Qt.transparent
            painter.fillRect(option.rect, bg_color)

            # paint
            value = float(index.model().data(index))
            if value == 0.0:
                painter.setPen(Qt.black if option.state
                               & QStyle.State_Selected else Qt.darkGray)
                painter.setBrush(Qt.NoBrush)
                mid_size = 3.0
            else:
                painter.setPen(Qt.darkCyan)
                painter.setBrush(Qt.cyan)
                mid_size = 4.0

            h_center = round(option.rect.x() + (option.rect.width() * .5))
            v_center = round(option.rect.y() + (option.rect.height() * .5))
            losange = QPolygonF()
            losange.append(QPointF(h_center, v_center - mid_size))
            losange.append(QPointF(h_center - mid_size, v_center))
            losange.append(QPointF(h_center, v_center + mid_size))
            losange.append(QPointF(h_center + mid_size, v_center))

            painter.drawPolygon(losange)

            # restore painter
            painter.restore()

        # FILE_STATE -------------------------------------------------------
        elif index.column() == FILE_STATE:

            # backup painter
            painter.save()

            # paint background
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            painter.fillRect(option.rect, bg_color)

            # paint circle
            value = index.model().data(index)

            pen_color = [
                Qt.darkRed,
                Qt.black if option.state & QStyle.State_Selected else Qt.gray,
                Qt.darkGreen
            ][value + 1]
            brush_color = [Qt.red, Qt.NoBrush, Qt.green][value + 1]

            painter.setPen(pen_color)
            painter.setBrush(brush_color)

            h_center = round(option.rect.x() + (option.rect.width() * .5))
            v_center = round(option.rect.y() + (option.rect.height() * .5))
            center = QPointF(h_center, v_center)

            painter.drawEllipse(center, 3.0, 3.0)

            # restore painter
            painter.restore()

        # NODE_NAME --------------------------------------------------------
        elif index.column() == NODE_NAME:
            text = index.model().data(index, Qt.DisplayRole)
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            txt_color = palette.highlightedText().color() \
                if option.state & QStyle.State_Selected \
                else palette.text().color()

            if MTTSettings.value('vizWrongNameState') \
                    and not MTTSettings.value('showWrongNameState'):
                file_name = os.path.splitext(
                    os.path.basename(index.model().data(
                        index.sibling(index.row(), NODE_FILE),
                        Qt.DisplayRole)))[0]
                if not re.split('[0-9]*$', text.rsplit(':')[-1])[0] == \
                        re.split('[0-9]*$', file_name)[0]:
                    bg_color = QBrush(
                        Qt.red if option.state
                        & QStyle.State_Selected else Qt.darkRed,
                        Qt.Dense4Pattern)

            if not MTTSettings.value('showNamespaceState'):
                splits = text.split(':')
                text = splits[len(splits) > 1]

            painter.save()
            painter.fillRect(option.rect, bg_color)
            painter.setPen(txt_color)
            rect = option.rect
            rect.setX(4)
            QApplication.style().drawItemText(painter, rect,
                                              Qt.AlignLeft | Qt.AlignVCenter,
                                              palette, True, text)
            painter.restore()

        # NODE_FILE ------------------------------------------------------------
        elif index.column() == NODE_FILE:
            palette = QApplication.palette()
            bg_color = palette.highlight().color() \
                if option.state & QStyle.State_Selected \
                else Qt.transparent
            txt_color = palette.highlightedText().color() \
                if option.state & QStyle.State_Selected \
                else palette.text().color()

            text = index.model().data(index, Qt.DisplayRole)
            if MTTSettings.value('vizExternalState'):
                if not text.startswith(self.ws_path):
                    bg_color = QBrush(
                        '#ef7900' if option.state
                        & QStyle.State_Selected else '#b05100',
                        Qt.Dense4Pattern)

            if MTTSettings.value('vizWrongPathState'):
                if not re.match(MTTSettings.PATH_PATTERN, text):
                    bg_color = QBrush(
                        Qt.red if option.state
                        & QStyle.State_Selected else Qt.darkRed,
                        Qt.Dense4Pattern)

            if MTTSettings.value('showBasenameState'):
                text = os.path.basename(text)
            elif not MTTSettings.value('showRealAttributeValue'):
                if not text.startswith('\\'):
                    text = os.path.normpath(cmds.workspace(projectPath=text))

            painter.save()
            painter.fillRect(option.rect, bg_color)
            painter.setPen(txt_color)
            QApplication.style().drawItemText(painter, option.rect,
                                              Qt.AlignLeft | Qt.AlignVCenter,
                                              palette, True, text)
            painter.restore()
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
示例#37
0
    def __init__ ( self, parent, editor, grid_color, selection_color ):
        QStyledItemDelegate.__init__( self, parent )

        self._editor          = editor
        self._grid_color      = grid_color
        self._selection_color = selection_color
示例#38
0
 def __init__(self, delegate):
     QStyledItemDelegate.__init__(self)
     self._delegate = delegate
示例#39
0
 def __init__(self, parent):
     QStyledItemDelegate.__init__(self, parent)
示例#40
0
 def setEditorData(self, editor, index):
     """ Sets the data to be displayed and edited by our custom editor. """
     if index.column() == 6:
         editor.starRating = StarRating(index.data())
     else:
         QStyledItemDelegate.setEditorData(self, editor, index)
示例#41
0
 def __init__(self, parent=None):
     QStyledItemDelegate.__init__(self, parent)
     self.edit_next_item = True
示例#42
0
 def setEditorData(self, editor, index):
     """ Sets the data to be displayed and edited by our custom editor. """
     if index.column() == 3:
         editor.starRating = StarRating(index.data())
     else:
         QStyledItemDelegate.setEditorData(self, editor, index)
示例#43
0
 def setModelDataReaction(self, editor, model, index):
     if index.column() == sbml_entitytablemodel.REACTION_ROW.REACTANTS:
         model.setData(index, editor.currentText())
     else:
         QStyledItemDelegate.setModelData(self, editor, model, index)
 def setModelDataReaction(self, editor, model, index):
     if index.column() == sbml_entitytablemodel.REACTION_ROW.REACTANTS:
         model.setData(index, editor.currentText())
     else:
         QStyledItemDelegate.setModelData(self, editor, model, index)