Example #1
0
 def __init__(self, parent, index_name, model):
     QItemDelegate.__init__(self, parent)
     self.index_name = index_name
     self.model = model
     self.document_type_row = -1
     self.display_valid_row = -1
     self.preservation_valid_row = -1
Example #2
0
 def paint(self, painter, option, index):
     value = index.data(Qt.DisplayRole)
     style = QApplication.style()
     opt = QStyleOptionComboBox()
     opt.text = str(value)
     opt.rect = option.rect
     style.drawComplexControl(QStyle.CC_ComboBox, opt, painter)
     QItemDelegate.paint(self, painter, option, index)
	def __init__(self, parent):
		QItemDelegate.__init__(self, parent)

		self.font = binaryninjaui.getMonospaceFont(parent)
		self.font.setKerning(False)
		self.baseline = QFontMetricsF(self.font).ascent()
		self.char_width = binaryninjaui.getFontWidthAndAdjustSpacing(self.font)[0]
		self.char_height = QFontMetricsF(self.font).height()
		self.char_offset = binaryninjaui.getFontVerticalOffset()

		self.expected_char_widths = [10, 32]
    def setEditorData(self, editor, index: QModelIndex):
        """
        Overriding inherited setEditorData class
        Args:
            editor: Current editor for the data
            index: Current index being modified

        """
        text = index.model().data(index, Qt.DisplayRole)
        if index.column() == TreeModelParamEntry.TYPE:
            editor.setCurrentText(text)
        else:
            QItemDelegate.setEditorData(self, editor, index)
    def setModelData(self, editor, model: QAbstractItemModel, index):
        """
        Overriding inherited setModelData class
        Args:
            editor: Current editor for the data
            model: Current model whose data is being set
            index: Current index being modified

        """
        if index.column() == TreeModelParamEntry.TYPE:
            model.setData(index, editor.getTypeName())
            # get type
            # get corresponding dict entry
            # update type (OrderedDict, str, etc.)  as necessary
            # get value
        else:
            QItemDelegate.setModelData(self, editor, model, index)
Example #6
0
    def setModelData(self, editor, model, index):

        row = index.row()
        column = index.column()

        if column == COLOR and editor is None:
            model.setData(index, None, Qt.BackgroundColorRole)
            model.setData(model.index(row, column+1), None, Qt.DisplayRole)
        elif column == COLOR:
            color = editor.currentColor()
            if color != QColor():
                color = color.getRgb()[:3]
                model.setData(index, color, Qt.BackgroundColorRole)
                model.setData(model.index(row, column+1),
                              color,
                              Qt.DisplayRole)
        elif column == COLORLABEL:
            if editor is None:
                model.setData(model.index(row, column-1),
                              None,
                              Qt.BackgroundColorRole)
                model.setData(index, None, Qt.DisplayRole)
            elif editor.text().lower() in openmc.plots._SVG_COLORS:
                svg = editor.text().lower()
                color = openmc.plots._SVG_COLORS[svg]
                model.setData(model.index(row, column-1),
                              color,
                              Qt.BackgroundColorRole)
                model.setData(index, svg, Qt.DisplayRole)
            else:
                try:
                    input = literal_eval(editor.text())
                except (ValueError, SyntaxError):
                    return None
                if not isinstance(input, tuple) or len(input) != 3:
                    return None
                for val in input:
                    if not isinstance(val, int) or not 0 <= val <= 255:
                        return None
                model.setData(model.index(row, column-1),
                              input,
                              Qt.BackgroundColorRole)
                model.setData(index, input, Qt.DisplayRole)
        else:
            QItemDelegate.setModelData(self, editor, model, index)
Example #7
0
    def createEditor(self, parent, option, index):

        if index.column() == COLOR:
            dialog = QColorDialog(parent)
            return dialog
        elif index.column() == COLORLABEL:
            return QLineEdit(parent)
        else:
            return QItemDelegate.createEditor(self, parent, option, index)
 def createEditor(self, parent, option, index):
     col = index.column()
     if col == index.model().i_diaph:
         row = index.row()
         combobox = QComboBox(parent)
         diaphs = (index.model().diaphs[row]).split(',')
         combobox.addItems(diaphs)
         # combobox.setEditable(True)
         return combobox
     else:
         return QItemDelegate.createEditor(self, parent, option, index)
Example #9
0
    def editorEvent(self, event, model, option, index):

        if index.column() in (COLOR, COLORLABEL):
            if not int(index.flags() & Qt.ItemIsEditable) > 0:
                return False
            if event.type() == QEvent.MouseButtonRelease \
                and event.button() == Qt.RightButton:
                self.setModelData(None, model, index)
                return True
            return False
        else:
            return QItemDelegate.editorEvent(self, event, model, option, index)
Example #10
0
    def sizeHint(self, option, index):

        fm = option.fontMetrics
        column = index.column()

        if column == ID:
            return QSize(fm.width("XXXXXX"), fm.height())
        elif column == COLOR:
            return QSize(fm.width("XXXXXX"), fm.height())
        elif column == COLORLABEL:
            return QSize(fm.width("X(XXX, XXX, XXX)X"), fm.height())
        elif column == MASK:
            return QSize(fm.width("XXXX"), fm.height())
        else:
            return QItemDelegate.sizeHint(self, option, index)
    def createEditor(self, parent: QWidget, option: QStyleOptionViewItem,
                     index: QModelIndex) -> QWidget:
        """
        Overriding inherited createdEditor class
        Args:
            parent: Parent widget
            option: Style options for the related view
            index: Specific index being edited

        Returns:

        """
        if index.column() == TreeModelParamEntry.TYPE:
            node = index.model().nodeFromIndex(index)
            combo = node.get_type_combobox(parent)  #dicts vs values
            #combo.setEditable(True)
            return combo
        else:
            return QItemDelegate.createEditor(self, parent, option, index)
    def createEditor(self, parent: QWidget, option: QStyleOptionViewItem,
                     index: QModelIndex) -> QWidget:
        """
        Overriding inherited createdEditor class.
        Note that the index contains information about the model being used.
        The editor's parent widget is specified by parent, and the item options by option.

        Args:
            parent: Parent widget
            option: Style options for the related view
            index: Specific index being edited

        Returns:
            Returns the editor to be used for editing the data item with the given index.
        """
        if index.column() == TreeModelParamEntry.TYPE:
            node = index.model().nodeFromIndex(index)
            combo = node.get_type_combobox(parent)  #dicts vs values
            return combo

        return QItemDelegate.createEditor(self, parent, option, index)
 def paint(self, painter, option, index):
     if self._is_entity_index(index):
         super().paint(painter, option, index)
     else:
         QItemDelegate.paint(self, painter, option, index)
Example #14
0
 def paint(self, painter, option, index):
     option.displayAlignment = QtCore.Qt.AlignCenter
     QItemDelegate.paint(self, painter, option, index)
Example #15
0
    def __init__(self, parent):

        QItemDelegate.__init__(self, parent)
Example #16
0
    def __init__(self, parent):

        QItemDelegate.__init__(self, parent)
        self.items = ["None"]
Example #17
0
 def paint(self, painter, option, index):
     if self._is_relationship_index(index):
         super().paint(painter, option, index)
     else:
         QItemDelegate.paint(self, painter, option, index)
Example #18
0
 def editorEvent(self, event, model, option, index):
     if self._is_relationship_index(index):
         return super().editorEvent(event, model, option, index)
     return QItemDelegate.editorEvent(self, event, model, option, index)
Example #19
0
    def paint(self, painter: QPainter, option: QStyleOptionViewItem,
              index: QModelIndex):
        """
        Displays dirty files in red with corresponding rebuild buttons
        if in developer mode (is_dev_mode). Otherwise, renders normally


        Args:
            painter (QPainter): Current painter
            option (QStyleOptionViewItem): Current option
            index (QModelIndex): Current index of related model



        """
        if self.is_dev_mode:
            source_model = self.get_source_model(index.model(),
                                                 self.source_model_type)

            model = index.model()

            # get data of filename
            filename = str(
                model.data(
                    model.sibling(index.row(), source_model.FILENAME, index)))

            if source_model.is_file_dirty(filename):
                if index.column() == source_model.FILENAME:

                    text = filename
                    palette = option.palette
                    document = QTextDocument()
                    document.setDefaultFont(option.font)
                    document.setHtml(f"<font color={'red'}>{text}</font>")
                    background_color = palette.base().color()
                    painter.save()
                    painter.fillRect(option.rect, background_color)
                    painter.translate(option.rect.x(), option.rect.y())
                    document.drawContents(painter)
                    painter.restore()

                elif index.column() == source_model.REBUILD:
                    if '.py' in filename:
                        text = "rebuild"
                        palette = option.palette
                        document = QTextDocument()
                        # needed to add Right Alignment:  qt bug :
                        # https://bugreports.qt.io/browse/QTBUG-22851
                        document.setTextWidth(option.rect.width())
                        text_options = document.defaultTextOption()
                        text_options.setTextDirection(Qt.RightToLeft)
                        document.setDefaultTextOption(
                            text_options)  # get right alignment
                        document.setDefaultFont(option.font)
                        document.setHtml(
                            f'<font color={"red"}> <b> {text}</b> </font>')
                        background_color = palette.base().color()
                        painter.save()
                        painter.fillRect(option.rect, background_color)
                        painter.translate(option.rect.x(), option.rect.y())
                        document.drawContents(painter)
                        painter.restore()

            else:
                QItemDelegate.paint(self, painter, option, index)

        else:
            QItemDelegate.paint(self, painter, option, index)