SavinaRoja / PyUserInput

A module for cross-platform control of the mouse and keyboard in python that is simple to install and use.
GNU General Public License v3.0
1.07k stars 244 forks source link

Allow reusing PyMouseEvent instance multiple times. #89

Closed qria closed 8 years ago

qria commented 8 years ago

Currently if you run an instance of PyMouseEvent after it is stopped once, it will immediately stop itself because self.state is set to False.

I wanted to reuse some of my PyMouseEvent classes so I simply added self.state=True in self.run().

I see no reason for this to not be a default behavior.

Here is a simple usecase/code for this.

from pymouse import PyMouseEvent

class OnetimeClickListener(PyMouseEvent):
    """ Waits for a user to click and save the position """
    def run(self):
        self.state = True
        super(OnetimeClickListener, self).run()
    def click(self, x, y, button, press):
        if not press:
            # Ignore Mouse Up events
            return
        self.position = (x, y)
        self.stop()

# Example code

listener = OnetimeClickListener()

print("Please click to set position1")
listener.run()
pos1 = listener.position

print("Please click to set position2")
listener.run()
pos2 = listener.position

print("Please click to set position3")
listener.run()
pos3 = listener.position
pepijndevos commented 8 years ago
                                                                                  Note that the project has moved to an organisation.I think that the issue is that some implementations use threads to listen to events, and as far as I know threads can not be restarted. I'll verify this later.                                                                                                                                                                                  ‎
qria commented 8 years ago

Oh should I repost there? Or maybe wait for you to verify it?

pepijndevos commented 8 years ago

See? https://github.com/PyUserInput/PyUserInput/blob/master/pymouse/base.py#L107 So definitely a wontfix.