3 """Public transport information for Vienna"""
5 __author__ = 'kelvan <kelvan@logic.at>'
7 __website__ = 'https://github.com/kelvan/gotoVienna/'
8 __license__ = 'GNU General Public License v3 or later'
10 from PySide.QtCore import *
11 from PySide.QtGui import *
12 from PySide.QtDeclarative import *
14 from gotovienna.utils import *
15 from gotovienna.realtime import *
21 class GotoViennaListModel(QAbstractListModel):
22 def __init__(self, objects=None):
23 QAbstractListModel.__init__(self)
26 self._objects = objects
27 self.setRoleNames({0: 'modelData'})
29 def set_objects(self, objects):
30 self._objects = objects
32 def get_objects(self):
35 def get_object(self, index):
36 return self._objects[index.row()]
38 def rowCount(self, parent=QModelIndex()):
39 return len(self._objects)
41 def data(self, index, role):
44 return self.get_object(index)
50 QObject.__init__(self)
51 self.itip = ITipParser()
54 # Read line names in categorized/sorted order
55 for _, lines in categorize_lines(self.itip.lines):
56 self.lines.extend(lines)
58 @Slot(result='QStringList')
63 def search(self, line, station):
65 station = station.decode('utf-8')
68 if line not in self.lines:
72 stations = sorted(self.itip.get_stations(line).items())
74 headers, stations = zip(*stations)
77 details = [(direction, name, url) for direction, stops in stations
78 for name, url in stops if match_station(station, name)]
80 except urllib2.URLError as e:
84 if __name__ == '__main__':
85 app = QApplication(sys.argv)
87 view = QDeclarativeView()
89 # instantiate the Python object
92 # expose the object to QML
93 context = view.rootContext()
94 context.setContextProperty('itip', itip)
96 if os.path.abspath(__file__).startswith('/usr/bin/'):
97 # Assume system-wide installation, QML from /usr/share/
98 view.setSource('/usr/share/gotovienna/qml/main.qml')
100 # Assume test from source directory, use relative path
101 view.setSource(os.path.join(os.path.dirname(__file__), 'qml/main.qml'))
103 view.showFullScreen()
105 sys.exit(app.exec_())