Hi,
I have a grid and a contextual menu that I can display on
the grid.
After the contextual menu fires I want to get the contents
of the grid under the menu ( actually I want to get the
contents by querying the table data source).
Here is a fragment of the application....
class MyGrid(wx.grid.Grid):
def __init__(self,parent):
wx.grid.Grid.__init__(self,parent)
self.lastPopup = None
self.popupmenu = wx.Menu()
for text in ["Show Field", "dick","harry"] :
item = self.popupmenu.Append(-1,text)
self.Bind(wx.EVT_MENU,self.OnPopupItemSelected,item)
#self.GetGridWindow().Bind(wx.EVT_CONTEXT_MENU,self.OnShowPopup)
self.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK,self.OnShowPopup)
def OnShowPopup(self,event):
pos=event.GetPosition()
self.lastPopup = pos
self.PopupMenu(self.popupmenu,pos)
def OnPopupItemSelected(self,event) :
item=self.popupmenu.FindItemById(event.GetId())
text = item.GetText()
row = self.YToRow(self.lastPopup[1])
col = self.XToCol(self.lastPopup[0])
content = self.GetTable().GetValue(row-1,col-1)
wx.MessageBox("row= %d, col= %d \n Content = %s" % (row,col, content))
The problem is that sometimes I get the right value and sometimes
I don't. I seem to have the best luck clicking in the upper left
corner of a grid box. Most of the time clicking in the rightmost column
shows a column of -1. ( Most of the time the resulting grid coordinates
are off by one in one direction or the other )
If I scroll the grid I will always get grid coordinates relative to the
initial screen ie if the grid is show rows 101-110 I will get rows in
the messagebox with values 1-10...
Accuracy (even in linux) gets worse it I resize the columns...
Any suggestions?
Jerry