···
-----Original Message-----
From: King Simon-NFHD78
Sent: Monday, January 26, 2009 14:47
To: wxpython-users@lists.wxwidgets.org
Subject: RE: [wxpython-users] How to create ListCtrl with single column thatspans the width of a parent frame ?
-----Original Message-----
From: Barak, Ron
Sent: 26 January 2009 12:35
To: wxpython-users@lists.wxwidgets.org
Subject: RE: [wxpython-users] How to create ListCtrl with single
column thatspans the width of a parent frame ?
Hi Simon,
Based on your suggestions, I changed my demo code to:
1 #!/usr/bin/env python
2
3 import sys
4 import wx
5
6 class ListControl(wx.Frame):
7 def __init__(self, parent, id, title, list,
max_list_width):
8 try:
9
wx.Frame.init(self,parent,id,title,size=(-1,-1),
style=wx.FRAME_FLOAT_ON_PARENT)
10 except wx.core.PyAssertionError:
11
wx.Frame.init(self,parent,id,title,size=(-1,-1))
12 self.list = list
13 self.list_ctrl = wx.ListCtrl(self, -1,
style=wx.LC_REPORT| wx.LC_NO_HEADER)
14 self.list_ctrl.InsertColumn(0, title)
15 for i,line in enumerate(list):
16 self.list_ctrl.InsertStringItem(i, line_)
17 self.list_ctrl.SetColumnWidth(0, max_list_width)
18
19 self.Bind(wx.EVT_LIST_ITEM_SELECTED,
self.OnItemSelected, self.list_ctrl)
20
21 self.Raise()
22 self.Show(True)
23
24 def OnItemSelected(self, evt):
25 item = evt.GetText()
26 max_list_width = 10 * len(item)
27 ListControl(None, -1, item, item, max_list_width)
28
29 if name == “main”:
30 list = [ “First Line”, “Second Line”, “Third Line”]
31 app = wx.App(redirect=False)
32 max_list_width = 6 * max([len(x) for x in list])
33 ListControl(None, -1, “Parent Window”, list,
max_list_width)
34 app.MainLoop()
However, the same problem still occurs (namely, the Parent Window gets
on top of the Child Window after the Child is created).
Could you point to the culprit lines which produce my problem ?
Bye,
Ron.
P.S.: the non-numbered code is attached.
You’re still not passing ‘self’ as the first parameter to ListControl.
Here is a version that works for me:
import sys
import wx
class ListControl(wx.Frame):
def init(self, parent, id, title, list, max_list_width,
style=wx.DEFAULT_FRAME_STYLE):
wx.Frame.init(self,parent,id,title,size=(-1,-1),
style=style)
self.list = list
self.list_ctrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT|
wx.LC_NO_HEADER)
self.list_ctrl.InsertColumn(0, title)
for i,line_ in enumerate(list):
self.list_ctrl.InsertStringItem(i, line_)
self.list_ctrl.SetColumnWidth(0, max_list_width)
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected,
self.list_ctrl)
self.Raise()
self.Show(True)
def OnItemSelected(self, evt):
item = evt.GetText()
max_list_width = 10 * len(item)
ListControl(self, -1, item, item, max_list_width,
style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_FLOAT_ON_PARENT)
if name == “main”:
list = [ “First Line”, “Second Line”, “Third Line”]
app = wx.App(redirect=False)
max_list_width = 6 * max([len(x) for x in list])
ListControl(None, -1, “Parent Window”, list, max_list_width)
app.MainLoop()
I’ve added a ‘style’ parameter to your constructor, which defaults to wx.DEFAULT_FRAME_STYLE. When creating the child ListControl window, I pass wx.DEFAULT_FRAME_STYLE|wx.FRAME_FLOAT_ON_PARENT as the style. (You can’t always use that style, because your first window doesn’t have a parent - I assume that’s why you had the try/except in your init method).
Hope that helps,
Simon