listbox in wx.Dialog

Hi List,

i have put a listBox Control in a wx.Frame and in a wx.Dialog. The
listbox in the wx.Frame works fine but th listbox in the wx.Dialog
select allway the last entry. I also can'd ist deselect with
'self.listBox1.Deselect(3)'. Look at the examples.

Who can help me?

File: test1.
Frame. Works fine
--->
#Boa:Frame:testFrame

import wx

def create(parent):
    return testFrame(parent)

[wxID_TESTFRAME, wxID_TESTFRAMELISTBOX1,
] = [wx.NewId() for _init_ctrls in range(2)]

class testFrame(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_TESTFRAME,
name=u'testFrame',
              parent=prnt, pos=wx.Point(597, 277), size=wx.Size(168,
204),
              style=wx.DEFAULT_FRAME_STYLE, title=u'testFrame')
        self.SetClientSize(wx.Size(168, 204))
        self.Bind(wx.EVT_ACTIVATE, self.OnFrame1Activate)

        self.listBox1 = wx.ListBox(choices=[],
id=wxID_TESTFRAMELISTBOX1,
              name='checkListBox1', parent=self, pos=wx.Point(0, 0),
              size=wx.Size(168, 204), style=wx.LB_MULTIPLE)

    def __init__(self, parent):
        self._init_ctrls(parent)

    def OnFrame1Activate(self, event):
        self.listBox1.InsertItems(['aaaa','bbbb','cccc','dddd'], 0)
        event.Skip()

if __name__ == '__main__':
    app = wx.PySimpleApp()
    wx.InitAllImageHandlers()
    frame = create(None)
    frame.Show()

    app.MainLoop(
---<

File: test2
Dialog. Works NOT fine
--->
#Boa:Dialog:testDialog

import wx

def create(parent):
    return testDialog(parent)

[wxID_TESTDIALOG, wxID_TESTDIALOGLISTBOX1,
] = [wx.NewId() for _init_ctrls in range(2)]

class testDialog(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_TESTDIALOG,
name=u'testDialog',
              parent=prnt, pos=wx.Point(558, 293), size=wx.Size(173,
229),
              style=wx.DEFAULT_DIALOG_STYLE, title=u'TestDialog')
        self.SetClientSize(wx.Size(173, 229))
        self.Bind(wx.EVT_INIT_DIALOG, self.OnTestDialogInitDialog)

        self.listBox1 = wx.ListBox(choices=[],
id=wxID_TESTDIALOGLISTBOX1,
              name='listBox1', parent=self, pos=wx.Point(8, 8),
              size=wx.Size(160, 208), style=wx.LB_MULTIPLE)

    def __init__(self, parent):
        self._init_ctrls(parent)

    def OnTestDialogInitDialog(self, event):
        self.listBox1.InsertItems(['aaaa','bbbb','cccc','dddd'], 0)
        # self.listBox1.Deselect(3) # also don's work
        event.Skip()

if __name__ == '__main__':
    app = wx.PySimpleApp()
    wx.InitAllImageHandlers()
    dlg = create(None)
    try:
        dlg.ShowModal()
    finally:
        dlg.Destroy()
    app.MainLoop()
---<

···

--
cu

Roland Kruggel mailto: rk-liste@gmx.de
System: Intel 3.2Ghz, Debian sid, 2.6.7, KDE 3.3.2

I tried both, and both programs work as expected. (they
always selects the first entry; deselect also work)

What platform and wxPython version do you have?

(me: WinXP, wxPy 2.5.4.1)

···

On Wed, 16 Mar 2005 09:56:44 +0100, "Roland M. Kruggel" <rk-liste@gmx.de> wrote:

Hi List,

i have put a listBox Control in a wx.Frame and in a wx.Dialog. The
listbox in the wx.Frame works fine but th listbox in the wx.Dialog
select allway the last entry. I also can'd ist deselect with
'self.listBox1.Deselect(3)'. Look at the examples.

--
Franz Steinhaeusler

Listbox demo is ok?
Core Windows/Controls => Listbox:
Select One: "three" selected
Select many: "zero" selected
Find Prefix: "eight" selected

···

On Wed, 16 Mar 2005 09:56:44 +0100, "Roland M. Kruggel" <rk-liste@gmx.de> wrote:

Hi List,

i have put a listBox Control in a wx.Frame and in a wx.Dialog. The
listbox in the wx.Frame works fine but th listbox in the wx.Dialog
select allway the last entry. I also can'd ist deselect with
'self.listBox1.Deselect(3)'. Look at the examples.

--
Franz Steinhaeusler

Hi Roland,

The Deselect did work, you just didn't see any effect as nothing was selected in the first place.

Have a look at the enclosed, I added a button which deselects the item which is initially selected.

You also need to check your frame example, I get a deadobject exception when closing it.

See you
Werner

Roland M. Kruggel wrote:

Dialog1.py (1.63 KB)

···

Hi List,

i have put a listBox Control in a wx.Frame and in a wx.Dialog. The listbox in the wx.Frame works fine but th listbox in the wx.Dialog select allway the last entry. I also can'd ist deselect with 'self.listBox1.Deselect(3)'. Look at the examples.

Who can help me?

File: test1. Frame. Works fine
--->
#Boa:Frame:testFrame

import wx

def create(parent):
   return testFrame(parent)

[wxID_TESTFRAME, wxID_TESTFRAMELISTBOX1, ] = [wx.NewId() for _init_ctrls in range(2)]

class testFrame(wx.Frame):
   def _init_ctrls(self, prnt):
       # generated method, don't edit
       wx.Frame.__init__(self, id=wxID_TESTFRAME, name=u'testFrame',
             parent=prnt, pos=wx.Point(597, 277), size=wx.Size(168, 204),
             style=wx.DEFAULT_FRAME_STYLE, title=u'testFrame')
       self.SetClientSize(wx.Size(168, 204))
       self.Bind(wx.EVT_ACTIVATE, self.OnFrame1Activate)

       self.listBox1 = wx.ListBox(choices=, id=wxID_TESTFRAMELISTBOX1,
             name='checkListBox1', parent=self, pos=wx.Point(0, 0),
             size=wx.Size(168, 204), style=wx.LB_MULTIPLE)

   def __init__(self, parent):
       self._init_ctrls(parent)

   def OnFrame1Activate(self, event):
       self.listBox1.InsertItems(['aaaa','bbbb','cccc','dddd'], 0)
       event.Skip()

if __name__ == '__main__':
   app = wx.PySimpleApp()
   wx.InitAllImageHandlers()
   frame = create(None)
   frame.Show()

   app.MainLoop(
---<

File: test2
Dialog. Works NOT fine
--->
#Boa:Dialog:testDialog

import wx

def create(parent):
   return testDialog(parent)

[wxID_TESTDIALOG, wxID_TESTDIALOGLISTBOX1, ] = [wx.NewId() for _init_ctrls in range(2)]

class testDialog(wx.Dialog):
   def _init_ctrls(self, prnt):
       # generated method, don't edit
       wx.Dialog.__init__(self, id=wxID_TESTDIALOG, name=u'testDialog',
             parent=prnt, pos=wx.Point(558, 293), size=wx.Size(173, 229),
             style=wx.DEFAULT_DIALOG_STYLE, title=u'TestDialog')
       self.SetClientSize(wx.Size(173, 229))
       self.Bind(wx.EVT_INIT_DIALOG, self.OnTestDialogInitDialog)

       self.listBox1 = wx.ListBox(choices=, id=wxID_TESTDIALOGLISTBOX1,
             name='listBox1', parent=self, pos=wx.Point(8, 8),
             size=wx.Size(160, 208), style=wx.LB_MULTIPLE)

   def __init__(self, parent):
       self._init_ctrls(parent)

   def OnTestDialogInitDialog(self, event):
       self.listBox1.InsertItems(['aaaa','bbbb','cccc','dddd'], 0)
       # self.listBox1.Deselect(3) # also don's work
       event.Skip()

if __name__ == '__main__':
   app = wx.PySimpleApp()
   wx.InitAllImageHandlers()
   dlg = create(None)
   try:
       dlg.ShowModal()
   finally:
       dlg.Destroy()
   app.MainLoop()
---<

Hi Roland,

The Deselect did work, you just didn't see any effect as nothing
was selected in the first place.

No. In the version with the wx.Dialog the last item (No. 3) is
selected whe i start the program. Now, that's my question. Do you
have nothig select in the listbox when you start up the program?

Have a look at the enclosed, I added a button which deselects the
item which is initially selected.

ok. It works by me too. But where can i delet this item on startup?

You also need to check your frame example, I get a deadobject
exception when closing it.

I am not. It works fine. Also wen i start it from a terminal.

···

Am Mittwoch, 16. März 2005 10:46 schrieb Werner F. Bruhin:

--
cu

Roland Kruggel mailto: rk-liste@gmx.de
System: Intel 3.2Ghz, Debian sid, 2.6.7, KDE 3.3.2

Hi Roland,

Roland M. Kruggel wrote:

Hi Roland,

The Deselect did work, you just didn't see any effect as nothing
was selected in the first place.
   
No. In the version with the wx.Dialog the last item (No. 3) is selected whe i start the program. Now, that's my question. Do you have nothig select in the listbox when you start up the program?

I changed your line in the event handler to select item number 2 (which is the third item), so when I start the program it is selected, then when you press the button it will get de-selected.

Have a look at the enclosed, I added a button which deselects the
item which is initially selected.
   
ok. It works by me too. But where can i delet this item on startup?

What about "self.listBox1.Delete(2)"

···

Am Mittwoch, 16. März 2005 10:46 schrieb Werner F. Bruhin:

You also need to check your frame example, I get a deadobject
exception when closing it.
   
I am not. It works fine. Also wen i start it from a terminal.