text alignment in listctrl

I’m using ListCtrl to display input files and associated metadata. Unfortunately, I’ve found that using wx.EXPAND when adding a ListCtrl to a sizer is very buggy, so they all end up with a fixed width. This is problematic when one of the files has a very long path that gets truncated at the end. Is there a way to change this behavior so that it shows the end of the string instead of the beginning? Using wx.LIST_FORMAT_RIGHT for the column format doesn’t do this - it will still chop off the end. Alternately, if I could at least have per-item tooltips that would be acceptable.

thanks,

Nat

Hi,

I'm using ListCtrl to display input files and associated metadata.
Unfortunately, I've found that using wx.EXPAND when adding a ListCtrl to a
sizer is very buggy, so they all end up with a fixed width. This is
problematic when one of the files has a very long path that gets truncated
at the end. Is there a way to change this behavior so that it shows the end
of the string instead of the beginning? Using wx.LIST_FORMAT_RIGHT for the
column format doesn't do this - it will still chop off the end.
Alternately, if I could at least have per-item tooltips that would be
acceptable.

thanks,
Nat

I have been using ObjectListView instead of the plain ListCtrl for all
my new applications. I know it can set the column widths, but I
couldn't find anything about tooltips.

Here's where to get it: ObjectListView — ObjectListView v1.2 documentation

Andrea also made a pure Python version that would probably do pretty
much anything you want. His site seems to be really slow right now,
but here's a link:

http://xoomer.alice.it/infinity77/main/UltimateListCtrl.html

···

On Nov 3, 6:37 pm, Nathaniel Echols <nathaniel.ech...@gmail.com> wrote:

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

I'm using ListCtrl to display input files and associated metadata.
  Unfortunately, I've found that using wx.EXPAND when adding a ListCtrl
to a sizer is very buggy, so they all end up with a fixed width.

Could you explain this problem a little more? Perhaps with a small sample app?

This
is problematic when one of the files has a very long path that gets
truncated at the end. Is there a way to change this behavior so that it
shows the end of the string instead of the beginning? Using
wx.LIST_FORMAT_RIGHT for the column format doesn't do this - it will
still chop off the end. Alternately, if I could at least have per-item
tooltips that would be acceptable.

It's not too hard to do. Catch the mouse motion events and use HitTest to find out which item the mouse is over, then set the listctrl's tooltip appropriately for that item.

···

On 11/3/09 4:37 PM, Nathaniel Echols wrote:

--
Robin Dunn
Software Craftsman

Yes, sorry, for some reason I thought this was a known problem. I should have been more specific: it’s fine when using a plain wx.Panel, but when using ScrolledPanel, the ListCtrl will grow with the panel but not shrink - so if I maximize the window and resize it to the original dimensions, I’m still stuck with a massive ListCtrl. Code below. It’s possible I’m just doing something dumb - I never entirely understood how the ScrolledPanel, sizers, and frame interact.

(Python 2.6, wxPython 2.8.10.1, Mac OS 10.6 - and I’ve also seen the same problem on Linux, but I didn’t test the sample app there.)

import wx

import wx.lib.scrolledpanel

class MyFrame (wx.Frame) :

def init (self, *args, **kwds) :

wx.Frame.init(self, *args, **kwds)

panel = wx.lib.scrolledpanel.ScrolledPanel(self)

frame_sizer = wx.BoxSizer(wx.VERTICAL)

frame_sizer.Add(panel, 1, wx.EXPAND)

panel_sizer = wx.BoxSizer(wx.VERTICAL)

panel.SetSizer(panel_sizer)

txt = wx.StaticText(panel, -1, “This is a text widget.”)

panel_sizer.Add(txt, 0, wx.ALL, 5)

listctrl = wx.ListCtrl(panel, -1, size=(600,200))

panel_sizer.Add(listctrl, 1, wx.EXPAND|wx.ALL, 5)

panel_sizer.Fit(panel)

panel.SetupScrolling()

self.Fit()

if name == “main” :

a = wx.App(0)

f = MyFrame(None, title=“Sample”)

f.Show()

a.MainLoop()

···

On Wed, Nov 4, 2009 at 1:59 PM, Robin Dunn robin@alldunn.com wrote:

On 11/3/09 4:37 PM, Nathaniel Echols wrote:

I’m using ListCtrl to display input files and associated metadata.

Unfortunately, I’ve found that using wx.EXPAND when adding a ListCtrl

to a sizer is very buggy, so they all end up with a fixed width.

Could you explain this problem a little more? Perhaps with a small

sample app?

It is a known problem, I just didn't recognize it from your description earlier. The issue is that for widgets that don't have a well defined best size, don't have a minsize, don't have children, and don't have a sizer, then wx will take their current size and use it as the best size. If the widget is expandable in the sizer then that means that whenever it gets larger so does its best size and so the sizer won't ever shrink it smaller than whatever its current size is. The workaround is to simply give it a minsize.

···

On 11/4/09 1:16 PM, Nathaniel Echols wrote:

On Wed, Nov 4, 2009 at 1:59 PM, Robin Dunn <robin@alldunn.com > <mailto:robin@alldunn.com>> wrote:

    On 11/3/09 4:37 PM, Nathaniel Echols wrote:
     > I'm using ListCtrl to display input files and associated metadata.
     > Unfortunately, I've found that using wx.EXPAND when adding a
    ListCtrl
     > to a sizer is very buggy, so they all end up with a fixed width.

    Could you explain this problem a little more? Perhaps with a small
    sample app?

Yes, sorry, for some reason I thought this was a known problem. I
should have been more specific: it's fine when using a plain wx.Panel,
but when using ScrolledPanel, the ListCtrl will grow with the panel but
not shrink - so if I maximize the window and resize it to the original
dimensions, I'm still stuck with a massive ListCtrl.

--
Robin Dunn
Software Craftsman