+ self.current_line = ''
+ self.current_stations = []
+ self.current_departures = []
+
+ @Slot(int, result=str)
+ def get_direction(self, idx):
+ return self.current_stations[idx][0]
+
+ @Slot(str, str, result='QStringList')
+ def get_stations(self, line, direction):
+ print 'line:', line, 'current line:', self.current_line
+ for dx, stations in self.current_stations:
+ print 'dx:', dx, 'direction:', direction
+ if dx == direction:
+ return [stationname for stationname, url in stations]
+
+ return ['no stations found']
+
+ directionsLoaded = Signal()
+
+ @Slot(str)
+ def load_directions(self, line):
+ def load_async():
+ stations = sorted(self.itip.get_stations(line).items())
+
+ self.current_line = line
+ self.current_stations = stations
+
+ self.directionsLoaded.emit()
+
+ threading.Thread(target=load_async).start()
+
+ #def map_departure(self, dep):
+ # """ prepare departure list for qml gui
+ # """
+ # dep['lowfloor'] = 1 if dep['lowfloor'] else 0
+ # dep['realtime'] = 1 if dep['realtime'] else 0
+ # dep['time'] = dep['ftime']
+ # return dep
+
+ departuresLoaded = Signal()
+
+ @Slot(str)
+ def load_departures_test(self, **args):
+ """ valid args combinations
+ station
+ line, station
+ """
+ def load_async():
+ if args.has_key('station'):
+ if args.has_key('line'):
+ self.current_departures = map(self.map_departure, \
+ self.itip.get_departures(args['line'], args['station']))
+ #print self.current_departures
+ self.departuresLoaded.emit()
+ else:
+ self.current_departures = map(self.map_departure, \
+ sort_departures(self.itip.get_departures_by_station(station)))
+ else:
+ raise KeyError('Missing valid argument combination')
+
+ threading.Thread(target=load_async).start()
+
+ @Slot(str)
+ def load_departures(self, url):
+ def load_async():
+ self.departureModel.setDepartures(self.itip.get_departures(url))
+ #print self.current_departures
+ self.departuresLoaded.emit()
+
+ threading.Thread(target=load_async).start()
+
+ @Slot(str)
+ def load_station_departures(self, station):
+ def load_async():
+ self.departureModel.setDepartures(sort_departures(self.itip.get_departures_by_station(station)))
+ self.departuresLoaded.emit()
+
+ threading.Thread(target=load_async).start()
+
+ @Slot(float, float)
+ def load_nearby_departures(self, lat, lon):
+ def load_async():
+ self.current_departures = []
+ try:
+ stations = get_nearby_stations(lat, lon)
+ print stations
+ for station in stations:
+ print station
+ try:
+ self.current_departures += self.itip.get_departures_by_station(station)
+ except Exception as e:
+ print e.message
+ self.current_departures = map(self.map_departure, \
+ sort_departures(self.current_departures))
+ #print self.current_departures
+ except Exception as e:
+ print e.message
+
+ print 'loaded'
+ self.departuresLoaded.emit()
+
+ threading.Thread(target=load_async).start()
+
+ @Slot(str, str, str, result=str)
+ def get_directions_url(self, line, direction, station):
+ return self.itip.get_url_from_direction(line, direction, station)
+