moved url debug output to logfile in home
[pywienerlinien] / gotoVienna.py
1 #!/usr/bin/env python
2
3 import sys
4 import os.path
5 import webbrowser
6 from PySide.QtCore import SIGNAL, QTranslator, QObject, Qt
7 from PySide.QtGui import QApplication, QMainWindow
8 from Ui_Qt import Ui_MainWindow
9 from wlSearch import Search
10 from history import History
11 import settings
12
13
14 class WienerLinienQt(QMainWindow, Ui_MainWindow):
15     types = ('stop', 'address', 'poi')
16
17     def __init__(self):
18         QMainWindow.__init__(self)
19         # quick&dirty workaround for non-maemo systems
20         try:
21             self.setAttribute(Qt.WA_Maemo5StackedWindow)
22         except:
23             pass
24         # _s is used to keep a reference to the Search object, so it does
25         # not get destroyed when it falls out of scope (the QML view is
26         # destroyed as soon as the Search object is destroyed!)
27         self._s = None
28         self.setupUi(self)
29         self.connect(self.btnSearch, SIGNAL("clicked()"), self.search)
30         self.connect(self.actionToggle, SIGNAL("activated()"), self.toggle)
31
32         self.history = History(settings.hist_file)
33         self.editOrigin.addItems(self.history)
34         self.editDestination.addItems(self.history)
35
36         self.editOrigin.clearEditText()
37         self.editDestination.clearEditText()
38
39     def search(self):
40         origin = self.editOrigin.currentText()
41         destination = self.editDestination.currentText()
42
43         if not (origin and destination):
44             self.btnSearch.setText(self.btnSearch.tr("Search - Missing input"))
45             return False
46
47         self.history.insert(0, origin)
48         self.history.insert(0, destination)
49
50         if not origin in self.history:
51             self.editOrigin.insertItems(0, origin)
52             self.editDestination.insertItems(0, origin)
53
54         if not destination in self.history:
55             self.editOrigin.insertItems(0, destination)
56             self.editDestination.insertItems(0, destination)
57
58         self._s = Search(origin, destination, \
59                    origin_type=self.types[self.comboOrigin.currentIndex()], \
60                    destination_type=self.types[self.comboDestination.currentIndex()], \
61                    parent=self)
62         self._s.open_qml()
63         return True
64
65     def toggle(self):
66         eo = self.editOrigin.currentText()
67         ed = self.editDestination.currentText()
68         self.editOrigin.setEditText(ed)
69         self.editDestination.setEditText(eo)
70
71         co = self.comboOrigin.currentIndex()
72         cd = self.comboDestination.currentIndex()
73         self.comboOrigin.setCurrentIndex(cd)
74         self.comboDestination.setCurrentIndex(co)
75
76 if __name__ == "__main__":
77     app = QApplication(sys.argv)
78     t = QTranslator()
79     t.load('', directory='lang', suffix='po')
80     app.installTranslator(t)
81     w = WienerLinienQt()
82     w.show()
83     sys.exit(app.exec_())