From: Florian Schweikert Date: Thu, 19 Jan 2012 20:29:51 +0000 (+0100) Subject: Settings page X-Git-Url: http://vcs.maemo.org/git/?p=pywienerlinien;a=commitdiff_plain;h=5a7604ed608be9e3e5466583f5a30ce7965d5540 Settings page settings page for updating stations.db enable/disable gps (setting PositionSource.active=false don't disable gps atm :/) --- diff --git a/README b/README index a661154..4a26555 100644 --- a/README +++ b/README @@ -7,7 +7,7 @@ This program ist unofficial. 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): diff --git a/gotovienna-qml b/gotovienna-qml index fd7b9a5..2ba243e 100755 --- a/gotovienna-qml +++ b/gotovienna-qml @@ -16,6 +16,8 @@ from PySide.QtDeclarative import QDeclarativeView 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 @@ -23,6 +25,42 @@ import sys 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) @@ -180,8 +218,8 @@ class Gui(QObject): 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) @@ -212,6 +250,7 @@ if __name__ == '__main__': view = QDeclarativeView() aboutInfo = AboutInfo() + config = Config() # instantiate the Python object itip = Gui() @@ -220,6 +259,7 @@ if __name__ == '__main__': 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/ diff --git a/gotovienna/cache.py b/gotovienna/cache.py index 0332a95..dce8cec 100644 --- a/gotovienna/cache.py +++ b/gotovienna/cache.py @@ -8,7 +8,6 @@ import shutil import defaults import realtime - def load(p, typ): if path.exists(p): try: @@ -28,7 +27,6 @@ def load(p, typ): return None - class Lines(dict): def __init__(self): self.load() diff --git a/gotovienna/tests/realtime.py b/gotovienna/tests/realtime.py index 52ca18a..0d3b08a 100644 --- a/gotovienna/tests/realtime.py +++ b/gotovienna/tests/realtime.py @@ -5,7 +5,7 @@ import sys 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 * diff --git a/gotovienna/tests/routing.py b/gotovienna/tests/routing.py index 635d814..20f93cd 100644 --- a/gotovienna/tests/routing.py +++ b/gotovienna/tests/routing.py @@ -4,7 +4,7 @@ from nose.tools import assert_equal, assert_true, assert_false 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() diff --git a/qml/Settings.qml b/qml/Settings.qml new file mode 100644 index 0000000..09852df --- /dev/null +++ b/qml/Settings.qml @@ -0,0 +1,133 @@ +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" + } + } 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 + } + } + } + } +} diff --git a/qml/UpdateDialog.qml b/qml/UpdateDialog.qml new file mode 100644 index 0000000..328eaa0 --- /dev/null +++ b/qml/UpdateDialog.qml @@ -0,0 +1,26 @@ +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 \ndescribe what you're doing getting this message" + } + } + + buttons: ButtonRow { + style: ButtonStyle { } + anchors.horizontalCenter: parent.horizontalCenter + Button {text: "OK"; onClicked: updateDialog.accept()} + } + } diff --git a/qml/main.qml b/qml/main.qml index 9e22346..5c97c50 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -27,7 +27,7 @@ PageStackWindow { id: positionSource updateInterval: 15000 - active: !(position.longitudeValid && position.latitudeValid) + active: config.getGpsEnabled() && !(position.longitudeValid && position.latitudeValid) } ToolBarLayout { @@ -57,16 +57,17 @@ PageStackWindow { 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 @@ -76,6 +77,10 @@ PageStackWindow { onClicked: mainPage.showNearby() } MenuItem { + text: 'Settings' + onClicked: pageStack.push(settings) + } + MenuItem { text: 'About gotoVienna' onClicked: aboutBox.show() }