source: coopr.gui.coopr/trunk/coopr/gui/coopr/Action.py @ 2135

Last change on this file since 2135 was 2135, checked in by wehart, 10 years ago

Adding Jython GUI components.

  • Property svn:executable set to *
File size: 1002 bytes
Line 
1# I don't really like the design of this one...
2from pawt import swing
3
4class Action(swing.AbstractAction):
5        def __init__(self, name, action=None, icon=None, description=None, needEvent=0):
6                if action is None:
7                        action = name
8                        name = action.__name__
9
10                #swing.AbstractAction.__init__(self, name)
11                self.name = name
12                self.icon = icon
13                if icon:
14                        self.setIcon(swing.Action.SMALL_ICON, icon)
15                if description:
16                        self.setText(swing.Action.SHORT_DESCRIPTION, description)
17                        self.description = description
18                else:
19                        self.description = name
20                self.action = action
21
22                self.enabled = 1
23                self.needEvent = needEvent
24
25        def actionPerformed(self, event):
26                if self.needEvent:
27                        self.action(event)
28                else:
29                        self.action()
30
31        def createMenuItem(self):
32                mi = swing.JMenuItem(self.name, actionListener=self, enabled=self.enabled)
33                return mi
34
35class TargetAction(Action):
36        def actionPerformed(self, event):
37                if self.needEvent:
38                        self.action(self.getTarget(), event)
39                else:
40                        self.action(self.getTarget())
Note: See TracBrowser for help on using the repository browser.