Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Provides control on item enability and selectability for DataView #1023

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions pyface/data_view/abstract_data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,44 @@ def get_value_type(self, row, column):
"""
raise NotImplementedError()

def is_enabled(self, row, column):
""" Whether the item located at row and column is enabled.

The default method returns True.

Parameters
----------
row : sequence of int
The indices of the row as a sequence from root to leaf.
column : sequence of int
The indices of the column as a sequence of length 0 or 1.

Returns
-------
can_set_value : bool
Whether or not the item is enabled.
"""
return True

def is_selectable(self, row, column):
""" Whether the item located at row and column is selectable.

The default method returns True.

Parameters
----------
row : sequence of int
The indices of the row as a sequence from root to leaf.
column : sequence of int
The indices of the column as a sequence of length 0 or 1.

Returns
-------
can_set_value : bool
Whether or not the item is selectable.
"""
return True

# Convenience methods

def is_row_valid(self, row):
Expand Down
16 changes: 10 additions & 6 deletions pyface/ui/qt4/data_view/data_view_item_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,18 @@ def flags(self, index):
row = self._to_row_index(index)
column = self._to_column_index(index)
value_type = self.model.get_value_type(row, column)
if row == () and column == ():
return Qt.ItemIsEnabled

flags = Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled
if is_qt5 and not self.model.can_have_children(row):
flags |= Qt.ItemNeverHasChildren

flags = Qt.ItemIsDragEnabled
try:
if self.model.is_enabled(row, column):
flags |= Qt.ItemIsEnabled

if self.model.is_selectable(row, column):
flags |= Qt.ItemIsSelectable

if is_qt5 and not self.model.can_have_children(row):
flags |= Qt.ItemNeverHasChildren

if value_type:
if value_type.has_editor_value(self.model, row, column):
flags |= Qt.ItemIsEditable
Expand Down