Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_mouse_listener_returns_listener_instance(self, mocker):
returned = get_mouse_listener(mocker.MagicMock())
assert isinstance(returned, mouse.Listener)
def test_reraise(self):
"""Tests that exception are reraised"""
class MyException(Exception): pass
def on_click(x, y, button, pressed):
raise MyException()
with self.assertRaises(MyException):
with pynput.mouse.Listener(
on_click=on_click) as l:
self.notify('Click any button')
l.join()
def sv_init(self, context):
self.width = 200
self.outputs.new('StringsSocket', 'image_out')
self.outputs.new('StringsSocket', 'width_out')
self.outputs.new('StringsSocket', 'height_out')
self.update_layout(context)
if not np.bl_listener:
from pynput import mouse
from ...utils import on_click_callback
np.bl_listener = mouse.Listener(on_click=on_click_callback, )
np.bl_listener.start()
np.bl_listener.wait()
def run_mouse_notifs(self):
"""Run methods for notification using mice activity"""
time.sleep(10)
try:
if not pynput_status:
self.get_by_mice()
else:
while 1:
# Starting mouse event listner
with mouse.Listener(on_move=self.on_move) as listener:
listener.join()
except Exception as e:
self.logger.log(
"Something went wrong: " + str(e) + " End of program",
logtype="error"
)
except KeyboardInterrupt as e:
self.logger.log(
"You pressed Ctrl+C!, Bye")
exit()
def stop_record(self):
if self.mListener.running or self.kListener.running:
self.recordLabel.setText('')
self.mListener.stop()
self.kListener.stop()
self.mListener = mouse.Listener(on_click=self.on_click)
self.kListener = keyboard.Listener(on_press=self.on_press, on_release=self.on_release)
self.keyEvents = self.keyEvents.iloc[:-2]
self.update_table()
def stop(self):
"""Stops listener by raising an exception."""
try:
raise pynput.mouse.Listener.StopException
except pynput.mouse.Listener.StopException:
return False
def scroll_listen(adjust_brightness_fn):
while True:
print("OK")
with Listener(on_scroll=adjust(adjust_brightness_fn)) as listener:
listener.join()
from pynput.mouse import Listener
import random
threshold = 0
syncopation_chance = 0
def on_move(x, y):
global threshold, syncopation_chance
threshold = y / 1800
syncopation_chance = x / 2079
# Collect events until released
Listener(on_move=on_move).start()
s = Session()
drum = s.new_part("taiko", (0, 116), num_channels=150)
violin = s.new_part("violin")
indispensibilities = get_indispensability_array(((2, 3), 2, 3, (2, 3), (2, 3, 2), (3, 2, 3, 3)), True) # (5, 7), (7, 11)
handle = None
pitch = None
while True:
for indispensibility in indispensibilities:
if indispensibility > 0.9:
if handle is None:
pitch = 65 + (1 - threshold) * 25
def start(self):
"""Initializes and starts listener for move and scroll events."""
self.listener = pynput.mouse.Listener(
on_move=self.on_move, on_scroll=self.on_scroll
)
self.listener.start()