Matching wx.ListCtrl's members to a data dictionary

Hi,

As my learning is progressing I've written a little app to link to a drug
database I have in postgres. I set myself a task of being able to select just
the vaccines, put them in a list, and then by clicking on one row, display
the vaccines product information.

I can't seem to match the data dictionary to the row in the list.

I enclose some code snippets to give anyone brave enough to help me the gist
of the problem.

The listcontrol and panel it is on is petty much stock snipped from the demo.
The other routines pull out the drug data, and load it into the list.

What happens, as you can see from the piccie, is that even when the drug
dictionary is in the correct order, the vaccines end up upside down in the
list. The text BTW pn staands for pneumo.... (type of bacteria) which brings
up the brand names of the vaccines against this organism.

I've strugged with this for several frustrating hours, getting nowhere.
Obviously its is something to do with sorting, however the when I put the
first item in the list, it ends up down the bottom, sorted inversly.

If someone can help, could you explicity write a few lines of example code,
not just say 'use bla bla....' because if you do I still won't have a clue to
implement it.

Thanks in anticipation

Richard

ian_vacc_main.png

temp_vacc_snippets (3.28 KB)

Richard Terry wrote:

Hi,

As my learning is progressing I've written a little app to link to a drug
database I have in postgres. I set myself a task of being able to select
just the vaccines, put them in a list, and then by clicking on one row,
display the vaccines product information.

I can't seem to match the data dictionary to the row in the list.

I enclose some code snippets to give anyone brave enough to help me the
gist of the problem.

The listcontrol and panel it is on is petty much stock snipped from the
demo. The other routines pull out the drug data, and load it into the
list.

What happens, as you can see from the piccie, is that even when the drug
dictionary is in the correct order, the vaccines end up upside down in
the list. The text BTW pn staands for pneumo.... (type of bacteria) which
brings up the brand names of the vaccines against this organism.

I've strugged with this for several frustrating hours, getting nowhere.
Obviously its is something to do with sorting, however the when I put the
first item in the list, it ends up down the bottom, sorted inversly.

If someone can help, could you explicity write a few lines of example
code, not just say 'use bla bla....' because if you do I still won't have
a clue to implement it.

Thanks in anticipation

Richard

Sorry, this response will be in the bla, bla category. I'm pretty sure I
see what your problem is, and it's one that I just had to deal with as
well. Your vaccinesdict is indexed by the original index of the item, but
once the column sort mixin gets through sorting, the item has moved to a
different index. If there were a way to store a pointer in the item
itself, then you could reconstruct the dict, but the only slot for user
data is used by the column sorter mixin. I wound up doing the sort myself.
That is, collect all the data into a list, sort it (list.sort()), then
write it into the list control.

···

--
Jeffrey Barish

Jeffrey Barish wrote:

Richard Terry wrote:

Hi,

As my learning is progressing I've written a little app to link to a drug
database I have in postgres. I set myself a task of being able to select
just the vaccines, put them in a list, and then by clicking on one row,
display the vaccines product information.

I can't seem to match the data dictionary to the row in the list.

I enclose some code snippets to give anyone brave enough to help me the
gist of the problem.

The listcontrol and panel it is on is petty much stock snipped from the
demo. The other routines pull out the drug data, and load it into the
list.

What happens, as you can see from the piccie, is that even when the drug
dictionary is in the correct order, the vaccines end up upside down in
the list. The text BTW pn staands for pneumo.... (type of bacteria) which
brings up the brand names of the vaccines against this organism.

I've strugged with this for several frustrating hours, getting nowhere.
Obviously its is something to do with sorting, however the when I put the
first item in the list, it ends up down the bottom, sorted inversly.

If someone can help, could you explicity write a few lines of example
code, not just say 'use bla bla....' because if you do I still won't have
a clue to implement it.

Thanks in anticipation

Richard

Sorry, this response will be in the bla, bla category. I'm pretty sure I
see what your problem is, and it's one that I just had to deal with as
well. Your vaccinesdict is indexed by the original index of the item, but
once the column sort mixin gets through sorting, the item has moved to a
different index. If there were a way to store a pointer in the item
itself, then you could reconstruct the dict, but the only slot for user
data is used by the column sorter mixin. I wound up doing the sort myself. That is, collect all the data into a list, sort it (list.sort()), then
write it into the list control.

The item data used by the ColumnSorterMixin can also be used for other purposes. The ColumnSorterMixin only requires that it be a unique value that maps to a set of data values. You could also use that unique value to map back to your original data set, or whatever is needed.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!