On Dec 3, 2010, at 9:03 AM, Iain Simpson wrote:
> a. click on any one of these buttons to take further action (eg display
> photo, file name etc.).
> I tried (unsuccessfully) to bind an event to the button :
>
> #def clickMap(self):
> # dabo.ui.info(self.Caption)
> #.
> #.
> #self.btn.bindEvent(dabo.dEvents.Hit,clickMap)
>
> .. but I'm not sure how to do it. If I click on a button it takes focus
> (eg. 4804)- changes colour etc. But how to I associate code with this
> button ?
Two ways: bindEvent() will do it explicitly, or you can pass in the
binding when you create the button: e.g.: btn = dabo.ui.dButton(self,
Caption="foo", OnHit=self.myButtonHandler)
The method that you bind to has to be an event handler; i.e., it has to
accept an event object parameter. Event handlers look something like:
def myButtonHandler(self, evt):
The 'evt' object received contains lots of information about the event
that was raised, such as 'evt.EventObject', which would be the object raising
the event (the button in this case), and 'evt.EventData', which contains
different bits of information depending on the type of the event.
If you have a behavior that is common to all buttons, you can make the
handler a form-level method, and then use evt.EventObject to get a reference to
the button that was clicked.
> b. How can I reset the image and destroy all the added buttons (apart
> from destroying & rebuilding the form)
> Using the dabo shell I can find the buttons :
>
> for a in self.Children : print a
> ..
> .
> <dButton50 (baseclass dabo.ui.dButton, id:-1672)>
> <dButton51 (baseclass dabo.ui.dButton, id:-1701)>
> <dButton52 (baseclass dabo.ui.dButton, id:-1714)>
> . etc
>
> How can I access the properties of each button ?
>
> (I suspect these involve areas of Python programming I haven't grasped
> yet !)
I would create a form-level attribute that holds a list of all the
buttons in question. At the beginning of the form's afterInit() code, create
that list:
self.buttons = []
Then when you create the buttons, add them to the list:
btn = dabo.ui.dButton(self, ...)
self.buttons.append(btn)
When you need to destroy them, you can call the release() method of
every button in the list, and then reset the list to [].
-- Ed Leafe
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message:
http://leafe.com/archives/byMID/[email protected]