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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
from tkinter import *
import matplotlib.pyplot as plt
import sqlite3
import datetime
from xlsxwriter.workbook import Workbook
import glob
import os
import time
root =Tk()
root.title("IrraSurvey")
root.geometry("800x600")
def chambre(x):
def start(x):
lancer.configure(state=DISABLED)
stopper.configure(state=NORMAL)
maj.configure(state=NORMAL)
calculer.configure(state=NORMAL)
def patient_name(event):
global dbname
date = datetime.datetime.now()
day = str(date.day)
month = str(date.month)
year = str(date.year)
dbname = ("Chambre"+str(x)+" - "+entree.get()+" - "+day+month+year)
conn = sqlite3.connect(dbname+".db")
cursor = conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS Décroissance(
Point TXT,
Valeur TXT,
Temps TXT
)''')
conn.close
fenetre.destroy()
fenetre = Tk()
fenetre.title("Patient")
value = StringVar(fenetre)
value.set("Nom du patient")
entree = Entry(fenetre, textvariable=value, width=30)
entree.pack()
entree.bind("<Return>", patient_name)
bcl = None
def request():
bcl = str("boucle"+str(x))
print("requete LB 5340 "+str(x))
bcl = root.after(1000,request)
bcl = root.after(1000,request)
fenetre.mainloop()
return
def stop(x):
workbook = Workbook(dbname+'.xlsx')
worksheet = workbook.add_worksheet()
conn=sqlite3.connect(dbname+".db")
c=conn.cursor()
c.execute("select * from Décroissance")
mysel=c.execute("select * from Décroissance ")
for i, row in enumerate(mysel):
for j, value in enumerate(row):
worksheet.write(i, j, value)
workbook.close()
conn.close
bcl = str("boucle"+str(x))
root.after_cancel(bcl)
print("STOP")
maj.configure(state=DISABLED)
stopper.configure(state=DISABLED)
calculer.configure(state=DISABLED)
lancer.configure(state=NORMAL)
return
def calcul(x):
fic = ('Chambre'+str(x)+'*.db')
newest = max(glob.iglob(fic), key=os.path.getctime)
print(newest)
conn=sqlite3.connect(newest)
c=conn.cursor()
c.execute('SELECT Valeur FROM Décroissance')
data = c.fetchall()
conn.close
plt.plot(data)
plt.show()
return
def update_val(x):
try:
fic = ('Chambre'+str(x)+'*.db')
newest = max(glob.iglob(fic), key=os.path.getctime)
print(newest)
conn=sqlite3.connect(newest)
c=conn.cursor()
c.execute('SELECT Valeur FROM Décroissance ')
data = c.fetchall()
lenght = (len(data))-1
dat = (data[lenght])
root.update_idletasks()
print(dat)
lblmaj = Label(root, text=dat).grid(row=x,column=4, padx = 5, pady = 20)
except IndexError:
fenetre = Tk()
fenetre.title("Erreur")
value = StringVar(fenetre)
value.set("Pas assez de valeurs dans la base")
lbl = Label(fenetre, textvariable=value, width=50)
lbl.pack()
lbl.mainloop()
except NameError:
fenetre = Tk()
fenetre.title("Erreur")
value = StringVar(fenetre)
value.set("Pas de base disponible, la mesure est-elle lancée ?")
lbl = Label(fenetre, textvariable=value, width=50)
lbl.pack()
lbl.mainloop()
lancer = Button(root,text="Start",command=lambda:start(x))
lancer.grid(row=x,column=0, padx = 5, pady = 20)
stopper = Button(root,text="Stop",command=lambda:stop(x))
stopper.grid(row=x,column=1, padx = 5, pady = 20)
calculer = Button(root,text="Calcul",command=lambda:calcul(x))
calculer.grid(row=x,column=2, padx = 5, pady = 20)
maj = Button(root,text="MAJ valeurs",command=lambda:update_val(x))
maj.grid(row=x,column=3, padx = 5, pady = 20)
maj.configure(state=DISABLED)
stopper.configure(state=DISABLED)
calculer.configure(state=DISABLED)
return
for c in range(0,9):
chambre(c)
root.mainloop() |