使用matplotlib区分单击和双击 [英] Distinguish between single and double click with matplotlib

查看:112
本文介绍了使用matplotlib区分单击和双击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图抓住我的图形上的单击和双击.

I'm trying to catch single clicks and double clicks on my figure.

如另一个答案所述,event包含event.dblclick,该值至少为False或True.版本1.4.2,因此可以双击.

As stated in another answer, the event contains event.dblclick which is False or True, at least in Version 1.4.2, so double clicks can be got.

唯一的问题是,区分单击和双击并不容易,因为双击事件会触发两次.第一次是event.dblclick=False,第二次是event.dblclick=True.

The only problem is that it's not easy to distinguish between a single click and a double click because when double-clicking the event gets fired twice. The first time it's with event.dblclick=False and the second time it's with event.dblclick=True.

对此有什么解决办法吗?我看到在此处中讨论了关于qt的相同问题. >.

Is there any solution to this? I saw that the same problem regarding qt is discussed here.

推荐答案

您需要一个软件去抖动器.

You need a software debouncer.

基本上,您会在第一次点击时启动一个计时器.如果计时器用尽,则继续处理单击事件.如果在计时器内检测到第二次单击,请处理双击事件.

Basically, you start a timer on the 1st click. If the timer runs out, then you proceed to process the single-click event. If a 2nd click is detected within the timer, process a double-click event.

实际上,如果需要,可以将其扩展为n次单击.我发现了三次点击事件的一些用途.

This can actually be expanded to n-clicks if needed. I've found some uses for triple-click events.

此处是用wxPython实现的.应该相对容易地移植到matplotlib.

Here is one implemented in wxPython. Should be relatively easy to port to matplotlib.

此外,如果您使用的是Windows,我建议您为计时器使用用户的双击速度(控制面板:鼠标").您可以通过以下方式访问它:

Also, if you're on Windows, I would recommend using the user's double-click speed for your timer (Control Panel: Mouse). You can access it with:

get_double_click_time():
    """ Gets the Windows double click time in ms """
    from ctypes import windll
    return int(windll.user32.GetDoubleClickTime())

我还没有弄清楚如何从Mac或Linux上获得点击时间(但是我也没有必要).

I haven't yet figured out how to grab the dclick time from Mac or Linux (but I also don't have a need to).

这篇关于使用matplotlib区分单击和双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆