FindWindowByName and multiple objects with same name

Does anyone know how the method FindWindowByName handles objects that
have the same name? If it strictly returns the first object with that
Name then can anyone suggest a workaround. Once I have found one, how
can I find the next?
I am trying to avoid loggind Object ID's to track if there are multple
objects with the same name.

Thanks

Lee,

···

On Fri, Sep 4, 2009 at 5:24 PM, Lee Walczak lee.walczak@gmail.com wrote:

Does anyone know how the method FindWindowByName handles objects that

have the same name? If it strictly returns the first object with that

Name then can anyone suggest a workaround. Once I have found one, how

can I find the next?

I am trying to avoid loggind Object ID’s to track if there are multple

objects with the same name.

Thanks

FindWindowByName is a Windows only hack that you would use only if you have the proper id that you got with a tool like Spy++. Since you create all your “windows” you can keep track of them yourself somehow. For example, the wx.Frame object has a “name” argument. Set each of these to something unique in your application you should be able to use the frame’s FindWindowByName() method to find out which it is…

Or am I confused as to what you require?


Mike Driscoll

Blog: http://blog.pythonlibrary.org

Lee Walczak wrote:

Does anyone know how the method FindWindowByName handles objects that
have the same name?

It stops at the first match.

If it strictly returns the first object with that
Name then can anyone suggest a workaround. Once I have found one, how
can I find the next?

There isn't a way in wx to do it, but writing your own Find function that recurses down through the containment hierarchy using the GetChildren method would be very simple to do.

···

--
Robin Dunn
Software Craftsman

Hi Guys, thanks for your feedback on this.

Unfortunately, the hierarchy for these mutliple objects is quite flat, so I am not sure how a find function will work here.
FYI, I have a notebook that contains several pages. On each page I have several objects, Button, Comboboxs etc. It is possible that each page could have an object identical by name and object type to one on another page. The requirement is:

  1. if I change the object value on one page then it should update the other(s)
  2. if I update the contents of all my objects ( presently done by referencing a list object names and using findwindowbyname() ) then identical named objects should also be updated by the with the same value.

Still, I submitted to building a dictionary that captures all IDs i.e. DICT[Obj.Name] = [Obj.GetId()] for all objects name upon creation. If I find an objName already present in the Dict then I extend the Id list. It wasn’t so bad to implement in the end but any alternative ideas and concepts are welcome!

Lee Walczak wrote:

Hi Guys, thanks for your feedback on this.

Unfortunately, the hierarchy for these mutliple objects is quite flat, so I am not sure how a find function will work here.
FYI, I have a notebook that contains several pages. On each page I have several objects, Button, Comboboxs etc. It is possible that each page could have an object identical by name and object type to one on another page. The requirement is:

1) if I change the object value on one page then it should update the other(s)
2) if I update the contents of all my objects ( presently done by referencing a list object names and using findwindowbyname() ) then identical named objects should also be updated by the with the same value.

Still, I submitted to building a dictionary that captures all IDs i.e. DICT[Obj.Name] = [Obj.GetId()] for all objects name upon creation. If I find an objName already present in the Dict then I extend the Id list. It wasn't so bad to implement in the end but any alternative ideas and concepts are welcome!

I think I would turn it inside-out and instead of tracking or finding all the widgets of certain names so you can notify them, just allow the widgets themselves to monitor for notifications that belong to them and to react accordingly. For example, you can use pubsub to allow the widgets to subscribe to messages of a certain topic(s) and then when you want update them you just send a message with that topic and all the appropriate subscribed widgets will be notified.

···

--
Robin Dunn
Software Craftsman