Application Changed Behavior After Upgrade

I upgraded wxPython from -2.6.3.2 to -2.8.0.1 and I'm finding new errors
when I run my application. The current one involves a wx.ComboBox() which
has not changed according to the 'Recent Changes' page of the web site.

   The definition of the widget is

   self.vname = wx.ComboBox(self, wx.ID_ANY, size=wx.Size(127, 25),
                               style=wx.TAB_TRAVERSAL|wx.RAISED_BORDER)

and when I look at the new API page I don't see those styles available. What
I do see are wx.CB_DROPDOWN and wx.CB_SORT. Are the former no longer valid?

   There's something else causing the error but I don't see what it is. The
function starts as,

   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()
       print 'Displayed in variable page: ', displayed, '\n'

   The print statement was added for debugging purposes. The identification
string is printed, but the variable is not. Do I now use
   self.vname.SetValue(item[1])
instead of self.vname.Append()?

   Huh! Guess not. Can't use self.vname.SetStringSelection() either.

   What's the replacement for Append(), please?

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

Rich Shepard wrote:

  I upgraded wxPython from -2.6.3.2 to -2.8.0.1 and I'm finding new errors
when I run my application. The current one involves a wx.ComboBox() which
has not changed according to the 'Recent Changes' page of the web site.

  The definition of the widget is

    self.vname = wx.ComboBox(self, wx.ID_ANY, size=wx.Size(127, 25),
                              style=wx.TAB_TRAVERSAL|wx.RAISED_BORDER)

and when I look at the new API page I don't see those styles available. What
I do see are wx.CB_DROPDOWN and wx.CB_SORT. Are the former no longer valid?

wx.TAB_TRAVERSAL is only for container windows, it probably won't have any effect on controls (unless the value happens to be the same as some control-specific style.) wx.RAISED_BORDER is a common style that is applicable to all widgets, but the native widget may or may not do anything with it. Neither of these has significantly changed behavior in recent memory.

  There's something else causing the error but I don't see what it is. The
function starts as,

  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()
      print 'Displayed in variable page: ', displayed, '\n'

  The print statement was added for debugging purposes. The identification
string is printed, but the variable is not. Do I now use
    self.vname.SetValue(item[1])
instead of self.vname.Append()?

  Huh! Guess not. Can't use self.vname.SetStringSelection() either.

  What's the replacement for Append(), please?

Nothing should have changed in this area either. Are you sure self.vname here is the same self.vname from above where the combobox was created? You use Append to add items to the drop-down list, (or AppendItems to add a list of items all at once) and SetValue to set the textctrl part if you want to set to a value that isn't in the list, or one of the SetSelection methods to set it to an item that is in the list.

···

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

wx.TAB_TRAVERSAL is only for container windows, it probably won't have any
effect on controls (unless the value happens to be the same as some
control-specific style.) wx.RAISED_BORDER is a common style that is
applicable to all widgets, but the native widget may or may not do
anything with it. Neither of these has significantly changed behavior in
recent memory.

Robin,

   That's what I thought. I had not edited that file since before the
upgrade.

Nothing should have changed in this area either. Are you sure self.vname
here is the same self.vname from above where the combobox was created?

   Yes. It's in the same module/class.

You use Append to add items to the drop-down list, (or AppendItems to add
a list of items all at once) and SetValue to set the textctrl part if you
want to set to a value that isn't in the list, or one of the SetSelection
methods to set it to an item that is in the list.

   That's what I have. This is strange.

   Also, some data are placed in widgets while other widgets are not filled.
This is all since the upgrade, but I need to fix the self.vname problem
before I work on tracking down the rest of the glitches.

   Here again is the console output:

Displayed in variable page:

Traceback (most recent call last):
   File "/data1/eikos/modelPage.py", line 203, in OnOpenMod
     DBtools().OpenDB(self.appData.dbFileName)
   File "/data1/eikos/dbMethods.py", line 302, in OpenDB
     Publisher().sendMessage(self.appData.projOpen, data=None)
   File
"/usr/lib/python2.4/site-packages/wx-2.8-gtk2-unicode/wx/lib/pubsub.py",
line 795, in sendMessage
     self.__deliveryCount += \
   File
"/usr/lib/python2.4/site-packages/wx-2.8-gtk2-unicode/wx/lib/pubsub.py",
line 483, in sendMessage
     deliveryCount += node.sendMessage(message)
   File
"/usr/lib/python2.4/site-packages/wx-2.8-gtk2-unicode/wx/lib/pubsub.py",
line 321, in sendMessage
     listener(message)
   File "/data1/eikos/variablePage.py", line 266, in loadWidgets
     stuff = [st for st in self.appData.varis if st[1] == displayed][0]
IndexError: list index out of range
You have mail in /var/spool/mail/rshepard

The lack of the 'displayed' variable (top line) almost certainly is the
reason for the IndexError. Here's the relevant code:

   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()
     print 'Displayed in variable page: ', displayed, '\n'
     stuff = [st for st in self.appData.varis if st[1] == displayed][0]

   I need to re-read the winpdb docs to see how to put a break point in a
non-loaded module. Perhaps that will give me more information. I did check,
and self.appData.varis contains all the records retrieved from the database.

Many thanks,

Rich

···

On Tue, 23 Jan 2007, Robin Dunn wrote:

--
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

Hi!

Robin, I am also found a several "funny" changes in behaviour (from my
memory: using Now() together with DateTimePicker produce an assertion
fault) but my question is completely different:

Does wxPython will get a standard unit-test suite in the observable
future? I don't beleive such big and complex library can be developed
peacefully without it.

Vladimir Ignatov

Rich Shepard wrote:

The lack of the 'displayed' variable (top line) almost certainly is the
reason for the IndexError. Here's the relevant code:

  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()
    print 'Displayed in variable page: ', displayed, '\n'
    stuff = [st for st in self.appData.varis if st[1] == displayed][0]

  I need to re-read the winpdb docs to see how to put a break point in a
non-loaded module. Perhaps that will give me more information. I did check,
and self.appData.varis contains all the records retrieved from the database.

But you never do anything that I see to set the current selection or value of the combobox, so yes GetValue is going to return an empty string. (If the value was being set to some item in the list by default before then that was a bug.) To boil down the issue, here is a short PyShell session:

  >>> cb = wx.ComboBox(shell, choices="one two three".split())
  >>> cb.GetValue()
  u''
  >>> cb.SetSelection(1)
  >>> cb.GetValue()
  u'two'

So if your list comprehension finds nothing matching '' then it will evaluate to an empty list so the [0] on the end is going to raise an IndexError.

···

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

Vladimir Ignatov wrote:

Hi!

Robin, I am also found a several "funny" changes in behaviour (from my
memory: using Now() together with DateTimePicker produce an assertion
fault)

This may have been fixed already, but please provide a sample app to be sure, just in case I am thinking of something else.

but my question is completely different:

Does wxPython will get a standard unit-test suite in the observable
future? I don't beleive such big and complex library can be developed
peacefully without it.

I would love to have one, but don't have the time or energy to get it started at the moment. If you or somebody would like to take on this task please do and send me the results. For starters I'd like to see the basic testing framework (anything wx specific needed beyond pyunit anyway) and a few examples of different kinds of tests (non-gui, gui, maybe some where different results are expected on different platforms, etc.) and for it to be easy to add new tests.

···

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

Robin,

   Bug or not, it did work before. Obviously I need to change the code so it
works now -- and in the future, but I'm having a difficult time figuring out
where and what to change -- other than .Apend() to .SetStringSelection().
That moves the error down one line, but I'm still not putting that string in
the top of the combo box.

   Again, the first few lines of the function are:

  def loadWidgets(self, event):
     # Load all variable names into vname.
     for item in self.appData.varis:
       self.vname.SetStringSelection(item[1])
     # now load rest of data associated with first item.
     displayed = self.vname.GetValue()
     print 'Displayed in variable page: ', displayed, '\n'
     stuff = [st for st in self.appData.varis if st[1] == displayed][0]

   self.vname() is the combo box. self.vname.SetSelection([item 1]) does not
work; it throws the same error as .Append(). The variable, 'displayed,' is
not assigned.

   Here is the first record in self.appData.varis:

[(1, u'Vegetation', u'Amounts, types, and uses of plant cover.',
u'Habitats', u'', u'External', u'x 100', u'Centroid', 0, 100,
0.20000000000000001, u'Strong', 5, u'Fuzzy Space', u'Minimum', u'Min-max'),

   It's a list of tuples, and I want to load the first string index[1] into
the combo box. The wx.ComboBox().SetStringSelection() does not accept a
subscripted index, that is, [0][1], for first tuple, second item.

   For whatever reason, seeing what to change when the existing code worked
before has become a big challenge. I thought that I understood what and why
it worked, but I'm still missing the key point.

Rich

···

On Wed, 24 Jan 2007, Robin Dunn wrote:

But you never do anything that I see to set the current selection or value of the combobox, so yes GetValue is going to return an empty string. (If the value was being set to some item in the list by default before then that was a bug.)

--
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

OK. Here's the problem. SetStringSelection() returns a boolean value
(True/False). I don't see a method in the API to place a string from the
list of tuples in the combo box' text field. Looking at Choice() and
ListBox() I don't see what might be an appropriate method.

   What method should I use to place the (string) value in the top of the combo
box?

Rich

···

On Fri, 26 Jan 2007, Rich Shepard wrote:

     self.vname.SetStringSelection(item[1])

--
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

The demo code I downloaded a while ago (apparently from 2.6.1.0) uses
.Append() to add data to an empty combo box:

  # This combobox is created with no values initially.
         cb = wx.ComboBox(self, 501, "default value", (90, 80), (95, -1), ,
             wx.CB_DROPDOWN)

         # Here we dynamically add our values to the second combobox.
         for item in sampleList:
             cb.Append(item, item.upper())

   I cannot find anything more current on the Wiki.

   This is what I used before, and it worked. Now it doesn't append the first
item in the list's first tuple to the display in the widget. What do I need
to change so this once again works?

TIA,

Rich

···

On Fri, 26 Jan 2007, Rich Shepard wrote:

What method should I use to place the (string) value in the top of the
combo box?

--
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:

  This is what I used before, and it worked. Now it doesn't append the first
item in the list's first tuple to the display in the widget. What do I need
to change so this once again works?

As I wrote the other day, you use Append or AppendItems to add strings to the drop-down list, you use SetValue to set the textctrl portion of the widget to a value that is not in the drop-down list, and you use SetSelection or SetStringSelection to set the value of the textctrl portion of the widget to a value that is in the drop-down list.

···

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

Robin,

   I thought that I had tried SetValue(), but apparently I had not. It's
greyed out on the API page; perhaps that's why I didn't try it.

   It works, all right. Now I wonder why Append() worked on the empty box
before. Regardless, thank you for putting the project back on the tracks.
I'm not normally this dense; probably juggling too many things and some
balls are dropped.

Much appreciated,

Rich

···

On Fri, 26 Jan 2007, Robin Dunn wrote:

As I wrote the other day, you use Append or AppendItems to add strings to
the drop-down list, you use SetValue to set the textctrl portion of the
widget to a value that is not in the drop-down list, and you use
SetSelection or SetStringSelection to set the value of the textctrl
portion of the widget to a value that is in the drop-down list.

--
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