Change QStringList to QVariant for Departures
[pywienerlinien] / gotovienna-qml
index e1779e6..45269ca 100755 (executable)
@@ -3,21 +3,25 @@
 """Public transport information for Vienna"""
 
 __author__ = 'kelvan <kelvan@logic.at>'
-__version__ = '1.0'
+__version__ = '0.8.2'
 __website__ = 'https://github.com/kelvan/gotoVienna/'
 __license__ = 'GNU General Public License v3 or later'
 
+from datetime import datetime
+
 from PySide.QtCore import QAbstractListModel, QModelIndex, QObject, Slot, Signal
 from PySide.QtGui import QApplication
 from PySide.QtDeclarative import QDeclarativeView
 
 from gotovienna.utils import *
 from gotovienna.realtime import *
+from gotovienna.gps import *
 
 import urllib2
 import os
 import sys
 import threading
+from datetime import time
 
 class GotoViennaListModel(QAbstractListModel):
     def __init__(self, objects=None):
@@ -93,8 +97,13 @@ class Gui(QObject):
     @Slot(str)
     def load_departures(self, url):
         def load_async():
-            self.current_departures = [str(x) for x in
-                    self.itip.get_departures(url)]
+            def map_departure(dep):
+                dep['lowfloor'] = 1 if dep['lowfloor'] else 0
+                if type(dep['time']) == time:
+                    dep['time'] = dep['time'].strftime('%H:%M')
+                return dep
+                
+            self.current_departures = map(map_departure, self.itip.get_departures(url))
             print self.current_departures
             self.departuresLoaded.emit()
 
@@ -108,10 +117,18 @@ class Gui(QObject):
     def get_lines(self):
         return self.lines
 
-    @Slot(result='QStringList')
+    @Slot(result='QVariant')
     def get_departures(self):
         return self.current_departures
 
+    @Slot(float, float, result=str)
+    def get_nearby_stations(self, lat, lon):
+        try:
+            return ', '.join(get_nearby_stations(lat, lon))
+        except Exception as e:
+            print e.message
+            return ''
+
     @Slot(str, str)
     def search(self, line, station):
         line = line.upper()