28 |
|
|
29 |
A command is identified by a name, it has a title (used in menu |
A command is identified by a name, it has a title (used in menu |
30 |
items and buttons, etc) and a callable object that can be invoked |
items and buttons, etc) and a callable object that can be invoked |
31 |
with the context as a single parameter. The context is currently the |
with the context as a single parameter. The context is an object |
32 |
mainwindow object. |
with a few public attributes for the application object, the session |
33 |
|
and the main window. |
34 |
|
|
35 |
Additionally, a command may have functions that can determine |
Additionally, a command may have functions that can determine |
36 |
whether the command can be invoked or whether it is checked in case |
whether the command can be invoked or whether it is checked in case |
37 |
of a toggled command. These functions are called with just the |
of a toggled command. These functions are called with just the |
38 |
context as parameters. |
context as parameters. |
39 |
""" |
""" |
40 |
|
|
41 |
args = () |
args = () |
42 |
kwargs = None |
kwargs = None |
43 |
sensitive = None |
sensitive = None |
104 |
or self.checked is not None |
or self.checked is not None |
105 |
or self.dyntext is not None) |
or self.dyntext is not None) |
106 |
|
|
107 |
|
def IsTool(self): |
108 |
|
"""Return whether the command represents a tool. |
109 |
|
|
110 |
|
This default implementation always returns 0. |
111 |
|
""" |
112 |
|
return 0 |
113 |
|
|
114 |
def Execute(self, context, args = ()): |
def Execute(self, context, args = ()): |
115 |
kw = self.kwargs |
kw = self.kwargs |
116 |
if kw is None: |
if kw is None: |
120 |
#print self.name, self.args, args |
#print self.name, self.args, args |
121 |
apply(self.function, (context,) + self.args + args, kw) |
apply(self.function, (context,) + self.args + args, kw) |
122 |
|
|
123 |
|
class ToolCommand(Command): |
124 |
|
|
125 |
|
"""A command tool activating a tool""" |
126 |
|
|
127 |
|
def IsTool(self): |
128 |
|
"""Return whether the command represents a tool, i.e. always 1""" |
129 |
|
return 1 |
130 |
|
|
131 |
|
|
132 |
class CommandRegistry: |
class CommandRegistry: |
133 |
|
|