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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Affiche un décompte de 60mn à 0 en plein écran.
'''
import tkinter
import threading
import time
import tkinter.tix
import os
import signal
import sys
from functools import partial
#La gestion par PID
chem = os.path.expanduser('~')
'''le pid mis dans un fichier'''
getPID = os.getpid()
monPid = open(chem+"/decompteur.pid", "w")
monPid.write(str(getPID))
monPid.close()
###############################################################################
def sec2hms(sd):
"""Transforme les secondes sd en chaine "hh:mm:ss" pour affichage"""
h=0
m=0
s=sd
if s >= 60:
m = s//60
s -= m*60
if m >= 60:
h = m//60
m -= h*60
return "%02d:%02d:%02d" % (h, m, s)
def sig_stoppe(self, signum):
"""Arrête le compte à rebours avant la fin normale"""
chrono.stop()
def sig_quitte(self, signum):
os.remove(chem+"/decompteur.pid")
sys.exit(0)
def sig_lance(self, signum):
chrono.start()
##################################################################
class Comptearebours(threading.Thread):
def __init__(self, h, m, s):
threading.Thread.__init__(self)
self.t = h*3600 + m*60 + s
self.encore = True
def run(self):
global varsaisie
t1 = int(time.time())
varsaisie.set(sec2hms(self.t))
while self.encore:
t2 = int(time.time())
if t2>t1:
self.t -= t2-t1
if self.t <= 0:
self.t = 0
self.encore = False
varsaisie.set(sec2hms(self.t))
t1 = t2
time.sleep(0.01)
def stop(self):
self.encore = False
##############################################################################
# lancement et affichage de la fenetre
#
if __name__ == "__main__":
#On réagit à un kill -15 (SIGTERM) pour quitter, -10 (SIGUSR1) pour stopper, -12 (SIGUSR2) pour lancer
signal.signal( signal.SIGTERM, sig_quitte )
signal.signal( signal.SIGUSR1, sig_stoppe )
signal.signal( signal.SIGUSR2, sig_lance )
#On lance FuseeLunaire.py
# os.system("python "+chem+"/FuseeLunaire.py &");
#affichage
topDecompte= tkinter.Toplevel(bg="lightgrey",borderwidth=3,padx=5,pady=5,relief="solid",cursor="none")
topDecompte.geometry(str(topDecompte.winfo_screenwidth())+"x"+str(topDecompte.winfo_screenheight())+"+0+0")
topDecompte.overrideredirect(True)
topDecompte.grab_set()
topDecompte.focus_set()
#frame
topf=tkinter.Frame(topDecompte, bg="lightgrey")
#Le titre
zoneTitre=tkinter.Label(topf, text="Démarrage des moteurs dans : ", fg="darkgreen", bg="lightgrey", font = ("Helvetica", 23, "bold"))
zoneTitre.pack(side="left", pady=2, padx=2)
topf.pack(side="top", expand=1, fill="both")
#La variable d'affichage
varsaisie = tkinter.StringVar()
varsaisie.set("")
#Affichage pour décompte
saisie=tkinter.Entry(topDecompte, disabledbackground="lightgrey", borderwidth=0, state="disabled", disabledforeground="darkred", textvariable=varsaisie, justify="center", font = ("Helvetica", 70, "bold"))
saisie.pack(expand=1, side="top")
#gérer le décompte
#topDecompte.grid_columnconfigure(0,weight=1)
topDecompte.resizable(True,True)
topDecompte.update()
"""Lance le compte à rebours"""
chrono = Comptearebours(1,0,0)
chrono.setDaemon(True)
topDecompte.mainloop() |
Partager