TrainDrive
unknown
python
3 years ago
8.7 kB
9
Indexable
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
import serial
class TrainDriveApp:
## Funkce pro kontaktování nrf a přidání nových modelů do seznamu na kartě domů
"""
def find_and_add_model(self):
try:
with serial.Serial('COM3', 9600, timeout=1) as ser: # změň 'COM3' na port, na kterém je modul připojen
ser.write(b'find_models') # příkaz pro zjištění modelů
response = ser.readline().decode('utf-8').strip() # přečtení odpovědi ze sériového portu
if not response:
messagebox.showinfo("Nenalezeny žádné nové modely", f"Nebyly nalezeny žádné nové modely v dosahu.")
else:
new_models = response.split(',')
self.model_combobox.insert(tk.END, *new_models)
messagebox.showinfo("Nové modely nalezeny", f"Byly nalezeny nové modely: {', '.join(new_models)}.")
except Exception as e:
messagebox.showerror("Chyba", f"Modul nrf24l01 není připojen na USB. \n\n{e}")
return
"""
model_tabs = []
def __init__(self, master):
# Vytvoření okna
pismo="Courier New"
self.master = master
self.master.title("TrainDrive")
self.tab_control = ttk.Notebook(self.master)
self.home_tab = ttk.Frame(self.tab_control)
self.tab_control.add(self.home_tab, text='Domů')
self.tab_control.pack(expand=1, fill='both')
# Add Model Section
self.add_model_frame = ttk.Frame(self.home_tab)
self.add_model_frame.pack(side=tk.TOP, pady=20)
ttk.Label(self.add_model_frame, text='Přidat nový model:').pack(side=tk.LEFT, padx=10)
find_add_button = tk.Button(self.add_model_frame, text='Najít a přidat model') ## command=self.find_and_add_model
find_add_button.pack(side=tk.LEFT, padx=10)
# Train Model Section
self.train_frame = ttk.Frame(self.home_tab)
self.train_frame.pack(side=tk.TOP, pady=20)
ttk.Label(self.train_frame, text='Výběr modelu:').pack(side=tk.LEFT, padx=10)
models = ['Model 1', 'Model 2'] # replace with code to get list of models
self.model_combobox = ttk.Combobox(self.train_frame, values=models)
self.model_combobox.pack(side=tk.LEFT, padx=10)
def add_model_tab():
model_name = self.model_combobox.get()
if model_name in self.model_tabs:
# Pokud již záložka pro model existuje, zobrazí se upozornění
messagebox.showerror("Upozornění", f"Záložka pro model {model_name} již existuje.")
pass
elif model_name == "":
messagebox.showerror("Upozornění", f"Nebyl vybrán žádný model.")
pass
else:
# Pokud záložka pro model neexistuje, vytvoří se nová záložka
# získání názvu modelu z comboboxu
self.model_tabs.append(model_name)
# vytvoření nové záložky s názvem modelu
self.train_tab = ttk.Frame(self.tab_control)
self.tab_control.add(self.train_tab, text=model_name)
# Model Name
ttk.Label(self.train_tab, text=model_name, font=(pismo, 18)).grid(row=0, column=0, pady=5)
# Horizontal Separator
ttk.Separator(self.train_tab, orient='horizontal').grid(row=1, column=0, pady=2)
# Collectors Section
self.collectors_frame = ttk.Frame(self.train_tab)
self.collectors_frame.grid(row=2, column=0, pady=20)
ttk.Label(self.collectors_frame, text='Sběrač 1', font=(pismo,12)).grid(row=3, column=0, padx=10)
ttk.Label(self.collectors_frame, text='Sběrač 2', font=(pismo,12)).grid(row=3, column=1, padx=10)
ttk.Button(self.collectors_frame, text='Nahoru').grid(row=4, column=0, padx=10)
ttk.Button(self.collectors_frame, text='Dolů').grid(row=5, column=0, padx=10,)
ttk.Button(self.collectors_frame, text='Nahoru').grid(row=4, column=1, padx=10)
ttk.Button(self.collectors_frame, text='Dolů').grid(row=5, column=1, padx=10)
ttk.Separator(self.train_tab, orient='horizontal').grid(row=6, column=0)
#světla
self.lights_frame = ttk.Frame(self.train_tab)
self.lights_frame.grid(row=7, column=0, pady=10)
ttk.Button(self.lights_frame, text='S1', style='White.TButton').grid(row=0, column=0, padx=5)
ttk.Button(self.lights_frame, text='S2', style='Red.TButton').grid(row=0, column=1, padx=5)
ttk.Button(self.lights_frame, text='S3', style='Red.TButton').grid(row=0, column=2, padx=5)
ttk.Button(self.lights_frame, text='S4', style='White.TButton').grid(row=0, column=3, padx=5)
ttk.Button(self.lights_frame, text='S5', style='White.TButton').grid(row=0, column=4, padx=5)
ttk.Button(self.lights_frame, text='S6', style='Red.TButton').grid(row=0, column=5, padx=5)
ttk.Button(self.lights_frame, text='S7', style='Red.TButton').grid(row=0, column=6, padx=5)
ttk.Button(self.lights_frame, text='S8', style='White.TButton').grid(row=0, column=7, padx=5)
# Horizontal Separator
ttk.Separator(self.train_tab, orient='horizontal').grid(row=9, column=0, pady=5)
# Vertical Section
self.speed_direction_frame = ttk.Frame(self.train_tab)
self.speed_direction_frame.grid(row=10, column=0, pady=10)
ttk.Label(self.speed_direction_frame, text='Rychlost:').grid(row=0, column=0, padx=5, pady=5, sticky='w')
self.speed_slider = ttk.Scale(self.speed_direction_frame, from_=0, to=100, length=400, orient='horizontal')
self.speed_slider.grid(row=1, column=0, padx=5, pady=5)
ttk.Button(self.speed_direction_frame, text='Směr').grid(row=2, column=0, padx=5, pady=5, sticky='w')
ttk.Button(self.speed_direction_frame, text='Potvrdit').grid(row=2, column=0, padx=5, pady=5, sticky='e')
# Vertical Separator
ttk.Separator(self.train_tab, orient='vertical').grid(row=2, column=1, rowspan=8, padx=20)
# Horizontal Section
self.interior_lights_frame = ttk.Frame(self.train_tab)
self.interior_lights_frame.grid(row=11, column=0, pady=20)
ttk.Button(self.interior_lights_frame, text='Zapnout/Vypnout interiérové světlo').grid(row=0, column=0, padx=5, pady=5)
# RFID Section
self.rfid_frame = ttk.Frame(self.train_tab)
self.rfid_frame.grid(row=12, column=0, pady=20)
ttk.Label(self.rfid_frame, text='RFID Tag 1:').grid(row=0, column=0, padx=5, pady=5, sticky='w')
ttk.Label(self.rfid_frame, text='RFID Tag 2:').grid(row=1, column=0, padx=5, pady=5, sticky='w')
ttk.Label(self.rfid_frame, text='RFID Tag 3:').grid(row=2, column=0, padx=5, pady=5, sticky='w')
ttk.Label(self.rfid_frame, text='Čas přijmu:').grid(row=0, column=1, padx=5, pady=5, sticky='e')
ttk.Label(self.rfid_frame, text='Čas přijmu:').grid(row=1, column=1, padx=5, pady=5, sticky='e')
ttk.Label(self.rfid_frame, text='Čas přijmu:').grid(row=2, column=1, padx=5, pady=5, sticky='e')
# Status Bar
self.status_bar = ttk.Frame(self.train_tab)
self.status_bar.grid(row=13, column=0, pady=10, sticky='we')
ttk.Label(self.status_bar, text='Stav spojení:').grid(row=0, column=0, padx=10, pady=5, sticky='w')
ttk.Label(self.status_bar, text='Stav baterie:').grid(row=0, column=2, padx=10, pady=5, sticky='e')
self.connection_status = ttk.Label(self.status_bar, text='OK')
self.connection_status.grid(row=0, column=1, padx=10, pady=5)
self.battery_status = ttk.Label(self.status_bar, text='100%')
pass
add_tab_button = ttk.Button(self.train_frame, text='Přidat kartu', command=add_model_tab)
add_tab_button.pack(side=tk.LEFT, padx=10)
root = tk.Tk()
main = TrainDriveApp(master=root)
root.mainloop()Editor is loading...