-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.py
More file actions
131 lines (99 loc) · 5.07 KB
/
interface.py
File metadata and controls
131 lines (99 loc) · 5.07 KB
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
import tkinter as tk
from tkinter import ttk
import serial
import moduleMesure as module
import time
import datetime
import connexionBD as bd
serialPort = serial.Serial("COM3")
class Interface(tk.Tk):
typeCapture = ""
def setCapture(self, typeCapture):
self.typeCapture = typeCapture
def demarrerSysteme(self, labelStatus, textBoxDescription):
#Si un type de capture est défini
if self.typeCapture != "":
labelStatus.config(text="ACTIVÉ", fg="green")
textBoxDescription.config(state="normal")
if self.typeCapture == "distance":
serialPort.write(b"DEMARRERDISTANCE\n")
elif self.typeCapture == "angle":
serialPort.write(b"DEMARRERANGLE\n")
def prendreMesure(self, labelStatus, textBoxDescription, listBoxMesures):
#Si une description est rentrée
if textBoxDescription.get("1.0", "end-1c") != "":
labelStatus.config(text="DÉSACTIVÉ", fg="red")
#Récuperer la description entrée
description = textBoxDescription.get("1.0", "end-1c")
textBoxDescription.delete('1.0', tk.END)
textBoxDescription.config(state="disabled")
serialPort.write(b"ARRETER\n")
data_in = serialPort.readline()
donnees = data_in.decode("utf-8").strip()
if self.typeCapture == "distance":
self.creerMesure(donnees, listBoxMesures, description, "distance")
elif self.typeCapture == "angle":
self.creerMesure(donnees, listBoxMesures, description, "angle")
else:
labelStatus.config(text="DÉSACTIVÉ", fg="red")
textBoxDescription.delete('1.0', tk.END)
textBoxDescription.config(state="disabled")
serialPort.write(b"DESCRIPTIONVIDE\n")
def creerMesure(self, mesure, listBoxMesures, description, typeDeMesure):
#Recupération du temps
#Création de la mesure
#Mise de l'objet mesure dans le listBox
date = datetime.datetime.now()
dateStr = date.strftime("%c")
objetMesure = module.Mesure(dateStr, description, mesure, typeDeMesure)
listBoxMesures.insert(tk.END, objetMesure)
#Envoyer l'objet à la base de données
bd.connexionDB()
if bd.verifierExisteTable("MESURES") == False:
bd.creationBaseDeDonnées()
bd.ajouterMesure(dateStr, description, mesure, typeDeMesure)
bd.fermetureDB()
print("-----------------------------------------------------")
def __init__(self):
super().__init__()
self.title("TP4 Eric Marin")
self.geometry("600x600")
self.resizable(False, False)
#Frame et logo
frame1 = ttk.Frame(self)
frame1.pack(side=tk.TOP)
frame2 = ttk.Frame(self)
frame2.pack(side=tk.BOTTOM)
labelLogo = tk.Label(frame1, text="SONAR STANCE\nTECHNOLOGIES", font=('Copperplate Gothic Bold', 10), borderwidth=1, relief="solid")
labelLogo.config(bg="orange")
labelLogo.pack()
#Titres et listBox
labelTitre = tk.Label(frame1, text="Logiciel de mesures", font=('Helvetica', 16))
labelTitre.pack()
labelMesures = tk.Label(frame1, text="Mesures:", font=('Helvetica', 12))
labelMesures.pack(pady=(10,0))
listBoxMesures = tk.Listbox(frame1, height=12, width=100)
listBoxMesures.pack()
#Radio boutons
labelChoix = tk.Label(frame1, text="Que voulez-vous capturer?", font=('Helvetica', 12))
labelChoix.pack()
radioVar = tk.IntVar()
radioDistance = tk.Radiobutton(frame1, text = "Distance", variable = radioVar, value = 1, command=lambda: self.setCapture("distance"))
radioDistance.pack()
radioAngle = tk.Radiobutton(frame1, text = "Angle du moteur", variable = radioVar, value = 2, command=lambda: self.setCapture("angle"))
radioAngle.pack()
#Description
labelDescription = tk.Label(frame1, text="Entrez une description:", font=('Helvetica', 12))
labelDescription.pack(pady=(20,0))
textBoxDescription = tk.Text(frame1, width=60, height=3, state="disabled")
textBoxDescription.pack()
labelStatus = tk.Label(frame1, text="DÉSACTIVÉ", font=('Helvetica', 12))
labelStatus.pack(pady=(20,0))
#Boutons démarrer / prendre mesure
boutonDemarrer = tk.Button(frame2, text="Démarrer la capture", bg='#3CBA4C', command=lambda: self.demarrerSysteme(labelStatus, textBoxDescription))
boutonDemarrer.pack(fill=tk.BOTH, expand=True, side=tk.LEFT)
boutonStop = tk.Button(frame2, text="Capturer la mesure", bg='#f44336', command=lambda: self.prendreMesure(labelStatus, textBoxDescription, listBoxMesures))
boutonStop.pack(fill=tk.BOTH, expand=True, side=tk.RIGHT)
if __name__ == "__main__":
app = Interface()
app.mainloop()