multi-line fields in wxListCtrl?

wxGrid experts,

Robin Dunn wrote:

Will Sadkin wrote:
> I need the functionality of a wxListCtrl, (ie, multi-columned list,
> with "row" selection), but I need to have the rows be of varying
> "thickness", containing newlines in the fields in certain columns.

[...]

> However, wxListCtrl (at least under MSW) doesn't handle newlines
> and/or varying thickness rows, wxGrid doesn't have much
> documentation, and its demo's show only cell selection, rather
> than row selection.
>
> Can anybody suggest how I can get the effect I need?

Use a third parameter to wxGrid.CreateGrid, like this:

         self.CreateGrid(25, 25, wxGrid.wxGridSelectRows)

Ok, well I've gone a long ways down this route and I've
basically got it working, but there are now a few issues
I can't figure out how to address:

1) I need to have clicking in any part of the row select
   the entire row, and I need to enforce that only one row
   be selected at a time. I thought I had a solution for this,
   but it doesn't work right. What follows is a code snippet
   for my wxGrid subclass:

    def __init__(self, [...]):
    [...]
        self.SetSelectionMode(wxGrid.wxGridSelectRows)
        EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect)

    def OnRangeSelect(self, evt):
        print "grid::OnRangeSelect"
        top_left, bottom_right = \
    evt.GetTopLeftCoords(), evt.GetBottomRightCoords()
    print top-left %s" % top_left
    print "bottom-right %s" % bottom_right
    print "selecting? %s\n" % repr(evt.Selecting())
            
        if top_left[0] != bottom_right[0] and evt.Selecting():
            print "multi-select; top_left[0] != bottom_right[0]"
            print "self.__leftClickRow:", self.__leftClickRow

            if self.__leftClickRow is not None:
                # pick last row selected
                if top_left[0] == self.__leftClickRow:
                    selectrow = bottom_right[0]
                else:
                    selectrow = top_left[0]
                self.__leftClickRow = None # reset for next event
            else:
                # pick top left (arbitrarily)
                selectrow = top_left[0]
            print "selectrow:", selectrow
            self.SelectRow ( selectrow )
        print 'calling evt.Skip()'
        evt.Skip()

In the code using the class, I've also registered a handler on
EVT_GRID_RANGE_SELECT, to wit:
  EVT_GRID_RANGE_SELECT(self.mygrid, self.OnSelectRule)

  def OnSelectRule(self, event=None):
        print 'parent's OnSelectRule'
    [...]

but it *never fires*, even though I'm clearly calling evt.skip()...
So I don't understand why the GRID_RANGE_SELECT event doesn't
propagate up the event handler chain, so the parent can take action
when the row selection changes.

Can anyone tell my why this doesn't work, or what I have to do
to get it to work?

2) The column headers in the grid are coming out taller than I want,
   even though I'm explicitly setting them to be:
  self.SetColLabelSize = self.GetDefaultRowSize()
   Instead, they appear to be 2x the size, and nothing I do has
   any effect. I also would like to change the font used for the
   labels, but there's no interface for this either that I can find.
   All of the demos suffer from the same issue; Is there anything
   I can do on either of these fronts?

3) Is there any way to get rid of the "thick" border around the
   selected cell?

That's all for now...

(Thanks in advance),
/Will Sadkin
Parlance Corporation

Will Sadkin wrote:

In the code using the class, I've also registered a handler on
EVT_GRID_RANGE_SELECT, to wit:
  EVT_GRID_RANGE_SELECT(self.mygrid, self.OnSelectRule)

  def OnSelectRule(self, event=None):
        print 'parent's OnSelectRule'
    [...]

but it *never fires*, even though I'm clearly calling evt.skip()...
So I don't understand why the GRID_RANGE_SELECT event doesn't propagate up the event handler chain, so the parent can take action when the row selection changes.

This is due to a bug that I just fixed on Monday. wxPython uses a per-instance dynamic event table instead of the per-class static event tables like in C++. There were a couple issues that prevented the dynamic tbales from behaving like the static tables when there where multiple bindings of the same event in the same instance (eventhough they were different Python classes...) I've avoided the issue in the past because the solution wasn't obvious and I didn't understand that part of the code very well. I was looking at the code the other day for a different reason and suddenly the solution jumped out at me and danced around, so I implemented it.

Can anyone tell my why this doesn't work, or what I have to do
to get it to work?

It will in the next release.

2) The column headers in the grid are coming out taller than I want,
   even though I'm explicitly setting them to be:
  self.SetColLabelSize = self.GetDefaultRowSize()
   Instead, they appear to be 2x the size, and nothing I do has
   any effect.

I don't know about this one...

I also would like to change the font used for the
   labels, but there's no interface for this either that I can find.
   All of the demos suffer from the same issue; Is there anything I can do on either of these fronts?

I think the labels use the default font, so you should probably be able to change them with code like grid.GetGridRowLabelWindow().SetFont(aFont)

3) Is there any way to get rid of the "thick" border around the
   selected cell?

Yes. Use grid.SetCellHighlightPenWidth(width)

ยทยทยท

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