Untitled
unknown
plain_text
10 months ago
2.5 kB
5
Indexable
def create_main_interface():
root = ctk.CTk()
root.title("Bin Interface")
root.geometry("1024x600+0+0")
root.overrideredirect(True)
# Set dark mode (can be changed)
dark_mode = False
bg_color = '#1c1c1e' if dark_mode else '#f5f5f7'
# Initialize turntable
turntable = TurntableController()
CircularProgress.set_turntable(turntable)
# Create main frame
main_frame = ctk.CTkFrame(root, fg_color=bg_color)
main_frame.pack(fill='both', expand=True)
# Add close button
close_button = CloseButton(main_frame, command=lambda: cleanup_and_exit(root, turntable))
close_button.place(relx=0.05, rely=0.95, anchor='center')
# Create circles frame
circles_frame = ctk.CTkFrame(main_frame, fg_color=bg_color)
circles_frame.place(relx=0.5, rely=0.5, anchor='center')
# Add padding frame
padding_frame = ctk.CTkFrame(circles_frame, fg_color=bg_color)
padding_frame.pack(padx=50)
# Create four bins
for i in range(1, 5):
container = ctk.CTkFrame(padding_frame, fg_color=bg_color)
container.pack(side='left', padx=15)
progress = CircularProgress(
container,
bin_id=f'bin{i}',
size=220
)
progress.pack()
progress.set_dark_mode(dark_mode)
# Bind cleanup to window closing
root.protocol("WM_DELETE_WINDOW", lambda: cleanup_and_exit(root, turntable))
# Start calibration in separate thread
def calibration_thread_func():
turntable.calibrate()
print("Turntable calibration complete")
calibration_thread = threading.Thread(
target=calibration_thread_func,
daemon=True
)
calibration_thread.start()
return root
def cleanup_and_exit(root, turntable):
"""Clean up hardware and exit"""
print("Performing cleanup...")
try:
# Clean up turntable
if turntable:
turntable.cleanup()
# Destroy root window
root.destroy()
except Exception as e:
print(f"Error during cleanup: {e}")
try:
root.destroy()
except:
pass
def main():
try:
root = create_main_interface()
root.mainloop()
except Exception as e:
print(f"Error in main loop: {e}")
finally:
print("Application closed")
if __name__ == "__main__":
main()Editor is loading...
Leave a Comment