From: Kevin A. <al...@se...> - 2001-08-19 17:43:22
|
To further emphasize the benefits of using the 'command' attribute I added buttons to the textIndexer sample that mirror the Go menu. I didn't have to make any changes to the code, only the .rsrc.py file since the command methods were already defined for the Go menu items. Here is the addition to the .rsrc.py file: { 'type':'Button', 'name':'btnFirstCard', 'position':(30, 210), 'label':'First', 'command':'goFirst'}, { 'type':'Button', 'name':'btnPrevCard', 'position':(110, 210), 'label':'Previous', 'command':'goPrev'}, { 'type':'Button', 'name':'btnNextCard', 'position':(190, 210), 'label':'Next', 'command':'goNext'}, { 'type':'Button', 'name':'btnLastCard', 'position':(270, 210), 'label':'Last', 'command':'goLast'}, You can change the 'command' attribute of a widget dynamically at runtime if you want, try it out with the Property Editor. If you have an action that you want to associate with multiple widgets, menu items, toolbar buttons (when we add those), etc. you should probably consider using a command; using commands can reduce the amount of code you need to write and make the logic of your UI clearer. ka > -----Original Message----- > From: pyt...@li... > [mailto:pyt...@li...]On Behalf Of Kevin > Altis > Sent: Saturday, August 18, 2001 12:13 PM > To: Pythoncard-Users > Subject: [Pythoncard-users] command events in textIndexer > > > 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... |