Python PyQt5.QtCore.QModelIndex() Examples
The following are 30
code examples of PyQt5.QtCore.QModelIndex().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
PyQt5.QtCore
, or try the search function
.
Example #1
Source File: completionmodel.py From qutebrowser with GNU General Public License v3.0 | 6 votes |
def columnCount(self, parent=QModelIndex()): """Override QAbstractItemModel::columnCount.""" # pylint: disable=unused-argument return 3
Example #2
Source File: ObjList.py From KStock with GNU General Public License v3.0 | 6 votes |
def removeObjects(self, i, num = 1): if (len(self.objects) == 0) or (num <= 0): return False i = min([max([0, i]), len(self.objects) - 1]) # Clamp i to a valid object index. num = min([num, len(self.objects) - i]) # Clamp num to a valid number of objects. if num == len(self.objects): # Make sure we have a template for inserting objects later. if self.templateObject is None: self.templateObject = self.objects[0] if self.isRowObjects: self.beginRemoveRows(QModelIndex(), i, i + num - 1) del self.objects[i:i+num] self.endRemoveRows() else: self.beginRemoveColumns(QModelIndex(), i, i + num - 1) del self.objects[i:i+num] self.endRemoveColumns() return True
Example #3
Source File: settings_model.py From CHATIMUSMAXIMUS with GNU General Public License v3.0 | 6 votes |
def index(self, row, column, parent): """Returns QModelIndex to row, column in parent (QModelIndex)""" if parent.isValid() and parent.column() != 0: return QtCore.QModelIndex() if parent.isValid(): parent_pointer = parent.internalPointer() parent_dict = self.root[parent_pointer] else: parent_dict = self.root parent_pointer = () row_key = list(parent_dict.keys())[row] child_pointer = (*parent_pointer, row_key) try: child_pointer = self.my_index[child_pointer] except KeyError: self.my_index[child_pointer] = child_pointer index = self.createIndex(row, column, child_pointer) return index
Example #4
Source File: wallet_data_models.py From dash-masternode-tool with MIT License | 6 votes |
def index(self, row, column, parent=None, *args, **kwargs): try: if not parent or not parent.isValid(): if 0 <= row < len(self.accounts): return self.createIndex(row, column, self.accounts[row]) else: return QModelIndex() parentNode = parent.internalPointer() if isinstance(parentNode, Bip44AccountType): addr = parentNode.address_by_index(row) if addr: return self.createIndex(row, column, addr) return QModelIndex() except Exception as e: log.exception('Exception while creating index') raise
Example #5
Source File: settings_model.py From CHATIMUSMAXIMUS with GNU General Public License v3.0 | 6 votes |
def parent(self, index): """ Returns the parent (QModelIndex) of the given item (QModelIndex) Top level returns QModelIndex() """ if not index.isValid(): return QtCore.QModelIndex() child_key_list = index.internalPointer() if child_key_list: parent_key_list = child_key_list[:-1] if parent_key_list == ((),): return QtCore.QModelIndex() try: parent_key_list = self.my_index[parent_key_list] except KeyError: self.my_index[parent_key_list] = parent_key_list return self.createIndex(self.get_row(parent_key_list), 0, parent_key_list) else: return QtCore.QModelIndex()
Example #6
Source File: first.py From FIRST-plugin-ida with GNU General Public License v2.0 | 6 votes |
def rowCount(self, parent=QtCore.QModelIndex()): '''The number of rows under the given parent. When the parent is valid it means that rowCount is returning the number of children of parent. Args: parent (:obj:`QtCore.QModelIndex`, optional): Parent Returns: int: Number of rows ''' if None == self._data: return 0 return len(self._data)
Example #7
Source File: ObjList.py From KStock with GNU General Public License v3.0 | 6 votes |
def insertObjects(self, i, num = 1): if ((len(self.objects) == 0) and (self.templateObject is None)) or (num <= 0): return False i = min([max([0, i]), len(self.objects)]) # Clamp i to within [0, # of objects]. if self.isRowObjects: self.beginInsertRows(QModelIndex(), i, i + num - 1) else: self.beginInsertColumns(QModelIndex(), i, i + num - 1) for objectIndex in range(i, i + num): if self.templateObject is not None: self.objects.insert(objectIndex, copy.deepcopy(self.templateObject)) elif len(self.objects): copyIndex = min([max([0, objectIndex]), len(self.objects) - 1]) # Clamp objectIndex to a valid object index. self.objects.insert(objectIndex, copy.deepcopy(self.objects[copyIndex])) if self.isRowObjects: self.endInsertRows() else: self.endInsertColumns() return True
Example #8
Source File: ddt4all.py From ddt4all with GNU General Public License v3.0 | 6 votes |
def ecuSel(self, index): if index.parent() == core.QModelIndex(): return item = self.list.model().itemData(self.list.model().index(index.row(), 0, index.parent())) if qt5: selected = item[0] else: selected = utf8(item[0].toString()) target = self.ecuscan.ecu_database.getTarget(selected) name = selected if target: self.ecuscan.addTarget(target) if target.addr in self.ecuscan.ecu_database.addr_group_mapping: group = self.ecuscan.ecu_database.addr_group_mapping[target.addr] else: group = "Unknown" print name, group name = "[ " + group + " ] " + name if selected: if name not in options.main_window.ecunamemap: options.main_window.ecunamemap[name] = selected self.treeview_ecu.addItem(name)
Example #9
Source File: DefinitionTreeModel.py From Uranium with GNU Lesser General Public License v3.0 | 6 votes |
def parent(self, child): if not self._container: return QModelIndex() if not child.isValid(): return QModelIndex() parent = child.internalPointer().parent if not parent: return QModelIndex() row = None if not parent.parent: row = self._container.definitions.index(parent) else: row = parent.parent.children.index(parent) return self.createIndex(row, 0, parent)
Example #10
Source File: completionmodel.py From qutebrowser with GNU General Public License v3.0 | 6 votes |
def index(self, row, col, parent=QModelIndex()): """Get an index into the model. Override QAbstractItemModel::index. Return: A QModelIndex. """ if (row < 0 or row >= self.rowCount(parent) or col < 0 or col >= self.columnCount(parent)): return QModelIndex() if parent.isValid(): if parent.column() != 0: return QModelIndex() # store a pointer to the parent category in internalPointer return self.createIndex(row, col, self._categories[parent.row()]) return self.createIndex(row, col, None)
Example #11
Source File: completionmodel.py From qutebrowser with GNU General Public License v3.0 | 6 votes |
def data(self, index, role=Qt.DisplayRole): """Return the item data for index. Override QAbstractItemModel::data. Args: index: The QModelIndex to get item flags for. Return: The item data, or None on an invalid index. """ if role != Qt.DisplayRole: return None cat = self._cat_from_idx(index) if cat: # category header if index.column() == 0: return self._categories[index.row()].name return None # item cat = self._cat_from_idx(index.parent()) if not cat: return None idx = cat.index(index.row(), index.column()) return cat.data(idx)
Example #12
Source File: sources_dock.py From kite with GNU General Public License v3.0 | 6 votes |
def __init__(self, parent, idx, *args, **kwargs): QtGui.QMenu.__init__(self, *args, **kwargs) self.parent = parent self.sandbox = parent.sandbox self.idx = idx def removeSource(): self.sandbox.sources.removeSource(self.idx) editAction = self.addAction( 'Edit', lambda: self.parent.editSource(self.idx)) self.addMenu( SourcesAddButton.SourcesAddMenu(self.sandbox, self)) self.addSeparator() removeAction = self.addAction( self.style().standardIcon( QtGui.QStyle.SP_DialogCloseButton), 'Remove', removeSource) if self.sandbox.sources.rowCount(QtCore.QModelIndex()) == 0: editAction.setEnabled(False) removeAction.setEnabled(False)
Example #13
Source File: main_window.py From uPyLoader with MIT License | 6 votes |
def open_local_file(self, idx): assert isinstance(idx, QModelIndex) model = self.localFilesTreeView.model() assert isinstance(model, QFileSystemModel) if model.isDir(idx): return local_path = model.filePath(idx) remote_path = local_path.rsplit("/", 1)[1] if Settings().external_editor_path: self.open_external_editor(local_path) else: if FileInfo.is_file_binary(local_path): QMessageBox.information(self, "Binary file detected", "Editor doesn't support binary files.") return with open(local_path) as f: text = "".join(f.readlines()) self.open_code_editor() self._code_editor.set_code(local_path, remote_path, text)
Example #14
Source File: DefinitionTreeModel.py From Uranium with GNU Lesser General Public License v3.0 | 5 votes |
def index(self, row, column, parent = QModelIndex()): if not self._container: return QModelIndex() if not self.hasIndex(row, column, parent): return QModelIndex() definition = None if not parent.isValid(): definition = self._container.definitions[row] else: definition = parent.internalPointer().children[row] return self.createIndex(row, column, definition)
Example #15
Source File: locationbrowser.py From PyPipboyApp with GNU General Public License v3.0 | 5 votes |
def rowCount(self, parent = QtCore.QModelIndex()): if self.pipWorldLocations: return self.pipWorldLocations.childCount() else: return 0
Example #16
Source File: radiowidget.py From PyPipboyApp with GNU General Public License v3.0 | 5 votes |
def columnCount(self, parent = QtCore.QModelIndex()): return 4
Example #17
Source File: databrowserwidget.py From PyPipboyApp with GNU General Public License v3.0 | 5 votes |
def index(self, row, column, parent): if not self.rootObject or not self.hasIndex(row, column, parent): return QtCore.QModelIndex() if not parent.isValid(): parentItem = self.rootObject else: parentItem = parent.internalPointer() childItem = parentItem.child(row) if childItem: return self.createIndex(row, column, childItem) else: return QtCore.QModelIndex()
Example #18
Source File: qmodels.py From linux-show-player with GNU General Public License v3.0 | 5 votes |
def columnCount(self, parent=QModelIndex()): return len(self.columns)
Example #19
Source File: DefinitionTreeModel.py From Uranium with GNU Lesser General Public License v3.0 | 5 votes |
def count(self, parent = QModelIndex()): if not self._container: return 0 if parent.column() > 0: return 0 if not parent.isValid(): return len(self._container.definitions) setting = parent.internalPointer() return len(setting.children)
Example #20
Source File: listviews.py From awesometts-anki-addon with GNU General Public License v3.0 | 5 votes |
def moveRowsDown(self, row, count): # pylint:disable=C0103 """Moves the given count of records at the given row down.""" parent = QtCore.QModelIndex() self.beginMoveRows(parent, row, row + count - 1, parent, row + count + 1) self.raw_data = (self.raw_data[0:row] + self.raw_data[row + count:row + count + 1] + self.raw_data[row:row + count] + self.raw_data[row + count + 1:]) self.endMoveRows() return True
Example #21
Source File: radiowidget.py From PyPipboyApp with GNU General Public License v3.0 | 5 votes |
def rowCount(self, parent = QtCore.QModelIndex()): if self.pipRadio: return self.pipRadio.childCount() else: return 0
Example #22
Source File: effectswidget.py From PyPipboyApp with GNU General Public License v3.0 | 5 votes |
def columnCount(self, parent = QtCore.QModelIndex()): return 6
Example #23
Source File: effectswidget.py From PyPipboyApp with GNU General Public License v3.0 | 5 votes |
def rowCount(self, parent = QtCore.QModelIndex()): return len(self.effectList)
Example #24
Source File: inventorymodel.py From PyPipboyApp with GNU General Public License v3.0 | 5 votes |
def rowCount(self, parent = QtCore.QModelIndex()): return len(self._components)
Example #25
Source File: inventorymodel.py From PyPipboyApp with GNU General Public License v3.0 | 5 votes |
def columnCount(self, parent = QtCore.QModelIndex()): return super().columnCount(parent) + 2
Example #26
Source File: inventorymodel.py From PyPipboyApp with GNU General Public License v3.0 | 5 votes |
def columnCount(self, parent = QtCore.QModelIndex()): return super().columnCount(parent) + 1
Example #27
Source File: inventorymodel.py From PyPipboyApp with GNU General Public License v3.0 | 5 votes |
def columnCount(self, parent = QtCore.QModelIndex()): return super().columnCount(parent) + 5
Example #28
Source File: inventorymodel.py From PyPipboyApp with GNU General Public License v3.0 | 5 votes |
def columnCount(self, parent = QtCore.QModelIndex()): return super().columnCount(parent) + 9
Example #29
Source File: inventorymodel.py From PyPipboyApp with GNU General Public License v3.0 | 5 votes |
def columnCount(self, parent = QtCore.QModelIndex()): return 5
Example #30
Source File: inventorymodel.py From PyPipboyApp with GNU General Public License v3.0 | 5 votes |
def rowCount(self, parent = QtCore.QModelIndex()): return len(self._items)