-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMouseInputThread.py
More file actions
57 lines (50 loc) · 2.19 KB
/
MouseInputThread.py
File metadata and controls
57 lines (50 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from pynput.mouse import Listener
from threading import Thread
class mouseInputThread(Thread):
'''
Thread for getting mouse input. Used to read scroll-wheel and thus
lower/raise the sample.
'''
def __init__(self, threadID, name, c_p, stepper_step_distance=0.0003,
piezo_step_distance=0.1, piezo_z=50, sleep_time=0.02):
Thread.__init__(self)
self.threadID = threadID
self.name = name
self.setDaemon(True)
self.c_p = c_p
self.piezo_step_distance = piezo_step_distance
self.stepper_step_distance = stepper_step_distance
self.sleep_time = sleep_time
def on_move(self, x, y):
"""
Used to check if the program is still running.
"""
return self.c_p['program_running']
def on_scroll(self, x, y, dx, dy):
'''
Moves the stage up/down depending on scroll. Will automagically shift
between using steppers and piezos depending on which are activated.
'''
if self.c_p['scroll_for_z']:
# TODO piezo elevation is causin more problem than it's worth, remove it!
if self.c_p['stage_piezos'] and self.c_p['piezos_activated'].get():
if dy < 0:
self.c_p['piezo_elevation'] -= self.piezo_step_distance
else:
self.c_p['piezo_elevation'] += self.piezo_step_distance
elif self.c_p['using_stepper_motors'] and self.c_p['stepper_activated'].get():
if dy < 0:
self.c_p['stepper_elevation'] -= self.stepper_step_distance
else:
self.c_p['stepper_elevation'] += self.stepper_step_distance
elif self.c_p['motor_z']:
if dy < 0:
self.c_p['z_movement'] -= 10
else:
self.c_p['z_movement'] += 10
return self.c_p['program_running']
def run(self):
# TODO This function can only stop when the mouse is mooved/scrolled
# Should probably let main interface handle the mouse positioning.
with Listener(on_move=self.on_move, on_click=None, on_scroll=self.on_scroll) as listener:
listener.join()