Hi !
I hope...
Try to catch the events that select the cell for you, like:
EVT_GRID_SELECT_CELL
EVT_GRID_LABEL_LEFT_CLICK
EVT_GRID_CELL_LEFT_CLICK
and with appropriated event method, see what cell was pressed and work
with it.
Can I prevent the event handler to it work with original methods ?
In Delphi I can prevent the running of original event handler method.
procedure MouseDown(X,Y:integer....);override;
begin
if ..... then inherited(X,Y...) # I can call the original handler
else domywork; # I don't call it, because it will doing a thing what I don't want
end;
So: how to prevent the range selection in mouse event handlers ?
Thanx for help: ft
One of the solutions is that, but that is ugly a little:
#Boa:Frame:Frame1
import wx
import wx.grid
def create(parent):
return Frame1(parent)
[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1GRID1,
] = [wx.NewId() for _init_ctrls in range(3)]
class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(346, 180), size=wx.Size(400, 479),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(392, 445))
self.grid1 = wx.grid.Grid(id=wxID_FRAME1GRID1, name='grid1',
parent=self, pos=wx.Point(72, 40), size=wx.Size(296, 296),
style=0)
self.grid1.Bind(wx.grid.EVT_GRID_SELECT_CELL,
self.OnGrid1GridSelectCell)
self.grid1.Bind(wx.grid.EVT_GRID_RANGE_SELECT,
self.OnGrid1GridRangeSelect)
self.grid1.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
self.OnGrid1GridCellChange)
self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label='button1',
name='button1', parent=self, pos=wx.Point(72, 352),
size=wx.Size(75, 23), style=0)
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
id=wxID_FRAME1BUTTON1)
def __init__(self, parent):
self._init_ctrls(parent)
self.grid1.CreateGrid(3,4)
self.SelectedC=1
self.SelectedR=1
self.OnRangeSelectOn=0
def OnGrid1GridSelectCell(self, event):
self.SetTitle('%s %s'%(event.GetCol(),event.GetRow()))
event.Skip()
def OnButton1Button(self, event):
self.grid1.SetGridCursor(2,3)
self.grid1.MakeCellVisible(2,3)
event.Skip()
def OnGrid1GridRangeSelect(self, event):
if self.OnRangeSelectOn: return
m=event.GetTopLeftCoords()
m=str(m)
m=m.replace('(','')
m=m.replace(')','')
m=m.split(',')
x=m[0].strip()
y=m[1].strip()
print x,y
#sc=self.grid1.GetSelectionBlockTopLeft()
#print sc
self.OnRangeSelectOn=True
try:
x,y=self.SelectedC,self.SelectedR
self.grid1.ClearSelection()
#self.grid1.SetGridCursor(y,x)
self.grid1.MakeCellVisible(y,x)
finally:
self.OnRangeSelectOn=False event.Skip()
def OnGrid1GridCellChange(self, event):
self.SelectedC=event.GetCol()
self.SelectedR=event.GetRow()
event.Skip()
if __name__ == '__main__':
app = wx.PySimpleApp()
wx.InitAllImageHandlers()
frame = create(None)
frame.Show()
app.MainLoop()