DataViewCtrl: how to get the item under the mouse cursor? (hit test)

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

DataViewCtrl: how to get the item under the mouse cursor? (hit test)

Dario Giovannetti
I'm trying to compute the DataViewItem that is under the mouse cursor: in ListCtrl that is done through the HitTest method, but the corresponding method for DataViewCtrl seems to behave differently, and I haven't understood how to use it. The following script, using a DataViewListCtrl, is as far as I've managed to get, can anybody help me? Thank you.

#########################################
import wx
import wx.dataview

def test():
    pos = view.ScreenToClient(wx.GetMousePosition())
    item = view.RowToItem(0)
    col = view.GetColumn(0)
    print(col.__class__)
    # How to get the item under the mouse cursor?
    print(view.HitTest(pos, item, col))
    #timer.Restart()

app = wx.App()
frame = wx.Frame(None)
view = wx.dataview.DataViewListCtrl(frame, style=wx.dataview.DV_MULTIPLE)
column = view.AppendTextColumn("Text", 0)
view.AppendItem(('Test1', ))
view.AppendItem(('Test2', ))
view.AppendItem(('Test3', ))
timer = wx.CallLater(3000, test)
frame.Centre()
frame.Show()
app.MainLoop()
#########################################

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: DataViewCtrl: how to get the item under the mouse cursor? (hit test)

werner-3
Hi,

On 05/03/2014 16:12, [hidden email] wrote:
> I'm trying to compute the DataViewItem that is under the mouse cursor:
> in ListCtrl that is done through the HitTest method, but the
> corresponding method for DataViewCtrl seems to behave differently, and
> I haven't understood how to use it. The following script, using a
> DataViewListCtrl, is as far as I've managed to get, can anybody help
> me? Thank you.
I gave it a shot and with 2.9.5 I get this exception:

File "h:\devProjectsT\aaTests\aaMisc\dariogiova\dvchitest.py", line 26,
in <module>
   app.MainLoop()
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_core.py", line
8660, in MainLoop
   wx.PyApp.MainLoop(self)
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_core.py", line
7952, in MainLoop
   return _core_.PyApp_MainLoop(*args, **kwargs)
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_misc.py", line
1367, in Notify
   self.notify()
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_core.py", line
16870, in Notify
   self.result = self.callable(*self.args, **self.kwargs)
File "h:\devProjectsT\aaTests\aaMisc\dariogiova\dvchitest.py", line 12,
in test
   print(view.HitTest(pos, item, col))
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\dataview.py", line
1817, in HitTest
   return _dataview.DataViewCtrl_HitTest(*args, **kwargs)

TypeError: in method 'DataViewCtrl_HitTest', expected argument 4 of type
'wxDataViewColumn *&'

even though 'col' at that time is an instance of 'wx.dataview.DataViewColumn

If I run it against Phoenix (3.0.1.dev75864) I get:

File "h:\devProjectsT\aaTests\aaMisc\dariogiova\dvchitest.py", line 28,
in <module>
   app.MainLoop()
File "c:\Python27\Lib\site-packages\wx-3.0.1-msw-phoenix\wx\core.py",
line 1878, in MainLoop
   rv = wx.PyApp.MainLoop(self)
File "c:\Python27\Lib\site-packages\wx-3.0.1-msw-phoenix\wx\core.py",
line 1940, in Notify
   self.notify()
File "c:\Python27\Lib\site-packages\wx-3.0.1-msw-phoenix\wx\core.py",
line 3017, in Notify
   self.result = self.callable(*self.args, **self.kwargs)
File "h:\devProjectsT\aaTests\aaMisc\dariogiova\dvchitest.py", line 14,
in test
   print(view.HitTest(pos, item, col))

TypeError: DataViewCtrl.HitTest(): too many arguments

So, looks like there is a problem with HitTest.

Could you use instead 'EVT_DATAVIEW_ITEM_ACTIVATED'?

Werner

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: DataViewCtrl: how to get the item under the mouse cursor? (hit test)

Dario Giovannetti


On Wednesday, March 5, 2014 11:45:37 PM UTC+8, werner wrote:
Hi,

On 05/03/2014 16:12, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="tWMUb0Q6I6kJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">dario...@... wrote:
> I'm trying to compute the DataViewItem that is under the mouse cursor:
> in ListCtrl that is done through the HitTest method, but the
> corresponding method for DataViewCtrl seems to behave differently, and
> I haven't understood how to use it. The following script, using a
> DataViewListCtrl, is as far as I've managed to get, can anybody help
> me? Thank you.
I gave it a shot and with 2.9.5 I get this exception:

File "h:\devProjectsT\aaTests\aaMisc\dariogiova\dvchitest.py", line 26,
in <module>
   app.MainLoop()
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_core.py", line
8660, in MainLoop
   wx.PyApp.MainLoop(self)
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_core.py", line
7952, in MainLoop
   return _core_.PyApp_MainLoop(*args, **kwargs)
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_misc.py", line
1367, in Notify
   self.notify()
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_core.py", line
16870, in Notify
   self.result = self.callable(*self.args, **self.kwargs)
File "h:\devProjectsT\aaTests\aaMisc\dariogiova\dvchitest.py", line 12,
in test
   print(view.HitTest(pos, item, col))
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\dataview.py", line
1817, in HitTest
   return _dataview.DataViewCtrl_HitTest(*args, **kwargs)

TypeError: in method 'DataViewCtrl_HitTest', expected argument 4 of type
'wxDataViewColumn *&'

even though 'col' at that time is an instance of 'wx.dataview.DataViewColumn

If I run it against Phoenix (3.0.1.dev75864) I get:

File "h:\devProjectsT\aaTests\aaMisc\dariogiova\dvchitest.py", line 28,
in <module>
   app.MainLoop()
File "c:\Python27\Lib\site-packages\wx-3.0.1-msw-phoenix\wx\core.py",
line 1878, in MainLoop
   rv = wx.PyApp.MainLoop(self)
File "c:\Python27\Lib\site-packages\wx-3.0.1-msw-phoenix\wx\core.py",
line 1940, in Notify
   self.notify()
File "c:\Python27\Lib\site-packages\wx-3.0.1-msw-phoenix\wx\core.py",
line 3017, in Notify
   self.result = self.callable(*self.args, **self.kwargs)
File "h:\devProjectsT\aaTests\aaMisc\dariogiova\dvchitest.py", line 14,
in test
   print(view.HitTest(pos, item, col))

TypeError: DataViewCtrl.HitTest(): too many arguments

So, looks like there is a problem with HitTest.

Could you use instead 'EVT_DATAVIEW_ITEM_ACTIVATED'?

Werner

Sorry, I should have mentioned that I'm using 3.0.0, which raises the same exception as 2.9.5. Is it a known bug? The only related report I've found is http://trac.wxwidgets.org/ticket/12582 which seems farily old, though still open.

Should 'EVT_DATAVIEW_ITEM_ACTIVATED' be trieggered when the mouse hovers over an item? The documentation says "This event is triggered by float clicking an item or pressing some special key (usually “Enter”) when it is focused": I don't know what "float clicking" is, but the only way I can trigger it seems to be by double-clicking the item, which is very far from what I need. What I'm trying to do is actually temporarily work around another bug, http://trac.wxwidgets.org/ticket/13531 while waiting for 3.0.1 to be released.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: DataViewCtrl: how to get the item under the mouse cursor? (hit test)

werner-3
Hi,

On 05/03/2014 17:01, [hidden email] wrote:
>
>
> On Wednesday, March 5, 2014 11:45:37 PM UTC+8, werner wrote:
...
> Sorry, I should have mentioned that I'm using 3.0.0, which raises the
> same exception as 2.9.5. Is it a known bug?
It looks like but I am not sure.

Yes, providing the version one uses is always good and if you get an
exception you should include it too, as often that is enough to help.

...
> Should 'EVT_DATAVIEW_ITEM_ACTIVATED' be trieggered when the mouse
> hovers over an item? The documentation says "This event is triggered
> by float clicking an item or pressing some special key (usually
> “Enter”) when it is focused": I don't know what "float clicking" is,
> but the only way I can trigger it seems to be by double-clicking the
> item, which is very far from what I need. What I'm trying to do is
> actually temporarily work around another bug,
> http://trac.wxwidgets.org/ticket/13531 while waiting for 3.0.1 to be
> released.
No it will not trigger on mouse hover, only when an item is 'selected',
most of the time that is when the user would expect something to happen.

Werner

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: DataViewCtrl: how to get the item under the mouse cursor? (hit test)

Dario Giovannetti


On Thursday, March 6, 2014 12:07:25 AM UTC+8, werner wrote:
Hi,

On 05/03/2014 17:01, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="maTzahtUZJcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">dario...@... wrote:
>
>
> On Wednesday, March 5, 2014 11:45:37 PM UTC+8, werner wrote:
...
> Sorry, I should have mentioned that I'm using 3.0.0, which raises the
> same exception as 2.9.5. Is it a known bug?
It looks like but I am not sure.

Yes, providing the version one uses is always good and if you get an
exception you should include it too, as often that is enough to help.


I see, thanks for your help. I thought it was me doing something wrong. Here's my exception:
########################
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/wx-3.0-gtk2/wx/_misc.py", line 1367, in Notify
    self.notify()
  File "/usr/lib/python2.7/site-packages/wx-3.0-gtk2/wx/_core.py", line 16866, in Notify
    self.result = self.callable(*self.args, **self.kwargs)
  File "test_dvlistc3.py", line 10, in test
    print(view.HitTest(pos, item, col))
  File "/usr/lib/python2.7/site-packages/wx-3.0-gtk2/wx/dataview.py", line 1817, in HitTest
    return _dataview.DataViewCtrl_HitTest(*args, **kwargs)
TypeError: in method 'DataViewCtrl_HitTest', expected argument 4 of type 'wxDataViewColumn *&'
########################

My system is:
Arch Linux x86_64
GTK+ 2.24.22
wxGTK 3.0.0
wxPython 3.0.0.0

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: DataViewCtrl: how to get the item under the mouse cursor? (hit test)

Robin Dunn
In reply to this post by werner-3
Werner wrote:

> Hi,
>
> On 05/03/2014 17:01, [hidden email] wrote:
>>
>>
>> On Wednesday, March 5, 2014 11:45:37 PM UTC+8, werner wrote:
> ...
>> Sorry, I should have mentioned that I'm using 3.0.0, which raises the
>> same exception as 2.9.5. Is it a known bug?
> It looks like but I am not sure.

Sorta. The method wrapper will need to be rewritten (Pythonized) to
return the item and col as a tuple instead of expecting to pass by
reference through the parameters.

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

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: DataViewCtrl: how to get the item under the mouse cursor? (hit test)

nepix32

On Saturday, March 15, 2014 5:51:43 AM UTC+1, Robin Dunn wrote:
like but I am not sure.

Sorta. The method wrapper will need to be rewritten (Pythonized) to
return the item and col as a tuple instead of expecting to pass by
reference through the parameters.
I am trying to use DataViewCtrl and I am quite happy with it.
Drag and Drop seems to work as well, but now I struggle to find on which DataViewItem the drop target is.
 
As mentioned above, HitTest throws this error:
 
TypeError: in method 'DataViewCtrl_HitTest', expected argument 4 of type 'wxDataViewColumn *&' 
 
because this is not wrapped yet.
 
Can I workaround this by providing a memoryview/buffer/pointer myself until this gets fixed?
 
With best regards

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: DataViewCtrl: how to get the item under the mouse cursor? (hit test)

Nathan McCorkle
In reply to this post by Dario Giovannetti
hmm, I tried passing col.this, as well as trying int(col.this) with no luck. 
:(

On Wednesday, March 5, 2014 7:12:23 AM UTC-8, [hidden email] wrote:
I'm trying to compute the DataViewItem that is under the mouse cursor: in ListCtrl that is done through the HitTest method, but the corresponding method for DataViewCtrl seems to behave differently, and I haven't understood how to use it. The following script, using a DataViewListCtrl, is as far as I've managed to get, can anybody help me? Thank you.

#########################################
import wx
import wx.dataview

def test():
    pos = view.ScreenToClient(wx.GetMousePosition())
    item = view.RowToItem(0)
    col = view.GetColumn(0)
    print(col.__class__)
    # How to get the item under the mouse cursor?
    print(view.HitTest(pos, item, col))
    #timer.Restart()

app = wx.App()
frame = wx.Frame(None)
view = wx.dataview.DataViewListCtrl(frame, style=wx.dataview.DV_MULTIPLE)
column = view.AppendTextColumn("Text", 0)
view.AppendItem(('Test1', ))
view.AppendItem(('Test2', ))
view.AppendItem(('Test3', ))
timer = wx.CallLater(3000, test)
frame.Centre()
frame.Show()
app.MainLoop()
#########################################

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: DataViewCtrl: how to get the item under the mouse cursor? (hit test)

nepix32
In reply to this post by Robin Dunn


On Saturday, March 15, 2014 5:51:43 AM UTC+1, Robin Dunn wrote:
Sorta. The method wrapper will need to be rewritten (Pythonized) to
return the item and col as a tuple instead of expecting to pass by
reference through the parameters.

In  wxPython/trunk/src/dataview.i in line 2419 there is already the telling comment:
// TODO:  Should probably change this to return the item and col as a tuple...)
virtual void HitTest( const wxPoint & point, wxDataViewItem &item, wxDataViewColumn* &column ) const;

As I have no idea whatsoever how to tell SWIG how to do that, can you give a short explanation what to change in the SWIG-file to get the behaviour in the comment, or is this very difficult to describe?
With thanks in advance

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: DataViewCtrl: how to get the item under the mouse cursor? (hit test)

Robin Dunn
nepix32 wrote:

>
>
> On Saturday, March 15, 2014 5:51:43 AM UTC+1, Robin Dunn wrote:
>
>     Sorta. The method wrapper will need to be rewritten (Pythonized) to
>     return the item and col as a tuple instead of expecting to pass by
>     reference through the parameters.
>
>
> In wxPython/trunk/src/dataview.i
> <http://trac.wxwidgets.org/browser/wxPython/trunk/src/dataview.i?rev=70457#L2419>
> in line 2419 there is already the telling comment:
> ||
> // TODO: Should probably change this to return the item and col as a
> tuple...)
> virtualvoidHitTest(constwxPoint &point,wxDataViewItem
> &item,wxDataViewColumn*&column )const;
>
> As I have no idea whatsoever how to tell SWIG how to do that, can you
> give a short explanation what to change in the SWIG-file to get the
> behaviour in the comment, or is this very difficult to describe?


Thanks for the reminder.  I've just implemented it for the CLassic 3.0.2
release.


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

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: DataViewCtrl: how to get the item under the mouse cursor? (hit test)

Dario Giovannetti
On 14/10/14 08:17, Robin Dunn wrote:
>
> Thanks for the reminder.  I've just implemented it for the CLassic
> 3.0.2 release.
>

Thank you Robin, does that fix http://trac.wxwidgets.org/ticket/12582 ?
And, if I understand well, would that provide a way to get the current
scroll position of the DataViewCtrl by using the top coordinates of that
window? (It was the only problem left unsolved in
https://groups.google.com/d/msg/wxpython-users/isAboUxaoFs/z9PRJClSPgwJ )

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.