tags:

views:

65

answers:

2

Greetings all,

I have a wxPython project (created with wxFormBuilder) that contains two panels, each of which contain a wxListCtrl. When loading the list control, each can have different columns displayed. Since the lists are contained in the panels, they both have the same ID, and the same routine is for both the list's populate routines.

I need to determine at runtime which list is being populated so that I can retrieve the appropriate configuration data. If I use the list.GetID() am I guaranteed that these values will be the same every time it is run? That is, can I safely save the config details based on the GetID() value so the next time it is run it does the right/same thing?

Is there a better, smarter, simpler way that eludes me?

Thanks!

A: 

I don't think there's any guarantee that GetID() will be consistent run to run.

Can you just assign your own ID to each list after it's made? Something like:

listctrl.myID = 5

Another idea is that if the child IDs aren't unique, maybe you could use GetParent() and build a tuple of both the parent and list IDs, and then this tuple would be unique.

And even if the assigned IDs aren't unique, the Python IDs will be.

tom10
Well, I could iterate over all of the panels that belong to a frame, and assign them a counter value. Or would that offend the gods?
Billy Pilgrim
Honestly, I don't quite understand the problem well enough to say exactly how you do this. Specifically, when you want to know the ID, what do you start with?
tom10
Maybe if you posted a little example I could figure out what the issue is. For example, why not just catch EVT_LIST_INSERT_ITEM for each list?
tom10
lets assume that I have a method: def populateList( list ): cols = get_list_columns( list ) which is used for any list in my Frame, and can be different for each list. This can be called anytime some companion control is changed, but will only have a 'self' reference. I want to look up which columns are to be available for a specific list (list A, list B, list C, etc). Therefore, I need a way to uniquely identify them so that I can pull out the right config data.BTW: wxFrame.GetChildren() returns a wxWindowList which is not documented -- help anyone?
Billy Pilgrim
If you want different populating methods for different lists, then you can just make that method an attribut, like listA.pop_method = population_method_A, and in your handler, you don't need to know that it's listA, since when you call listctrl.pop_method() it will call the one you set. Also, you can use functools.partial is the functions are similar but just need different parameters, or a class method, etc.
tom10
BTW, it's too tiresome to do this all in the abstract, so since you're not posting any code, I think the above is my last answer. You're question certainly has an easy solution, but it's hard to guess at the exact details that would work for you since I don't know the exact details of your problem.
tom10
A: 

Can you give each a different value for the name attribute, then use FindWindowByName when you need to refer to one or the other?

Bryan Oakley