wx.dataview EVT_DATAVIEW_ITEM_CONTEXT_MENU GetPosition always returns (-1, -1)

94 views
Skip to first unread message

Adit Panchal

unread,
Aug 17, 2016, 5:13:19 PM8/17/16
to wxPython-users
Hello,

I am trying to make the context menu work with wx.dataview but the function GetPosition() always returns (-1, -1) using wxPython Phoenix (Python 3.5). The results are reproducible on both Mac and Windows.

I am using: wxPython-Phoenix==3.0.3.dev2445+ca34d71

I tried binding the event in the demo as well as the following attached sample (modified from the demo) and cannot figure out why it returns this value each time.

I also tried this with both a DataViewCtrl and a DataViewListCtrl with the same results.

Actually, no matter what event I register for, wx.dataview.DataViewEvent always returns (-1, -1) for GetPosition()

Hope someone has some insight.

Thanks!

Adit
dvlistctrl.py

Adit Panchal

unread,
Aug 17, 2016, 5:22:40 PM8/17/16
to wxPython-users
I also just noticed that it returns (-1, -1) on wxPython Classic 3.0.2.0 (Python 2.7.11) on the Mac.

I wonder if A. Using the event function properly or B. the event function never worked?

Scott Talbert

unread,
Aug 17, 2016, 11:41:01 PM8/17/16
to wxPython-users
Looking at the wxWidgets code, it appears that the position isn't set for
wxEVT_DATAVIEW_ITEM_CONTEXT_MENU. It looks like the only thing that is
set is the item, so you could call GetItem() to see which item is
selected.

Robin Dunn

unread,
Aug 18, 2016, 7:17:37 PM8/18/16
to wxpytho...@googlegroups.com
Adit Panchal wrote:
> I also just noticed that it returns (-1, -1) on wxPython Classic
> 3.0.2.0 (Python 2.7.11) on the Mac.
>
> I wonder if A. Using the event function properly or B. the event
> function never worked?

Looking at the wxWidgets source code shows that the position is never
set for that event. You can use wx.GetMouseState to get the current
position of the cursor and the sate of the modifier keys.

--
Robin Dunn
Software Craftsman
http://wxPython.org

Aditya Panchal

unread,
Aug 18, 2016, 10:32:20 PM8/18/16
to wxpytho...@googlegroups.com
I tried GetItem() and it works on Windows but not on the Mac, because I think Windows by default selects the item immediately before the event is fired.

My original use case was for wx.PopupMenu, which I thought wouldn't work without a position, but apparently it does.

I'll look into wx.GetMouseState for some additional functionality as well.

So do you think this is a bug for that event or is it intended functionality?

Thanks for the quick replies!

Adit


--
You received this message because you are subscribed to a topic in the Google Groups "wxPython-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/4M4wCKfaCCE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages