Permalink
Browse files

ToolBar: Listen to Action name changes for toolbar actions.

Checkable actions especially change their name in response to
checked state change, toolbar buttons now honor the change in
the action's name and change the button text accordingly.
  • Loading branch information...
1 parent 8d896ff commit d43e0d5b963e91b7882bc8f427b6a1764a73dd3d @pankajp pankajp committed Jul 26, 2013
Showing with 13 additions and 0 deletions.
  1. +13 −0 pyface/ui/qt4/action/action_item.py
@@ -300,6 +300,9 @@ def __init__(self, parent, tool_bar, image_cache, item, controller,
action.on_trait_change(self._on_action_enabled_changed, 'enabled')
action.on_trait_change(self._on_action_visible_changed, 'visible')
action.on_trait_change(self._on_action_checked_changed, 'checked')
+ action.on_trait_change(self._on_action_name_changed, 'name')
+ action.on_trait_change(self._on_action_accelerator_changed,
+ 'accelerator')
# Detect if the control is destroyed.
self.control.destroyed.connect(self._qt4_on_destroyed)
@@ -389,6 +392,16 @@ def _on_action_checked_changed(self, action, trait_name, old, new):
if self.control is not None:
self.control.setChecked(action.checked)
+ def _on_action_name_changed(self, action, trait_name, old, new):
+ """ Called when the name trait is changed on an action. """
+ if self.control is not None:
+ self.control.setText(action.name)
+
+ def _on_action_accelerator_changed(self, action, trait_name, old, new):
+ """ Called when the accelerator trait is changed on an action. """
+ if self.control is not None:
+ self.control.setShortcut(action.accelerator)
+
class _PaletteTool(HasTraits):
""" A tool palette representation of an action item. """

0 comments on commit d43e0d5

Please sign in to comment.