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 _on_data_changed(self, model: ResourceDatabaseGenericModel,
                      top_left: QtCore.QModelIndex,
                      bottom_right: QtCore.QModelIndex, roles):
     first_row = top_left.row()
     last_row = bottom_right.row()
     if first_row == last_row:
         self.ResourceChanged.emit(
             self.db.get_by_type(model.resource_type)[first_row])
Beispiel #3
0
    def data(self, index: QModelIndex, role):
        if not index.isValid():
            return None

        if role == self.DeviceClassRoles.DEVICE_CLASS_NAME:
            return self.classes[index.row()]['name']

        if role == self.DeviceClassRoles.DEVICE_CLASS_VALUE:
            return self.classes[index.row()]['value']
    def data(self, index: QModelIndex, role):
        if not index.isValid():
            return None

        if role == DeviceRoles.CATEGORY:
            return 'main' if index.row() < self._device_count_ else self._category_

        for x in range(len(self._ui_dev_info_)):
            if x == index.row():
                dev_cls = self._ui_dev_info_[x]
                return getattr(dev_cls, DeviceRolePropertyMap[role])
        return None
Beispiel #5
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 #6
0
    def prompt_delete_folder(self, index: qtc.QModelIndex) -> None:
        """Opens a message box prompt which confirms if the user wants to delete a folder."""
        folder: Folder = index.internalPointer()
        response = qtw.QMessageBox.question(
            None, "Prompt",
            "Are you sure you want to delete '" + folder.title + "'?",
            qtw.QMessageBox.Yes | qtw.QMessageBox.No)
        if response == qtw.QMessageBox.Yes:

            self.feed_view_model.beginRemoveRows(index.parent(), index.row(),
                                                 index.row())
            self.feed_manager.delete_folder(folder)
            self.feed_view_model.endRemoveRows()
Beispiel #7
0
 def prompt_delete_feed(self, index: qtc.QModelIndex) -> None:
     """
     Opens a message box prompt which confirms if the user wants to delete a feed.
     Deletes a feed from the view, then tells the feed manager to remove it from the database.
     """
     feed: Feed = index.internalPointer()
     response = qtw.QMessageBox.question(
         None, "Prompt", "Are you sure you want to delete '" +
         (feed.user_title if feed.user_title is not None else feed.title) +
         "'?", qtw.QMessageBox.Yes | qtw.QMessageBox.No)
     if response == qtw.QMessageBox.Yes:
         self.feed_view_model.beginRemoveRows(index.parent(), index.row(),
                                              index.row())
         self.feed_manager.delete_feed(feed)
         self.feed_view_model.endRemoveRows()
Beispiel #8
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 ""
Beispiel #9
0
 def on_tableview_currentRowChanged(self, current: QModelIndex,
                                    previous: QModelIndex):
     if current.isValid():
         row = current.row()
         self._on_currentListDataChanged(self._acqs[row])
         pass
     pass
Beispiel #10
0
 def tableActivated(self, index: QtCore.QModelIndex):
     """
     Slot for when a row is selected in the model, updates the description tab with that row's data
     """
     self.ui.textView.setText(
         str(self.loggingModel.logMessages[index.row()][
             self.loggingModel.columnCount()]))
Beispiel #11
0
 def setCurrentIndex(self, index: QModelIndex,
                     command: QItemSelectionModel.SelectionFlags) -> None:
     if not index.isValid():
         return
     # always focus column 3
     index = self.model().index(index.row(), 3)
     super().setCurrentIndex(index, command)
Beispiel #12
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
 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 #14
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 #15
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 #16
0
 def data(self, index:QtCore.QModelIndex, role:int=...) -> typing.Any:
     """ For given index and DisplayRole return name of the selected city"""
     # Return None if the index is not valid
     if not index.isValid():
         return None
     # If the role is the DisplayRole, return name of the city
     if role == QtCore.Qt.DisplayRole:
         return self.city_list[index.row()]["muniLabel"]
Beispiel #17
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 #19
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 #20
0
    def data(self, index: QModelIndex, role: int):
        """
        Returns the data of the object in a Qt-conforming way. If the given
        role is DisplayRole it returns the name of the device as a string, if
        it's DecorationRole it returns an icon according to it's mount state.

        :param index: Index of the item in the data structure.
        :type index: QModelIndex
        :param role: Item role according to Qt.
        :type role: int
        :return: Device name or icon according to mount state.
        """
        if role == Qt.DisplayRole:
            return self.devices[index.row()].sys_name
        if role == Qt.DecorationRole:
            if (self.get_mount_point(self.devices[index.row()]) != ''):
                return QIcon.fromTheme('media-eject')
            else:
                return QIcon.fromTheme('drive-harddisk')
Beispiel #21
0
 def on_listview_point_select(self, current: QModelIndex,
                              previous: QModelIndex):
     if current.isValid():
         row = current.row()
         print(rf'some point be selected {row}')
         #todo sync with four axes and right list?
         #save to local ?
         #self._on_currentListDataChanged(self._acqs[row])
         pass
     pass
Beispiel #22
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 #23
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 #24
0
 def data(self, index: QModelIndex, role: int = None):
     index = index.row()
     item = self.items[index]
     if role == self.ID:
         return item["id"]
     elif role == self.FILENAME:
         return item["filename"]
     elif role == self.VOLUME:
         return item["volume"]
     elif role == self.FILEPATH:
         return item["filepath"]
Beispiel #25
0
    def removeEntry(self):
        selectedIndexes = self.ui.ganttView.selectionModel().selectedIndexes()
        if len(selectedIndexes) > 0:
            index = selectedIndexes[0]
        else:
            index = QModelIndex()

        if not index.isValid():
            return

        self.model.removeRow(index.row(), index.parent())
Beispiel #26
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 #27
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 #28
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 #29
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 #30
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