Beispiel #1
0
 def data(self, index: QModelIndex, role=...):
     if not index.isValid():
         return None
     if index.row() >= self.rowCount() or index.column() >= self.columnCount():
         return None
     if role == Qt.DisplayRole:
         return self._table[index.row()][index.column()]
Beispiel #2
0
 def flags(self, index: QtCore.QModelIndex) -> QtCore.Qt.ItemFlags:
     result = QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
     if self.allow_edits:
         if index.row() == len(self._get_items()):
             if index.column() == 0:
                 result |= QtCore.Qt.ItemIsEditable
         else:
             if index.column() > 0:
                 result |= QtCore.Qt.ItemIsEditable
     return result
Beispiel #3
0
    def data(self, index: QModelIndex, role: int = ...) -> typing.Any:
        data_arg_in = {
            "index": index,
            "role": role
        }
        logging.debug(data_arg_in)
        if not index.isValid():
            return None
        r = int(Qt.DisplayRole)
        c = index.column()
        if role != Qt.DisplayRole:
            val = index.internalPointer().data(index.column())
            return None

        return index.internalPointer().data(index.column())
Beispiel #4
0
    def data(self, index: QtCore.QModelIndex, role: int = ...) -> typing.Any:
        if role not in {Qt.DisplayRole, Qt.EditRole}:
            return None

        all_items = self._get_items()
        if index.row() < len(all_items):
            resource = all_items[index.row()]
            field = self.all_columns()[index.column()]
            return field.to_qt(getattr(resource, field.field_name))

        elif role == Qt.DisplayRole:
            if index.column() == 0:
                return "New..."
        else:
            return ""
 def setData(self, index: QModelIndex, value: Any, _role: int = 0) -> bool:
     if not index.isValid():
         return False
     col = self.getColumnKey(index.column())
     row = index.row()
     asyncio.create_task(self.setDataInternal(col, row, str(value)))
     return True
Beispiel #6
0
 def flags(self, index: QtCore.QModelIndex) -> QtCore.Qt.ItemFlags:
     if index.row() == 0:
         return Qt.ItemIsSelectable
     elif index.column() == 0:
         return Qt.ItemIsSelectable | Qt.ItemIsEnabled
     else:
         return Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable
Beispiel #7
0
    def createEditor(self, parent, option, index: QtCore.QModelIndex):
        col = index.column()

        self.items = []
        if col == 2:
            self.items = ["Pocket", "Inside", "Outside", "Engrave"]
        if col == 7:
            self.items = ["Union", "Intersection", "Difference", "Xor"]
        if col == 8:
            self.items = ["Conventional", "Climb"]
        if col == 9:
            self.items = ["inch", "mm"]

        editor = PMFComboBox(parent, self.items)

        op = index.model().get_operation(index)
        attr = index.model().get_operation_attr(index)

        editor.assign_object(op)
        editor.assign_object_attribute(attr)
        editor.fill_control()

        # to flush a "setModelData" in place - it works! but model still has old value -
        editor.currentIndexChanged.connect(self.onEditorCurrentIndexChanged)

        return editor
Beispiel #8
0
 def data(self, index: QtCore.QModelIndex, role: int) -> typing.Any:
     """
     Override QAbstractTableModel data for displaying pandas dataframe data
     """
     if role == QtCore.Qt.DisplayRole:
         return self.logMessages[index.row()][index.column()]
     else:
         return None
Beispiel #9
0
    def flags(self, index: QtCore.QModelIndex) -> QtCore.Qt.ItemFlags:
        if not index.isValid():
            return None

        if index.column() == 1:
            # not editable
            return super().flags(index) | ~QtCore.Qt.ItemIsEditable
        else:
            return super().flags(index)
Beispiel #10
0
 def data(self, index: QModelIndex, role=...):
     if not index.isValid():
         return None
     if index.row() >= self.rowCount() or index.column() >= len(
             self._header_data):
         return None
     if role == Qt.DisplayRole:
         g = self._goods[index.row()]
         if index.column() == 0:
             return g.name
         elif index.column() == 1:
             return g.type.name
         elif index.column() == 2:
             return str(g.create_time)
         else:
             return g.comment if g.comment is not None else ''
     if role == Qt.EditRole:
         return self._goods[index.row()]
 def flags(self, index: QModelIndex) -> Qt.ItemFlags:
     if not index.isValid():
         return Qt.NoItemFlags
     col = self.getColumnKey(index.column())
     if col in ('package', 'filename', 'category', 'priority',):
         mod = self.modmodel[index.row()]
         if col in ('priority',) and mod.datatype not in ('mod', 'udf',):
             return Qt.ItemIsEnabled | Qt.ItemIsSelectable
         return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsEditable
     return Qt.ItemIsEnabled | Qt.ItemIsSelectable
Beispiel #12
0
    def data(self, index: QModelIndex, role: int = Qt.UserRole + 1) -> t.Any:

        if not index.isValid():
            return None

        if role != Qt.DisplayRole:
            return None

        item = index.internalPointer()
        return item.data(index.column())
Beispiel #13
0
    def handleNewvalue(self, index: QtCore.QModelIndex, value: Any):
        print("--------------------------------", "handleNewvalue")

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

        attrib = self.header[col]

        print("handleNewvalue OLD -> %s" % (str(self.operations[row])))
        print("handleNewvalue NEW -> %s %s" % (attrib, value))
Beispiel #14
0
    def data(self, index: QModelIndex, role: Qt = Qt.ItemDataRole) -> None:
        """Override method from QAbstractTableModel

        Return data cell from the pandas DataFrame
        """
        if not index.isValid():
            return None

        if role == Qt.DisplayRole:
            return str(self._dataframe.iloc[index.row(), index.column()])

        return None
Beispiel #15
0
    def onTableCellChanged(self, i1: QtCore.QModelIndex,
                           i2: QtCore.QModelIndex):

        model: GCodeTableModel = self.sender()

        if i1.column() != 1:
            return

        # Inserting new line at end
        if i1.row() == (model.rowCount() -
                        1) and str(model.data(model.index(i1.row(), 1))) != "":
            model.setData(model.index(model.rowCount() - 1, 2),
                          GCodeItem.States.InQueue)
            model.insertRow(model.rowCount())

            if not self.m_programLoading:
                self.ui.tblProgram.setCurrentIndex(model.index(
                    i1.row() + 1, 1))
        # Remove last line
        '''elif (i1.row() != (model.rowCount() - 1) and str(model.data(model.index(i1.row(), 1))) == "": 
            self.ui.tblProgram.setCurrentIndex(model.index(i1.row() + 1, 1))
            self.m_tableModel.removeRow(i1.row())
        '''

        if not self.m_programLoading:

            # Clear cached args
            model.setData(model.index(i1.row(), 5), None)

            # Drop heightmap cache
            #if self.m_currentModel == self.m_programModel:
            #    self.m_programHeightmapModel.clear()

            # Update visualizer
            self.updateParser()

            # Hightlight w/o current cell changed event (double hightlight on current cell changed)
            alist = self.m_viewParser.getLineSegmentList()

            #for (int i = 0 i < list.count() and list[i].getLineNumber() <= m_currentModel.data(m_currentModel.index(i1.row(), 4)).toInt() i++):
            #    alist[i].setIsHightlight(True)

            k = 0
            while True:
                if not (k < len(alist) and alist[k].getLineNumber() <=
                        (int)(self.m_currentModel.data(
                            self.m_currentModel.index(i1.row(), 4)))):
                    break

                alist[k].setIsHightlight(True)

                k += 1
Beispiel #16
0
    def handleNewvalue(self, index: QtCore.QModelIndex, value: Any):
        row = index.row()
        col = index.column()

        attrib = self.header[col]

        # update pycut GUI
        if attrib in ["x", "y", "radius", "enabled"]:
            cnc_tab = self.tabs[row]
            setattr(cnc_tab, attrib, value)

            tabs = [tab.to_dict() for tab in self.tabs]
            self.mainwindow.display_cnc_tabs(tabs)
Beispiel #17
0
    def rowCount(self, parent: QModelIndex = ...) -> int:
        row_count_arg_in = {"parent": parent}
        logging.debug("rowCount")
        logging.debug(row_count_arg_in)
        if parent.column() > 0:
            return 0

        if not parent.isValid():
            parent_item = self.__root
        else:
            parent_item = parent.internalPointer()
        logging.debug({"return": parent_item.child_count()})
        return parent_item.child_count()
Beispiel #18
0
 def data(self, index: QtCore.QModelIndex, role: int = ...):
     if role == Qt.DisplayRole:
         tax = self._data[index.row()]
         col = index.column()
         if col == 0:
             return str(tax.id)
         elif col == 1:
             return str(tax.tax_type)
         elif col == 2:
             return str(tax.tax_rate)
         elif col == 3:
             return str(tax.tax_subtotal)
         elif col == 4:
             return str(tax.label)
Beispiel #19
0
    def setData(self, index: QtCore.QModelIndex, value: typing.Any,
                role: int) -> bool:
        if role == Qt.EditRole:
            col = index.column()
            row = index.row()

            # ID
            if col == 0:
                return False

            # Product Code
            elif col == 1:
                self._data[row].load_user_input_str(value)

            return True
Beispiel #20
0
    def createEditor(self, parent, option, index: QtCore.QModelIndex):
        editor = PyCutDoubleSpinBox(parent)

        op = index.model().get_operation(index)
        attr = index.model().get_operation_attr(index)

        editor.assign_object(op)
        editor.assign_object_attribute(attr)

        # to flush an "setModelData" in place - it works!
        editor.valueChanged.connect(self.onEditorValueChanged)

        self.xeditors[(index.row(), index.column())] = editor

        return editor
Beispiel #21
0
 def data(self, index: QtCore.QModelIndex, role: int = ...) -> typing.Any:
     if role == Qt.DisplayRole:
         product = self._data[index.row()]
         col = index.column()
         if col == 0:
             return str(product.id)
         elif col == 1:
             xs = []
             for x in product.taxes:
                 if x == '00' and len(xs) == 0:
                     xs = ['00']
                     break
                 elif x == '00':
                     break
                 xs.append(x)
             return ''.join(xs)
Beispiel #22
0
 def setData(self, index: QtCore.QModelIndex, value: typing.Any, role: int = ...) -> bool:
     if role == Qt.ItemDataRole.EditRole:
         all_items = self._get_items()
         if index.row() < len(all_items):
             resource = all_items[index.row()]
             field = self.all_columns()[index.column()]
             valid, new_value = field.from_qt(value)
             if valid:
                 all_items[index.row()] = dataclasses.replace(
                     resource, **{field.field_name: new_value},
                 )
                 self.dataChanged.emit(index, index, [Qt.ItemDataRole.DisplayRole])
                 return True
         else:
             if value:
                 return self.append_item(self._create_item(value))
     return False
Beispiel #23
0
    def handleNewvalue(self, index: QtCore.QModelIndex, value: Any):
        row = index.row()
        col = index.column()

        attrib = self.header[col]

        # update pycut GUI
        if attrib in [
                "cam_op", "enabled", "paths", "units", "cutDepth", "ramp",
                "combinaison", "margin", "width"
        ]:
            cnc_op = self.operations[row]
            setattr(cnc_op, attrib, value)

            self.mainwindow.display_cnc_ops_geometry(self.operations)

        if self.view is not None:
            self.view.enable_disable_cells()
Beispiel #24
0
    def paint(self, painter: QPainter, option: QStyleOptionViewItem,
              index: QModelIndex) -> None:
        itemOption = QStyleOptionViewItem(option)

        # disable focus outline
        if itemOption.state & QStyle.State_HasFocus:
            itemOption.state ^= QStyle.State_HasFocus
        # hover whole row
        if index.row() == option.styleObject.hoverIndexRow:
            itemOption.state |= QStyle.State_MouseOver

        super().paint(painter, itemOption, index)

        # draw lines around numeric columns
        if index.column() in (5, 12):
            oldpen = painter.pen()
            painter.setPen(self.linepen)
            painter.drawLine(itemOption.rect.topRight() + QPoint(0, 0),
                             itemOption.rect.bottomRight() + QPoint(0, 0))
            painter.setPen(oldpen)
Beispiel #25
0
    def setData(self,
                index: QtCore.QModelIndex,
                value: typing.Any,
                role: int = ...):
        if role == Qt.EditRole:
            col = index.column()
            row = index.row()

            # ID
            if col == 0:
                return False

            # Tax Type
            elif col == 1:
                if value not in ['$', '%']:
                    return False
                self._data[row].tax_type = value

            # Tax Rate
            elif col == 2:
                if len(value) != 6:
                    return False
                self._data[row].tax_rate = value

            # Tax Subtotal
            elif col == 3:
                if value not in ['Y', 'N']:
                    return False
                self._data[row].tax_subtotal = value

            # Label
            elif col == 4:
                trimmed = value[:15]
                label_len = len(trimmed)
                if label_len < 15:
                    trimmed += ' ' * (15 - label_len)
                print(len(trimmed))
                self._data[row].label = trimmed

            return True
Beispiel #26
0
    def data(self, index: QtCore.QModelIndex, role: QtCore.Qt.EditRole):
        op = self.get_operation(index)
        attr = self.get_operation_attr(index)

        # for check box, data is displayed in the "editor"
        col = index.column()

        if col == 11:  # button
            return None
        if col == 12:  # button
            return None
        if col == 13:  # button
            return None

        # for checkboxes only
        if col == 2:  # checkbox
            return None
        if col == 6:  # checkbox
            return None

        if role == QtCore.Qt.DisplayRole:
            val = getattr(op, attr)

            if col == 3:  # make a string of the list
                # list of svg paths ids
                val = str(val)

            return val
        if role == QtCore.Qt.EditRole:
            val = getattr(op, attr)

            if col == 3:
                # list of svg paths ids
                val = str(val)

            return val

        return None
Beispiel #27
0
    def data(self, index: QtCore.QModelIndex, role: QtCore.Qt.EditRole):
        tab = self.get_tab(index)
        attr = self.get_tab_attr(index)

        # for check box, data is displayed in the "editor"
        col = index.column()

        if col == 4:  # button
            return None

        # for checkboxes only
        if col == 3:  # checkbox
            return None

        if role == QtCore.Qt.DisplayRole:
            val = getattr(tab, attr)

            return val
        if role == QtCore.Qt.EditRole:
            val = getattr(tab, attr)

            return val

        return None
Beispiel #28
0
 def setData(self, index: QtCore.QModelIndex, value: Any, role = QtCore.Qt.EditRole) -> bool:
     if index.isValid() and role == QtCore.Qt.EditRole:
         if index.column() == 0: 
             return False
         elif index.column() ==  1: 
             self.m_data[index.row()].command = str(value)
         elif index.column() ==  2: 
             self.m_data[index.row()].state = GCodeItem.States(value)
         elif index.column() ==  3: 
             self.m_data[index.row()].response = str(value)
         elif index.column() ==  4: 
             self.m_data[index.row()].line = int(value)
         elif index.column() ==  5: 
             self.m_data[index.row()].args = [str(value)] ## FIXME: toStringList()
     
         self.dataChanged.emit(index, index)
         return True
     
     return False
Beispiel #29
0
    def data(self, index: QtCore.QModelIndex, role = QtCore.Qt.DisplayRole) -> Any :
        if not index.isValid(): 
            return None # QVariant()

        if index.row() >= len(self.m_data) :
            return None # QVariant()

        if role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
            if index.column() == 0: 
                return "" if index.row() == self.rowCount() - 1 else str(index.row() + 1)
            elif index.column() ==  1: return self.m_data[index.row()].command
            elif index.column() ==  2:
                if index.row() == self.rowCount() - 1: 
                    return ""
                if self.m_data[index.row()].state == GCodeItem.States.InQueue: 
                    return "In queue"
                elif self.m_data[index.row()].state == GCodeItem.States.Sent: 
                    return "Sent"
                elif self.m_data[index.row()].state == GCodeItem.States.Processed: 
                    return "Processed"
                elif self.m_data[index.row()].state == GCodeItem.States.Skipped: 
                    return "Skipped"
                else:
                    return "Unknown"
            elif index.column() ==  3: 
                return self.m_data[index.row()].response
            elif index.column() ==  4: 
                return self.m_data[index.row()].line
            elif index.column() ==  5: 
                return self.m_data[index.row()].args

        if role == QtCore.Qt.TextAlignmentRole:
            return QtCore.Qt.AlignVCenter

        if role == QtCore.Qt.FontRole:
            if index.column() == 1: # text items are bold.
                font = QtGui.QFont()
                font.setBold(True)
                return font

        return None  # QVariant()
    def data(self, index: QModelIndex, role: Qt.ItemDataRole = Qt.DisplayRole) -> Any:
        if not index.isValid():
            return None
        col = self.getColumnKey(index.column())
        if not col:
            return None

        if role == Qt.FontRole:
            if col in ('datatype', 'size',):
                return QFontDatabase.systemFont(QFontDatabase.FixedFont)
            return None

        if role == Qt.CheckStateRole:
            if col in ('enabled',):
                mod = self.modmodel[index.row()]
                val = mod[col]
                return Qt.Checked if val else Qt.Unchecked
            return None

        if role == Qt.BackgroundRole:
            mod = self.modmodel[index.row()]
            if not mod.enabled:
                return self._colorDisabled
            if col in ('priority',) and mod.datatype not in ('mod', 'udf',):
                return self._colorUnavailable
            if mod.installdate > self._lastUpdate:
                return self._colorNewest
            if mod.installdate > self._lastInitialization:
                return self._colorRecent
            if not mod.installed:
                return self._colorUnmanaged
            return None

        if role == Qt.ForegroundRole:
            mod = self.modmodel[index.row()]
            if not mod.enabled:
                return QColor(60, 60, 60)
            elif col in ('scriptFiles',):
                if mod.filename in self.modmodel.conflicts.scripts \
                and self.modmodel.conflicts.scripts[mod.filename]:
                    return QColor('#E55934')
            elif col in ('bundledFiles',):
                if mod.filename in self.modmodel.conflicts.bundled \
                and self.modmodel.conflicts.bundled[mod.filename]:
                    return QColor('#b08968')
            return None

        if role == Qt.DecorationRole:
            if col in ('datatype',):
                mod = self.modmodel[index.row()]
                val = mod[col]
                return self._icons[val] if val in self._icons else self._icons['udf']
            return None

        if role == Qt.ToolTipRole:
            mod = self.modmodel[index.row()]
            if col in ('datatype',):
                val = mod[col]
                return self._datatypes[val] if val in self._datatypes else self._datatypes['udf']
            if col in ('enabled',):
                val = mod[col]
                return 'Enabled' if val else 'Disabled'
            return str(mod[col])

        if role == Qt.TextAlignmentRole:
            if col in ('size',):
                # Right|VCenter
                return 0x0082
            if col in ('priority', 'installdate', 'binFiles', 'menuFiles', 'settings',
                       'inputs', 'contentFiles', 'scriptFiles', 'bundledFiles',):
                # HCenter|VCenter
                return 0x0084
            # Left|VCenter
            return 0x0081

        if role == Qt.EditRole:
            if col in ('package', 'filename', 'category', 'priority',):
                mod = self.modmodel[index.row()]
                return str(mod[col])
            return None

        # role used for sorting
        if role == Qt.UserRole:
            mod = self.modmodel[index.row()]
            if col in ('priority',):
                return f'{"-" if int(mod[col]) < 0 else "+"}{abs(int(mod[col])): >20} {mod["filename"]}'
            if col in ('size',):
                return int(mod[col])
            if col in ('binFiles', 'menuFiles', 'contentFiles', \
                       'scriptFiles', 'settings', 'inputs', 'bundledFiles',):
                return len(mod[col])
            return str(mod[col])

        if role == Qt.DisplayRole:
            if col in ('enabled',):
                return None
            mod = self.modmodel[index.row()]
            if col in ('datatype',):
                return str(mod[col]).upper()
            if col in ('priority',):
                val = mod[col]
                if val < 0:
                    return 'none'
                return val
            if col in ('installdate',):
                return mod[col].astimezone(tz=None).strftime('%Y-%m-%d %H:%M:%S')
            if col in ('size',):
                val = mod[col]
                frm = 'b'
                val /= 1024
                frm = 'K'
                if val // 1024:
                    val /= 1024
                    frm = 'M'
                return '%.1f %s' % (val, frm)
            if col in ('inputs', 'settings',):
                val = 0
                for s in mod[col]:
                    for n in s.config.sections():
                        val += len(s.config.items(n))
                return val if val else None

            if col in ('binFiles', 'menuFiles', 'contentFiles', 'scriptFiles', 'bundledFiles',):
                val = len(mod[col])
                if val < 1:
                    return ''
                return val
            return str(mod[col])

        return None