Sizing of a List Box on OS-X

Christopher Barker Chris.Barker at noaa.gov
Mon Jan 8 15:51:16 PST 2007


Hi all,

I'm making a very simple little dialog that just puts up a list box and =

lets the user select an item from the list.

However, I can't get it to size right on OS-X.

With wxPython 2.6.3, it makes the list box just a bit too small =

horizontally. It seems to be not taking into account the scrollbar.

With wxPython 2.8.0, it doesn't work at all -- the size seems to have =

nothing to do with how long the strings are in the listbox.

By the way, in both versions, if you make the box beg enough that it =

doesn't need the scrollbar, it still draws something there -- a blank =

space of sorts.

Is there some other sizing call I could be making?

Sample enclosed.

-Chris



-- =

Christopher Barker, Ph.D.
Oceanographer

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

Chris.Barker at noaa.gov
-------------- next part --------------
#!/usr/bin/env python
"""
ChooseFromListDialog module
"""

import wx

class ChooseFromListDialog(wx.Dialog):
    """
    This is a Dialog that lets you choose a particular string from a
    list of strings
    """
     =

    def __init__(self, *args, **kwargs):
        """
        args and kwargs are the usual wx.dialog ones -- passed on
        """
        list =3D kwargs.pop("list", [""])             # input list for list=
box
        selection =3D kwargs.pop("selection", "")     # initial selection i=
n the listbox
        msg =3D kwargs.pop("msg", "") # message for dialog

        wx.Dialog.__init__(self, *args, **kwargs)
        =

        # create list title
        self.dlgListTitle =3D wx.StaticText( self, label=3Dmsg)
        =

        # create list box
        self.dlgListBox =3D wx.ListBox( self,
                                      choices=3Dlist,
                                      size =3D (-1, 100),
                                      style=3Dwx.LB_SINGLE )
        self.dlgListBox.SetStringSelection(selection)

        print "Size:", self.dlgListBox.GetSize()
        print "Best Size:", self.dlgListBox.GetBestSize()

        # add Cancel and OK buttons
        btnCancel =3D wx.Button( self, wx.ID_CANCEL)
        btnOK =3D wx.Button( self, wx.ID_OK)
        =

        # put all in Sizer
        dlgSizer =3D wx.BoxSizer( wx.VERTICAL )
        dlgSizer.Add(self.dlgListTitle, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
        dlgSizer.Add(self.dlgListBox, 1, wx.ALIGN_CENTER|wx.ALL|wx.EXPAND, =
5 ) # 1 - expand to fill out dialog height
        btnSizer =3D wx.BoxSizer( wx.HORIZONTAL )
        btnSizer.Add((1,1), 1) # stretchable space to move button to the ri=
ght
        btnSizer.Add(btnCancel, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
        btnSizer.Add(btnOK, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
        dlgSizer.Add(btnSizer, 0, wx.ALIGN_CENTER|wx.ALL|wx.EXPAND, 5 )
        self.SetSizerAndFit(dlgSizer)
#        self.CenterOnParent()
   =

    def _getItemSelected(self):
        return self.dlgListBox.GetStringSelection()

    itemSelected =3D property(_getItemSelected) =



##some test code:
if __name__ =3D=3D "__main__":
    a =3D wx.App(False)
    l =3D ["An item",
         "Another Item",
         "This is a really, really, very ultra, extremely long one",
         "And this is one more."
         "and another",
         "And even yet more",
         "And more still!",
         ]
    d =3D ChooseFromListDialog(None,
                              list=3Dl,
                              selection=3Dl[1],
                              msg=3D"Pick Something",
                              title =3D "Select a Release Run",
                              size =3D (-1, 200),
                              style=3Dwx.RESIZE_BORDER | wx.DEFAULT_DIALOG_=
STYLE)

    if d.ShowModal()=3D=3D wx.ID_OK:
        print d.GetSize()
        print "OK Selected"
        print "Selected Item is:", d.itemSelected
    else:
        print "Cancel selected"


More information about the wxpython-users mailing list