stdeb-based packaging for Harmattan
[pywienerlinien] / gotovienna-qml
1 #!/usr/env/python
2
3 """Public transport information for Vienna"""
4
5 __author__ = 'kelvan <kelvan@logic.at>'
6 __version__ = '1.0'
7 __website__ = 'https://github.com/kelvan/gotoVienna/'
8 __license__ = 'GNU General Public License v3 or later'
9
10 from PySide import QtCore, QtGui, QtDeclarative
11 from gotovienna.utils import *
12 from gotovienna.realtime import *
13
14 import urllib2
15 import os
16 import sys
17
18
19 class Gui(QtCore.QObject):
20     @QtCore.Slot(str, str)
21     def search(self, line, station):
22         line = line.upper()
23         station = station.decode('utf-8')
24         print line, station
25         
26         itip = ITipParser()
27         print itip.lines
28         if not line in itip.lines:
29             return "Invalid line"
30         
31         try:
32             stations = sorted(itip.get_stations(line).items())
33             print stations
34             headers, stations = zip(*stations)
35             print headers
36             print stations
37             details = [(direction, name, url) for direction, stops in stations
38                         for name, url in stops if match_station(station, name)]
39             print details
40         except urllib2.URLError as e:
41             print e.message
42             return e.message
43
44 if __name__ == '__main__':
45     app = QtGui.QApplication(sys.argv)
46
47     view = QtDeclarative.QDeclarativeView()
48
49     # instantiate the Python object
50     itip = Gui()
51
52     # expose the object to QML
53     context = view.rootContext()
54     context.setContextProperty("itip", itip)
55
56     if os.path.abspath(__file__).startswith('/usr/bin/'):
57         # Assume system-wide installation, QML from /usr/share/
58         view.setSource('/usr/share/gotovienna/qml/main.qml')
59     else:
60         # Assume test from source directory, use relative path
61         view.setSource(os.path.join(os.path.dirname(__file__), 'qml/main.qml'))
62
63     view.showFullScreen()
64
65     sys.exit(app.exec_())
66