wxChoice on Mac OS-X

Thanks. Here's the essential code:

···

------------------------------------------------------
# Module KeywordMapClass
"""This module implements a map of keywords that have been applied to the selected Episode"""

import os
# load wxPython for GUI and MySQLdb for Database Access
from wxPython.wx import *

# Declare Control IDs
# Series List Combo Box
ID_SERIESLIST = 1001
# Episode List Combo Box
ID_EPISODELIST = 1002

class KeywordMap(wxFrame):
    """ This is the Main Window for the Keyword Map application """
    def __init__(self, parent, ID, title):

        # Create the basic Frame structure with a white background
        self.frame = wxFrame.__init__(self, parent, ID, title, pos=(10, 10), size=(780, 560), style=wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
        self.SetBackgroundColour(wxWHITE)

        # Get all Series Records
        # Create a Choice Box of Series IDs
        # Create a label for the choice box
        self.lblSeries = wxStaticText(self, -1, "Series:", wxPoint(10,10))
        # This data structure mirrors what is returned from the Database calls
        SeriesIDs = (('Series1',), ('Series2',), ('Series3',))
        # put all the Series IDs into a List Object
        choiceList = ['']
        for (Series,) in SeriesIDs:
            choiceList.append(Series)
        self.SeriesList = wxChoice(self, ID_SERIESLIST, wxPoint(60,7), size=(300, 26), choices=choiceList)
        self.SeriesList.SetSelection(0)
        EVT_CHOICE(self, ID_SERIESLIST, self.SeriesSelect)
        
        # Create a Choice Box for Episodes, even though it's not needed yet
        self.lblEpisode = wxStaticText(self, -1, "Episode:", wxPoint(400,10))
        self.lblEpisode.Show(false)
        # Initialize the list with 10 elements to get a decent-sized dropdown when it is populated later (!)
        choiceList = ['', '', '', '', '', '', '', '', '', '']
        self.EpisodeList = wxChoice(self, ID_EPISODELIST, wxPoint(450, 7), size = (300, 26), choices = choiceList)
        self.EpisodeList.Show(false)
        EVT_CHOICE(self, ID_EPISODELIST, self.EpisodeSelect)

        # Add a Status Bar
        self.CreateStatusBar()

        # Show the Frame
        self.Show(true)

    def SeriesSelect(self, event):
        # This data structure mirrors what is returned from the database
        EpisodeIDs = (('%s, Episode1' % event.GetString(),), ('%s, Episode2' % event.GetString(),), ('%s, Episode3' % event.GetString(),))
        self.EpisodeList.Clear()
        self.EpisodeList.Append('')
        for (Episode,) in EpisodeIDs:
            self.EpisodeList.Append(Episode)
        self.EpisodeList.SetSelection(0)
        self.lblEpisode.Show(true)
        self.EpisodeList.Show(true)

        self.SetStatusText('Series %s selected.' % event.GetString())
    
    def EpisodeSelect(self, event):
        self.SetStatusText('Episode %s selected.' % event.GetString())
        # Populate the drawing
# self.ProcessEpisode()

class MyApp(wxApp):
    def OnInit(self):
        frame = KeywordMap(None, -1, "Transana Keyword Map")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

# run the application
app = MyApp()
app.MainLoop()
------------------------------------------------------

This code produces the results as if the database returned 3 rows to the first query. If you change the relevant line (line 28) to:

        SeriesIDs = (('Series1',))

then you will see what happens when the database returns only one row.

In Windows, the choice box has a blank line as the first entry, and when you choose something in the "Series" choice box, the "Episode" choice box appears populated with appropriate values based on the value of Series. On the Mac, there is no blank entry (the user cannot clear the screen by deselecting), and making a selection in either box returns the wrong result, as reflected in the status bar and in the entries that populate the Episode dropdown.

(Note: I am at home, where I don't have access to a Mac, so I have not tested this exact code to prove that it fails as I describe. However, based on what occurred at the office today, I'm confident it will when I try it on Monday.)

Thanks for your time and assistance,

David Woods, Ph.D.
Wisconsin Center for Education Research
University of Wisconsin, Madison

Chris.Barker@noaa.gov 12/13/02 13:50 PM >>>

David Woods wrote:

If
the database returns only a single record, there's no way to select
anything, so the next round of processing never gets triggered. Worse, if
you have multiple records, when you make a selection, the program thinks you
selected the item in the list above it. That is, choose line 3, and the
programs processes it as if you had selected line 2. There's no way to
select and have properly processed the last item in the list.

I'm not quite sure I follow this

Is this a bug in the Mac version of wxPython? Is this an issue with Mac
OS-X that I have to work around? Am I just missing something obvious?
(Always a possibility.) Anyone have any suggestions for how I should
proceed?

I've used a wxChoice on OS-X, and the only problem I had was it no
automatically sizing for me. However, I never tried to put a blank line
in either.

If you make a small demo, with nothing but a couple of wxChoices and
simple callbacks that demonstrate the problem, I'd be glad to take a
look

-Chris

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Okay, I've now double-checked this code and confirmed that it demonstrates
the problem I encountered on the Mac.

In Windows, you start the app, and you get a single choice box that has a
blank entry selected. You select, say, the second entry, Series 2. You
will see a message in the Status Bar saying that Series 2 is selected, and
the Episode choice box will appear with the blank entry selected. When you
look at the list of items, you will see that all items reflect that Series 2
was selected in the Series Choice Box. Selecting the third entry in the
Episode box causes a message in the Status Bar saying that Episode "Series
2, Episode 3" has been selected.

On the Mac, when you start the app, and you get a single choice box that has
no blank entry and the first entry with text "Series 1" is selected. You
select, say, the second entry, Series 2. You will see a message in the
Status Bar saying that Series _1_ is selected, though it sure looks in the
Series Choice box like Series 2 is selected as intended. The Episode choice
box will appear with no blank entry, and with an entry "Series 1, Episode 1"
selected. When you look at the list of items, you will see that all items
reflect that Series 1, not Series 2, was selected in the Series Choice Box.
Selecting the third entry in the Episode box causes a message in the Status
Bar saying that Episode "Series 1, Episode 2" has been selected, when in
fact the Choice Boxes reflect that Series 2, Episode 3 is what was selected.

To fix the problem, I simply replaced the blank entry ('') in the Choice Box
with an entry that consisted of a single space (' '), and now the app works
as expected. Still, since the Mac version functions differently than the
Windows version, and since it produces behavior that differs from what seems
reasonable, I would suggest that this might be a bug in the Mac version.

David Woods
Wisconsin Center for Education Research
University of Wisconsin, Madison

···

-----Original Message-----
From: David Woods [mailto:DWoods@education.wisc.edu]
Sent: Friday, December 13, 2002 6:49 PM
To: wxPython-users@lists.wxwindows.org
Subject: Re: [wxPython-users] wxChoice on Mac OS-X

Thanks. Here's the essential code:

------------------------------------------------------
# Module KeywordMapClass
"""This module implements a map of keywords that have been applied to the
selected Episode"""

import os
# load wxPython for GUI and MySQLdb for Database Access
from wxPython.wx import *

# Declare Control IDs
# Series List Combo Box
ID_SERIESLIST = 1001
# Episode List Combo Box
ID_EPISODELIST = 1002

class KeywordMap(wxFrame):
    """ This is the Main Window for the Keyword Map application """
    def __init__(self, parent, ID, title):

        # Create the basic Frame structure with a white background
        self.frame = wxFrame.__init__(self, parent, ID, title, pos=(10, 10),
size=(780, 560), style=wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
        self.SetBackgroundColour(wxWHITE)

        # Get all Series Records
        # Create a Choice Box of Series IDs
        # Create a label for the choice box
        self.lblSeries = wxStaticText(self, -1, "Series:", wxPoint(10,10))
        # This data structure mirrors what is returned from the Database
calls
        SeriesIDs = (('Series1',), ('Series2',), ('Series3',))
        # put all the Series IDs into a List Object
        choiceList = ['']
        for (Series,) in SeriesIDs:
            choiceList.append(Series)
        self.SeriesList = wxChoice(self, ID_SERIESLIST, wxPoint(60,7),
size=(300, 26), choices=choiceList)
        self.SeriesList.SetSelection(0)
        EVT_CHOICE(self, ID_SERIESLIST, self.SeriesSelect)

        # Create a Choice Box for Episodes, even though it's not needed yet
        self.lblEpisode = wxStaticText(self, -1, "Episode:",
wxPoint(400,10))
        self.lblEpisode.Show(false)
        # Initialize the list with 10 elements to get a decent-sized
dropdown when it is populated later (!)
        choiceList = ['', '', '', '', '', '', '', '', '', '']
        self.EpisodeList = wxChoice(self, ID_EPISODELIST, wxPoint(450, 7),
size = (300, 26), choices = choiceList)
        self.EpisodeList.Show(false)
        EVT_CHOICE(self, ID_EPISODELIST, self.EpisodeSelect)

        # Add a Status Bar
        self.CreateStatusBar()

        # Show the Frame
        self.Show(true)

    def SeriesSelect(self, event):
        # This data structure mirrors what is returned from the database
        EpisodeIDs = (('%s, Episode1' % event.GetString(),), ('%s, Episode2'
% event.GetString(),), ('%s, Episode3' % event.GetString(),))
        self.EpisodeList.Clear()
        self.EpisodeList.Append('')
        for (Episode,) in EpisodeIDs:
            self.EpisodeList.Append(Episode)
        self.EpisodeList.SetSelection(0)
        self.lblEpisode.Show(true)
        self.EpisodeList.Show(true)

        self.SetStatusText('Series %s selected.' % event.GetString())

    def EpisodeSelect(self, event):
        self.SetStatusText('Episode %s selected.' % event.GetString())
        # Populate the drawing
# self.ProcessEpisode()

class MyApp(wxApp):
    def OnInit(self):
        frame = KeywordMap(None, -1, "Transana Keyword Map")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

# run the application
app = MyApp()
app.MainLoop()
------------------------------------------------------

This code produces the results as if the database returned 3 rows to the
first query. If you change the relevant line (line 28) to:

        SeriesIDs = (('Series1',))

then you will see what happens when the database returns only one row.

In Windows, the choice box has a blank line as the first entry, and when you
choose something in the "Series" choice box, the "Episode" choice box
appears populated with appropriate values based on the value of Series. On
the Mac, there is no blank entry (the user cannot clear the screen by
deselecting), and making a selection in either box returns the wrong result,
as reflected in the status bar and in the entries that populate the Episode
dropdown.

(Note: I am at home, where I don't have access to a Mac, so I have not
tested this exact code to prove that it fails as I describe. However, based
on what occurred at the office today, I'm confident it will when I try it on
Monday.)

Thanks for your time and assistance,

David Woods, Ph.D.
Wisconsin Center for Education Research
University of Wisconsin, Madison

Chris.Barker@noaa.gov 12/13/02 13:50 PM >>>

David Woods wrote:

If
the database returns only a single record, there's no way to select
anything, so the next round of processing never gets triggered. Worse, if
you have multiple records, when you make a selection, the program thinks

you

selected the item in the list above it. That is, choose line 3, and the
programs processes it as if you had selected line 2. There's no way to
select and have properly processed the last item in the list.

I'm not quite sure I follow this

Is this a bug in the Mac version of wxPython? Is this an issue with Mac
OS-X that I have to work around? Am I just missing something obvious?
(Always a possibility.) Anyone have any suggestions for how I should
proceed?

I've used a wxChoice on OS-X, and the only problem I had was it no
automatically sizing for me. However, I never tried to put a blank line
in either.

If you make a small demo, with nothing but a couple of wxChoices and
simple callbacks that demonstrate the problem, I'd be glad to take a
look

-Chris

--
Christopher Barker, Ph.D.
Oceanographer

NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

David Woods wrote:

Okay, I've now double-checked this code and confirmed that it demonstrates
the problem I encountered on the Mac.

I get exactly the same results. On wxGTK, it works like you want it too,
and on OS-X it doesn't.

To fix the problem, I simply replaced the blank entry ('') in the Choice Box
with an entry that consisted of a single space (' '), and now the app works
as expected.

That's the fix I was going to suggest.

Still, since the Mac version functions differently than the
Windows version, and since it produces behavior that differs from what seems
reasonable, I would suggest that this might be a bug in the Mac version.

Well, I suspect that it is a difference in the native control, which you
could or could not call a bug. You might want to post a note to the
wxPython-mac list. ( http://lists.wxwindows.org/ ). You may very well
want to post a bug report on sourceforge. If nothing else, it would be
noce to have a note in the docs that empty strings passed to a wxChoice
behaves differently on wxMac. You might try wx-usres as well, to confirm
whther the behaviour is the same with C++. It's unlikely but I suppose
it's possible that the wrappers are somehow doing something a little
different.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov