Multi-column listbox and Pmw boring problem stories

Hans-Joachim Widmaier hjwidmaier at web.de
Wed May 14 08:54:25 EDT 2003


In one of my programs, I want to display filenames in a Listbox, each
one of them prepended by a tag of fixed length (let's say just a
single character plus some padding). The straightforward, extremely
simply way is to use a fixed-width font for that Listbox and be done.
Alas, That Listbox is one of several, stacked vertically. In order for
the whole thing to look not terribly awful, I'd have to use the same
fixed-width font for all of them. Besides only removing the 'terribly'
from the looks, it has the real disadvantage that you either have to
make the widgets wider or deal with much less displayed text. This is
not acceptable for me. So I looked around for multi-column Listbox
widgets. There's not a lot of them. The one in the contrib directory
of Pmw, while being quite nice, doesn't really look and feel like a
'normal' Listbox. (I like to scroll with the mouse wheel.)

Ok. Programming in Python is fun, there's something to learn, so why
not accept the challenge and write your own?

My first attempts, based on Pmw's ScrolledListBox, failed miserably. I
couldn't get the layout right, and dragging the handle of the
scrollbar only scrolled by lines---I never found out why. I also never
really understood the internals of Pmw, despite reading the
descriptions several times. What I found by reading them, though, was
a probable solution: You can supply your own Listbox widget to
ScrolledListBox.

That way I finally managed to get something that _almost_ does
everything I want it to. Almost, of course, as there's always that one
last obstacle you can't overcome.

Embarrassed, I have to ask the experts for help again.

The 'selectioncommand' doesn't get called because ScrolledListBox
looks up the widget the event is associated with in a cache. This
cache holds the widget I gave to it as 'the' Listbox, which is, of
course, the container Frame. The event comes from the child, though,
and gets ignored. I currently see no way I can make the
selectioncommand work short of adapting PmwScrolledListBox.py to stash
the child widgets in that cache. I'd rather leave it alone.
I thought about calling the callback from my class, but I realized
that I don't even have a handle on the parent widget. (Sure, that
could be set by the apllication. Or I could install the callback not
in the ScrolledListBox but in my TwoColumnListbox. Yech.)

Any ideas on how I might get it to work?

If anyone's interested in the (unpolished) code, I'll gladly post it.
(It's not too big, around 110 lines.)

Apologies for always posting that much crap alongside a simple
question. ;-)

Hans-Joachim Widmaier




More information about the Python-list mailing list