Tobii Pro SDK Python API
notifications.py
1 def execute(eyetracker):
2  if eyetracker is not None:
3  notifications(eyetracker)
4 
5 
6 # <BeginExample>
7 import tobii_research as tr
8 
9 
10 def notification_callback(notification, data):
11  print("Notification {0} received at time stamp {1}.".format(notification, data.system_time_stamp))
12 
13 
14 def notifications(eyetracker):
15  all_notifications =\
16  (tr.EYETRACKER_NOTIFICATION_CONNECTION_LOST,
17  tr.EYETRACKER_NOTIFICATION_CONNECTION_RESTORED,
18  tr.EYETRACKER_NOTIFICATION_CALIBRATION_MODE_ENTERED,
19  tr.EYETRACKER_NOTIFICATION_CALIBRATION_MODE_LEFT,
20  tr.EYETRACKER_NOTIFICATION_CALIBRATION_CHANGED,
21  tr.EYETRACKER_NOTIFICATION_DISPLAY_AREA_CHANGED,
22  tr.EYETRACKER_NOTIFICATION_GAZE_OUTPUT_FREQUENCY_CHANGED,
23  tr.EYETRACKER_NOTIFICATION_EYE_TRACKING_MODE_CHANGED,
24  tr.EYETRACKER_NOTIFICATION_DEVICE_FAULTS,
25  tr.EYETRACKER_NOTIFICATION_DEVICE_WARNINGS,
26  tr.EYETRACKER_NOTIFICATION_STREAM_BUFFER_OVERFLOW,
27 )
28 
29  # Subscribe to all notifications.
30  for notification in all_notifications:
31  eyetracker.subscribe_to(notification,
32  lambda x, notification=notification: notification_callback(notification, x))
33  print("Subscribed to {0} for eye tracker with serial number {1}.".
34  format(notification, eyetracker.serial_number))
35 
36  # Trigger some notifications
37  calibration = tr.ScreenBasedCalibration(eyetracker)
38 
39  calibration.enter_calibration_mode()
40 
41  calibration.leave_calibration_mode()
42 
43  # Unsubscribe from notifications.
44  for notification in all_notifications:
45  eyetracker.unsubscribe_from(notification)
46  print("Unsubscribed from {0}.".format(notification))
47 # <EndExample>