Roman, I made a few changes and the script does run
but it is not outputting the information I need to be displayed in the Label ( the time from the gps). Here is the updated script:
Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Licence: GPL v.3 http://www.gnu.org/licenses/gpl.html
# This is an XBMC addon for demonstrating the capabilities
# and usage of PyXBMCt framework.
import os
import sys
import time
import xbmc, xbmcaddon, xbmcgui
from pyxbmct.addonwindow import *
from gps import *
import threading
import subprocess
_addon = xbmcaddon.Addon()
_addon_path = _addon.getAddonInfo('path')
gpsd = None #seting the global variable
os.system('clear') #clear the terminal (optional)
class MyAddon(AddonDialogWindow):
def __init__(self, title=''):
super(MyAddon, self).__init__(title)
self.setGeometry(1200, 750, 10, 3)
self.set_info_controls()
self.set_active_controls()
# Connect a key action (Backspace) to close the window.
self.connect(ACTION_NAV_BACK, self.close)
def set_info_controls(self):
label_center = Label ("Time")
self.placeControl(label_center, 1,1)
print "check 1"
def set_active_controls(self):
int_label = Label('Interactive Controls', alignment=ALIGN_CENTER)
self.placeControl(int_label, 0, 2, 1, 2)
print "check 2"
# start_button_update
self.button = Button('Close')
self.placeControl(self.button, 8, 2)
# Connect control to close the window.
self.connect(self.button, self.close)
print "check 3"
# Update button caption on toggle
time_label = Label("%s" %(GpsPoller.gpstime), alignment=ALIGN_CENTER)
self.placeControl(time_label, 3, 1)
print "check 4"
class GpsPoller(threading.Thread):
print "check 5"
def __init__(self):
threading.Thread.__init__(self)
global gpsd #bring it in scope
gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
self.current_value = None
self.running = True #setting the thread running to true
print "check 6"
def run(self):
print "check 7"
global gpsd
while gpsp.running:
gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer
print "check 8"
def gpstime(self):
global line1
line1 = 'time utc ' , gpsd.utc,' + ', gpsd.fix.time
if __name__ == '__main__':
gpsp = GpsPoller() # create the thread
window = MyAddon('PyXBMCt Demo')
window.doModal()
try:
print "A"
gpsp.start()
while True:
print "B"
#It may take a second or two to get good data
#print gpsd.fix.latitude,', ',gpsd.fix.longitude,' Time: ',gpsd.utc
os.system('clear')
#print
#print ' GPS reading'
#print '----------------------------------------'
#print 'latitude ' , gpsd.fix.latitude
#print 'longitude ' , gpsd.fix.longitude
line1 = 'time utc ' , gpsd.utc,' + ', gpsd.fix.time
#print 'time utc ' , gpsd.utc,' + ', gpsd.fix.time
#print 'altitude (m)' , gpsd.fix.altitude
#print 'eps ' , gpsd.fix.eps
#print 'epx ' , gpsd.fix.epx
#print 'epv ' , gpsd.fix.epv
#print 'ept ' , gpsd.fix.ept
#print 'speed (m/s) ' , gpsd.fix.speed
#print 'climb ' , gpsd.fix.climb
#print 'track ' , gpsd.fix.track
#print 'mode ' , gpsd.fix.mode
#print
#print 'sats ' , gpsd.satellites
print line1
print "check C"
time.sleep(5)
except (KeyboardInterrupt, SystemExit):
#when you press ctrl+c
print "\nKilling Thread..."
gpsp.running = False
gpsp.join() # wait for the thread to finish what it's doing
print "Done.\nExiting."
and here is the log info. ( note that the check 1, check 2, etc are only there to see the program status.)
Code:
1195.16:04:27 T:2853958688 NOTICE: check 5
1196.16:04:27 T:2853958688 NOTICE: check 6
1197.16:04:28 T:2853958688 NOTICE: check 1
1198.16:04:28 T:2853958688 NOTICE: check 2
1199.16:04:28 T:2853958688 NOTICE: check 3
1200.16:04:28 T:2853958688 NOTICE: check 4
1201.16:04:29 T:2706371616 NOTICE: B
1202.16:04:29 T:2706371616 NOTICE: check C
1203.16:04:29 T:2723148832 NOTICE: B
1204.16:04:30 T:2723148832 NOTICE: check C
1205.16:04:34 T:2706371616 NOTICE: B
1206.16:04:34 T:2706371616 NOTICE: check C
1207.16:04:35 T:2723148832 NOTICE: B
1208.16:04:35 T:2723148832 NOTICE: check C
1209.16:04:39 T:2706371616 NOTICE: B
1210.16:04:39 T:2706371616 NOTICE: check C
1211.16:04:40 T:2723148832 NOTICE: B
1212.16:04:40 T:2723148832 NOTICE: check C
1213.16:04:44 T:2706371616 NOTICE: B
1214.16:04:45 T:2706371616 NOTICE: check C
1215.16:04:45 T:2723148832 NOTICE: B
1216.16:04:45 T:2723148832 NOTICE: check C
1217.16:04:50 T:2706371616 NOTICE: B
1218.16:04:50 T:2706371616 NOTICE: check C
1219.16:04:50 T:2723148832 NOTICE: B
1220.16:04:50 T:2723148832 NOTICE: check C
1221.16:04:52 T:2853958688 NOTICE: A
1222.16:04:52 T:2853958688 NOTICE: B
1223.16:04:52 T:2738611232 NOTICE: check 7
1224.16:04:52 T:2853958688 NOTICE: ('time utc ', u'2015-07-22T16:04:30.000Z', ' + ', u'2015-07-22T16:04:29.000Z')
1225.16:04:52 T:2853958688 NOTICE: check C
1226.16:04:54 T:2669536288 NOTICE: Thread JobWorker start, auto delete: true
1227.16:04:55 T:2706371616 NOTICE: Previous line repeats 1 times.
1228.16:04:55 T:2706371616 NOTICE: B
1229.16:04:55 T:2706371616 NOTICE: check C
1230.16:04:55 T:2723148832 NOTICE: B
1231.16:04:55 T:2723148832 NOTICE: check C
1232.16:04:57 T:2853958688 NOTICE: B
1233.16:04:58 T:2853958688 NOTICE: ('time utc ', u'2015-07-22T16:04:58.000Z', ' + ', 1437581098.0)
1234.16:04:58 T:2853958688 NOTICE: check C
1235.16:04:58 T:2657088544 NOTICE: Thread LanguageInvoker start, auto delete: false
1236.16:04:58 T:2657088544 NOTICE: -->Python Interpreter Initialized<--
1237.16:04:59 T:2657088544 NOTICE: Kodi Log Uploader: started
1238.16:04:59 T:2657088544 NOTICE: Kodi Log Uploader: settings: len(email)=17
1239.16:04:59 T:2657088544 NOTICE: Kodi Log Uploader: settings: skip_oldlog=True
1240.16:05:00 T:2706371616 NOTICE: B
1241.16:05:00 T:2706371616 NOTICE: check C
1242.16:05:00 T:2723148832 NOTICE: B
1243.16:05:00 T:2723148832 NOTICE: check C
1244.16:05:02 T:2657088544 NOTICE: Kodi Log Uploader: reading log...