Package Camelot :: Package camelot :: Package view :: Package controls :: Module action_widget |
[frames] | no frames]

# Source Code for Module Camelot.camelot.view.controls.action_widget

     1  '''
     2  Created on May 22, 2010
     3
     4  @author: tw55413
     5  '''
     6  from PyQt4 import QtGui, QtCore
     7
     8  from camelot.view.model_thread import post
     9
    10 -class ActionWidget(QtGui.QPushButton):
    11      """A button that can be pushed to trigger an action"""
    12
    13 -    def __init__(self, action, entity_getter, parent):
    14          super(QtGui.QPushButton, self).__init__( unicode(action.get_name() ) )
    15          if action.get_icon():
    16              self.setIcon( action.get_icon().getQIcon() )
    17          self._action = action
    18          self._entity_getter = entity_getter
    19          self.connect( self, QtCore.SIGNAL( 'clicked()' ), self.triggered )
    20
    21 -    def triggered(self):
    22          """This slot is triggered when the user triggers the action."""
    23          self._action.run( self._entity_getter )
    24
    25 -    def changed(self):
    26          """This slot is triggered when the entity displayed has changed, which means
    27          the state of the widget needs to be updated"""
    28          post( self._is_enabled, self._set_enabled )
    29
    30 -    def _set_enabled(self, enabled):
    31          self.setEnabled( enabled )
    32
    33 -    def _is_enabled(self):
    34          obj = self._entity_getter()
    35          return self._action.enabled(obj)
    36