Running unit tests:
-$ python -m gotovienna.tests.runner
+$ nosetests gotovienna/tests/*.py
To build the package with aegis tokens (install python-stdeb and ar first):
from gotovienna.utils import *
from gotovienna.realtime import *
from gotovienna.gps import *
+from gotovienna.update import *
+from gotovienna.config import config as conf
import urllib2
import os
import threading
from datetime import time
+class Config(QObject):
+ def __init__(self):
+ QObject.__init__(self)
+
+ @Slot(result=bool)
+ def getGpsEnabled(self):
+ return conf.getGpsEnabled()
+
+ @Slot(bool, result=unicode)
+ def setGpsEnabled(self, val):
+ # TODO
+ return conf.setGpsEnabled(val)
+
+ @Slot(result=unicode)
+ def getLastUpdate(self):
+ # TODO
+ return conf.getLastStationsUpdate()
+
+ @Slot(result=unicode)
+ def updateStations(self):
+ # TODO
+ try:
+ update_stations()
+ return datetime.now().strftime('%c')
+ except Exception as e:
+ print e
+ return ''
+
+ @Slot(result=bool)
+ def checkStationsUpdate(self):
+ # FIXME exception handling foo
+ try:
+ return check_stations_update()
+ except:
+ return False
+
class AboutInfo(QObject):
def __init__(self):
QObject.__init__(self)
def get_nearby_stations(self, lat, lon):
try:
return get_nearby_stations(lat, lon)
- except Exception as e:
- print e.message
+ except BaseException as e:
+ # No/wrong stations.db file
return []
@Slot(str, str)
view = QDeclarativeView()
aboutInfo = AboutInfo()
+ config = Config()
# instantiate the Python object
itip = Gui()
context = view.rootContext()
context.setContextProperty('itip', itip)
context.setContextProperty('aboutInfo', aboutInfo)
+ context.setContextProperty('config', config)
if os.path.abspath(__file__).startswith('/usr/bin/'):
# Assume system-wide installation, QML from /usr/share/
import defaults
import realtime
-
def load(p, typ):
if path.exists(p):
try:
return None
-
class Lines(dict):
def __init__(self):
self.load()
import os
from datetime import time
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
-DATAPATH = 'data'
+DATAPATH = os.path.join(os.path.dirname(__file__), 'data')
from gotovienna.realtime import *
from datetime import datetime
from gotovienna.routing import *
-DATAPATH = 'data'
+DATAPATH = os.path.join(os.path.dirname(__file__), 'data')
underground_routing = open(os.path.join(DATAPATH, 'underground_routing.html'), 'r').read()
underground_foot_routing = open(os.path.join(DATAPATH, 'underground_foot_routing.html'), 'r').read()
--- /dev/null
+import QtQuick 1.1
+import com.nokia.meego 1.0
+import "UIConstants.js" as UIConstants
+import "ExtrasConstants.js" as ExtrasConstants
+
+Page {
+ tools: settingsTools
+
+ ToolBarLayout {
+ id: settingsTools
+ x: 0
+ y: 0
+ ToolIcon { iconId: "toolbar-back"; onClicked: { menu.close(); pageStack.pop(null,false); } }
+ }
+
+ Flickable {
+ id: settingsContent
+ anchors.fill: parent
+ anchors.margins: UIConstants.DEFAULT_MARGIN
+
+ contentHeight: content_column.height + 2 * UIConstants.DEFAULT_MARGIN
+ flickableDirection: Flickable.VerticalFlick
+
+ Component.onCompleted: {
+ }
+
+ Column {
+ id: content_column
+ spacing: UIConstants.DEFAULT_MARGIN
+ width: parent.width
+
+ Text {
+ text: qsTr("Settings")
+ font.pixelSize: UIConstants.FONT_XLARGE
+ color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
+ anchors.left: parent.left
+ }
+
+ Row {
+ anchors.left: parent.left
+ anchors.right: parent.right
+ Text {
+ text: "Enable GPS"
+ anchors.left: parent.left
+ font.pixelSize: UIConstants.FONT_LARGE
+ color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
+ anchors.verticalCenter: parent.verticalCenter
+ }
+ CheckBox {
+ id: gpsEnable
+ anchors.right: parent.right
+ checked: config.getGpsEnabled()
+
+ onCheckedChanged: {
+ var gps = config.setGpsEnabled(checked);
+ if(gps !== '') {
+ // Unable to set config
+ console.log(gps);
+ checked=!checked;
+ } else {
+ positionSource.active = checked;
+ }
+ }
+ }
+ }
+
+ UpdateDialog {
+ id:updateDialog
+ }
+
+ Row {
+ anchors.left: parent.left
+ anchors.right: parent.right
+ Text {
+ text: "Update stations"
+ anchors.left: parent.left
+ font.pixelSize: UIConstants.FONT_LARGE
+ color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
+ anchors.verticalCenter: parent.verticalCenter
+ }
+
+ Button {
+ id: btnUpdate
+ anchors.right: parent.right
+ text: "Update"
+ width: 100
+
+ Component.onCompleted: {
+ if (config.checkStationsUpdate()) {
+ btnUpdate.color = "green"
+ }
+ }
+
+ onClicked: {
+ var updateAvailable = config.checkStationsUpdate();
+ if (updateAvailable) {
+ var updated = config.updateStations();
+ if (updated !== '') {
+ updateDialog.text = "Stations updated"
+ txtLastUpdate.text = updated
+ } else {
+ updateDialog.text = "[UpdateError]:\nTry again later or send me an email:\n<gotovienna@logic.at>"
+ }
+ } else {
+ updateDialog.text = "No updates available";
+ }
+ updateDialog.open();
+ }
+ }
+ }
+
+ Row {
+ anchors.left: parent.left
+ anchors.right: parent.right
+ Text {
+ anchors.left: parent.left
+ text: "Last updated:"
+ font.pixelSize: UIConstants.FONT_LSMALL
+ color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
+ anchors.verticalCenter: parent.verticalCenter
+ }
+ Text {
+ id: txtLastUpdate
+ anchors.right: parent.right
+ text: config.getLastUpdate()
+ font.pixelSize: UIConstants.FONT_LSMALL
+ color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
+ anchors.verticalCenter: parent.verticalCenter
+ }
+ }
+ }
+ }
+}
--- /dev/null
+import QtQuick 1.1
+import com.nokia.meego 1.0
+
+Dialog {
+ id: updateDialog
+ property alias text: messageContent.text
+
+ content:Item {
+ id: message
+ height: 85
+ width: parent.width
+ Text {
+ id: messageContent
+ font.pixelSize: 22
+ anchors.centerIn: parent
+ color: "white"
+ text: "If you see this message\nsend me an email\nto <gotovienna@logic.at>\ndescribe what you're doing getting this message"
+ }
+ }
+
+ buttons: ButtonRow {
+ style: ButtonStyle { }
+ anchors.horizontalCenter: parent.horizontalCenter
+ Button {text: "OK"; onClicked: updateDialog.accept()}
+ }
+ }
id: positionSource
updateInterval: 15000
- active: !(position.longitudeValid && position.latitudeValid)
+ active: config.getGpsEnabled() && !(position.longitudeValid && position.latitudeValid)
}
ToolBarLayout {
text: ''
anchors {
- bottomMargin: 10
- bottom: parent.bottom
left: logo.right
leftMargin: 10
- top: logo.top
+ top: parent.top
+ topMargin: 10
}
font.pixelSize: 16
}
}
+ Settings{id: settings}
+
Menu {
id: menu
onClicked: mainPage.showNearby()
}
MenuItem {
+ text: 'Settings'
+ onClicked: pageStack.push(settings)
+ }
+ MenuItem {
text: 'About gotoVienna'
onClicked: aboutBox.show()
}