[wxPython] ListBox problem: full code example

Full code for my listbox selection problem included below...
couldn't really get it much under 100 lines without losing
all relevance to what I'm doing with it. Hope this makes
sense - can anyone tell me why it doesn't set the selected
items as desired? You can see what they're supposed to be
by the output to stdout.

Regards,
Denny

PS : if you can't read this due to mail client weirdness or
other reason, there is a copy you can download or view at:
http://www-edc.eng.cam.ac.uk/~djd33/listbox.txt

--- [ code ] ---

#!/usr/local/bin/python
from wxPython.wx import *

main_size = wxSize (300, 100) ; dialog_size = wxSize (320, 240)
params = ['param 1', 'param 2', 'param 3', 'param 4', 'param 5']
data = {}
data ['model'] = {}
data ['model']['parameters'] = {}
for num in range (1,6):
  data ['model']['parameters'][num] = {}
  paramstr = 'param ' + str(num)
        data ['model']['parameters'][num][paramstr] = ''
data ['model']['tasks'] = {}
for each in range (1,4):
  data ['model']['tasks'][each] = {}
  namestr = 'task ' + str(each)
  data ['model']['tasks'][each]['name'] = namestr
        data ['model']['tasks'][each]['inputs'] = {}
data ['model']['tasks'][2]['inputs'][3] = 'param 3'
data ['model']['tasks'][2]['inputs'][5] = 'param 5'

class spEditTasksDialogTwo (wxDialog):
        def __init__ (self, parent, ID, intask):
                wxDialog.__init__ (self, parent, ID, 'b0rked wxListBox',
                        wxDefaultPosition, dialog_size, wxRESIZE_BORDER)

    self.task = intask

          param_label = wxStaticText (self, -1, "Parameters")
    self.param_list = wxListBox (self, 1013, choices = params,
                                       style = wxLB_EXTENDED)
          d = data ['model']['tasks']
    for x in d.keys():
      if d[x]['name'] == self.task ['name']:
                                # preselect appropriate parameters
                                self.param_list.Deselect (0) # b0rked
                                temp = d [x]['inputs']
                    l = temp.keys()
                          l.sort()
                              for i in l:
                            # b0rked: this doesn't work
                            self.param_list.SetSelection (i-1)

                                        p = data ['model']['parameters']
                                        s = p [i].keys()[0]
                                        print str(i) + ' : ' + s # TEST

                                        # b0rked: this doesn't work either
                                        self.param_list.SetStringSelection (s)

    param_hbox = wxBoxSizer (wxHORIZONTAL)
    param_hbox.Add (param_label, 1, wxSHAPED | wxALIGN_LEFT |
                            wxALIGN_CENTER_VERTICAL | wxALL, 5)
    param_hbox.Add (self.param_list, 1, wxEXPAND | wxALL |
                                            wxALIGN_CENTER, 5)

    top_vbox = wxBoxSizer (wxVERTICAL)
    top_vbox.Add (param_hbox, 1, wxEXPAND)

    close_button = wxButton (self, 1099, "Close")
    EVT_BUTTON (self, 1099, self.OnClose)

    bottom_hbox = wxBoxSizer (wxHORIZONTAL)
    bottom_hbox.Add (close_button, 1, wxEXPAND | wxALIGN_RIGHT |
                                                    wxLEFT, 5)
    main_vbox = wxBoxSizer (wxVERTICAL)
    main_vbox.Add (top_vbox, 1, wxEXPAND | wxALL, 5)
    main_vbox.Add (bottom_hbox, 0, wxEXPAND | wxALL, 5)

    self.SetAutoLayout (true)
    self.SetSizer (main_vbox)

  def OnClose (self, event):
          self.Close()

class spFrame (wxFrame):
        def __init__ (self, parent, ID, title):
                wxFrame.__init__ (self, parent, ID, title, wxDefaultPosition,
                                                                main_size)
                edit_tasks_button = wxButton (self, 1001, "Edit Tasks")
                EVT_BUTTON (self, 1001, self.OnEditTasks)

  def OnEditTasks (self, event):
                task = {}
          task ['name'] = 'task 2'
          dialog = spEditTasksDialogTwo (self, -1, task)
          dialog.ShowModal()

class spApp (wxApp):
        def OnInit (self):
                win = spFrame (NULL, -1, 'b0rked wxListBox example')
                win.Show (true)
                return (true)

app = spApp()
app.MainLoop()

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users