def __init__(self): self.gconf = gconf.client_get_default() self.database = Database() self.database.connect('database-created', lambda *args: self.update_database(initial_sync=True)) guid = self.gconf.get_string(GUID_KEY) self.dialog = StopEntryDialog() self.dialog.connect('destroy', lambda *args: gtk.main_quit()) self.dialog.set_progress_indicator(True) self.dialog.show() def _connection_event(connection, event): self.w = WebService(guid=guid, callback=self.client_ready) self.dialog.connect('stop-entered', self.retrieve_stop_info) self.dialog.connect('search-by-name', lambda *args: self.search_by_name()) self.dialog.connect('find-nearby-stops', lambda *args: self.find_nearby_stops()) self.dialog.connect('update-database', lambda *args: self.update_database(force=True)) self.dialog.connect('show-favourites', lambda *args: self.show_favourites()) self.update_database() # FIXME: no signal from Conic # connection = conic.Connection() # connection.connect("connection-event", _connection_event) # connection.request_connection(conic.CONNECT_FLAG_NONE) _connection_event(None, None)
class Client(object): def __init__(self): self.gconf = gconf.client_get_default() self.database = Database() self.database.connect('database-created', lambda *args: self.update_database(initial_sync=True)) guid = self.gconf.get_string(GUID_KEY) self.dialog = StopEntryDialog() self.dialog.connect('destroy', lambda *args: gtk.main_quit()) self.dialog.set_progress_indicator(True) self.dialog.show() def _connection_event(connection, event): self.w = WebService(guid=guid, callback=self.client_ready) self.dialog.connect('stop-entered', self.retrieve_stop_info) self.dialog.connect('search-by-name', lambda *args: self.search_by_name()) self.dialog.connect('find-nearby-stops', lambda *args: self.find_nearby_stops()) self.dialog.connect('update-database', lambda *args: self.update_database(force=True)) self.dialog.connect('show-favourites', lambda *args: self.show_favourites()) self.update_database() # FIXME: no signal from Conic # connection = conic.Connection() # connection.connect("connection-event", _connection_event) # connection.request_connection(conic.CONNECT_FLAG_NONE) _connection_event(None, None) def client_ready(self, guid): self.gconf.set_string(GUID_KEY, guid) self.dialog.set_progress_indicator(False) def retrieve_stop_info(self, dialog, stopNo): try: stopinfo = self.database.getStop(stopNo) except Exception, e: dialog = gtk.Dialog(title=e.message) dialog.show() dialog.run() dialog.destroy() return dialog = StopDisplayDialog() dialog.set_stop_info(stopinfo) dialog.set_progress_indicator(True) dialog.show() fav_stops = self.gconf.get_list(FAVOURITE_STOPS, gconf.VALUE_INT) dialog.set_favourite(dialog.stopNo in fav_stops) def _update_trams(): dialog.set_progress_indicator(True) self.w.GetNextPredictedRoutesCollection(stopNo, callback=_got_trams) return True def _got_trams(trams): # print trams dialog.set_progress_indicator(False) dialog.set_tram_info(trams) def _favourite_toggled(dialog, favourited): fav_stops = self.gconf.get_list(FAVOURITE_STOPS, gconf.VALUE_INT) if favourited: fav_stops.append(dialog.stopNo) else: fav_stops.remove(dialog.stopNo) self.gconf.set_list(FAVOURITE_STOPS, gconf.VALUE_INT, fav_stops) def _find_nearby_stops(dialog, lat, long): stops = self.database.getNearbyStops(lat, long, exclude_stop=dialog.stopNo) dialog2 = ListStopsDialog(stops, with_distance=True, titletxt='Nearby Stops') dialog2.connect('stop-entered', self.retrieve_stop_info) dialog2.show() _update_trams() timeout_id = gobject.timeout_add_seconds(30, _update_trams) dialog.connect('destroy', lambda *args: gobject.source_remove(timeout_id)) dialog.connect('favourite-toggled', _favourite_toggled) dialog.connect('find-nearby-stops', _find_nearby_stops) dialog.connect('tram-entered', self.retrieve_tram_info)