-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathGridHoverRow.py
72 lines (57 loc) · 2.01 KB
/
GridHoverRow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import wx
import wx.grid
from ColGrid import ColGrid
class ColGridHoverRow( ColGrid ):
def __init__( self, *args, **kwargs ):
super().__init__( *args, **kwargs )
self.GetGridWindow().Bind( wx.EVT_MOTION, self.OnMotionHover )
# self.GetGridWindow().Bind( wx.EVT_LEAVE_WINDOW, self.OnLeaveHover )
def HitRowTest(self,x,y):
"""Convert client coordinates to cell position.
@return: a tuple of (row,col). If the position is not over a column or row,
then it will have a value of -1.
Note: client coordinates are client coordinates of wx.Grid.GetGridWindow(), not
the grid itself!
"""
x, y = self.CalcUnscrolledPosition(x, y)
return self.YToRow(y)
def OnLeaveHover( self, event ):
self.ClearSelection()
def OnMotionHover( self, event ):
row = self.HitRowTest( event.GetX(), event.GetY() )
if row < 0:
self.ClearSelection()
else:
self.SelectRow( row )
def AugmentGridHoverRow( grid ):
def HitRowTest( x, y ):
"""Convert client coordinates to cell position.
@return: a tuple of (row,col). If the position is not over a column or row,
then it will have a value of -1.
Note: client coordinates are client coordinates of wx.Grid.GetGridWindow(), not
the grid itgrid!
"""
x, y = grid.CalcUnscrolledPosition(x, y)
return grid.YToRow(y)
def OnLeaveHover( event ):
grid.ClearSelection()
def OnMotionHover( event ):
row = HitRowTest( event.GetX(), event.GetY() )
if row < 0:
grid.ClearSelection()
else:
grid.SelectRow( row )
grid.GetGridWindow().Bind( wx.EVT_MOTION, OnMotionHover )
# grid.GetGridWindow().Bind( wx.EVT_LEAVE_WINDOW, OnLeaveHover )
return grid
if __name__ == '__main__':
app = wx.App(False)
mainWin = wx.Frame(None,title="CrossMan", size=(600,200))
grid = ColGridHoverRow( mainWin )
max_cols = 10
max_rows = 10
colnames = ['Col {}'.format(c) for c in range(max_cols)]
data = [['({},{})'.format(r, c) for r in range(max_rows)] for c in range(max_cols)]
grid.Set( data=data, colnames=colnames )
mainWin.Show()
app.MainLoop()