Understanding handling wx.grid.Grid events

Dear all!

I want to highlight specific row when I click on any cell in that row.
Just like selection background colour shows up over row when one clicks on the row label cell.
I setup binder for left mouse click:

self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnCellLeftClick)

and wrote the handler:

def OnCellLeftClick(self, event):
    self.grid.SelectRow(event.GetRow(),False)
    event.Skip()

And it doesn’t work, but if I comment out line event.Skip(), it works fine.
Well, not quite, because it disables editing the cell.

I understand that if I remove command event.Skip(), left mouse click event are erased from the event
stack and therefore will be impossible to “gather” two left click in the row, needed for detecting Dclick.

But I must admit that I don’t understand the behavior of the self.grid.SelectRow(event.GetRow(),False)
in that event handling setup. The same self.grid.SelectRow() command works fine out of the event
handler method.

Can you, please, help me to understand what is going on here?

Thank you very much,

Regards,

Neven

Dear all!

I want to highlight specific row when I click on any cell in that row.
Just like selection background colour shows up over row when one clicks
on the row label cell.
I setup binder for left mouse click:

     self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnCellLeftClick)

and wrote the handler:

     def OnCellLeftClick(self, event):
         self.grid.SelectRow(event.GetRow(),False)
         event.Skip()

Did you also put the grid in row selection mode? Something like this:

         self.SetSelectionMode(wx.grid.Grid.SelectRows)

And it doesn't work, but if I comment out line event.Skip(), it works fine.
Well, not quite, because it disables editing the cell.

Correct. You'll also disable anything else that is triggered by mouse clicks. So instead of hooking in at the mouse event level I would let the grid do all it wants with the mouse and do the row selection from the EVT_GRID_SELECT_CELL higher-level event instead.

         self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.onSelectCell, self)

     def onSelectCell(self, evt):
         self.SelectRow(evt.GetRow())
         evt.Skip()

···

On 2/28/10 2:04 PM, Neven Goršić wrote:

--
Robin Dunn
Software Craftsman

Thank you - it WORKS! :slight_smile:

I would still like to know were I did wrong, or why .SelectRow() doesn’t work with mouse event.
Where I can find a good (but not too expert) text about wxPython events
as a next step from the wxPython in Action (event part)?

Thanks again!

Neven

···

On Mon, Mar 1, 2010 at 10:04 PM, Robin Dunn robin@alldunn.com wrote:

On 2/28/10 2:04 PM, Neven Goršić wrote:

Dear all!

I want to highlight specific row when I click on any cell in that row.

Just like selection background colour shows up over row when one clicks

on the row label cell.

I setup binder for left mouse click:

 self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnCellLeftClick)

and wrote the handler:

 def OnCellLeftClick(self, event):

     self.grid.SelectRow(event.GetRow(),False)

     event.Skip()

Did you also put the grid in row selection mode? Something like this:

    self.SetSelectionMode(wx.grid.Grid.SelectRows)

And it doesn’t work, but if I comment out line event.Skip(), it works fine.

Well, not quite, because it disables editing the cell.

Correct. You’ll also disable anything else that is triggered by mouse clicks. So instead of hooking in at the mouse event level I would let the grid do all it wants with the mouse and do the row selection from the EVT_GRID_SELECT_CELL higher-level event instead.

    self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.onSelectCell, self)





def onSelectCell(self, evt):

    self.SelectRow(evt.GetRow())

    evt.Skip()

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Hi Neven,

···

On Mar 3, 4:22 am, Neven Goršić <neven.gor...@gmail.com> wrote:

Thank you - it WORKS! :slight_smile:

I would still like to know were I did wrong, or why .SelectRow() doesn't
work with mouse event.
Where I can find a good (but not too expert) text about wxPython events
as a next step from the wxPython in Action (event part)?

Thanks again!

Neven

Do a search for "event" or "events" on the wxPython wiki. There are a
bunch of pages on the subject.

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

Blog: http://blog.pythonlibrary.org

Hi!

I want to do 2 simple actions on a grid, but choosing appropriate events are still out of my rich :slight_smile:

  1. I want to move grid cursor to the right instead of down after editing cell.
    I tried with:

self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,self.onCellChange)

and

def onCellChange(self,event):
        . . .
    self.grid.MoveCursorRight(False)
    self.grid.MoveCursorUp(False)

I can see blinking on these cells (right and up) for a second and than the cursor is set down instead of right by the grid automatism.

  1. I want to use Ctrl key for deselecting rows from already selected group of rows. I see that grid provides Ctrl mechanism for appending selected new row to the existing group of selected rows. But holding Ctrl key and left klicking on some ALREADY selected row doesn’ deselect it as it should.
    I tried:

self.Bind(wx.grid.EVT_GRID_LABEL_LEFT_CLICK, self.OnLabelLeftClick)

and

def OnLabelLeftClick(self, evt):
    if evt.ControlDown() and evt.GetRow() in self.grid.GetSelectedRows():
        self.grid.DeselectRow(evt.GetRow())

But it doesn’t work …
Can you help me?

Regards,

Neven

···

On Wed, Mar 3, 2010 at 11:22 AM, Neven Goršić neven.gorsic@gmail.com wrote:

Thank you - it WORKS! :slight_smile:

I would still like to know were I did wrong, or why .SelectRow() doesn’t work with mouse event.

Where I can find a good (but not too expert) text about wxPython events
as a next step from the wxPython in Action (event part)?

Thanks again!

Neven


On Mon, Mar 1, 2010 at 10:04 PM, Robin Dunn robin@alldunn.com wrote:

On 2/28/10 2:04 PM, Neven Goršić wrote:

Dear all!

I want to highlight specific row when I click on any cell in that row.

Just like selection background colour shows up over row when one clicks

on the row label cell.

I setup binder for left mouse click:

 self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnCellLeftClick)

and wrote the handler:

 def OnCellLeftClick(self, event):

     self.grid.SelectRow(event.GetRow(),False)

     event.Skip()

Did you also put the grid in row selection mode? Something like this:

    self.SetSelectionMode(wx.grid.Grid.SelectRows)

And it doesn’t work, but if I comment out line event.Skip(), it works fine.

Well, not quite, because it disables editing the cell.

Correct. You’ll also disable anything else that is triggered by mouse clicks. So instead of hooking in at the mouse event level I would let the grid do all it wants with the mouse and do the row selection from the EVT_GRID_SELECT_CELL higher-level event instead.

    self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.onSelectCell, self)





def onSelectCell(self, evt):

    self.SelectRow(evt.GetRow())

    evt.Skip()

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Look at the GridEnterHandler.py in the demo for an example of this.

···

On 3/7/10 1:33 AM, Neven Goršić wrote:

Hi!

I want to do 2 simple actions on a grid, but choosing appropriate events
are still out of my rich :slight_smile:

1. I want to move grid cursor to the right instead of down after editing
cell.
I tried with:

self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,self.onCellChange)

and

     def onCellChange(self,event):
             . . .
         self.grid.MoveCursorRight(False)
         self.grid.MoveCursorUp(False)

I can see blinking on these cells (right and up) for a second and than
the cursor is set down instead of right by the grid automatism.

--
Robin Dunn
Software Craftsman

Thank you for showing me example for positioning grid cursor to the right after editing.

But I still doesn’t know how to solve second problem: deselecting already selected rows by holding Ctrl key. Can you help me?

Thanks!

Kind regards,

Neven

···

On Wed, Mar 10, 2010 at 1:05 AM, Robin Dunn robin@alldunn.com wrote:

On 3/7/10 1:33 AM, Neven Goršić wrote:

Hi!

I want to do 2 simple actions on a grid, but choosing appropriate events

are still out of my rich :slight_smile:

  1. I want to move grid cursor to the right instead of down after editing

cell.

I tried with:

self.grid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,self.onCellChange)

and

 def onCellChange(self,event):

         . . .

     self.grid.MoveCursorRight(False)

     self.grid.MoveCursorUp(False)

I can see blinking on these cells (right and up) for a second and than

the cursor is set down instead of right by the grid automatism.

Look at the GridEnterHandler.py in the demo for an example of this.

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Sorry, I forgot to mention that we'll need more information to help with that. What exactly does "it doesn't work" mean? Can you provide a small runnable sample for people to experiment with?

···

On 3/10/10 10:45 PM, Neven Goršić wrote:

Thank you for showing me example for positioning grid cursor to the
right after editing.

But I still doesn't know how to solve second problem: deselecting
already selected rows by holding Ctrl key. Can you help me?

--
Robin Dunn
Software Craftsman