Пример #1
0
    def setup(self):
        """
        Initialize the tobii libraries and start finding the eyetracker.
        """
        tobii.eye_tracking_io.init()
        self.tracker_mainloop_thread = MainloopThread()

        self.search_for_trackers()
Пример #2
0
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Upgrade Tool")
        self.window.connect("delete_event", self.delete_event)
        self.window.connect("destroy", self.destroy)
        self.window.set_border_width(3)
        self.window.set_size_request(550, -1)

        self.mainloop = MainloopThread()
        self.mainloop.start()

        self.vbox = gtk.VBox()
        self.vbox.set_spacing(3)

        self.selector = EyetrackerSelector(self.mainloop, self._on_selected)

        self.file_filter = gtk.FileFilter()
        self.file_filter.set_name("Tobii Upgrade Packages")
        self.file_filter.add_pattern("*.tobiipkg")

        self.chooser = gtk.FileChooserButton(title="Select Firmware File")
        self.chooser.add_filter(self.file_filter)
        self.chooser.connect('file-set', self._on_file_selected)

        self.hbox1 = gtk.HBox()
        self.hbox1.pack_start(self.selector)
        self.hbox1.pack_end(self.chooser)

        self.progress = gtk.ProgressBar()
        self.cancel = gtk.Button("Cancel")
        self.cancel.set_sensitive(False)
        self.start = gtk.Button("Start Upgrade")
        self.start.set_sensitive(False)
        self.start.connect('clicked', self._start_upgrade)

        self.hbox2 = gtk.HBox()
        self.hbox2.pack_start(self.progress)
        self.hbox2.pack_end(self.cancel, expand=False)
        self.hbox2.pack_end(self.start, expand=False)

        self.vbox.pack_start(self.hbox1, expand=False)
        self.vbox.pack_end(self.hbox2, expand=False)

        self.window.add(self.vbox)
        self.window.show_all()

        self.upgrading_device = None
        self.selected_file = None
        self.upgrade_started = False
Пример #3
0
def backcall(event_type, event_name, tracker_id):
    if event_type == tobii.eye_tracking_io.browsing.EyetrackerBrowser.FOUND:
        print(event_type)
        print(event_name)
        loop = MainloopThread()
        e = Eyetracker.create_async(
            loop, tracker_id,
            lambda error, eyetracker: new_tracker_callback(error, eyetracker))
        print(e)
Пример #4
0
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Upgrade Tool")
        self.window.connect("delete_event", self.delete_event)
        self.window.connect("destroy", self.destroy)
        self.window.set_border_width(3)              
        self.window.set_size_request(550, -1)
        
        self.mainloop = MainloopThread()
        self.mainloop.start()
        
        self.vbox = gtk.VBox()
        self.vbox.set_spacing(3)

        self.selector = EyetrackerSelector(self.mainloop, self._on_selected)
        
        self.file_filter = gtk.FileFilter()
        self.file_filter.set_name("Tobii Upgrade Packages")
        self.file_filter.add_pattern("*.tobiipkg")

        self.chooser = gtk.FileChooserButton(title="Select Firmware File")
        self.chooser.add_filter(self.file_filter)
        self.chooser.connect('file-set', self._on_file_selected)

        self.hbox1 = gtk.HBox()
        self.hbox1.pack_start(self.selector)
        self.hbox1.pack_end(self.chooser)

        self.progress = gtk.ProgressBar()
        self.cancel = gtk.Button("Cancel")
        self.cancel.set_sensitive(False)
        self.start = gtk.Button("Start Upgrade")
        self.start.set_sensitive(False)
        self.start.connect('clicked', self._start_upgrade)
        
        self.hbox2 = gtk.HBox()
        self.hbox2.pack_start(self.progress)
        self.hbox2.pack_end(self.cancel, expand=False)
        self.hbox2.pack_end(self.start, expand=False)
        
        self.vbox.pack_start(self.hbox1, expand=False)
        self.vbox.pack_end(self.hbox2, expand=False)
        
        self.window.add(self.vbox)
        self.window.show_all()
        
        self.upgrading_device = None
        self.selected_file = None
        self.upgrade_started = False
Пример #5
0
    #print("Tracking")
    if gaze and is_blinking(gaze):
        print("Blinked at " + str(gaze.Timestamp))


def is_blinking(gaze):
    NO_DATA = Point2D(-1.0, -1.0)
    return compare(gaze.RightGazePoint2D, NO_DATA) and compare(
        gaze.LeftGazePoint2D, NO_DATA)


def compare(p1, p2):
    return p1.x == p2.x and p1.y == p2.y


def backcall(event_type, event_name, tracker_id):
    if event_type == tobii.eye_tracking_io.browsing.EyetrackerBrowser.FOUND:
        print(event_type)
        print(event_name)
        loop = MainloopThread()
        e = Eyetracker.create_async(
            loop, tracker_id,
            lambda error, eyetracker: new_tracker_callback(error, eyetracker))
        print(e)


tobii.eye_tracking_io.init()
ml = MainloopThread()
print(type(ml))
et = EyetrackerBrowser(mainloop=ml, callback=backcall)
Пример #6
0
class UpgradeTool(object):
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Upgrade Tool")
        self.window.connect("delete_event", self.delete_event)
        self.window.connect("destroy", self.destroy)
        self.window.set_border_width(3)
        self.window.set_size_request(550, -1)

        self.mainloop = MainloopThread()
        self.mainloop.start()

        self.vbox = gtk.VBox()
        self.vbox.set_spacing(3)

        self.selector = EyetrackerSelector(self.mainloop, self._on_selected)

        self.file_filter = gtk.FileFilter()
        self.file_filter.set_name("Tobii Upgrade Packages")
        self.file_filter.add_pattern("*.tobiipkg")

        self.chooser = gtk.FileChooserButton(title="Select Firmware File")
        self.chooser.add_filter(self.file_filter)
        self.chooser.connect('file-set', self._on_file_selected)

        self.hbox1 = gtk.HBox()
        self.hbox1.pack_start(self.selector)
        self.hbox1.pack_end(self.chooser)

        self.progress = gtk.ProgressBar()
        self.cancel = gtk.Button("Cancel")
        self.cancel.set_sensitive(False)
        self.start = gtk.Button("Start Upgrade")
        self.start.set_sensitive(False)
        self.start.connect('clicked', self._start_upgrade)

        self.hbox2 = gtk.HBox()
        self.hbox2.pack_start(self.progress)
        self.hbox2.pack_end(self.cancel, expand=False)
        self.hbox2.pack_end(self.start, expand=False)

        self.vbox.pack_start(self.hbox1, expand=False)
        self.vbox.pack_end(self.hbox2, expand=False)

        self.window.add(self.vbox)
        self.window.show_all()

        self.upgrading_device = None
        self.selected_file = None
        self.upgrade_started = False

    def _on_file_selected(self, chooser):
        self.selected_file = self.chooser.get_filename()
        self._check_match()

    def _on_selected(self, device_info):
        self.upgrading_device = device_info
        self._check_match()

    def _check_match(self):
        if self.upgrading_device is None or self.selected_file is None:
            return

        self.chooser.set_sensitive(False)
        self.selector.set_sensitive(False)
        self.start.set_sensitive(False)
        self.cancel.set_sensitive(False)

        try:
            code = upgrade.package_is_compatible_with_device(
                self.mainloop, self.selected_file, self.upgrading_device)

            if code == 0:
                self.progress.set_text("")
                self.start.set_sensitive(True)
            else:
                msg = tobii.eye_tracking_io.error_code_to_string(code)
                if msg.startswith("TOBII_SDK_ERROR_"):
                    msg = msg[len("TOBII_SDK_ERROR_"):]
                self.progress.set_text("Not compatible: %s" % (msg))
                self.start.set_sensitive(False)

        finally:
            self.chooser.set_sensitive(True)
            self.selector.set_sensitive(True)

    def _start_upgrade(self, button):
        if self.upgrade_started or self.upgrading_device is None:
            return

        self.start.set_sensitive(False)
        self.cancel.set_sensitive(False)
        self.upgrade_started = True

        try:
            self._upgrade_progress_init = False
            upgrade.begin_upgrade(
                self.mainloop, self.selected_file, self.upgrading_device,
                lambda code: glib_idle_add(self._on_upgrade_complete, code),
                lambda c, n, p: glib_idle_add(self._on_upgrade_progress, c, n,
                                              p),
                lambda c: glib_idle_add(self._on_upgrade_cancancel_changed, c))

        except Exception, ex:
            self.upgrade_started = False
            self.start.set_sensitive(True)
            print "ERROR: ", ex
Пример #7
0
 def OnBrowserEvent(self, event_type, event_name, tracker_id):
     if event_type == tobii.eye_tracking_io.browsing.EyetrackerBrowser.FOUND:
         loop = MainloopThread()
         e = Eyetracker.create_async(
             loop, tracker_id,
             lambda error, eyetracker: self.OnNewTracker(error, eyetracker))
Пример #8
0
 def StartTest(self):
     tobii.eye_tracking_io.init()
     ml = MainloopThread()
     et = EyetrackerBrowser(mainloop=ml, callback=self.OnBrowserEvent)
Пример #9
0
class UpgradeTool(object):
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Upgrade Tool")
        self.window.connect("delete_event", self.delete_event)
        self.window.connect("destroy", self.destroy)
        self.window.set_border_width(3)              
        self.window.set_size_request(550, -1)
        
        self.mainloop = MainloopThread()
        self.mainloop.start()
        
        self.vbox = gtk.VBox()
        self.vbox.set_spacing(3)

        self.selector = EyetrackerSelector(self.mainloop, self._on_selected)
        
        self.file_filter = gtk.FileFilter()
        self.file_filter.set_name("Tobii Upgrade Packages")
        self.file_filter.add_pattern("*.tobiipkg")

        self.chooser = gtk.FileChooserButton(title="Select Firmware File")
        self.chooser.add_filter(self.file_filter)
        self.chooser.connect('file-set', self._on_file_selected)

        self.hbox1 = gtk.HBox()
        self.hbox1.pack_start(self.selector)
        self.hbox1.pack_end(self.chooser)

        self.progress = gtk.ProgressBar()
        self.cancel = gtk.Button("Cancel")
        self.cancel.set_sensitive(False)
        self.start = gtk.Button("Start Upgrade")
        self.start.set_sensitive(False)
        self.start.connect('clicked', self._start_upgrade)
        
        self.hbox2 = gtk.HBox()
        self.hbox2.pack_start(self.progress)
        self.hbox2.pack_end(self.cancel, expand=False)
        self.hbox2.pack_end(self.start, expand=False)
        
        self.vbox.pack_start(self.hbox1, expand=False)
        self.vbox.pack_end(self.hbox2, expand=False)
        
        self.window.add(self.vbox)
        self.window.show_all()
        
        self.upgrading_device = None
        self.selected_file = None
        self.upgrade_started = False

    def _on_file_selected(self, chooser):
        self.selected_file = self.chooser.get_filename()
        self._check_match()

    def _on_selected(self, device_info):
        self.upgrading_device = device_info
        self._check_match()

    def _check_match(self):
        if self.upgrading_device is None or self.selected_file is None:
            return
        
        self.chooser.set_sensitive(False)
        self.selector.set_sensitive(False)
        self.start.set_sensitive(False)
        self.cancel.set_sensitive(False)
        
        try:
            code = upgrade.package_is_compatible_with_device(self.mainloop,
                                                             self.selected_file,
                                                             self.upgrading_device)
            
            if code == 0:
                self.progress.set_text("")
                self.start.set_sensitive(True)
            else:
                msg = tobii.eye_tracking_io.error_code_to_string(code)
                if msg.startswith("TOBII_SDK_ERROR_"):
                    msg = msg[len("TOBII_SDK_ERROR_"):]
                self.progress.set_text("Not compatible: %s" % (msg)) 
                self.start.set_sensitive(False)

        finally:
            self.chooser.set_sensitive(True)
            self.selector.set_sensitive(True)
    
    def _start_upgrade(self, button):
        if self.upgrade_started or self.upgrading_device is None:
            return
        
        self.start.set_sensitive(False)
        self.cancel.set_sensitive(False)
        self.upgrade_started = True
        
        try:
            self._upgrade_progress_init = False
            upgrade.begin_upgrade(self.mainloop, 
                                  self.selected_file, 
                                  self.upgrading_device, 
                                  lambda code: glib_idle_add(self._on_upgrade_complete, code), 
                                  lambda c, n, p: glib_idle_add(self._on_upgrade_progress, c, n, p), 
                                  lambda c: glib_idle_add(self._on_upgrade_cancancel_changed, c))
            
        except Exception, ex:
            self.upgrade_started = False
            self.start.set_sensitive(True)
            print "ERROR: ", ex 
Пример #10
0
class EyeTrackControl:
    """
    Class for finding, setting up and calibrating the
    eyetracker.
    """

    def __init__(self, output_filename):
        # These variables are initialized as None because the
        # actual objects they will be assigned can only
        # be created once the tobii modules have been
        # properly set up, but it's still a good idea to list
        # all the class's properties in __init__() method
        # so that you know what they are
        self.tracker_mainloop_thread = None
        self.browser = None
        self.eyetracker = None
        self.tracker_info = None
        self.clock = None
        self.tracker_activated = False
        self.data_recorder = EyeDataRecorder(output_filename)

    def setup(self):
        """
        Initialize the tobii libraries and start finding the eyetracker.
        """
        tobii.eye_tracking_io.init()
        self.tracker_mainloop_thread = MainloopThread()

        self.search_for_trackers()

    def start_tracking(self):
        self.eyetracker.StartTracking()

    def stop_tracking(self):
        self.eyetracker.StopTracking()

    def setup_recording(self):
        gaze_handler = self.data_recorder.process_gaze_sample
        self.eyetracker.events.OnGazeDataReceived += gaze_handler

    def search_for_trackers(self):
        """
        Open up an EyetrackerBrowser instance and add the first available
        tracker.
        """
        self.browser = tobii.eye_tracking_io.browsing.EyetrackerBrowser(
            mainloop=self.tracker_mainloop_thread,
            callback=self.add_found_tracker
        )

    def add_found_tracker(self, event_type, event_name, info_obj):
        """
        Processes the callbacks from ``EyetrackerBrowser``, which in this
        case is fairly simple, since all that needs to be done is
        to attach the first tracker found.
        """
        if event_type == tobii.eye_tracking_io.browsing.EyetrackerBrowser.FOUND:
            print("Found tracker: {}".format(info_obj.product_id))
            self.tracker_info = info_obj
            # NOTE: I don't actually *want* to be creating the tracker
            #   asynchronously, but that seems to be the only option
            #   offered by the SDK? At the moment I start this,
            #   and then just call wait_for_connect() in a loop
            #   until the tracker is actually found, i.e. I'm not
            #   using the asynchrony at all.
            tobii.eye_tracking_io.eyetracker.Eyetracker.create_async(
                self.tracker_mainloop_thread,
                info_obj,
                self.set_tracker
            )

    def set_tracker(self, error, eyetracker):
        """
        Now that the tracker has been found, attach it to the
        current instance and stop the browser.
        """
        if error:
            print(
                """
                Connection to tracker failed because of an exception: {}
                """.format(error)
            )
        else:
            self.eyetracker = eyetracker
            print("Connected!")
            print("Disconnecting from browser:")
            self.browser.stop()
            self.browser = None
            print("Browser stopped.")
            self.tracker_activated = True

    def set_illumination_mode(self, mode):
        self.eyetracker.SetIlluminationMode(mode, self._on_illumination_set)

    def _on_illumination_set(self, error, msg):
        if error != 0:
            print("Error setting illumination mode:")
            print("Error code: {}, Info: {}".format(error, msg))

    def create_clock(self):
        """
        Create a synced clock instance that is hooked into
        the tracker_mainloop_thread, to allow it to
        synchronize timestamps between the computer's
        internal clock and the eyetracker.

        Needs to be called after the eyetracker has been
        connected.
        """
        self.clock = SyncedClock(
            self.tracker_info, self.tracker_mainloop_thread)

    def wait_for_connect(self):
        """
        Because the tracker is added asynchronously, need to wait
        until it's been connected before continuing on with
        the main thread. This just keeps checking for a connection
        until one is created.
        """
        max_wait_secs = 10
        start_time = time.time()
        while not self.tracker_activated:
            total_wait_time = time.time() - start_time
            if total_wait_time > max_wait_secs:
                raise RuntimeError(
"""
Couldn't connect to the tracker after {} seconds.
Try again or check the connection to the tracker.
""".format(max_wait_secs)
                )
            # Sleep for a short time so we don't just run through
            # the loop millions of times a second
            time.sleep(0.1)
        return

    def check_tracker(self):
        """
        Quickly print some information about the connected
        eyetracker as a basic check of whether the connection
        is working correctly.
        """
        print("""
        Tracker info:
            {}
        """.format(self.eyetracker.GetUnitInfo()))

    def calibrate(self, window):
        """
        Show calibration targets, and allow the user to keep retrying
        particular points until the calibration is good. See
        ``TrackerCalibrator`` for more info.
        """
        calibrator = TrackerCalibratorPsychopy(
            tracker=self.eyetracker,
            window=window
        )
        window.setMouseVisible(False)
        calibrator.start_calibration()
        calibrator.check_calibration()
        window.setMouseVisible(True)

        print("Calibration ended.")
        self.eyetracker.StopCalibration()

    def shut_down(self):
        """
        Make sure the eyetracker is stopped properly.
        """
        self.eyetracker.StopTracking()
        self.eyetracker = None
        print("Tracking stopped.")
        self.tracker_mainloop_thread.stop()
        self.data_recorder.close_files()