- #!/usr/env/python
+ #!/usr/bin/env python
"""Public transport information for Vienna"""
__author__ = 'kelvan <kelvan@logic.at>'
-__version__ = '0.8.1'
+__version__ = '0.8.2'
__website__ = 'https://github.com/kelvan/gotoVienna/'
__license__ = 'GNU General Public License v3 or later'
import os
import sys
import threading
+from datetime import time
class GotoViennaListModel(QAbstractListModel):
def __init__(self, objects=None):
threading.Thread(target=load_async).start()
+ def map_departure(self, dep):
+ dep['lowfloor'] = 1 if dep['lowfloor'] else 0
+ if type(dep['time']) == time:
+ dep['time'] = dep['time'].strftime('%H:%M')
+ return dep
+
departuresLoaded = Signal()
@Slot(str)
def load_departures(self, url):
def load_async():
- self.current_departures = [x['ftime'] for x in
- self.itip.get_departures(url)]
- print self.current_departures
+ self.current_departures = map(self.map_departure, \
+ 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.current_departures = map(self.map_departure, \
+ sort_departures(self.itip.get_departures_by_station(station)))
+ #print self.current_departures
+ 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()
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)
+ @Slot(float, float, result='QStringList')
def get_nearby_stations(self, lat, lon):
try:
- return ', '.join(get_nearby_stations(lat, lon))
+ return get_nearby_stations(lat, lon)
except Exception as e:
print e.message
- return ''
+ return []
@Slot(str, str)
def search(self, line, station):
import QtQuick 1.1
import com.nokia.meego 1.0
+import QtMobility.location 1.1
import "UIConstants.js" as UIConstants
import "ExtrasConstants.js" as ExtrasConstants
Page {
tools: commonTools
- property bool canRefresh: realtimeResult.sourceUrl != ''
+ property bool canRefresh: realtimeResult.sourceUrl != '' || (realtimeResult.isStation && realtimeResult.gstation != '')
+ //property alias stationSelect: stationSelector
+ property variant nearbyStations
function refresh() {
realtimeResult.refresh()
}
+ function fillNearbyStations(lat, lon) {
+ nearbyStations = itip.get_nearby_stations(lat, lon)
+ }
+
+ function showNearby() {
+ console.log("show nearby")
+
+ var stations = nearbyStations
+ stationSelectorModel.clear()
+ for (var idx in stations) {
+ stationSelectorModel.append({'name': stations[idx]})
+ }
+
+ stationSelector.open()
+ }
+
+ PositionSource {
+ id: positionSource
+ updateInterval: 10000
+
+ active: true
+
+ onPositionChanged: {
+ fillNearbyStations(positionSource.position.coordinate.latitude, positionSource.position.coordinate.longitude)
+ }
+ }
+
SelectionDialog {
id: lineSelector
titleText: 'Select line'
}
}
+ SelectionDialog {
+ id: stationSelector
+ titleText: 'Select nearby station'
+
+ model: ListModel {
+ id: stationSelectorModel
+ }
+
+ onAccepted: {
+ realtimeResult.isStation = true
+ realtimeResult.gstation = stationSelectorModel.get(selectedIndex).name
+ realtimeResult.gline = ''
+ realtimeResult.sourceUrl = ''
+ gline.text = ''
+ gstation.text = stationSelectorModel.get(selectedIndex).name
+ console.log('station to get: ' + realtimeResult.gstation)
+ }
+ }
+
TextField {
placeholderText: 'Line'
// set selectedIndex in lineSelector to the right item
gstation.text = ''
- text = text.toUpperCase()
-
- if (lineSelector.selectedIndex == -1) {
+ if (lineSelector.selectedIndex === -1) {
++ text = text.toUpperCase()
return
}
// Disable selection in line selector if user changes the text
- if (lineSelectorModel.get(lineSelector.selectedIndex).name != text) {
+ if (lineSelectorModel.get(lineSelector.selectedIndex).name !== text) {
lineSelector.selectedIndex = -1
}
}
Behavior on opacity { PropertyAnimation { } }
- opacity: gline.text != '' // XXX: Check if the line is valid
+ opacity: gline.text !== '' // XXX: Check if the line is valid
width: lineSearchButton.width * opacity
//iconSource: 'image://theme/icon-m-common-location-picker'