Beispiel #1
0
 def start(cls):
     if TobiiTrackerBrowser._mainloop is None:
         TobiiPy.init()
         TobiiTrackerBrowser._mainloop = TobiiPyMainloopThread()
         TobiiTrackerBrowser._mainloop.start()
         TobiiTrackerBrowser._event_queue=Queue.Queue()
         TobiiTrackerBrowser._browser = TobiiPyEyetrackerBrowser(TobiiTrackerBrowser._mainloop, TobiiTrackerBrowser.on_eyetracker_browser_event)
         cls._active=True
    def initLibrary(self):
        """ Mandatory initialization of the whole library """

        # TOBII SDK
        try:
            if (not self.simul):
                sdk.init()
                self.mainLoopThread = sdk.mainloop.MainloopThread()
                self.mainLoopThread.start()
        except Exception, e:
            print e
    def __init__(
            self,
            eyetracker_info=None,
            product_id=None,
            model=None,
            mainloop=None,
            create_sync_manager=True):
        self._eyetracker_info = eyetracker_info
        self._requested_product_id = product_id
        self._requested_model = model
        self._mainloop = mainloop
        self._eyetracker = None
        self._queue = None
        self._tobiiClock = None
        self._getTobiiClockResolution = None
        self._getTobiiClockTime = None
        self._sync_manager = None
        self._syncTimeEventDeque = None
        self._isRecording = False

        if eyetracker_info is None:
            if not TobiiTrackerBrowser.isActive():
                TobiiTrackerBrowser.start()
                self._eyetracker_info = TobiiTrackerBrowser.findDevice(
                    model, product_id)
                if self._eyetracker_info:
                    self._mainloop = TobiiTrackerBrowser.getMainLoop()
                TobiiTrackerBrowser.stop()
            else:
                self._eyetracker_info = TobiiTrackerBrowser.findDevice(
                    model, product_id)

        if self._eyetracker_info is None:
            raise exceptions.BaseException(
                'Could not find a Tobii Eye Tracker matching requirements.')

        if self._mainloop is None:
            if TobiiTrackerBrowser.isActive():
                self._mainloop = TobiiTrackerBrowser.getMainLoop()
            else:
                TobiiPy.init()
                self._mainloop = TobiiPyMainloopThread()
                self._mainloop.start()

        self._queue = Queue.Queue()

        TobiiPyEyeTracker.create_async(
            self._mainloop,
            self._eyetracker_info,
            self.on_eyetracker_created)

        stime = getTime()
        while getTime() - stime < 10.0:
            try:
                event = self._queue.get(block=True, timeout=.1)
                if isinstance(event, TobiiTrackerCreatedEvent):
                    self._eyetracker = event.tracker_object
                    self._eyetracker.events.OnFramerateChanged += self.on_external_framerate_change
                    if hasattr(
                            self._eyetracker.events,
                            'OnHeadMovementBoxChanged'):
                        self._eyetracker.events.OnHeadMovementBoxChanged += self.on_head_box_change
                    elif hasattr(self._eyetracker.events, 'OnTrackBoxChanged'):
                        self._eyetracker.events.OnTrackBoxChanged += self.on_head_box_change
                    else:
                        print 'WARNING: TobiiClasses could not set callback hook for "self.on_head_box_change".'
                    self._eyetracker.events.OnXConfigurationChanged += self.on_x_series_physical_config_change

                    break
                self._queue.task_done()
            except Queue.Empty:
                pass

        if self._eyetracker is None:
            raise exceptions.BaseException(
                'Could not connect to Tobii. Timeout.')

        if create_sync_manager:
            self._eyetracker.events.OnError += self.on_eyetracker_error
            self._tobiiClock = TobiiPyClock()
            self._getTobiiClockResolution = self._tobiiClock.get_resolution
            self._getTobiiClockTime = self._tobiiClock.get_time
            self._syncTimeEventDeque = collections.deque(maxlen=32)
            self._sync_manager = TobiiPySyncManager(self._tobiiClock,
                                                    self._eyetracker_info,
                                                    self._mainloop,
                                                    self.on_sync_error,
                                                    self.on_sync_status)
Beispiel #4
0
    def __init__(self,
                 eyetracker_info=None,
                 product_id=None,
                 model=None,
                 mainloop=None,
                 create_sync_manager=True):
        self._eyetracker_info = eyetracker_info
        self._requested_product_id = product_id
        self._requested_model = model
        self._mainloop = mainloop
        self._eyetracker = None
        self._queue = None
        self._tobiiClock = None
        self._getTobiiClockResolution = None
        self._getTobiiClockTime = None
        self._sync_manager = None
        self._syncTimeEventDeque = None
        self._isRecording = False

        if eyetracker_info is None:
            if not TobiiTrackerBrowser.isActive():
                TobiiTrackerBrowser.start()
                self._eyetracker_info = TobiiTrackerBrowser.findDevice(
                    model, product_id)
                if self._eyetracker_info:
                    self._mainloop = TobiiTrackerBrowser.getMainLoop()
                TobiiTrackerBrowser.stop()
            else:
                self._eyetracker_info = TobiiTrackerBrowser.findDevice(
                    model, product_id)

        if self._eyetracker_info is None:
            raise exceptions.BaseException(
                'Could not find a Tobii Eye Tracker matching requirements.')

        if self._mainloop is None:
            if TobiiTrackerBrowser.isActive():
                self._mainloop = TobiiTrackerBrowser.getMainLoop()
            else:
                TobiiPy.init()
                self._mainloop = TobiiPyMainloopThread()
                self._mainloop.start()

        self._queue = Queue.Queue()

        TobiiPyEyeTracker.create_async(self._mainloop, self._eyetracker_info,
                                       self.on_eyetracker_created)

        stime = getTime()
        while getTime() - stime < 10.0:
            try:
                event = self._queue.get(block=True, timeout=.1)
                if isinstance(event, TobiiTrackerCreatedEvent):
                    self._eyetracker = event.tracker_object
                    self._eyetracker.events.OnFramerateChanged += self.on_external_framerate_change
                    if hasattr(self._eyetracker.events,
                               'OnHeadMovementBoxChanged'):
                        self._eyetracker.events.OnHeadMovementBoxChanged += self.on_head_box_change
                    elif hasattr(self._eyetracker.events, 'OnTrackBoxChanged'):
                        self._eyetracker.events.OnTrackBoxChanged += self.on_head_box_change
                    else:
                        print 'WARNING: TobiiClasses could not set callback hook for "self.on_head_box_change".'
                    self._eyetracker.events.OnXConfigurationChanged += self.on_x_series_physical_config_change

                    break
                self._queue.task_done()
            except Queue.Empty:
                pass

        if self._eyetracker is None:
            raise exceptions.BaseException(
                'Could not connect to Tobii. Timeout.')

        if create_sync_manager:
            self._eyetracker.events.OnError += self.on_eyetracker_error
            self._tobiiClock = TobiiPyClock()
            self._getTobiiClockResolution = self._tobiiClock.get_resolution
            self._getTobiiClockTime = self._tobiiClock.get_time
            self._syncTimeEventDeque = collections.deque(maxlen=32)
            self._sync_manager = TobiiPySyncManager(self._tobiiClock,
                                                    self._eyetracker_info,
                                                    self._mainloop,
                                                    self.on_sync_error,
                                                    self.on_sync_status)