camelot.camelot.view.controls.actions

Package camelot :: Package camelot :: Package view :: Package controls :: Module actions |
[hide private]
[frames] | no frames]

# Source Code for Module camelot.camelot.view.controls.actions

     1  #  ==================================================================================
     2  #
     3  #  Copyright (C) 2007-2008 Conceptive Engineering bvba. All rights reserved.
     4  #  www.conceptive.be / project-camelot@conceptive.be
     5  #
     6  #  This file is part of the Camelot Library.
     7  #
     8  #  This file may be used under the terms of the GNU General Public
     9  #  License version 2.0 as published by the Free Software Foundation
    10  #  and appearing in the file LICENSE.GPL included in the packaging of
    11  #  this file.  Please review the following information to ensure GNU
    12  #  General Public Licensing requirements will be met:
    13  #  http://www.trolltech.com/products/qt/opensource.html
    14  #
    15  #  If you are unsure which license is appropriate for your use, please
    16  #  review the following information:
    17  #  http://www.trolltech.com/products/qt/licensing.html or contact
    18  #  project-camelot@conceptive.be.
    19  #
    20  #  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
    21  #  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    22  #
    23  #  For use of this library in commercial applications, please contact
    24  #  project-camelot@conceptive.be
    25  #
    26  #  ==================================================================================
    27
    28  """Action buttons"""
    29  import logging
    30
    31  logger = logging.getLogger('controls.actions')
    32
    33  from PyQt4 import QtCore, QtGui
    34
    35  _ = lambda x:x
    36
    37  from camelot.view.remote_signals import get_signal_handler
    38
    39 -class ActionsBox(QtGui.QGroupBox):
    40    """A box containing actions to be applied to a form view"""
    41
    42 -  def __init__(self, parent, model_thread, entity_getter):
    43      logger.debug('create actions box')
    44      QtGui.QGroupBox.__init__(self, _('Actions'), parent)
    45      self.group = QtGui.QButtonGroup()
    46      self.mt = model_thread
    47      self.rsh = get_signal_handler()
    48      self.entity_getter = entity_getter
    49      self.connect(self.group, QtCore.SIGNAL('buttonPressed(int)'), self.executeAction)
    50
    51 -  def setActions(self, actions):
    52      logger.debug('setting actions to %s'%str(actions))
    53      self.actions = []
    54      layout = QtGui.QVBoxLayout()
    55      for i,(name,functor) in enumerate(actions):
    56        button = QtGui.QPushButton(_(name))
    57        layout.addWidget(button)
    58        self.group.addButton(button, i)
    59        self.actions.append((name, functor))
    60      layout.addStretch()
    61      self.setLayout(layout)
    62
    63 -  def executeAction(self, button_id):
    64
    65      def execute_and_flush():
    66        from elixir import session
    67        entity = self.entity_getter()
    68        self.actions[button_id][1](entity)
    69        session.flush([entity])
    70        self.rsh.sendEntityUpdate(self, entity)
    71
    72      def executed(result):
    73        logger.debug('action %i executed'%button_id)
    74
    75      self.mt.post(execute_and_flush, executed )
    76
    77 -  def __del__(self):
    78      logger.debug('delete actions box')
    79