Skip to content

Commit

Permalink
code-clean: make action-enabled a function for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
pboettch authored and jeandet committed Nov 17, 2023
1 parent 22bc25e commit bc01c33
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions tscat_gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,30 +121,34 @@ def __state_changed(self, action: str, type: Union[Type[_Catalogue], Type[_Event
self.programmatic_select = False

if action == 'active_select':
self.move_to_trash_action.setEnabled(False)
self.restore_from_trash_action.setEnabled(False)
self.delete_action.setEnabled(False)
self.new_event_action.setEnabled(False)
self.export_action.setEnabled(False)

if uuids:
if len(uuids) == 1:
self.new_event_action.setEnabled(True)

enable_restore = False
enable_move_to_trash = False

from .tscat_driver.model import tscat_model
for entity in tscat_model.entities_from_uuids(uuids):
if entity.is_removed():
enable_restore |= True
else:
enable_move_to_trash |= True

self.restore_from_trash_action.setEnabled(enable_restore)
self.move_to_trash_action.setEnabled(enable_move_to_trash)
self.delete_action.setEnabled(True)
self.export_action.setEnabled(True)
self._enable_disable_symbol_actions(uuids)

def _enable_disable_symbol_actions(self, uuids: Sequence[str]) -> None:
# Enable/disable actions based on the current selection
self.move_to_trash_action.setEnabled(False)
self.restore_from_trash_action.setEnabled(False)
self.delete_action.setEnabled(False)
self.new_event_action.setEnabled(False)
self.export_action.setEnabled(False)

if uuids:
if len(uuids) == 1:
self.new_event_action.setEnabled(True)

enable_restore = False
enable_move_to_trash = False

from .tscat_driver.model import tscat_model
for entity in tscat_model.entities_from_uuids(uuids):
if entity.is_removed():
enable_restore |= True
else:
enable_move_to_trash |= True

self.restore_from_trash_action.setEnabled(enable_restore)
self.move_to_trash_action.setEnabled(enable_move_to_trash)
self.delete_action.setEnabled(True)
self.export_action.setEnabled(True)

def __current_event_changed(self, _: QtCore.QModelIndex, __: QtCore.QModelIndex) -> None:
if not self.programmatic_select:
Expand Down

0 comments on commit bc01c33

Please sign in to comment.