Function Works -- But Not As Intended

I would appreciate guidance from you more experienced python/wxPython
coders. The following function works, but it loads the widgets with data for
the _last_ item appended to the first widget (self.vname) rather than the first
one. It is apparently an indexing problem, but I've not been able to discern
how to do this correctly.

   def loadWidgets(self, event):
     # Load all variable names into vname.
     for item in self.appData.varis:
       self.vname.Append(item[1])

     # now load rest of data associated with first item.
     displayed = self.vname.GetValue()
     stuff = [st[0] for st in self.appData.varis if st[1] == displayed]
     if stuff == [1]:
       for st in self.appData.varis:
         self.vdesc.SetValue(st[2])
         self.vpol.SetValue(st[3])
         self.vsub.SetValue(st[4])
         self.vsource.SetStringSelection(st[5])
         self.vscale.SetStringSelection(st[6])
         self.vdefuz.SetStringSelection(st[7])
         self.vlowEnd.SetValue(st[8])
         self.vhighEnd.SetValue(st[9])
         self.valphaVal.SetValue(st[10])
         self.valphaType.SetStringSelection(st[11])
         self.vtermSetNum.SetValue(st[12])
         self.vRHS.SetStringSelection(st[13])
         self.vCorrMeth.SetStringSelection(st[14])
         self.vImplMeth.SetStringSelection(st[15])

   The index stuff[1] is the record ID for the first row retrieved from the
database, and self.vname displays that string correctly.

Rich

···

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(tm)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

If self.vname is a combo box, I think you want
     displayed = self.vname.GetString(0)

Phil

···

At 11:20 AM 12/29/2006, you wrote:

  I would appreciate guidance from you more experienced python/wxPython
coders. The following function works, but it loads the widgets with data for
the _last_ item appended to the first widget (self.vname) rather than the first
one. It is apparently an indexing problem, but I've not been able to discern
how to do this correctly.

  def loadWidgets(self, event):
    # Load all variable names into vname.
    for item in self.appData.varis:
      self.vname.Append(item[1])

    # now load rest of data associated with first item.
    displayed = self.vname.GetValue()
    snip...

Phil,

   Both GetValue() and GetString(0) return the same -- and correct -- string.

   The problem is that after all of the first tuple items are appended to the
combo box, vname, the other 14 items displayed are in the last tuple, not
the first.

Thanks,

Rich

···

On Fri, 29 Dec 2006, Phil Mayes wrote:

If self.vname is a combo box, I think you want
   displayed = self.vname.GetString(0)

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(tm)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Phil,

   Perhaps I'm not asking the correct question.

   I have a list of tuples, [(a1, a2, a3, ..., a15), (b1, b2, b3, ..., bN),
... (x1, ... xn15]. I know that a0, b0, etc. are there; they are the rowID
for the records and of no interest. At least, I don't think they are of
interest.

   How do I specify a2, a3, a4, etc. because what is happening is that a1 is
displayed in self.vname, but the rest of the widgets display x2, x3, ...,
x15.

Thanks,

Rich

···

On Fri, 29 Dec 2006, Phil Mayes wrote:

If self.vname is a combo box, I think you want
   displayed = self.vname.GetString(0)

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(tm)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Rich Shepard wrote:

If self.vname is a combo box, I think you want
   displayed = self.vname.GetString(0)

Phil,

  Perhaps I'm not asking the correct question.

  I have a list of tuples, [(a1, a2, a3, ..., a15), (b1, b2, b3, ..., bN),
... (x1, ... xn15]. I know that a0, b0, etc. are there; they are the rowID
for the records and of no interest. At least, I don't think they are of
interest.

  How do I specify a2, a3, a4, etc. because what is happening is that a1 is
displayed in self.vname, but the rest of the widgets display x2, x3, ...,
x15.

It's because of the last for loop in the code you quoted. You are setting the other widgets over and over again to each item in self.appData.varis until you get to the last item, no matter which one matches what is in your combo. Something like this might be closer to what you want:

     # now load rest of data associated with first item.
     displayed = self.vname.GetValue()
     stuff = [st for st in self.appData.varis if st[1] == displayed][0]
     self.vdesc.SetValue(stuff[2])
     self.vpol.SetValue(stuff[3])
     ...

···

On Fri, 29 Dec 2006, Phil Mayes wrote:

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

Rich Shepard wrote:

You probably didn't see the extra [0] I had at the end of the line where
stuff is assigned.

Robin,

  Mea culpa! I didn't.

  This appears to answer the question I posed in my latest posting: now
there are two indices for stuff. But, to what does that second index apply?
It works now, but I don't understand why.

In your code the list comprehension evaluates to a list which, in this case, has a just a single item in it, and adding the extra [0] at the end evaluates to the first (only) item in that list, and so that is what is assigned to stuff. If the list comprehension is confusing you then you can also write it out this way:

  for st in self.appData.varis:
    if st[1] == displayed:
      stuff = st
      break

BTW, you were right in your prior message. You can append extra 's to get at the items in sequences of sequences. The first is applied to the item and evaluates to the appropriate subitem, which then has the next applied to it which evaluates to some sub-subitem if it's a sequence, and so on for additional 's.

···

On Fri, 29 Dec 2006, Robin Dunn wrote:

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