-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path_plugin.py
71 lines (53 loc) · 1.79 KB
/
_plugin.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import logging
from pyglui import ui
import zmq_tools
from plugin import Plugin
from pi_preview import Linked_Device
from pi_preview.connection import Connection
logger = logging.getLogger(__name__)
IMG_WIDTH = 1088
IMG_HEIGHT = 1080
class PI_Preview(Plugin):
icon_chr = "PI"
order = 0.02 # ensures init after all plugins
def __init__(
self, g_pool, linked_device=...,
):
super().__init__(g_pool)
if linked_device is ...:
linked_device = Linked_Device(None, None)
else:
linked_device = Linked_Device(*linked_device)
self.connection = Connection(linked_device, update_ui_cb=self.update_ndsi_menu,)
self._num_prefix_elements = 0
self.gaze_pub = zmq_tools.Msg_Streamer(
self.g_pool.zmq_ctx, self.g_pool.ipc_pub_url
)
def recent_events(self, events):
gaze = self.connection.fetch_data()
if gaze:
for gaze_datum in gaze:
self.gaze_pub.send(gaze_datum)
if "gaze" not in events:
events["gaze"] = gaze
else:
events["gaze"].extend(gaze)
def init_ui(self):
self.add_menu()
self.menu.label = "Pupil Invisible Preview"
self.menu.append(ui.Info_Text("Connection settings"))
self._num_prefix_elements = len(self.menu)
self.update_ndsi_menu()
def deinit_ui(self):
self.remove_menu()
def update_ndsi_menu(self):
del self.menu[self._num_prefix_elements :]
self.connection.add_ui_elements(self.menu)
def cleanup(self):
self.gaze_pub = None
self.connection.close()
self.connection = None
def get_init_dict(self):
return {
"linked_device": self.connection.sensor.linked_device,
}