Hi!
Is there any way to capture which object generated an event? I'm using the
eventManager to have a better control of things here --- I must update
comboboxes and choiceboxes accordingly to prior selections on other
comboboxes and choiceboxes on the same wxPanel --- and I would like to know
if I can obtain the calling object name without creating a function to each
one.
Let me try to clarify this... I have the following code:
···
-------------------------------------------------------------------------------
eventManager.Register(self.__PreencherCodSubGrupos, EVT_CHOICE,
self.choiceCodGrupo)
eventManager.Register(self.__PreencherCodSubGrupos, EVT_CHOICE,
self.choiceCodGrupoFuncao)
-------------------------------------------------------------------------------
Is there any way in self.__PreencherCodSubGrupos to know if it was called
due to an event in self.choiceCodGrupo or self.choiceCodGrupoFuncao?
TIA,
--
Godoy. <godoy@ieee.org>
http://www.wxwindows.org/manuals/2.5.1/wx_wxevent.html#topic336
event.GetEventObject() should do it.
···
On Mon, 03 May 2004 08:53:10 -0300, Jorge Godoy <godoy@ieee.org> wrote:
Hi!
Is there any way to capture which object generated an event? I'm using the
eventManager to have a better control of things here --- I must update
comboboxes and choiceboxes accordingly to prior selections on other
comboboxes and choiceboxes on the same wxPanel --- and I would like to know
if I can obtain the calling object name without creating a function to each
one.
Let me try to clarify this... I have the following code:
-------------------------------------------------------------------------------
eventManager.Register(self.__PreencherCodSubGrupos, EVT_CHOICE,
self.choiceCodGrupo)
eventManager.Register(self.__PreencherCodSubGrupos, EVT_CHOICE,
self.choiceCodGrupoFuncao)
-------------------------------------------------------------------------------
Is there any way in self.__PreencherCodSubGrupos to know if it was called
due to an event in self.choiceCodGrupo or self.choiceCodGrupoFuncao?
TIA,
--
Peter Damoc
Hacker Wannabe
http://www.sigmacore.net/about.html
I had already tried that. Is there any way to get the object's name, as I
asked? I printed the output from an 'OK' button clicked:
<wxPython.controls.wxButton instance; proxy of C++ wxButton instance at
_845f020_wxButton_p>
I know that a button was clicked, but which one? There are two on the
screen. And, with buttons it's easier to handle their IDs, but how can I
deal with choice boxes, combo boxes, etc. without assigning them individual
IDs? The output for those widgets is the same as the one shown above, where
I know what kind of object was clicked, but I don't know which of these
objects was it. And using event.GetId I get a meaningless result for those
objects. One of my comboboxes returns '-220'. For such a combobox I have
the following:
GetId: -220
GetEventType: 10043
GetEventObject: <wxPython.controls.wxComboBox instance; proxy of C++
wxComboBox instance at _8420e78_wxComboBox_p>
The object name is 'comboDep', created by the following line:
self.comboDep = wxComboBox(self.notebook_1_pane_1, -1, choices=[""],
style=wxCB_DROPDOWN)
Is there any way to recover the name 'comboDep' from the event generated?
And thanks for the docs, but I tried them before writing here. I'm using
wxPython 2.4.2.4, with wxWidgets compiled with GTK 2 on Linux.
Thanks for the hint.
Be seeing you,
···
On Ter 04 Mai 2004 02:54, Peter Damoc wrote:
http://www.wxwindows.org/manuals/2.5.1/wx_wxevent.html#topic336
event.GetEventObject() should do it.
--
Godoy. <godoy@ieee.org>
well... take one step back and ask yourself what you really want. You want information; where is the information you want, how do you get that information.
hints:
think OOP, you're dealing with objects! objects carry information!
So... event.GetEventObject() will give you access to the object that triggered the event. Interogate that object. You want the ID of the object NOT the ID of the event.
You can attach info to the object:
self.choiceCodGrupo.choicesMap = [....]
will allow you to do something like this in the event handler:
combo = event.GetEventObject()
for choice in combo.choicesMap:
self.someOtherWidget.MeaningfulMethod(choice)
Put information you need somewhere easy to access.
···
On Tue, 04 May 2004 08:38:43 -0300, Jorge Godoy <godoy@ieee.org> wrote:
I know that a button was clicked, but which one? There are two on the
screen. And, with buttons it's easier to handle their IDs, but how can I
deal with choice boxes, combo boxes, etc. without assigning them individual
IDs? The output for those widgets is the same as the one shown above, where
I know what kind of object was clicked, but I don't know which of these
objects was it. And using event.GetId I get a meaningless result for those objects.
--
Peter Damoc
Hacker Wannabe
http://www.sigmacore.net/about.html
I know that a button was clicked, but which one? There are two on the
screen. And, with buttons it's easier to handle their IDs, but how can I
deal with choice boxes, combo boxes, etc. without assigning them individual
IDs? The output for those widgets is the same as the one shown above, where
I know what kind of object was clicked, but I don't know which of these
objects was it. And using event.GetId I get a meaningless result for those
objects. One of my comboboxes returns '-220'. For such a combobox I have
the following:
GetId: -220
GetEventType: 10043
GetEventObject: <wxPython.controls.wxComboBox instance; proxy of C++
wxComboBox instance at _8420e78_wxComboBox_p>
The object name is 'comboDep', created by the following line:
self.comboDep = wxComboBox(self.notebook_1_pane_1, -1, choices=[""],
style=wxCB_DROPDOWN)
# Definition
self.comboDep = ...
...
# Dispatch
obj = evt.GetEventObject()
if obj = self.comboDep :
...
elif ...:
else: ...
If you're doing this because you want the response to
each button to be different, why not use custom events
and bind each button/event to a separate handler. Then
wxPython takes care of dispatch automagically.
Is there any way to recover the name 'comboDep' from the event generated?
No. Nor from the object (which you can get from the event)
unless you assign it after creating the object:
self.comboDep = ...
setattr( self.comboDep, '_ownerRefName', 'comboDep' )
Yuck!
- Sam
···
At 2004-05-04 08:38 AM -0300, you wrote:
__________________________________________________________
Spinward Stars, LLC Samuel Reynolds
Software Consulting and Development 303-805-1446
http://SpinwardStars.com/ sam@SpinwardStars.com
If you're doing this because you want the response to
each button to be different, why not use custom events
and bind each button/event to a separate handler. Then
wxPython takes care of dispatch automagically.
Because with that I'd have to create several methods to wrap up another one
that will do the desired job. I'm doing some experiences and I have
multiple possibilities here a control might appear and all lead to the same
action, but the source of the information that will be used as a filter
changes accordingly to the selected widget.
No. Nor from the object (which you can get from the event)
unless you assign it after creating the object:
self.comboDep = ...
setattr( self.comboDep, '_ownerRefName', 'comboDep' )
Yuck!
Robin's answer solved the problem:
if event.GetEventObject() is <objectThatGeneratedTheEvent>:
do_something()
This works here and solves my problem.
Thanks for your help Samuel.
···
On Ter 04 Mai 2004 13:18, Samuel Reynolds wrote:
--
Godoy. <godoy@ieee.org>