Aigars
October 22, 2008, 11:07am
1
Good day!
I want to find which cell (row, col) in my grid is selected (moving by keyboard or select by mouse).
Only one method I have found that could do something like that is wx.grid.Grid.GetSelectedCells(). But it allways returns empty list - [ ].
What am I doing wrong, or maybe there is another method?
My code is as follows. Running on windows, python 2.5, wxpython - 2.8.7.1
Thank you in advance.
Aigars
import wx
import wx.grid
class TestFrame(wx.Frame):
def init (self):
wx.Frame.init (self, None, title = “Grid”, size = (640, 480))
self.grid = wx.grid.Grid(self)
self.grid.CreateGrid(50, 50)
#self.grid.SetSelectionMode(0)
self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnSelectCell, self.grid)
for row in range(10):
for col in range(10):
self.grid.SetCellValue(row, col, "cell (%s, %s)" % (row, col))
def OnSelectCell(self, event):
print self.grid.GetSelectedCells()
event.Skip()
app = wx.PySimpleApp()
frame = TestFrame()
frame.Show()
app.MainLoop()
Hello,
Aigars wrote:
Good day!
I want to find which cell (row, col) in my grid is selected (moving by keyboard or select by mouse).
Only one method I have found that could do something like that is wx.grid.Grid.GetSelectedCells(). But it allways returns empty list - .
What am I doing wrong, or maybe there is another method?
My code is as follows. Running on windows, python 2.5, wxpython - 2.8.7.1
Thank you in advance.
Aigars
import wx
import wx.grid
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title = "Grid", size = (640, 480))
self.grid = wx.grid.Grid(self)
self.grid.CreateGrid(50, 50)
#self .grid.SetSelectionMode(0)
self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnSelectCell, self.grid)
for row in range(10):
for col in range(10):
self.grid.SetCellValue(row, col, "cell (%s, %s)" % (row, col))
def OnSelectCell(self, event):
print self.grid.GetSelectedCells()
event.Skip()
app = wx.PySimpleApp()
frame = TestFrame()
frame.Show()
app.MainLoop()
I suggest you following modifications:
# Bind to other event than select cell
self.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.OnSelectCell, self.grid)
def OnSelectCell(self, event):
# Select cell, range of cells, rows and column and right click on the grid
print "Cells:\n", self.grid.GetSelectedCells()
print "Rows:\n", self.grid.GetSelectedRows()
print "Cols:\n", self.grid.GetSelectedCols()
print "Top left: ", self.grid.GetSelectionBlockTopLeft()
print "Bottom right: ", self.grid.GetSelectionBlockBottomRight()
event.Skip()
Regards,
Mathias
Aigars
October 22, 2008, 12:14pm
3
Hi,
Event wx.grid.EVT_GRID_SELECT_CELL works fine - it is redirected to handler and all prints are performed. However, I also tried wx.grid.EVT_GRID_CELL_RIGHT_CLICK, as you suggested, results are the same:
all prints are performed, but all of functions return empty List, and my program output is as follows:
Cells:
Rows:
Cols:
Top left:
Bottom right:
I expected some row and col coordinates there.
Aigars
Quoting Mathias Lorente mathias.lorente@insilicio.com :
···
Hello,
Aigars wrote:
Good day!
I want to find which cell (row, col) in my grid is selected (moving by
keyboard or select by mouse).
Only one method I have found that could do something like that is
wx.grid.Grid.GetSelectedCells(). But it allways returns empty list - .
What am I doing wrong, or maybe there is another method?
My code is as follows. Running on windows, python 2.5, wxpython - 2.8.7.1
Thank you in advance.
Aigars
import wx
import wx.grid
class TestFrame(wx.Frame):
def init (self):
wx.Frame.init (self, None, title = “Grid”,
size = (640, 480))
self.grid = wx.grid.Grid(self)
self.grid.CreateGrid(50, 50)
#self .grid.SetSelectionMode(0)
self.Bind(wx.grid.EVT_GRID_SELECT_CELL,
self.OnSelectCell, self.grid)
for row in range(10):
for col in range(10):
self.grid.SetCellValue(row,
col, “cell (%s, %s)” % (row, col))
def OnSelectCell(self, event):
print self.grid.GetSelectedCells()
event.Skip()
app = wx.PySimpleApp()
frame = TestFrame()
frame.Show()
app.MainLoop()
I suggest you following modifications:
Bind to other event than select cell
self.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.OnSelectCell,
self.grid)
def OnSelectCell(self, event):
Select cell, range of cells, rows and column and right click on the grid
print “Cells:\n”, self.grid.GetSelectedCells()
print “Rows:\n”, self.grid.GetSelectedRows()
print “Cols:\n”, self.grid.GetSelectedCols()
print "Top left: ", self.grid.GetSelectionBlockTopLeft()
print "Bottom right: ", self.grid.GetSelectionBlockBottomRight()
event.Skip()
Regards,
Mathias
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Aigars wrote:
Hi,
Event wx.grid.EVT_GRID_SELECT_CELL works fine - it is
redirected to handler and all prints are performed. However,
I also tried wx.grid.EVT_GRID_CELL_RIGHT_CLICK, as you
suggested, results are the same:
all prints are performed, but all of functions return empty
List, and my program output is as follows:
Cells:
Rows:
Cols:
Top left:
Bottom right:
I expected some row and col coordinates there.
According to the docs, GetSelectedCells() returns "an array of singly
selected cells".
If you are trying to select a range of cells, there is
wx.EVT_GRID_RANGE_SELECT.
The event has the following methods (amongst others) -
evt.GetTopLeftCoords()
evt.GetBottomRightCoords()
evt.GetTopRow()
evt.GetBottomRow()
evt.GetLeftCol()
evt.GetRightCol()
I have not tried any of this, but maybe it is what you are looking for.
Frank Millman
Aigars wrote:
I want to find which cell (row, col) in my grid is selected (moving by keyboard or select by mouse).
Use GetGridCursorRow() and GetGridCursorCol().
To make things faster, in my derived wx.grid.grid I have written this function:
def CurCell(self):
curcell = []
curcell.append(self.GetGridCursorRow())
curcell.append(self.GetGridCursorCol())
return curcell
···
2008/10/22 Frank Millman frank@chagford.com
Aigars wrote:
Hi,
Event wx.grid.EVT_GRID_SELECT_CELL works fine - it is
redirected to handler and all prints are performed. However,
I also tried wx.grid.EVT_GRID_CELL_RIGHT_CLICK, as you
suggested, results are the same:
all prints are performed, but all of functions return empty
List, and my program output is as follows:
Cells:
Rows:
Cols:
Top left:
Bottom right:
I expected some row and col coordinates there.
According to the docs, GetSelectedCells() returns "an array of singly
selected cells".
If you are trying to select a range of cells, there is
wx.EVT_GRID_RANGE_SELECT.
The event has the following methods (amongst others) -
evt.GetTopLeftCoords()
evt.GetBottomRightCoords()
evt.GetTopRow()
evt.GetBottomRow()
evt.GetLeftCol()
evt.GetRightCol()
I have not tried any of this, but maybe it is what you are looking for.
Frank Millman
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
raffaello wrote:
Aigars wrote:
/I want to find which cell (row, col) in my grid is selected (moving by keyboard or select by mouse)./
Oups...
you just have to work with the event:
event.Row, event.Col or event.GetRow(), event.GetCol()
Sorry I read to quickly.
Mathias
···
Use GetGridCursorRow() and GetGridCursorCol().
To make things faster, in my derived wx.grid.grid I have written this function:
def CurCell(self):
curcell =
curcell.append(self.GetGridCursorRow())
curcell.append(self.GetGridCursorCol())
return curcell
2008/10/22 Frank Millman <frank@chagford.com <mailto:frank@chagford.com>>
Aigars wrote:
>
> Hi,
>
> Event wx.grid.EVT_GRID_SELECT_CELL works fine - it is
> redirected to handler and all prints are performed. However,
> I also tried wx.grid.EVT_GRID_CELL_RIGHT_CLICK, as you
> suggested, results are the same:
>
> all prints are performed, but all of functions return empty
> List, and my program output is as follows:
> Cells:
> Rows:
> Cols:
> Top left:
> Bottom right:
>
> I expected some row and col coordinates there.
>
According to the docs, GetSelectedCells() returns "an array of singly
selected cells".
If you are trying to select a range of cells, there is
wx.EVT_GRID_RANGE_SELECT.
The event has the following methods (amongst others) -
evt.GetTopLeftCoords()
evt.GetBottomRightCoords()
evt.GetTopRow()
evt.GetBottomRow()
evt.GetLeftCol()
evt.GetRightCol()
I have not tried any of this, but maybe it is what you are looking
for.
Frank Millman