【问题标题】:How can I handle a mouseMiddleDrag event in PythonCard?如何在 PythonCard 中处理 mouseMiddleDrag 事件?
【发布时间】:2010-10-29 07:43:46
【问题描述】:

我想在一个用 Python 编写并使用 PythonCard/wxPython 作为 GUI 的应用程序中使用鼠标中键拖动图像。

最新版本的 PythonCard 仅实现“鼠标左键拖动”事件,我正在尝试修改 PythonCard 以处理“鼠标中键拖动”。

这里是来自 Lib\site-packages\PythonCard\event.py 的相关代码:

class MouseMoveEvent(MouseEvent, InsteadOfTypeEvent):
    name = 'mouseMove'
    binding = wx.EVT_MOTION
    id = wx.wxEVT_MOTION

    def translateEventType(self, aWxEvent):
        if aWxEvent.Dragging():
            return MouseDragEvent.id
        else:
            return self.id

class MouseDragEvent(MouseMoveEvent):
    name = 'mouseDrag'
    id = wx.NewEventType()

class MouseMiddleDragEvent(MouseMoveEvent): #My addition
    name = 'mouseMiddleDrag'
    id = wx.NewEventType()

我的添加不起作用。我能做些什么呢?有没有可以用来绕过 PythonCard 的特定 wxPython 方法?

【问题讨论】:

    标签: python user-interface wxpython mouse pythoncard


    【解决方案1】:

    事实证明,无论按下鼠标上的哪个按钮,mouseDrag 事件都是活动的。要过滤鼠标中键,需要从MouseEvent中调用MiddleIsDown()方法。

    def on_mouseDrag( self, event ):       
        do_stuff()
    
        if event.MiddleIsDown():
            do_other_stuff()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-06
      • 2021-02-19
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-17
      相关资源
      最近更新 更多