I want to popup a context menu for a right-click in a wx grid. The contents of the menu will depend on which cell the user right clicks. How do I determine the cell where the right-click occurred? The grid itself does not seem to have any selected cells when the event occurs.
Does the event instance contain any information on which cell was right clicked? The GetEventObject method seems to just return the wx.grid.Grid instance. If the information isn’t in the event and the grid doesn’t have any selected cells, am I out of luck?
Thanks,
Ryan
P.S. My full script is attached, but it won’t run without other modules of mine.
Τη Τετάρτη, 25 Σεπτεμβρίου 2013 12:32:54 π.μ. UTC+3, ο χρήστης Ryan Krauss έγραψε:
I want to popup a context menu for a right-click in a wx grid. The contents of the menu will depend on which cell the user right clicks. How do I determine the cell where the right-click occurred? The grid itself does not seem to have any selected cells when the event occurs.
Does the event instance contain any information on which cell was right clicked? The GetEventObject method seems to just return the wx.grid.Grid instance. If the information isn’t in the event and the grid doesn’t have any selected cells, am I out of luck?
Thanks,
Ryan
P.S. My full script is attached, but it won’t run without other modules of mine.
Taken from one of the 9872364590827645 Robins answers and tips:
x, y = [YOUR GRID OBJECT].CalcUnscrolledPosition(event.GetX(),event.GetY())
Τη Τετάρτη, 25 Σεπτεμβρίου 2013 12:32:54 π.μ. UTC+3, ο χρήστης Ryan Krauss έγραψε:
I want to popup a context menu for a right-click in a wx grid. The contents of the menu will depend on which cell the user right clicks. How do I determine the cell where the right-click occurred? The grid itself does not seem to have any selected cells when the event occurs.
Does the event instance contain any information on which cell was right clicked? The GetEventObject method seems to just return the wx.grid.Grid instance. If the information isn’t in the event and the grid doesn’t have any selected cells, am I out of luck?
Thanks,
Ryan
P.S. My full script is attached, but it won’t run without other modules of mine.
Taken from one of the 9872364590827645 Robins answers and tips:
x, y = [YOUR GRID OBJECT].CalcUnscrolledPosition(event.GetX(),event.GetY())
coords = [YOUR GRID OBJECT].XYToCell(x, y)
col = coords[1]
row = coords[0]
Dont thank me , i just copied it…
Elias
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
in show_popup_menu
Traceback (most recent call last):
File “block_diagram_gui.py”, line 161, in show_popup_menu
x, y = self.params_grid.CalcUnscrolledPosition(event.GetX(), \
AttributeError: ‘GridEvent’ object has no attribute ‘GetX’
So, it seems like a wx.grid.EVT_GRID_CELL_RIGHT_CLICK doesn’t have a GetX method…
On Tue, Sep 24, 2013 at 6:36 PM, Elias Alhanatis ealha...@gmail.com wrote:
Τη Τετάρτη, 25 Σεπτεμβρίου 2013 12:32:54 π.μ. UTC+3, ο χρήστης Ryan Krauss έγραψε:
I want to popup a context menu for a right-click in a wx grid. The contents of the menu will depend on which cell the user right clicks. How do I determine the cell where the right-click occurred? The grid itself does not seem to have any selected cells when the event occurs.
Does the event instance contain any information on which cell was right clicked? The GetEventObject method seems to just return the wx.grid.Grid instance. If the information isn’t in the event and the grid doesn’t have any selected cells, am I out of luck?
Thanks,
Ryan
P.S. My full script is attached, but it won’t run without other modules of mine.
Taken from one of the 9872364590827645 Robins answers and tips:
x, y = [YOUR GRID OBJECT].CalcUnscrolledPosition(event.GetX(),event.GetY())
coords = [YOUR GRID OBJECT].XYToCell(x, y)
col = coords[1]
row = coords[0]
Dont thank me , i just copied it…
Elias
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
Thank you Mike and Elias. This is now working exactly like I would want it to.
Mike, I had originally grabbed my code off of your blog. Though I miss used it and caused my own problem, it would be great to put this short example (grid_rclick.py) on this page:
Glad you got it figured out. I went ahead and updated my blog article too. Hopefully someone else will find it useful in the future. Thank you for your readership!
Mike
···
On Wednesday, September 25, 2013 9:09:02 AM UTC-5, Ryan Krauss wrote:
Thank you Mike and Elias. This is now working exactly like I would want it to.
Mike, I had originally grabbed my code off of your blog. Though I miss used it and caused my own problem, it would be great to put this short example (grid_rclick.py) on this page:
Τη Τετάρτη, 25 Σεπτεμβρίου 2013 12:32:54 π.μ. UTC+3, ο χρήστης Ryan
Krauss έγραψε:
I want to popup a context menu for a right-click in a wx grid. The
contents of the menu will depend on which cell the user right
clicks. How do I determine the cell where the right-click occurred?
The grid itself does not seem to have any selected cells when the
event occurs.
Does the event instance contain any information on which cell was
right clicked? The GetEventObject method seems to just return the
wx.grid.Grid instance. If the information isn't in the event and the
grid doesn't have any selected cells, am I out of luck?
Thanks,
Ryan
P.S. My full script is attached, but it won't run without other
modules of mine.
Taken from one of the 9872364590827645 Robins answers and tips:
That's pretty amazing considering I've only been alive somewhere around 1486895020 seconds.
x, y = [YOUR GRID OBJECT].CalcUnscrolledPosition(event.GetX(),event.GetY())
coords = [YOUR GRID OBJECT].XYToCell(x, y)
col = coords[1]
row = coords[0]
Dont thank me , i just copied it.....
That approach is good if you need to translate from an arbitrary pixel position to a cell, but in this case EVT_GRID_CELL_RIGHT_CLICK will do all of that for you. The event object passed to the handler has GetRow and GetCol methods.
The event object passed to the handler has GetRow and GetCol methods.
That makes sense. I really did try and google for documentation on EVT_GRID_CELL_RIGHT_CLICK. I say that but googling “wxpython EVT_GRID_CELL_RIGHT_CLICK” lead me to these two links as results #1 and 3:
On Wed, Sep 25, 2013 at 2:25 PM, Robin Dunn robin@alldunn.com wrote:
Elias Alhanatis wrote:
Τη Τετάρτη, 25 Σεπτεμβρίου 2013 12:32:54 π.μ. UTC+3, ο χρήστης Ryan
Krauss έγραψε:
I want to popup a context menu for a right-click in a wx grid. The
contents of the menu will depend on which cell the user right
clicks. How do I determine the cell where the right-click occurred?
The grid itself does not seem to have any selected cells when the
event occurs.
For now, I just have this to bind the event:
self.params_grid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK,
self.show_popup_menu)
and this little shell of an event handler:
def show_popup_menu(self, event):
print('in show_popup_menu')
pdb.set_trace()
Does the event instance contain any information on which cell was
right clicked? The GetEventObject method seems to just return the
wx.grid.Grid instance. If the information isn't in the event and the
grid doesn't have any selected cells, am I out of luck?
Thanks,
Ryan
P.S. My full script is attached, but it won't run without other
modules of mine.
Taken from one of the 9872364590827645 Robins answers and tips:
That’s pretty amazing considering I’ve only been alive somewhere around 1486895020 seconds.
x, y = [YOUR GRID OBJECT].CalcUnscrolledPosition(event.GetX(),event.GetY())
coords = [YOUR GRID OBJECT].XYToCell(x, y)
col = coords[1]
row = coords[0]
Dont thank me , i just copied it…
That approach is good if you need to translate from an arbitrary pixel position to a cell, but in this case EVT_GRID_CELL_RIGHT_CLICK will do all of that for you. The event object passed to the handler has GetRow and GetCol methods.
Taken from one of the 9872364590827645 Robins answers and tips:
That’s pretty amazing considering I’ve only been alive somewhere around
1486895020 seconds.
Well you are the one with the time machine, you know!
x, y = [YOUR GRID OBJECT].CalcUnscrolledPosition(event.GetX(),event.GetY())
coords = [YOUR GRID OBJECT].XYToCell(x, y)
col = coords[1]
row = coords[0]
Dont thank me , i just copied it…
That approach is good if you need to translate from an arbitrary pixel
position to a cell, but in this case EVT_GRID_CELL_RIGHT_CLICK will do
all of that for you. The event object passed to the handler has GetRow
and GetCol methods.