Question on wxListCtrl an column width

I am trying to set the columns of a dialog with wxListCtrl before any item is inserted in the list with:

     def createListLayout(self) :
         """Create the list viewing panel. All data is empty.
         """
         # populate the list with the data
         # 3 columns: Name, IP address/file , Type
         info = wxListItem()
         info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE | wxLIST_MASK_FORMAT
         info.m_image = -1
         info.m_format = 0
         info.m_text = "column 1"
         self.list.InsertColumnInfo(0, info)

         info.m_format = 0 # wxLIST_FORMAT_RIGHT
         info.m_text = "the second column"
         self.list.InsertColumnInfo(1, info)

         info.m_format = 0
         info.m_text = "the third one"
         self.list.InsertColumnInfo(2, info)

         info.m_format = 0
         info.m_text = "The very last column"
         self.list.InsertColumnInfo(3, info)

         self.list.SetColumnWidth(0, 300)
         self.list.SetColumnWidth(1, 80)
         self.list.SetColumnWidth(2, 80)
         self.list.SetColumnWidth(3, 80) # wxLIST_AUTOSIZE_USEHEADER )

The application shows the list OK but the size of the columns is not set according to the SetColumnWidth(). I tried using wxLIST_AUTOSIZE_USEHEADER but that did not work either.

The column width are set properly once I populate the list with some data and use :

  self.list.SetColumnWidth(colIdx, wxLIST_AUTOSIZE)

···

------------
I am testing this on: Python 2.1.3, wxPython 2.4.2.4, Win32 (XP).
-------------

Thanks for your time!

Pierre

I am trying to set the columns of a dialog with wxListCtrl before any
item is inserted in the list with:

Did you try without using item ? Like:

           self.InsertColumn(0, "Column1")
           self.InsertColumn(1, "the second column")
           self.InsertColumn(2, "the third one")
           self.InsertColumn(3, "The very last column")

         self.list.SetColumnWidth(0, 300)
         self.list.SetColumnWidth(1, 80)
         self.list.SetColumnWidth(2, 80)
         self.list.SetColumnWidth(3, 80) # wxLIST_AUTOSIZE_USEHEADER )

It works fine for me (Linux, python 2.2.1, wxPython 2.4.1.2).
Does it work for you this way ?

···

On Wednesday 08 October 2003 15:47, Pierre Rouleau wrote:

--
   Frederic

   http://linux.gbiloba.org

Frederic wrote:

I am trying to set the columns of a dialog with wxListCtrl before any
item is inserted in the list with:

Did you try without using item ? Like:

           self.InsertColumn(0, "Column1")
           self.InsertColumn(1, "the second column")
           self.InsertColumn(2, "the third one")
           self.InsertColumn(3, "The very last column")

        self.list.SetColumnWidth(0, 300)
        self.list.SetColumnWidth(1, 80)
        self.list.SetColumnWidth(2, 80)
        self.list.SetColumnWidth(3, 80) # wxLIST_AUTOSIZE_USEHEADER )

It works fine for me (Linux, python 2.2.1, wxPython 2.4.1.2).
Does it work for you this way ?

It does not, I get a stack trace dump telling me that the argument should be an integer:

C:\dev\cv\vsm>wxApp1
Traceback (most recent call last):
   File "C:\dev\cv\vsm\wxApp1.py", line 24, in ?
     main()
   File "C:\dev\cv\vsm\wxApp1.py", line 20, in main
     application = BoaApp(0)
   File "C:\Python23\Lib\site-packages\wxPython\wx.py", line 1957, in __init__
     _wxStart(self.OnInit)
   File "C:\dev\cv\vsm\wxApp1.py", line 13, in OnInit
     self.main = wxFrame1.create(None)
   File "C:\dev\cv\vsm\wxFrame1.py", line 11, in create
     return wxFrame1(parent)
   File "C:\dev\cv\vsm\wxFrame1.py", line 154, in __init__
     self._init_ctrls(parent)
   File "C:\dev\cv\vsm\wxFrame1.py", line 149, in _init_ctrls
     self.listCtrl = TestListCtrlPanel(self)
   File "C:\dev\cv\vsm\wxFrame1.py", line 339, in __init__
     self.createListLayout()
   File "C:\dev\cv\vsm\wxFrame1.py", line 394, in createListLayout
     self.list.SetColumnWidth(0,"the first column") # columnTitles[0])
   File "C:\Python23\Lib\site-packages\wxPython\controls2.py", line 462, in SetColumnWidth
     val = controls2c.wxListCtrl_SetColumnWidth(self, *_args, **_kwargs)
TypeError: an integer is required
10:48:30: Debug: e:\Projects\wx2.4\src\msw\app.cpp(439): 'UnregisterClass(canvas)' failed with error 0x00000584 (class still has open windows.).

···

On Wednesday 08 October 2003 15:47, Pierre Rouleau wrote:

Oops, forget my last post, I was trying SetColumnWidth() not InsertColumn()... I will test more...

Pierre Rouleau wrote:

···

Frederic wrote:

On Wednesday 08 October 2003 15:47, Pierre Rouleau wrote:

I am trying to set the columns of a dialog with wxListCtrl before any
item is inserted in the list with:

Did you try without using item ? Like:

           self.InsertColumn(0, "Column1")
           self.InsertColumn(1, "the second column")
           self.InsertColumn(2, "the third one")
           self.InsertColumn(3, "The very last column")

        self.list.SetColumnWidth(0, 300)
        self.list.SetColumnWidth(1, 80)
        self.list.SetColumnWidth(2, 80)
        self.list.SetColumnWidth(3, 80) # wxLIST_AUTOSIZE_USEHEADER )

It works fine for me (Linux, python 2.2.1, wxPython 2.4.1.2).
Does it work for you this way ?

It does not, I get a stack trace dump telling me that the argument should be an integer:

C:\dev\cv\vsm>wxApp1
Traceback (most recent call last):
  File "C:\dev\cv\vsm\wxApp1.py", line 24, in ?
    main()
  File "C:\dev\cv\vsm\wxApp1.py", line 20, in main
    application = BoaApp(0)
  File "C:\Python23\Lib\site-packages\wxPython\wx.py", line 1957, in __init__
    _wxStart(self.OnInit)
  File "C:\dev\cv\vsm\wxApp1.py", line 13, in OnInit
    self.main = wxFrame1.create(None)
  File "C:\dev\cv\vsm\wxFrame1.py", line 11, in create
    return wxFrame1(parent)
  File "C:\dev\cv\vsm\wxFrame1.py", line 154, in __init__
    self._init_ctrls(parent)
  File "C:\dev\cv\vsm\wxFrame1.py", line 149, in _init_ctrls
    self.listCtrl = TestListCtrlPanel(self)
  File "C:\dev\cv\vsm\wxFrame1.py", line 339, in __init__
    self.createListLayout()
  File "C:\dev\cv\vsm\wxFrame1.py", line 394, in createListLayout
    self.list.SetColumnWidth(0,"the first column") # columnTitles[0])
  File "C:\Python23\Lib\site-packages\wxPython\controls2.py", line 462, in SetColumnWidth
    val = controls2c.wxListCtrl_SetColumnWidth(self, *_args, **_kwargs)
TypeError: an integer is required
10:48:30: Debug: e:\Projects\wx2.4\src\msw\app.cpp(439): 'UnregisterClass(canvas)' failed with error 0x00000584 (class still has open windows.).

Frederic wrote:

I am trying to set the columns of a dialog with wxListCtrl before any
item is inserted in the list with:

Did you try without using item ? Like:

           self.InsertColumn(0, "Column1")
           self.InsertColumn(1, "the second column")
           self.InsertColumn(2, "the third one")
           self.InsertColumn(3, "The very last column")

        self.list.SetColumnWidth(0, 300)
        self.list.SetColumnWidth(1, 80)
        self.list.SetColumnWidth(2, 80)
        self.list.SetColumnWidth(3, 80) # wxLIST_AUTOSIZE_USEHEADER )

It works fine for me (Linux, python 2.2.1, wxPython 2.4.1.2).
Does it work for you this way ?

Thanks Frederic,

I tried the InsertColumn(index,title) method you proposed and i get the same results as in my original post: the columns so not expand to their size until some data is stored inside the list and the call to self.list.SetColumnWidth(colIdx, wxLIST_AUTOSIZE) is made.

Any idea on where I should look for more information?

Pierre

···

On Wednesday 08 October 2003 15:47, Pierre Rouleau wrote:

Pierre Rouleau wrote:

I am trying to set the columns of a dialog with wxListCtrl before any item is inserted in the list with:

[...]

The application shows the list OK but the size of the columns is not set according to the SetColumnWidth(). I tried using wxLIST_AUTOSIZE_USEHEADER but that did not work either.

I commented out the code that populates the listctrl in the demo and adjusted the SetColumnWidth's to use fixed values and the column widths were still set correctly. Can you provide a small as possible sample app that shows this problem?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Pierre Rouleau wrote:

I am trying to set the columns of a dialog with wxListCtrl before any item is inserted in the list with:

[...]

The application shows the list OK but the size of the columns is not set according to the SetColumnWidth(). I tried using wxLIST_AUTOSIZE_USEHEADER but that did not work either.

I commented out the code that populates the listctrl in the demo and adjusted the SetColumnWidth's to use fixed values and the column widths were still set correctly. Can you provide a small as possible sample app that shows this problem?

I figured out the problem. It was inside my application: at initialization, it was executing the self.list.SetColumnWidth() twice on empty data and the second time the flag was wxLIST_AUTOSIZE. Since there was no data, the layout of the column was showing as all very small columns.

Problem fixed. Sorry for the commotion.

Thanks,

Pierre