1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#! /usr/bin/python
# -*- coding: utf-8 -*-
# Written by Dan Mandle http://dan.mandle.me September 2012
# License: GPL 2.0
#Importation des differentes librairies
from gps import *
from Tkinter import *
import threading
#import os
#from time import *
#import time
gpsd = None #Initialise la variable globale
def FIN(): #Definition de la fonction FIN
gpsp.running = False #stop le thread gpsp
fen.running = False #stop le thread fen
gpsp.join() #attend la fin du thread gpsp
fen.join() #attends la fin du thread fen
class GpsPoller(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
global gpsd #donne acces à la variable global gpsp
gpsd = gps(mode=WATCH_ENABLE) #commence la collect des données du GPS
self.current_value = None
self.running = True #setting the thread running to true
def run(self):
global gpsd
while gpsp.running:
gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer
print '1' #Affiche un 1 pour voir si le thread fonctionne
class Window(threading.Thread):
def __init__(self):
threading.Thread.__init__ (self)
self.current_value = None
self.running = True
def run (self):
Fenetre=Tk() #Création de la fenetre
Fenetre.geometry("300x100") #Defini la taille de la fenetre
Fenetre.title ('Coordonnées GPS') #Définition du titre de la fenêtre
VarLatitude=gpsd.fix.latitude #Acquisition de la Latitude
VarLongitude=gpsd.fix.longitude #Acquisition de la Longitude
VarTime=gpsd.utc #Acquisition de l'heure UTC
TextLatitude=Label(Fenetre, text='Latitude : ' +str(VarLatitude)) #Création du Label Latitude
TextLatitude.pack(side = TOP) #Positionnement
TextLongitude=Label(Fenetre, text='Longitude : '+str(VarLongitude)) #Création du Label Longitude
TextLongitude.pack(side = TOP) #Positionnement
TextTime=Label(Fenetre, text='Heure : '+str(VarTime)) #Création du Label Time
TextTime.pack(side = TOP) #Positionnement
Button2=Button(Fenetre, text='FIN', command=FIN) #Création du bouton FIN
Button2.pack(side = BOTTOM) #Positionnement
while True:
VarLatitude=gpsd.fix.latitude #Acquisition de la Latitude
VarLongitude=gpsd.fix.longitude #Acquisition de la Longitude
VarTime=gpsd.utc #Acquisition de l'heure UTC
TextLatitude.configure(text='Latitude : ' +str(VarLatitude)) #MAJ du Label Latitude
TextLongitude.configure(text='Longitude : '+str(VarLongitude)) #MAJ du Label Longitude
TextTime.configure(text='Heure : '+str(VarTime)) #MAJ du Label Time
print '2' #Affiche un 2 pour voir si le thread fonctionne
#C'est la que ca coince
#Quand Fenetre.update_idletasks() est actif, le bouton FIN ne repond pas MAIS les données GPS sont MAJ
#Quand Fenetre.mainloop() est actif, le bouton FIN répond MAIS les données GPS ne sont pas MAJ
#Fenetre.mainloop() #Activation de la Fenetre
Fenetre.update_idletasks()
#Fin du problème
# Main Program
if __name__ == '__main__':
gpsp = GpsPoller() #Creation du thread GPS
fen = Window() #Creation du thread de la fenetre
gpsp.start() #Lancement du thread gpsp
fen.start() #Lancement du thread fen |
Partager