From 960896dfb4e5bfa1583f0c082efe47bda3a84ebf Mon Sep 17 00:00:00 2001 From: jon Date: Thu, 10 Jun 2010 23:25:49 +0100 Subject: [PATCH] Exit cleanly, adjust threading --- src/opt/gigfinder/gigfinder.py | 71 +++++++++++++++++++++------------------- src/opt/gigfinder/locator.py | 7 ++-- 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/opt/gigfinder/gigfinder.py b/src/opt/gigfinder/gigfinder.py index c5dc609..c06d36f 100755 --- a/src/opt/gigfinder/gigfinder.py +++ b/src/opt/gigfinder/gigfinder.py @@ -39,25 +39,29 @@ 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 """ + gtk.gdk.threads_enter() program = hildon.Program.get_instance() menu = self.create_menu() self.win.set_title(self.app_title) - self.win.connect("destroy", gtk.main_quit, None) + self.win.connect("destroy", self.quit, None) self.win.set_app_menu(menu) - self.add_button_area() - self.update_thread.start() + self.update(None, None) self.win.show_all() - gtk.gdk.threads_enter() gtk.main() gtk.gdk.threads_leave() + def quit(self, widget, data): + self.location.stop(widget, data) + thread.exit() + gtk.main_quit() + return False + def show_about(self, widget, data): """ Show about dialog """ dialog = gtk.AboutDialog() @@ -69,34 +73,6 @@ class GigFinder: dialog.set_copyright(__copyright__) dialog.show_all() - def update(self, widget, data): - """ Start update process """ - self.win.set_title(self.app_title) - self.location.reset() - self.win.remove(self.pannable_area) - self.update_thread.start() - - def update_gigs(self): - """ Get gig info """ - gobject.idle_add(self.show_message, "Getting events") - - if not 'applications' in os.path.abspath(__file__): - gobject.idle_add(self.location.update_location) - - # if no gps fix wait - # TODO: needs a timeout - while not self.location.lat or not self.location.long: - time.sleep(1) - else: - self.location.lat = float(51.517369) - self.location.long = float(-0.082998) - - events = self.events.get_events(self.location.lat, - self.location.long, - self.distance,) - gobject.idle_add(self.show_events, events) - gobject.idle_add(self.hide_message) - def show_message(self, message): """ Set window progress indicator and show message """ hildon.hildon_gtk_window_set_progress_indicator(self.win, 1) @@ -185,6 +161,35 @@ class GigFinder: self.box.pack_start(button) self.box.show_all() + def update(self, widget, data): + """ Start update process """ + self.win.set_title(self.app_title) + self.location.reset() + if getattr(self, 'pannable_area', None): + self.win.remove(self.pannable_area) + self.add_button_area() + self.location.update_location() + Thread(target=self.update_gigs).start() + + def update_gigs(self): + """ Get gig info """ + gobject.idle_add(self.show_message, "Getting events") + + if not 'applications' in os.path.abspath(__file__): + # if no gps fix wait + while not self.location.lat or not self.location.long: + time.sleep(1) + else: + self.location.lat = float(51.517369) + self.location.long = float(-0.082998) + + events = self.events.get_events(self.location.lat, + self.location.long, + self.distance,) + gobject.idle_add(self.show_events, events) + gobject.idle_add(self.hide_message) + return True + if __name__ == "__main__": finder = GigFinder() finder.main() diff --git a/src/opt/gigfinder/locator.py b/src/opt/gigfinder/locator.py index 5621faa..0dc7629 100644 --- a/src/opt/gigfinder/locator.py +++ b/src/opt/gigfinder/locator.py @@ -1,5 +1,6 @@ import gobject import location +import thread class LocationUpdater: @@ -13,7 +14,7 @@ class LocationUpdater: preferred_interval=location\ .INTERVAL_DEFAULT) self.control.connect("error-verbose", self.on_error, self.control) - self.control.connect("gpsd-stopped", self.on_stop, None) + self.control.connect("gpsd-stopped", self.stop, None) self.device = location.GPSDevice() self.device.connect("changed", self.on_changed, self.control) @@ -39,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 """ - control.stop() + self.control.stop() def start_location(self, data): """ Start the location service """ -- 1.7.9.5