Improve the mouse plug-in

Questions and comments specific to a particular plugin should go here.
Post Reply
TheRetroPirate
Posts: 2
Joined: Thu Mar 06, 2014 9:32 pm

Improve the mouse plug-in

Post by TheRetroPirate » Fri Mar 07, 2014 12:07 am

I'd like to use the mouse plug-ins function "GoDirection" with a gamepad but it is really inconvenient,
the mouse cursor starts off way too slow, takes too long to accelerate and the max speed could also be higher.

So I'd like to propose that this plug-in is changed from "core" to a normal plug-in with an options page for the mouse speed/acceleration.

This changed "Mouse" class should be sufficient to get it configurable,
but even after changing the plug-in "kind" to "other" I can't add it because eventghost says it is already loaded.

Code: Select all

class Mouse(eg.PluginBase):

    def __init__(self):
        self.AddEvents()

        self.AddAction(GoDirection)
        self.AddAction(LeftButton)
        self.AddAction(MiddleButton)
        self.AddAction(RightButton)
        self.AddAction(LeftDoubleClick)
        self.AddAction(RightDoubleClick)
        self.AddAction(ToggleLeftButton)
        self.AddAction(MoveAbsolute)
        self.AddAction(MoveRelative)
        self.AddAction(MouseWheel)


    def __start__(self, initSpeed = 60, maxSpeed = 7000, accelerationFactor = 3, accelerationStopFactor = 100):
        self.thread                        = MouseThread()
        self.thread.iniSpeed               = initSpeed              * 0.001
        self.thread.maxSpeed               = maxSpeed               * 0.001
        self.thread.accelerationFactor     = accelerationFactor     * 0.001
        self.thread.accelerationStopFactor = accelerationStopFactor * 0.001
        self.leftMouseButtonDown = False
        self.lastMouseEvent = None
        self.mouseButtonWasBlocked = [False, False, False, False, False]
        SetMouseCallback(self.MouseCallBack)


    @eg.LogIt
    def __stop__(self):
        SetMouseCallback(None)
        self.thread.receiveQueue.put(-1)


    @eg.LogIt
    def __close__(self):
        pass


    def MouseCallBack(self, buttonName, buttonNum, param):
        if param:
            if self.lastMouseEvent:
                self.lastMouseEvent.SetShouldEnd()
            shouldBlock = HasActiveHandler("Mouse." + buttonName)
            self.mouseButtonWasBlocked[buttonNum] = shouldBlock
            self.lastMouseEvent = self.TriggerEnduringEvent(buttonName)
            return shouldBlock
        else:
            if self.lastMouseEvent:
                self.lastMouseEvent.SetShouldEnd()
            return self.mouseButtonWasBlocked[buttonNum]
        return False


    def Configure(self, initSpeed = 60, maxSpeed = 7000, accelerationFactor = 3, accelerationStopFactor = 100):
        panel        = eg.ConfigPanel(self, resizable=True)
        optionsSizer = wx.GridBagSizer(0, 5)
        
        initSpeedLabel = wx.StaticText(panel, -1, 'Initial mouse speed')
        optionsSizer.Add(initSpeedLabel, (0, 0))
        initSpeedSpin = eg.SpinIntCtrl(panel, -1, initSpeed, 10, 2000)
        optionsSizer.Add(initSpeedSpin, (1, 0))
        
        maxSpeedLabel = wx.StaticText(panel, -1, 'Maximum mouse speed')
        optionsSizer.Add(maxSpeedLabel, (3, 0))
        maxSpeedSpin = eg.SpinIntCtrl(panel, -1, maxSpeed, 4000, 32000)
        optionsSizer.Add(maxSpeedSpin, (4, 0))
        
        accelerationFactorLabel = wx.StaticText(panel, -1, 'Acceleration factor')
        optionsSizer.Add(accelerationFactorLabel, (6, 0))
        accelerationFactorSpin = eg.SpinIntCtrl(panel, -1, accelerationFactor, 1, 200)
        optionsSizer.Add(accelerationFactorSpin, (7, 0))
        
        accelerationStopFactorLabel = wx.StaticText(panel, -1, 'Acceleration stop factor')
        optionsSizer.Add(accelerationStopFactorLabel, (9, 0))
        accelerationStopFactorSpin = eg.SpinIntCtrl(panel, -1, accelerationStopFactor, 50, 2000)
        optionsSizer.Add(accelerationStopFactorSpin, (10, 0))
        
        panel.sizer.Add(optionsSizer, 0, wx.TOP, 10)
        
        while panel.Affirmed():
            panel.SetResult(
                initSpeedSpin.GetValue(),
                maxSpeedSpin.GetValue(),
                accelerationFactorSpin.GetValue(),
                accelerationStopFactorSpin.GetValue()
            )

Sem;colon
Experienced User
Posts: 609
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Improve the mouse plug-in

Post by Sem;colon » Fri Mar 07, 2014 7:42 pm

Hello TheRetroPirate,

There was already a topic for the mouse plugin:
viewtopic.php?f=9&t=5481&p=26729&hilit=mouse#p26729

anyway, just changing the king doesn't work - you need to give it a different guid:
line 44: guid = "{6B1751BF-F94E-4260-AB7E-64C0693FD959}",

Also I think it would be better to extend the old plugin instead of creating a new one or changing the kind.
speed and acceleration could be set in the "GoDirection" function for example.

Sem;colon
Experienced User
Posts: 609
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Improve the mouse plug-in

Post by Sem;colon » Thu Feb 12, 2015 10:39 am

I updated the mouse plugin with this feature.
viewtopic.php?f=9&t=5481&p=26729&hilit=mouse#p26729

Post Reply