From 21d9f51cb6cde4164cf5f9b045f3981e74e4c728 Mon Sep 17 00:00:00 2001 From: jon Date: Wed, 2 Jun 2010 00:35:13 +0100 Subject: [PATCH] Trying to improve threading for the location --- src/opt/gigfinder/gigfinder.py | 8 +++++--- src/opt/gigfinder/locator.py | 11 +++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/opt/gigfinder/gigfinder.py b/src/opt/gigfinder/gigfinder.py index d360de9..c5dc609 100755 --- a/src/opt/gigfinder/gigfinder.py +++ b/src/opt/gigfinder/gigfinder.py @@ -39,6 +39,7 @@ class GigFinder: self.events = Events() self.win = hildon.StackableWindow() self.app_title = "Gig Finder" + self.update_thread = Thread(target=self.update_gigs) def main(self): """ Build the gui and start the update thread """ @@ -50,10 +51,12 @@ class GigFinder: self.win.set_app_menu(menu) self.add_button_area() - Thread(target=self.update_gigs).start() + self.update_thread.start() self.win.show_all() + gtk.gdk.threads_enter() gtk.main() + gtk.gdk.threads_leave() def show_about(self, widget, data): """ Show about dialog """ @@ -71,7 +74,7 @@ class GigFinder: self.win.set_title(self.app_title) self.location.reset() self.win.remove(self.pannable_area) - Thread(target=self.update_gigs).start() + self.update_thread.start() def update_gigs(self): """ Get gig info """ @@ -93,7 +96,6 @@ class GigFinder: self.distance,) gobject.idle_add(self.show_events, events) gobject.idle_add(self.hide_message) - thread.exit() def show_message(self, message): """ Set window progress indicator and show message """ diff --git a/src/opt/gigfinder/locator.py b/src/opt/gigfinder/locator.py index 8ed0ece..deab13e 100644 --- a/src/opt/gigfinder/locator.py +++ b/src/opt/gigfinder/locator.py @@ -7,7 +7,6 @@ class LocationUpdater: self.lat = None self.long = None self.loop = gobject.MainLoop() - self.fix_count = 0 self.control = location.GPSDControl.get_default() self.control.set_properties(preferred_method=location\ @@ -36,22 +35,18 @@ class LocationUpdater: if not device: return if device.fix: - # once fix is found and long, lat available set long lat - if device.fix[1] & location.GPS_DEVICE_LATLONG_SET: - # wait for a second fix before exiting - self.fix_count += 1 - if self.fix_count > 1: + # once fix is found and horizontal accuracy is 1km + if location.GPS_DEVICE_LATLONG_SET: + if device.fix[6] <= 100000: self.lat, self.long = device.fix[4:6] data.stop() def on_stop(self, control, data): """ Stop the location service """ - print "quitting" data.quit() def start_location(self, data): """ Start the location service """ - self.fix_count = 0 data.start() return False -- 1.7.9.5