mirror of
https://github.com/rbreu/beeref.git
synced 2026-03-11 08:54:28 +00:00
Fix: (re-)building menu sets actiongroup enabled status
This commit is contained in:
parent
5448d7bb7b
commit
5fde9f35a7
3 changed files with 45 additions and 19 deletions
|
|
@ -50,7 +50,6 @@ actions = [
|
|||
'shortcuts': ['Ctrl+Z'],
|
||||
'callback': 'on_action_undo',
|
||||
'group': 'active_when_can_undo',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'redo',
|
||||
|
|
@ -58,7 +57,6 @@ actions = [
|
|||
'shortcuts': ['Ctrl+Shift+Z'],
|
||||
'callback': 'on_action_redo',
|
||||
'group': 'active_when_can_redo',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'copy',
|
||||
|
|
@ -86,7 +84,6 @@ actions = [
|
|||
'shortcuts': ['Del'],
|
||||
'callback': 'on_action_delete_items',
|
||||
'group': 'active_when_selection',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'normalize_height',
|
||||
|
|
@ -94,7 +91,6 @@ actions = [
|
|||
'shortcuts': ['Shift+H'],
|
||||
'callback': 'on_action_normalize_height',
|
||||
'group': 'active_when_selection',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'normalize_width',
|
||||
|
|
@ -102,7 +98,6 @@ actions = [
|
|||
'shortcuts': ['Shift+W'],
|
||||
'callback': 'on_action_normalize_width',
|
||||
'group': 'active_when_selection',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'normalize_size',
|
||||
|
|
@ -110,7 +105,6 @@ actions = [
|
|||
'shortcuts': ['Shift+S'],
|
||||
'callback': 'on_action_normalize_size',
|
||||
'group': 'active_when_selection',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'arrange_optimal',
|
||||
|
|
@ -118,21 +112,18 @@ actions = [
|
|||
'shortcuts': ['Shift+O'],
|
||||
'callback': 'on_action_arrange_optimal',
|
||||
'group': 'active_when_selection',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'arrange_horizontal',
|
||||
'text': '&Horizontal',
|
||||
'callback': 'on_action_arrange_horizontal',
|
||||
'group': 'active_when_selection',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'arrange_vertical',
|
||||
'text': '&Vertical',
|
||||
'callback': 'on_action_arrange_vertical',
|
||||
'group': 'active_when_selection',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'flip_horizontally',
|
||||
|
|
@ -140,7 +131,6 @@ actions = [
|
|||
'shortcuts': ['H'],
|
||||
'callback': 'on_action_flip_horizontally',
|
||||
'group': 'active_when_selection',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'flip_vertically',
|
||||
|
|
@ -148,7 +138,6 @@ actions = [
|
|||
'shortcuts': ['V'],
|
||||
'callback': 'on_action_flip_vertically',
|
||||
'group': 'active_when_selection',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'new_scene',
|
||||
|
|
@ -168,28 +157,24 @@ actions = [
|
|||
'shortcuts': ['2'],
|
||||
'callback': 'on_action_fit_selection',
|
||||
'group': 'active_when_selection',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'reset_scale',
|
||||
'text': 'Reset &Scale',
|
||||
'callback': 'on_action_reset_scale',
|
||||
'group': 'active_when_selection',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'reset_rotation',
|
||||
'text': 'Reset &Rotation',
|
||||
'callback': 'on_action_reset_rotation',
|
||||
'group': 'active_when_selection',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'reset_flip',
|
||||
'text': 'Reset &Flip',
|
||||
'callback': 'on_action_reset_flip',
|
||||
'group': 'active_when_selection',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'reset_transforms',
|
||||
|
|
@ -197,7 +182,6 @@ actions = [
|
|||
'shortcuts': ['R'],
|
||||
'callback': 'on_action_reset_transforms',
|
||||
'group': 'active_when_selection',
|
||||
'enabled': False,
|
||||
},
|
||||
{
|
||||
'id': 'select_all',
|
||||
|
|
|
|||
|
|
@ -38,6 +38,14 @@ class ActionsMixin:
|
|||
self.clear_actions(menu)
|
||||
self._create_actions()
|
||||
menu = self._create_menu(self.bee_actions, menu, menu_structure)
|
||||
|
||||
self.actiongroup_set_enabled(
|
||||
'active_when_can_redo', self.undo_stack.canRedo())
|
||||
self.actiongroup_set_enabled(
|
||||
'active_when_can_undo', self.undo_stack.canUndo())
|
||||
self.actiongroup_set_enabled(
|
||||
'active_when_selection', self.scene.has_selection())
|
||||
|
||||
return menu
|
||||
|
||||
def clear_actions(self, menu):
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@ from ..base import BeeTestCase
|
|||
|
||||
|
||||
class FooWidget(QtWidgets.QWidget, ActionsMixin):
|
||||
settings = MagicMock
|
||||
settings = MagicMock()
|
||||
undo_stack = MagicMock()
|
||||
scene = MagicMock()
|
||||
|
||||
def on_foo(self):
|
||||
pass
|
||||
|
|
@ -120,8 +122,8 @@ class ActionsMixinTestCase(BeeTestCase):
|
|||
}]
|
||||
self.menu_mock.__iter__.return_value = ['foo']
|
||||
self.widget.build_menu_and_actions()
|
||||
assert len(self.widget.actions()) == 1
|
||||
qaction = self.widget.actions()[0]
|
||||
assert len(self.widget.bee_actiongroups) == 1
|
||||
assert self.widget.bee_actiongroups['bar'] == [qaction]
|
||||
|
||||
def test_build_menu_and_actions_with_actions(self):
|
||||
|
|
@ -184,6 +186,38 @@ class ActionsMixinTestCase(BeeTestCase):
|
|||
assert self.widget.bee_actions['foo'].isEnabled() is False
|
||||
assert self.widget.bee_actions['bar'].isEnabled() is True
|
||||
|
||||
def test_build_menu_and_actions_enables_actiongroups(self):
|
||||
self.widget.scene.has_selection.return_value = True
|
||||
self.actions_mock.__iter__.return_value = [
|
||||
{
|
||||
'id': 'foo',
|
||||
'text': '&Foo',
|
||||
'callback': 'on_foo',
|
||||
'group': 'active_when_selection',
|
||||
},
|
||||
]
|
||||
|
||||
self.menu_mock.__iter__.return_value = ['foo']
|
||||
self.widget.build_menu_and_actions()
|
||||
qaction = self.widget.actions()[0]
|
||||
assert qaction.isEnabled() is True
|
||||
|
||||
def test_build_menu_and_actions_disables_actiongroups(self):
|
||||
self.widget.scene.has_selection.return_value = False
|
||||
self.actions_mock.__iter__.return_value = [
|
||||
{
|
||||
'id': 'foo',
|
||||
'text': '&Foo',
|
||||
'callback': 'on_foo',
|
||||
'group': 'active_when_selection',
|
||||
},
|
||||
]
|
||||
|
||||
self.menu_mock.__iter__.return_value = ['foo']
|
||||
self.widget.build_menu_and_actions()
|
||||
qaction = self.widget.actions()[0]
|
||||
assert qaction.isEnabled() is False
|
||||
|
||||
@patch('beeref.config.BeeSettings.get_recent_files')
|
||||
@patch('PyQt6.QtGui.QAction.triggered')
|
||||
def test_recent_files(self, triggered_mock, files_mock):
|
||||
|
|
@ -240,7 +274,7 @@ class ActionsMixinTestCase(BeeTestCase):
|
|||
qaction = self.widget.actions()[0]
|
||||
assert qaction.text() == '&Bar'
|
||||
assert self.widget.bee_actions == {'bar': qaction}
|
||||
assert self.widget.bee_actiongroups == {'bar': [qaction]}
|
||||
assert self.widget.bee_actiongroups['bar'] == [qaction]
|
||||
|
||||
def test_clear_actions(self):
|
||||
self.actions_mock.__iter__.return_value = [{
|
||||
|
|
|
|||
Loading…
Reference in a new issue