ListCtrl AutoWidth Mixin & xrc

Hi,
I have a problem with the AutoWidthMixin of a ListCtrl, in combination
with xrc. The pure python examples are perfectly clear but with xrc it
does not work completely yet. I am using two stage creation to setup a
custom AutoWidthListCtrl widget:

Python code:

class AutoWidthListCtrl(wx.ListCtrl, ListMixins.ListCtrlAutoWidthMixin):
  def __init__(self):
    Pre = wx.PreListCtrl()
    self.PostCreate(Pre)
    ListMixins.ListCtrlAutoWidthMixin.__init__(self)
    self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)

xrc code:
<object class="wxListCtrl" name="my_list" subclass="MyApp.AutoWidthListCtrl">

Now when my window is created, the width of the (only, last) ListControl
column is not adjusted to the ListControl window size. But when I resize
the window, it does work.

I guess that I need to call the __init__ method of the mixin
differently, but do not know how. In the xrc code there is no reference
to the mixin class. This might be (part of) the problem. How do I solve
this?

Second remark: it would be very great if an mixin could be enabled with
a checkbox in xrced. For the user, the autowidth feature is just normal
feature like sunken_border

bye,

Martijn

Martijn Brouwer wrote:

···

On Tue, 2008-03-18 at 21:32 -0700, Robin Dunn wrote:

Martijn Brouwer wrote:

Hi,
I have a problem with the AutoWidthMixin of a ListCtrl, in combination
with xrc. The pure python examples are perfectly clear but with xrc it
does not work completely yet. I am using two stage creation to setup a
custom AutoWidthListCtrl widget:

Python code:

class AutoWidthListCtrl(wx.ListCtrl, ListMixins.ListCtrlAutoWidthMixin):
  def __init__(self):
    Pre = wx.PreListCtrl()
    self.PostCreate(Pre)
    ListMixins.ListCtrlAutoWidthMixin.__init__(self)
    self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)

xrc code:
<object class="wxListCtrl" name="my_list" subclass="MyApp.AutoWidthListCtrl">

Now when my window is created, the width of the (only, last) ListControl
column is not adjusted to the ListControl window size. But when I resize
the window, it does work.

I guess that I need to call the __init__ method of the mixin
differently, but do not know how.

Does it make any difference if you call it from the OnCreate method?

No, I can call the Mixin __init__ either in the AutoWidhtListCtrl
__init__ after the self.PostCreate(Pre) line or in the OnCreate method
without any difference. Calling it earlier results in a long list of
error messages :slight_smile:

In the xrc code there is no reference
to the mixin class. This might be (part of) the problem. How do I solve
this?

All you need in the xrc is the name of the derived class. Be sure to include the module name.

I did, as you can see from the xrc sniplet.

Oops, I missed that before. Ok, I guess it's time to send a runnable sample now.

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

Martijn Brouwer wrote:

I tried calling the AutoWidthListCtrl's Update(), Refresh() and even
Show() methods immediately after
ListMixins.ListCtrlAutoWidthMixin.__init__(self) but neither of them
redraws the ListCtrl column correctly, i.e. matching the size of the
ListCtrl.

ListCtrlAutoWidthMixin does its thing in the EVT_SIZE handler. Does it resize the last col if you resize the listctrl a bit after it is shown?

···

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

Martijn Brouwer wrote:

···

On Sat, 2008-03-22 at 15:30 -0700, Robin Dunn wrote:

Martijn Brouwer wrote:

On Wed, 2008-03-19 at 17:52 -0700, Robin Dunn wrote:

Martijn Brouwer wrote:

Yes, resizing the frame, with the listctrl immediately results in a
correctly sized last column of the listctrl

Then this is a hint that giving it an extra size event will take care of the problem. Try adding wx.CallAfter(self.SendSizeEvent) to the end of your OnCreate method.

This does work. Would it be better if the AutoWidthListCtrl Mixin's
__init__ method executed the code that is now executed by the event
handler for the SizeEvent?

That would likely cause problems in other 2-phase create situations.

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