Exemplo n.º 1
0
class LogFilePositionSource(QGeoPositionInfoSource):
    def __init__(self, parent):
        QGeoPositionInfoSource.__init__(self, parent)
        self.logFile = QFile(self)
        self.timer = QTimer(self)

        self.timer.timeout.connect(self.readNextPosition)

        self.logFile.setFileName(translate_filename('simplelog.txt'))
        assert self.logFile.open(QIODevice.ReadOnly)

        self.lastPosition = QGeoPositionInfo()

    def lastKnownPosition(self, fromSatellitePositioningMethodsOnly):
        return self.lastPosition

    def minimumUpdateInterval(self):
        return 100

    def startUpdates(self):
        interval = self.updateInterval()

        if interval < self.minimumUpdateInterval():
            interval = self.minimumUpdateInterval()

        self.timer.start(interval)

    def stopUpdates(self):
        self.timer.stop()

    def requestUpdate(self, timeout):
        # For simplicity, ignore timeout - assume that if data is not available
        # now, no data will be added to the file later
        if (self.logFile.canReadLine()):
            self.readNextPosition()
        else:
            self.updateTimeout.emit()

    def readNextPosition(self):
        line = self.logFile.readLine().trimmed()

        if not line.isEmpty():
            data = line.split(' ')
            hasLatitude = True
            hasLongitude = True
            timestamp = QDateTime.fromString(str(data[0]), Qt.ISODate)
            latitude = float(data[1])
            longitude = float(data[2])
            if timestamp.isValid():
                coordinate = QGeoCoordinate(latitude, longitude)
                info = QGeoPositionInfo(coordinate, timestamp)
                if info.isValid():
                    self.lastPosition = info
                    # Currently segfaulting. See Bug 657
                    # http://bugs.openbossa.org/show_bug.cgi?id=657
                    self.positionUpdated.emit(info)
Exemplo n.º 2
0
class LogFilePositionSource(QGeoPositionInfoSource):
    def __init__(self, parent):
        QGeoPositionInfoSource.__init__(self, parent)
        self.logFile = QFile(self)
        self.timer = QTimer(self)

        self.timer.timeout.connect(self.readNextPosition)

        self.logFile.setFileName(translate_filename('simplelog.txt'))
        assert self.logFile.open(QIODevice.ReadOnly)

        self.lastPosition = QGeoPositionInfo()

    def lastKnownPosition(self, fromSatellitePositioningMethodsOnly):
        return self.lastPosition

    def minimumUpdateInterval(self):
        return 100

    def startUpdates(self):
        interval = self.updateInterval()

        if interval < self.minimumUpdateInterval():
            interval = self.minimumUpdateInterval()

        self.timer.start(interval)

    def stopUpdates(self):
        self.timer.stop()

    def requestUpdate(self, timeout):
        # For simplicity, ignore timeout - assume that if data is not available
        # now, no data will be added to the file later
        if (self.logFile.canReadLine()):
            self.readNextPosition()
        else:
            self.updateTimeout.emit()

    def readNextPosition(self):
        line = self.logFile.readLine().trimmed()

        if not line.isEmpty():
            data = line.split(' ')
            hasLatitude = True
            hasLongitude = True
            timestamp = QDateTime.fromString(str(data[0]), Qt.ISODate)
            latitude = float(data[1])
            longitude = float(data[2])
            if timestamp.isValid():
                coordinate = QGeoCoordinate(latitude, longitude)
                info = QGeoPositionInfo(coordinate, timestamp)
                if info.isValid():
                    self.lastPosition = info
                    # Currently segfaulting. See Bug 657
                    # http://bugs.openbossa.org/show_bug.cgi?id=657
                    self.positionUpdated.emit(info)
Exemplo n.º 3
0
 def testHuge(self):
     handle = QFile(":manychars.txt")
     handle.open(QFile.ReadOnly)
     original = open(os.path.join(self.testdir, "manychars.txt"), "r")
     self.assertEqual(handle.readLine(), original.readline())
Exemplo n.º 4
0
 def testAlias(self):
     handle = QFile(":jack")
     handle.open(QFile.ReadOnly)
     original = open(os.path.join(self.testdir, "shining.txt"), "r")
     self.assertEqual(handle.readLine(), original.readline())
Exemplo n.º 5
0
 def testSimple(self):
     handle = QFile(":words.txt")
     handle.open(QFile.ReadOnly)
     original = open(os.path.join(self.testdir, "words.txt"), "r")
     self.assertEqual(handle.readLine(), original.readline())
Exemplo n.º 6
0
 def testHuge(self):
     handle = QFile(":manychars.txt")
     handle.open(QFile.ReadOnly)
     original = open(os.path.join(self.testdir, "manychars.txt"), "r")
     self.assertEqual(handle.readLine(), original.readline())
Exemplo n.º 7
0
 def testAlias(self):
     handle = QFile(":jack")
     handle.open(QFile.ReadOnly)
     original = open(os.path.join(self.testdir, "shining.txt"), "r")
     self.assertEqual(handle.readLine(), original.readline())
Exemplo n.º 8
0
 def testSimple(self):
     handle = QFile(":words.txt")
     handle.open(QFile.ReadOnly)
     original = open(os.path.join(self.testdir, "words.txt"), "r")
     self.assertEqual(handle.readLine(), original.readline())