-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinterface.py
89 lines (72 loc) · 4.09 KB
/
interface.py
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
import tkinter as tk
import subprocess
import sys
from tkinter import messagebox
from customtkinter import *
class MyGUI(tk.Tk):
def __init__(self):
super().__init__()
set_appearance_mode("dark")
self.title("Z-AXIS Force")
self.geometry("600x400")
self.entry=None
self.initUI()
def initUI(self):
frame= CTkFrame(master=self,fg_color="#424242",border_color="#000000",border_width=2)
frame.pack(expand=True)
self.status_label0=tk.Label(master=frame,text="XYZ Force Sensor",bg="#424242", fg="white")
self.status_label=tk.Label(master=frame,text="no process is running",bg="#424242", fg="white")
self.status_label.place(relx=0.5,rely=0.8,anchor='center')
btn=CTkButton(master=frame,text=' submit Z force ',corner_radius=32,fg_color="#0B614B",hover_color="#04B404",command=self.on_button_click)
btn1=CTkButton(master=frame,text=' Break script ',corner_radius=32,fg_color="#0B614B",hover_color="#04B404",command=self.break_script)
btn2=CTkButton(master=frame,text='run CNC and Keithley',corner_radius=32,fg_color="#0B614B",hover_color="#04B404",command=self.run_otherScripts)
self.entry=CTkEntry(master=frame,placeholder_text="Type Z-axis value...",width=200,)
self.status_label0.pack(anchor="s",expand=True,pady=10,padx=30)
self.entry.pack(anchor="s",expand=True,pady=20,padx=30)
self.status_label.pack(anchor="s",expand=True,pady=10,padx=30)
btn.pack(anchor="n",expand=True,pady=15,padx=20)
btn1.pack(anchor="n",expand=True,pady=15,padx=20)
btn2.pack(anchor="n",expand=True,pady=15,padx=20)
def break_script(self):
if self.process is not None and self.process.poll() is None: #poll() lorsque le process est en cours elle retourne none sinon elle retourne le résultat du process mais ici on l'a utilisé que pour none
self.process.terminate()
print("script stopped")
self.status_label.config(text="Script stopped",fg="red")
else:
print("no process is running")
self.status_label.config(text="no process is running")
def on_button_click(self):
forceZ_value=self.entry.get()
if forceZ_value.strip() and forceZ_value.isnumeric():
print(f"entered value:{forceZ_value}")
try:
forceZ_value_float=float(forceZ_value)
command=['python3','./XYZ_Force_Sensor_test.py','--forcez',str(forceZ_value_float)]
self.process=subprocess.Popen(command)
print("XYZ_Force_Sensor_test started successfully...")
except ValueError:
messagebox.showerror("Error", "Please enter a valid number for the Z-axis force.")
else:
messagebox.showerror("Error", "Please enter a valid number for the Z-axis force.")
def run_otherScripts(self):
try:
self.status_label.config(text="Running CNC_Gcode...", fg="blue")
if subprocess.run(['python3', './CNC_Gcode.py']).returncode==0:
self.status_label.config(text="CNC_Gcode completed successfully.", fg="green")
print("CNC_Gcode started successfully...")
else:
self.status_label.config(text="Error while running CNC_Gcode.", fg="red")
print("error while running CNC_Gcode.")
self.status_label.config(text="Running Mux_Keithley_V3...", fg="blue")
if subprocess.run(['python3', './Mux_Keithley_V3.py']).returncode==0:
self.status_label.config(text="Mux_Keithley_V3 completed successfully.", fg="green")
print("Mux_Keithley_V3 started successfully...")
else:
self.status_label.config(text="Error while running Mux_Keithley_V3.", fg="red")
print("error while running Mux_Keithley_V3.")
except Exception as e :
self.status_label.config(text=f"Error starting scripts: {e}", fg="red")
messagebox.showerror("Error", f"Error starting Scripts: {e}")
if __name__ == "__main__":
app = MyGUI()
app.mainloop()