Exit cleanly, adjust threading
[gigfinder] / src / opt / gigfinder / locator.py
index deab13e..0dc7629 100644 (file)
@@ -1,20 +1,20 @@
 import gobject
 import location
+import thread
 
 class LocationUpdater:
 
     def __init__(self):
         self.lat = None
         self.long = None
-        self.loop = gobject.MainLoop()
 
         self.control = location.GPSDControl.get_default()
         self.control.set_properties(preferred_method=location\
                                             .METHOD_USER_SELECTED,
                                     preferred_interval=location\
                                             .INTERVAL_DEFAULT)
-        self.control.connect("error-verbose", self.on_error, self.loop)
-        self.control.connect("gpsd-stopped", self.on_stop, self.loop)
+        self.control.connect("error-verbose", self.on_error, self.control)
+        self.control.connect("gpsd-stopped", self.stop, None)
 
         self.device = location.GPSDevice()
         self.device.connect("changed", self.on_changed, self.control)
@@ -23,7 +23,6 @@ class LocationUpdater:
         """ Run the loop and update lat and long """
         self.reset()
         gobject.idle_add(self.start_location, self.control)
-        self.loop.run()
 
     def on_error(self, control, error, data):
         """ Handle errors """
@@ -41,9 +40,9 @@ class LocationUpdater:
                     self.lat, self.long = device.fix[4:6]
                     data.stop()
 
-    def on_stop(self, control, data):
+    def stop(self, widget, data):
         """ Stop the location service """
-        data.quit()
+        self.control.stop()
 
     def start_location(self, data):
         """ Start the location service """