|
From: Kevin A. <al...@se...> - 2001-08-18 19:12:25
|
In order to increase the usefulness of the textIndexer as a testing ground
for the PythonCard prototype I used command events for all of the menu
items. Rowland added command events quite a while ago, but this is the first
time I have used them. Since we haven't really talked about the 'command'
attribute before I thought I would show what it looks like by comparing
equivalent functionality in searchexplorer and textIndexer.
searchexplorer.rsrc.py
{ 'type':'MenuItem',
'name':'menuEditCopy',
'label':'&Copy\tCtrl-C'},
searchexplorer.py
def on_menuEditCopy_select(self, menu, event):
widget = self.findFocus()
if hasattr(widget, 'editable') and widget.canCopy():
widget.copy()
textIndexer.rsrc.py
{ 'type':'MenuItem',
'name':'menuEditCopy',
'label':'&Copy\tCtrl-C',
'command':'editCopy'},
textIndexer.py
def on_editCopy_command(self, menu, event):
widget = self.findFocus()
if hasattr(widget, 'editable') and widget.canCopy():
widget.copy()
As you can see there isn't much to it. Any widget can have an associated
command event, so a button could also be tied to 'editCopy'. Part of the
reason for doing command events is that you can disable a command and then
it will be disabled for all associated menus and widgets. Rowland will have
to go into more detail when he has a chance.
ka
---
Kevin Altis
al...@se...
|