1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
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
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
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
78 logger.debug('delete actions box')
79