views:

59

answers:

1

I would like to use the middle mouse button to drag an image in an application written in Python and using PythonCard/wxPython for the GUI.

The latest version of PythonCard only implements a "left mouse button drag" event and I am trying to modify PythonCard to handle a "middle mouse button drag" as well.

Here is the relevant code from 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()

My addition does not work. What can I do instead? Is there a specific wxPython method that I could use to bypass PythonCard?

+1  A: 

It turns out the the mouseDrag event is active regardless of which button on the mouse is pressed. To filter the middle mouse button, you need to call the MiddleIsDown() method from the MouseEvent.

def on_mouseDrag( self, event ):       
    do_stuff()

    if event.MiddleIsDown():
        do_other_stuff()
JcMaco