How to create ListCtrl with single column that spans the width of a parent frame ?

Hi,

I want to create a ListCtrl with only one column, that will display several text lines from a list.
Following is a demo:

#!/usr/bin/env python

import sys
import wx

from Debug import _line as line

class ListControl(wx.Frame):
def init(self, parent, id, title, list_, max_list_width):
wx.Frame.init(self,parent,id,“LogManager”, size=(max_list_width,-1))
self.list_ = list_
self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT)
self.list.InsertColumn(0, title)
for i,line_ in enumerate(list_):
self.list.InsertStringItem(i, line_)
self.list.SetColumnWidth(0, max_list_width)

    self.SetFocus()
    self.Raise()
    self.Show(True)

if name == “main”:
list_ = [ “Between ‘2009 Dec 15 16:17:24’ and ‘2009 Dec 15 16:17:24’, the following occured:\n”,
‘1 Volume failover event of Domain 5:DVol1_2\n’,
‘1 Volume failover event of Domain 5:DVol1_1\n’]
app = wx.App(redirect=False)
max_list_width = 6 * max([len(x) for x in list_])
frame = ListControl(None, -1, “events”, list_, max_list_width)
app.MainLoop()

My problems:

  1. I want the ListCtrl’s single column to span the width of the parent Frame, but am unable to find the way to do this.
  2. When I instantiate ListControl from another window, how can I leave the created ListControl as the top window, without the window that created it becoming top window again ?

Googling and Manning’s book didn’t show me the light (to paraphrase Jake Blues).

Could someone point what I’m doing wrong ?

Thanks,
Ron.

P.S.: in case the question is raised - I’m using a ListCtrl so that I could easily determine on which line user has clicked, without need to calculate characters/rows sizes.

Hi,

Toni Ruža in http://stackoverflow.com/questions/215132/wxpython-expand-list-control-vertically-not-horizontally gave me a (partial?) solution to my first question. It’s not quite intutivie (he suggested using wx.LC_NO_HEADER) so that maybe why I missed it before.

My revised program is:

#!/usr/bin/env python

import sys
import wx

class ListControl(wx.Frame):
def init(self, parent, id, title, list_, max_list_width):
wx.Frame.init(self,parent,id,“LogManager”, size=(-1,-1))
self.list_ = list_
self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT| wx.LC_NO_HEADER)
self.list.InsertColumn(0, title)
for i,line_ in enumerate(list_):
self.list.InsertStringItem(i, line_)
self.list.SetColumnWidth(0, max_list_width)

    self.Show(True)

if name == “main”:
list_ = [ “Between ‘2009 Dec 15 16:17:24’ and ‘2009 Dec 15 16:17:24’, the following occurred:\n”,
‘1 Volume failover event of Domain 5:DVol1_2\n’,
‘1 Volume failover event of Domain 5:DVol1_1\n’]
app = wx.App(redirect=False)
max_list_width = 6 * max([len(x) for x in list_])
frame = ListControl(None, -1, “events”, list_, max_list_width)
app.MainLoop()

Could anyone answer the second question:

  • When I instantiate ListControl from another window, how can I leave the created ListControl as the top window, without the window that created it becoming top window again ?
    Or, more generally, how does one instruct a Frame window to stay the top window ?
    Thanks,

Ron.

P.S.: I tried self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT | wx.STAY_ON_TOP | wx.LC_NO_HEADER), but it did not work.

···

From: Barak, Ron [mailto:Ron.Barak@lsi.com]
Sent: Sunday, January 25, 2009 16:05
To:
wxpython-users@lists.wxwidgets.org
Subject: [wxpython-users] How to create ListCtrl with single column that spans the width of a parent frame ?

Hi,

I want to create a ListCtrl with only one column, that will display several text lines from a list.
Following is a demo:

#!/usr/bin/env python

import sys
import wx

from Debug import _line as line

class ListControl(wx.Frame):
def init(self, parent, id, title, list_, max_list_width):
wx.Frame.init(self,parent,id,“LogManager”, size=(max_list_width,-1))
self.list_ = list_
self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT)
self.list.InsertColumn(0, title)
for i,line_ in enumerate(list_):
self.list.InsertStringItem(i, line_)
self.list.SetColumnWidth(0, max_list_width)

      self.SetFocus()
      self.Raise()
      self.Show(True)

if name == “main”:
list_ = [ “Between ‘2009 Dec 15 16:17:24’ and ‘2009 Dec 15 16:17:24’, the following occured:\n”,
‘1 Volume failover event of Domain 5:DVol1_2\n’,
‘1 Volume failover event of Domain 5:DVol1_1\n’]
app = wx.App(redirect=False)
max_list_width = 6 * max([len(x) for x in list_])
frame = ListControl(None, -1, “events”, list_, max_list_width)
app.MainLoop()

My problems:

  1. I want the ListCtrl's single column to span the width of the parent Frame, but am unable to find the way to do this.
    
  2. When I instantiate ListControl from another window, how can I leave the created ListControl as the top window, without the window that created it becoming top window again ?

Googling and Manning’s book didn’t show me the light (to paraphrase Jake Blues).

Could someone point what I’m doing wrong ?

Thanks,
Ron.

P.S.: in case the question is raised - I’m using a ListCtrl so that I could easily determine on which line user has clicked, without need to calculate characters/rows sizes.

Hi Ron,

···

2009/1/25 Barak, Ron <Ron.Barak@lsi.com>:

When I instantiate ListControl from another window, how can I leave the
created ListControl as the top window, without the window that created it
becoming top window again ?
Or, more generally, how does one instruct a Frame window to stay the top
window ?

frame.Raise() raises the frame to be the top most window. Of course,
the user can then click another window to bring that one in front of
your frame.

Cheers, Frank

  1. I want the ListCtrl’s single column to span the width of the parent Frame, but am unable to find the way to do this.

You’re trying to do something clever with calculating the “max list size” without -really- doing any such calculation: 6 * chars isn’t going to give you a real size, and that’s also a static point in time.

Instead, why not just pass in a really large dummy value? What if you have a single log entry that’s really wide-- so wide your parent frame will be /too/ wide to fit on your screen? Isn’t having the ListCtrl as a naturally scrolling window better?

e.g., self.list.SetColumnWidth(0, 1000)

To me that makes it much more useful. But, if you -don’t- want to do that, then you’re going to have to bind to the EVT_SIZE event and re-size that column everytime the parent frame is resized. E.g.

# in __init__
self.list.Bind(wx.EVT_SIZE, self.OnResize)
...

def OnResize(self, event):
    self.list.SetColumnWidth(0, event.GetSize()[0])
  1. When I instantiate ListControl from another window, how can I leave the created ListControl as the top window, without the window that created it becoming top window again ?

I’m not 100% sure what you’re asking (especially since ListControl isn’t a control at all in the common term of it, but instead a Frame and as such a top-level window in its own right), but I think you just want it to be .Raise()'d. Maybe throw another window into that demo to show the multiple-frame interaction you’re seeing?

P.S., I totally don’t mean any offense by it but your variable naming scheme makes my eyes bleed :slight_smile: To have self.list_ and self.list in one context makes Baby Spaghetti Monster cry.

···

Stephen Hansen

Development
Advanced Prepress Technology

shansen@advpubtech.com
(818) 748-9282

Hi Frank,

I’m using Raise, but probably not doing it right.
When the child window is created, the parent is immediately shown above it, as the following code shows:

#!/usr/bin/env python

import sys
import wx

class ListControl(wx.Frame):
def init(self, parent, id, title, list_, max_list_width):
wx.Frame.init(self,parent,id,title,size=(-1,-1))
self.list_ = list_
self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT| wx.LC_NO_HEADER)
self.list.InsertColumn(0, title)
for i,line_ in enumerate(list_):
self.list.InsertStringItem(i, line_)
self.list.SetColumnWidth(0, max_list_width)

    self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)

    self.Raise()
    self.Show(True)

def OnItemSelected(self, evt):
    item = evt.GetText()
    max_list_width = 10 * len(item)
    ListControl(None, -1, item, item, max_list_width)

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

Bye,
Ron.

···

-----Original Message-----
From: Frank Niessink
Sent: Sunday, January 25, 2009 17:22
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] How to create ListCtrl with single column that spans the width of a parent frame ?

Hi Ron,

2009/1/25 Barak, Ron Ron.Barak@lsi.com:

When I instantiate ListControl from another window, how can I leave
the created ListControl as the top window, without the window that
created it becoming top window again ?
Or, more generally, how does one instruct a Frame window to stay the
top window ?

frame.Raise() raises the frame to be the top most window. Of course, the user can then click another window to bring that one in front of your frame.

Cheers, Frank

Hi Stephen,

The following code demonstrate my second question, namely, my inability to keep the child window as the top window after it is created.
(The child window is created by clicking on one of the parent window lines).

#!/usr/bin/env python

import sys
import wx

class ListControl(wx.Frame):
def init(self, parent, id, title, list, max_list_width):
wx.Frame.init(self,parent,id,title,size=(-1,-1))
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(None, -1, item, item, max_list_width)

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

Bye,
Ron.

···

From: Stephen Hansen [mailto:apt.shansen@gmail.com]
Sent: Sunday, January 25, 2009 21:13
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] How to create ListCtrl with single column that spans the width of a parent frame ?

  1.   I want the ListCtrl's single column to span the width of the parent Frame, but am unable to find the way to do this.
    

You’re trying to do something clever with calculating the “max list size” without -really- doing any such calculation: 6 * chars isn’t going to give you a real size, and that’s also a static point in time.

Instead, why not just pass in a really large dummy value? What if you have a single log entry that’s really wide-- so wide your parent frame will be /too/ wide to fit on your screen? Isn’t having the ListCtrl as a naturally scrolling window better?

e.g., self.list.SetColumnWidth(0, 1000)

To me that makes it much more useful. But, if you -don’t- want to do that, then you’re going to have to bind to the EVT_SIZE event and re-size that column everytime the parent frame is resized. E.g.

# in __init__
  self.list.Bind(wx.EVT_SIZE, self.OnResize)
  ...

  def OnResize(self, event):
      self.list.SetColumnWidth(0, event.GetSize()[0])
  1. When I instantiate ListControl from another window, how can I leave the created ListControl as the top window, without the window that created it becoming top window again ?

I’m not 100% sure what you’re asking (especially since ListControl isn’t a control at all in the common term of it, but instead a Frame and as such a top-level window in its own right), but I think you just want it to be .Raise()'d. Maybe throw another window into that demo to show the multiple-frame interaction you’re seeing?

P.S., I totally don’t mean any offense by it but your variable naming scheme makes my eyes bleed :slight_smile: To have self.list_ and self.list in one context makes Baby Spaghetti Monster cry.

Stephen Hansen
Development
Advanced Prepress Technology

shansen@advpubtech.com
(818) 748-9282

Hi Ron,

Firstly, you need to pass 'self' as the first parameter to your child
windows, so they know who their parent is. Secondly, you need to include
the window style wx.FRAME_FLOAT_ON_PARENT (or wx.STAY_ON_TOP). Other
frame styles are documented here:

http://docs.wxwidgets.org/stable/wx_wxframe.html

Hope that helps,

Simon

···

-----Original Message-----
From: Barak, Ron
Sent: 26 January 2009 08:13
To: shansen@advpubtech.com
Cc: wxpython-users@lists.wxwidgets.org
Subject: RE: [wxpython-users] How to create ListCtrl with
single column thatspans the width of a parent frame ?

Hi Stephen,

The following code demonstrate my second question, namely, my
inability to keep the child window as the top window after it
is created.
(The child window is created by clicking on one of the parent
window lines).

#!/usr/bin/env python

import sys
import wx

class ListControl(wx.Frame):
    def __init__(self, parent, id, title, list, max_list_width):
        wx.Frame.__init__(self,parent,id,title,size=(-1,-1))
        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(None, -1, item, item, max_list_width)

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

Bye,
Ron.

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.

ListCtrl_demo4.py (1.18 KB)

···

-----Original Message-----
From: King Simon-NFHD78 [mailto:simon.king@motorola.com]
Sent: Monday, January 26, 2009 13:18
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 08:13
To: shansen@advpubtech.com
Cc: wxpython-users@lists.wxwidgets.org
Subject: RE: [wxpython-users] How to create ListCtrl with single
column thatspans the width of a parent frame ?

Hi Stephen,

The following code demonstrate my second question, namely, my
inability to keep the child window as the top window after it is
created.
(The child window is created by clicking on one of the parent window
lines).

#!/usr/bin/env python

import sys
import wx

class ListControl(wx.Frame):
def init(self, parent, id, title, list, max_list_width):
wx.Frame.init(self,parent,id,title,size=(-1,-1))
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(None, -1, item, item, max_list_width)

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

Bye,
Ron.

Hi Ron,

Firstly, you need to pass ‘self’ as the first parameter to your child windows, so they know who their parent is. Secondly, you need to include the window style wx.FRAME_FLOAT_ON_PARENT (or wx.STAY_ON_TOP). Other frame styles are documented here:

http://docs.wxwidgets.org/stable/wx_wxframe.html

Hope that helps,

Simon

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

···

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

Hi Simon,
Your mail below solved my problem.
(Only when I did a ‘diff’, did I notice the ListControl(None, -1, item, item, max_list_width) in my code ;-(
And your usage of style=wx.DEFAULT_FRAME_STYLE is definitely mandatory (though I’m not sure why, as the documentation states that that is the default style, no pun intended :wink:
Thanks so much,
Ron.

···

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

From: Barak, Ron [mailto:Ron.Barak@lsi.com]
Sent: 26 January 2009 13:52
To: King Simon-NFHD78
Cc: wxpython-users@lists.wxwidgets.org
Subject: RE: [wxpython-users] How to create ListCtrl with
single column that spans the width of a parent frame ?

Hi Simon,
Your mail below solved my problem.
(Only when I did a 'diff', did I notice the ListControl(None,
-1, item, item, max_list_width) in my code ;-(
And your usage of style=wx.DEFAULT_FRAME_STYLE is definitely
mandatory (though I'm not sure why, as the documentation
states that that is the default style, no pun intended :wink:
Thanks so much,
Ron.

Window styles are specified as a bitmask, by combining each desired
style using '|'. According to the docs, wx.DEFAULT_FRAME_STYLE is
defined as wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER |
wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN

If you just pass style=wx.FRAME_FLOAT_ON_PARENT, you are *explicitly*
saying that that is the only style you want - all the other bits in the
bitmask are set to 0. To get the default frame style plus some other
fields, you need to combine them yourself, hence wx.DEFAULT_FRAME_STYLE

wx.FRAME_FLOAT_ON_PARENT.

Simon

···

-----Original Message-----