def remove_row(self): index_list = [] for model_index in self.view.table.selectionModel().selectedRows(): index = QtCore.QPersistentModelIndex(model_index) index_list.append(index) for index in index_list: self.model.removeRow(index.row()) self.view.update_view()
def __init__(self, index): """Display a given dataset in the MDI area. """ # The main application window self.vtgui = vtutils.getVTApp().gui # The data structure (LeafNode/LinkNode instance) whose dataset # is being displayed dbt_model = self.vtgui.dbs_tree_model self.dbt_leaf = dbt_model.nodeFromIndex(index) # The tables.Node instance tied to that data structure pt_node = self.dbt_leaf.node if hasattr(pt_node, 'target'): # The selected item is a link and must be dereferenced leaf = pt_node() else: leaf = pt_node self.leaf_model = df_model.try_opening_as_dataframe(leaf) if not self.leaf_model: self.leaf_model = leaf_model.LeafModel(leaf) self.leaf_view = leaf_view.LeafView(self.leaf_model) super(DataSheet, self).__init__(self.vtgui.workspace, QtCore.Qt.SubWindow) self.setWidget(self.leaf_view) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) # Customize the title bar if not isinstance(leaf.title, str): title = str(leaf.title) else: title = leaf.title wtitle = "{0}\t{1}".format(self.dbt_leaf.name, title) self.setWindowTitle(wtitle) self.setWindowIcon(self.dbt_leaf.icon) # Eventually update the Node menu actions self.dbt_leaf.has_view = True self.vtgui.updateActions() self.pindex = QtCore.QPersistentModelIndex(index) # Connect signals to slots self.aboutToActivate.connect(self.syncTreeView) self.leaf_view.doubleClicked.connect(self.zoomCell) self.clip = QApplication.clipboard() self.md_array(self.leaf_view.tmodel)
def activateNode(self, index): """Expand an item via `Enter`/`Return` key or mouse double click. When the user activates a collapsed item (by pressing `Enter`, `Return` or by double clicking the item) then it is expanded. If the user activates the node by double clicking on it while the `Shift` key is pressed, the item is edited (if editing is enabled). Lazy population of the model is partially implemented in this method. Expanded items are updated so that children items are added if needed. This fact improves enormously the performance when files whit a large number of nodes are opened. This method is a slot connected to the activated(QModelIndex) signal in the ctor. :Parameter index: the index of the activated item """ modifiers = QtWidgets.QApplication.keyboardModifiers() if (modifiers & QtCore.Qt.ShiftModifier) or \ (modifiers & QtCore.Qt.ControlModifier): return node = self.dbt_model.nodeFromIndex(index) if node.node_kind.count('group'): if not self.isExpanded(index): self.expand(index) elif node.has_view: ## Activate already-open window. # wrkspc = self.vtgui.workspace pcurrent = QtCore.QPersistentModelIndex(index) for window in wrkspc.subWindowList(): if pcurrent == window.pindex: wrkspc.setActiveSubWindow(window) else: self.vtapp.nodeOpen(index)