From 38f1067e54ec6d892a867ecb5bf8bfc6bfe055f8 Mon Sep 17 00:00:00 2001 From: kelvan Date: Sun, 20 Nov 2011 00:47:23 +0100 Subject: [PATCH] Change QStringList to QVariant for Departures Fixing wrong destination View times italic if lowfloor --- gotovienna-qml | 14 ++- qml/ResultRealtime.qml | 263 ++++++++++++++++++++++++------------------------ 2 files changed, 142 insertions(+), 135 deletions(-) diff --git a/gotovienna-qml b/gotovienna-qml index 0a82381..45269ca 100755 --- a/gotovienna-qml +++ b/gotovienna-qml @@ -3,7 +3,7 @@ """Public transport information for Vienna""" __author__ = 'kelvan ' -__version__ = '0.8.1' +__version__ = '0.8.2' __website__ = 'https://github.com/kelvan/gotoVienna/' __license__ = 'GNU General Public License v3 or later' @@ -21,6 +21,7 @@ import urllib2 import os import sys import threading +from datetime import time class GotoViennaListModel(QAbstractListModel): def __init__(self, objects=None): @@ -96,8 +97,13 @@ class Gui(QObject): @Slot(str) def load_departures(self, url): def load_async(): - self.current_departures = [x['ftime'] for x in - self.itip.get_departures(url)] + def map_departure(dep): + dep['lowfloor'] = 1 if dep['lowfloor'] else 0 + if type(dep['time']) == time: + dep['time'] = dep['time'].strftime('%H:%M') + return dep + + self.current_departures = map(map_departure, self.itip.get_departures(url)) print self.current_departures self.departuresLoaded.emit() @@ -111,7 +117,7 @@ class Gui(QObject): def get_lines(self): return self.lines - @Slot(result='QStringList') + @Slot(result='QVariant') def get_departures(self): return self.current_departures diff --git a/qml/ResultRealtime.qml b/qml/ResultRealtime.qml index 3532743..fafc85d 100644 --- a/qml/ResultRealtime.qml +++ b/qml/ResultRealtime.qml @@ -35,141 +35,142 @@ Item { var departures = itip.get_departures() for (var d in departures) { - console.log('departure: ' + departures[d]) - // XXX: destination might be wrong?! - var row = {'line': resultRealtime.gline, 'station': resultRealtime.gstation, 'destination': gdirection, 'departure': departures[d]} - console.log('inserting: ' + row) + console.log('time: ' + departures[d].time) + var row = {'line': departures[d].line, 'station': departures[d].station, 'destination': departures[d].direction, 'departure': departures[d].time, 'lowfloor': departures[d].lowfloor} departuresModel.append(row) } } } Component { - id: departureDelegate - - Item { - width: parent.width - height: 80 - - BorderImage { - anchors.fill: parent - visible: mouseArea.pressed - source: theme.inverted ? 'image://theme/meegotouch-list-inverted-background-pressed-vertical-center': 'image://theme/meegotouch-list-background-pressed-vertical-center' - } - - Item { - anchors.fill: parent - anchors.margins: UIConstants.DEFAULT_MARGIN - - Row { - spacing: 10 - Text { - id: l - text: line // <---- - anchors.verticalCenter: parent.verticalCenter - width: 70 - font.pixelSize: UIConstants.FONT_XLARGE - font.bold: true - font.family: ExtrasConstants.FONT_FAMILY_LIGHT - color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND - } - - Column { - anchors.verticalCenter: parent.verticalCenter - - Text { - id: s - text: station // <---- - width: parent.parent.parent.width - l.width - dep.width - 10 - elide: Text.ElideRight - font.pixelSize: UIConstants.FONT_LARGE - font.family: ExtrasConstants.FONT_FAMILY_LIGHT - color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND - } - - Text { - id: d - text: destination // <---- - color: !theme.inverted ? UIConstants.COLOR_SECONDARY_FOREGROUND : UIConstants.COLOR_INVERTED_SECONDARY_FOREGROUND - font.family: ExtrasConstants.FONT_FAMILY_LIGHT - font.pixelSize: UIConstants.FONT_LSMALL - } - } - } - } - - Column { - anchors.right: parent.right - anchors.verticalCenter: parent.verticalCenter - Text { - id: dep - // FIXME strange int float transformation appears - text: departure - anchors.right: parent.right - anchors.rightMargin: UIConstants.DEFAULT_MARGIN - font.bold: true - font.pixelSize: UIConstants.FONT_XLARGE - font.family: ExtrasConstants.FONT_FAMILY_LIGHT - color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND - } - } - - MouseArea { - id: mouseArea - anchors.fill: parent - onClicked: { - console.debug("clicked: " + l.text) - } - } - } - } - - ListView { - id: list - width: parent.width; height: parent.height - - header: Rectangle { - width: parent.width - height: childrenRect.height + 2*UIConstants.DEFAULT_MARGIN - color: "lightsteelblue" - radius: 5.0 - smooth: true - - Text { - anchors { - top: parent.top - left: parent.left - right: parent.right - margins: UIConstants.DEFAULT_MARGIN - } - - text: 'Richtung ' + gdirection - elide: Text.ElideRight - font.bold: true - font.family: ExtrasConstants.FONT_FAMILY_LIGHT - font.pixelSize: UIConstants.FONT_LSMALL - } - } - - model: ListModel { - id: departuresModel - } - delegate: departureDelegate - - visible: !resultRealtime.busy && resultRealtime.sourceUrl != '' - } - - ScrollDecorator { - id: scrolldecorator - flickableItem: list - platformStyle: ScrollDecoratorStyle {} - } - - BusyIndicator { - id: busyIndicator - visible: resultRealtime.busy && resultRealtime.sourceUrl != '' - running: visible - platformStyle: BusyIndicatorStyle { size: 'large' } - anchors.centerIn: parent - } + id: departureDelegate + + Item { + width: parent.width + height: 80 + + BorderImage { + anchors.fill: parent + visible: mouseArea.pressed + source: theme.inverted ? 'image://theme/meegotouch-list-inverted-background-pressed-vertical-center': 'image://theme/meegotouch-list-background-pressed-vertical-center' + } + + Item { + anchors.fill: parent + anchors.margins: UIConstants.DEFAULT_MARGIN + + Row { + spacing: 10 + Text { + id: l + text: line // <---- + anchors.verticalCenter: parent.verticalCenter + //width: 70 + font.pixelSize: UIConstants.FONT_XLARGE + font.bold: true + font.family: ExtrasConstants.FONT_FAMILY_LIGHT + color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND + } + + Column { + anchors.verticalCenter: parent.verticalCenter + + Text { + id: s + text: station // <---- + width: parent.parent.parent.width - l.width - dep.width - 15 + elide: Text.ElideRight + font.pixelSize: UIConstants.FONT_LARGE + font.family: ExtrasConstants.FONT_FAMILY_LIGHT + color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND + } + + Text { + id: d + text: destination // <---- + width: parent.parent.parent.width - l.width - dep.width - 15 + elide: Text.ElideRight + color: !theme.inverted ? UIConstants.COLOR_SECONDARY_FOREGROUND : UIConstants.COLOR_INVERTED_SECONDARY_FOREGROUND + font.family: ExtrasConstants.FONT_FAMILY_LIGHT + font.pixelSize: UIConstants.FONT_LSMALL + } + } + } + } + + Column { + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + Text { + id: dep + // FIXME strange int float transformation appears + text: departure + anchors.right: parent.right + anchors.rightMargin: UIConstants.DEFAULT_MARGIN + font.italic: lowfloor == 1 + font.bold: true + font.pixelSize: UIConstants.FONT_XLARGE + font.family: ExtrasConstants.FONT_FAMILY_LIGHT + color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND + } + } + + MouseArea { + id: mouseArea + anchors.fill: parent + onClicked: { + console.debug("clicked: " + l.text) + } + } + } + } + + ListView { + id: list + width: parent.width; height: parent.height + + header: Rectangle { + width: parent.width + height: childrenRect.height + 2*UIConstants.DEFAULT_MARGIN + color: "lightsteelblue" + radius: 5.0 + smooth: true + + Text { + anchors { + top: parent.top + left: parent.left + right: parent.right + margins: UIConstants.DEFAULT_MARGIN + } + + text: 'Richtung ' + gdirection + elide: Text.ElideRight + font.bold: true + font.family: ExtrasConstants.FONT_FAMILY_LIGHT + font.pixelSize: UIConstants.FONT_LSMALL + } + } + + model: ListModel { + id: departuresModel + } + delegate: departureDelegate + + visible: !resultRealtime.busy && resultRealtime.sourceUrl != '' + } + + ScrollDecorator { + id: scrolldecorator + flickableItem: list + platformStyle: ScrollDecoratorStyle {} + } + + BusyIndicator { + id: busyIndicator + visible: resultRealtime.busy && resultRealtime.sourceUrl != '' + running: visible + platformStyle: BusyIndicatorStyle { size: 'large' } + anchors.centerIn: parent + } } -- 1.7.9.5