diff --git a/.gitignore b/.gitignore index 76e0c92..d3257f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.py[cod] +*~ # C extensions *.so diff --git a/README.md b/README.md index 5dc4e11..cde21bf 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ PyKeyboardEvent, so here's an example of subclassing PyMouseEvent: from pymouse import PyMouseEvent def fibo(): - a = 1 + a = 0 yield a b = 1 yield b diff --git a/examples/clickonacci.py b/examples/clickonacci.py new file mode 100644 index 0000000..1f07dbb --- /dev/null +++ b/examples/clickonacci.py @@ -0,0 +1,26 @@ +from pymouse import PyMouseEvent + +def fibo(): + a = 0 + yield a + b = 1 + yield b + while True: + a, b = b, a+b + yield b + +class Clickonacci(PyMouseEvent): + def __init__(self): + PyMouseEvent.__init__(self) + self.fibo = fibo() + + def click(self, x, y, button, press): + '''Print Fibonacci numbers when the left click is pressed.''' + if button == 1: + if press: + print(self.fibo.next()) + else: # Exit if any other mouse button used + self.stop() + +C = Clickonacci() +C.run() \ No newline at end of file