1

Trying to get a self updating speedometer and clock working for my truck using gps. So far I have been able to get the read out that I want using easygui and msgbox but it is not self updating which will not help much on either application. Below is the code. Any help would be much appreciated, I know this is pretty ugly and probably not correct but I am new to python.

import gps
from easygui import *
import sys
# Listen on port 2947 (gpsd) of localhost
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)
while True:
     try:
          report = session.next()
          if report['class'] == 'TPV':
               if hasattr(report, 'time'):
                    hour = int(report.time[11:13])
                    hourfix = hour - 7
                    if hourfix < 12:
                         time = 'Current Time Is: ' + report.time[5:7] + '/' + report.time[8:10] + '/' + report.time[0:4] + ' ' + str(hourfix) + report.time[13:19] + ' am'
                    else:
                         hourfix = hourfix - 12
                         time =  'Current Time Is: ' + report.time[5:7] + '/' + report.time[8:10] + '/' + report.time[0:4] + ' ' + str(hourfix) + report.time[13:19] + ' pm'
          if report['class'] == 'TPV':
               if hasattr(report, 'speed'):
                    speed = int(report.speed * gps.MPS_TO_MPH)
                    strspeed = str(speed)
                    currentspeed = 'Current Speed Is: ' + strspeed + ' MPH'
                    msgbox(time + "\n" + currentspeed, "SPEEDO by Jono")
     except KeyError:
          pass
     except KeyboardInterrupt:
          quit()
     except StopIteration:
          session = None
          print "GPSD has terminated"
  • just an aside, instead of `while True:try:report = session.next()` I am pretty sure that you can simply say `for report in session:` ... in addition typically a messageBox is a popup window that blocks further execution until the window is closed ... – Joran Beasley Jul 07 '14 at 23:03
  • Thanks for the quick response Joran. Any idea on the best way to show the information on a self updating GUI so that the script will just run in the background and all I'll see is the Speed and Time? – user3814232 Jul 07 '14 at 23:10
  • no idea with easygui (Ive never heard of it ...) there is an example speedometer in the wxPython demos (I am most familiar with wxPython) .. that said I imagine there is a way to do it in easygui ... – Joran Beasley Jul 07 '14 at 23:18
  • Answer: No, not currently possible. The gui waits until you press a button. An aside question: What if msgbox had a timeout option so if the user didn't do anything it would return after n seconds? The code above would cause the GUI to flash after each loop. Would that be acceptable? – Robert Lugg Dec 17 '14 at 07:11

0 Answers0