How to efficiently highlight cells in a virtual grid?

Hi,
I'm developping a grid application where in new input from one cells
affect the background colors of the other cells. I was developping on
Ubuntu and there it works fine just with overriding the GetAttr
method. Unfortunately on Windows this doesn't work. I've modified the
demo to show what I mean. Right clicking forces a refresh. (It is
completely absurd, but it explains the problem well.) So my question
is what is the best way to quickly change all the background colours
when a new cell value is entered:
- a combination of overriding table.GetAttr and grid.ForceRefresh
- overriding SetValue to do grid.SetBackGroundColour calls looping
over all cells
- implenting a custom renderer (seems overkill as I only need to
change the background colour)

A second issue is that I am placing a wxchoice with a custom editor in
the first column. The problem is that EndEdit is called before the
choice is made. So I implemented an onChoice event handler in which I
do a SetValue call. Is this the best way?

    def BeginEdit(self, row, col, grid):
        #store row, col, grid for onChoice, rather than EndEdit
        self._row = row
        self._col = col
        self._grid = grid
        self.startValue = grid.GetTable().GetValue(row, col)
        self._tc.SetStringSelection(self.startValue)
        self._tc.SetFocus()

    def EndEdit(selff, row, col, grid):
        return False

    def onChoice(self, event):

        val = self._tc.GetStringSelection()

        if val != self.startValue:
            changed = True
            self._grid.table.SetValue(self._row, self._col, val) #
update the table

        self.startValue = ''
        self._tc.SetSelection(0)

Thanks in advance,

Stani

GridHugeTable.py.txt (2.49 KB)

···

--
http://pythonide.stani.be
http://pythonide.stani.be/screenshots
http://pythonide.stani.be/manual/html/manual.html

SPE Stani's Python Editor wrote:

Hi,
I'm developping a grid application where in new input from one cells
affect the background colors of the other cells. I was developping on
Ubuntu and there it works fine just with overriding the GetAttr
method. Unfortunately on Windows this doesn't work. I've modified the
demo to show what I mean. Right clicking forces a refresh. (It is
completely absurd, but it explains the problem well.) So my question
is what is the best way to quickly change all the background colours
when a new cell value is entered:
- a combination of overriding table.GetAttr and grid.ForceRefresh

I think this is the best, and fits the design of the Grid class. The refresh causes all the visible cells to be redrawn, which results in the attribute object for each cell to be fetched again, giving you the chance to override the colors for each cell.

- overriding SetValue to do grid.SetBackGroundColour calls looping
over all cells
- implenting a custom renderer (seems overkill as I only need to
change the background colour)

A second issue is that I am placing a wxchoice with a custom editor in
the first column. The problem is that EndEdit is called before the
choice is made. So I implemented an onChoice event handler in which I
do a SetValue call. Is this the best way?

I think it would be better to figure out why the EndEdit is called too soon. Can you put together a small sample that shows this?

···

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

SPE Stani's Python Editor wrote:
> So my question
> is what is the best way to quickly change all the background colours
> when a new cell value is entered:
> - a combination of overriding table.GetAttr and grid.ForceRefresh

I think this is the best, and fits the design of the Grid class. The
refresh causes all the visible cells to be redrawn, which results in the
attribute object for each cell to be fetched again, giving you the
chance to override the colors for each cell.

Great! That was the direction I took anyway.

> - overriding SetValue to do grid.SetBackGroundColour calls looping
> over all cells
> - implenting a custom renderer (seems overkill as I only need to
> change the background colour)
>
> A second issue is that I am placing a wxchoice with a custom editor in
> the first column. The problem is that EndEdit is called before the
> choice is made. So I implemented an onChoice event handler in which I
> do a SetValue call. Is this the best way?

I think it would be better to figure out why the EndEdit is called too
soon. Can you put together a small sample that shows this?

I'll dive into it later. At the moment I am rushing to get this
application ready for my next show in Paris, so unfortunately I have
to hurry.

Many thanks for answering!!

Stani

···

On 4/21/06, Robin Dunn <robin@alldunn.com> wrote:

--

http://pythonide.stani.be/screenshots
http://pythonide.stani.be/manual/html/manual.html

I should have looked at the wiki earlier: there it stated I needed to
include: evtHandler.SetEvtHandlerEnabled(False)

I'm wondering is this on purpose?

The wiki mentions (http://wiki.wxpython.org/index.cgi/wxGridCellChoiceEditor2):
I've found that on Linux the Choice box just doesn't work. Seems that
when you click on the cell and start editing it, you have to click on
it again to show the wxChoice. The evtHandler passes that up the event
chain and calls EndEdit, before it even shows the list of choices!
Hence no changes.

This proposal seems to work on Windows as well. So is it better to
imply like this for all platforms or should I do a platform check?

Stani

···

On 4/21/06, SPE Stani's Python Editor <spe.stani.be@gmail.com> wrote:

On 4/21/06, Robin Dunn <robin@alldunn.com> wrote:
> > A second issue is that I am placing a wxchoice with a custom editor in
> > the first column. The problem is that EndEdit is called before the
> > choice is made. So I implemented an onChoice event handler in which I
> > do a SetValue call. Is this the best way?
>
> I think it would be better to figure out why the EndEdit is called too
> soon. Can you put together a small sample that shows this?
I'll dive into it later. At the moment I am rushing to get this
application ready for my next show in Paris, so unfortunately I have
to hurry.

--

http://pythonide.stani.be/screenshots
http://pythonide.stani.be/manual/html/manual.html

SPE Stani's Python Editor wrote:

···

On 4/21/06, SPE Stani's Python Editor <spe.stani.be@gmail.com> wrote:

On 4/21/06, Robin Dunn <robin@alldunn.com> wrote:

A second issue is that I am placing a wxchoice with a custom editor in
the first column. The problem is that EndEdit is called before the
choice is made. So I implemented an onChoice event handler in which I
do a SetValue call. Is this the best way?

I think it would be better to figure out why the EndEdit is called too
soon. Can you put together a small sample that shows this?

I'll dive into it later. At the moment I am rushing to get this
application ready for my next show in Paris, so unfortunately I have
to hurry.

I should have looked at the wiki earlier: there it stated I needed to
include: evtHandler.SetEvtHandlerEnabled(False)

I'm wondering is this on purpose?

No, it sounds like a bug... The evtHandler basically just intercepts some key events and uses them for canceling or completing the edit, moving to other cells, etc., and also watches for focus changes. If the focus is changing when the popup is shown then that would explain the behavior you are seeing...

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