Untitled
unknown
plain_text
9 months ago
5.5 kB
7
Indexable
class ManualRotationScreen(ctk.CTkToplevel):
def __init__(self, parent, dark_mode: bool, language='EN', settings_menu=None):
super().__init__(parent)
self.language = getattr(parent, 'LANGUAGE', 'EN')
self.settings_menu = settings_menu
self._destroyed = False
self._closing = False
# Use CircularProgress's class-level turntable reference
self.turntable = CircularProgress._turntable
self.bin_config = BinConfiguration()
# Make it fullscreen and disable all close operations
self.overrideredirect(True)
self.geometry(f"{self.winfo_screenwidth()}x{self.winfo_screenheight()}+0+0")
self.protocol("WM_DELETE_WINDOW", lambda: None)
self.attributes('-topmost', True)
# Set colors to match main screen
self.dark_mode = dark_mode
self.bg_color = '#1c1c1e' if dark_mode else '#f5f5f7'
self.configure(fg_color=self.bg_color)
# Create title label
self.title_label = ctk.CTkLabel(
self,
text=TRANSLATIONS[self.language].get('manual_move_bin_text', 'Manual_Move_Bin_Text'),
font=("Dongle", 40, "bold"),
text_color='white' if dark_mode else 'black'
)
self.title_label.place(relx=0.5, rely=0.18, anchor='center')
# Create circles frame with transparent background
self.circles_frame = ctk.CTkFrame(self, fg_color="transparent")
self.circles_frame.place(relx=0.5, rely=0.5, anchor='center')
# Add padding frame with transparent background
self.padding_frame = ctk.CTkFrame(self.circles_frame, fg_color="transparent")
self.padding_frame.pack(padx=50)
# Create Grey Circles for each bin
for bin_config in self.bin_config.bins:
container = ctk.CTkFrame(self.padding_frame, fg_color="transparent")
container.pack(side='left', padx=15)
progress = RotationCircleButton(
container,
bin_id=bin_config['id'],
size=220,
language=language,
dark_mode=dark_mode,
command=lambda bid=bin_config['id']: self._rotate_to_position(bid)
)
progress.pack()
progress.set_dark_mode(dark_mode)
# Add close button
self.close_button = ctk.CTkLabel(
self,
text="×",
width=60,
height=60,
text_color='white' if dark_mode else 'black',
font=("Arial", 48, "bold"),
cursor="hand2"
)
self.close_button.place(relx=0.995, rely=0.01, anchor="ne")
self.close_button.bind("<Button-1>", self.handle_close)
self.close_button.bind("<Enter>", lambda e: self.close_button.configure(text_color="#ff3b30"))
self.close_button.bind("<Leave>", lambda e: self.close_button.configure(
text_color='white' if dark_mode else 'black'
))
# Close settings menu immediately
if self.settings_menu and self.settings_menu.is_open:
self.settings_menu.close_menu()
def handle_close(self, event=None):
"""Handle closing the screen safely with a delay"""
if self._closing or self._destroyed:
return
self._closing = True
self.after(250, self.destroy) # Add small delay before destroying
def _rotate_to_position(self, bin_id):
"""Rotate to the specified bin position"""
if self._closing or self._destroyed:
return
print(f"Starting rotation to {bin_id}")
if not self.turntable or not self.turntable.is_initialized:
print("No turntable controller available or not initialized")
MessageDialog(
self.winfo_toplevel(),
TRANSLATIONS[self.language].get('please_wait', 'Please wait'),
self.dark_mode
)
return
# Create loading screen
loading_screen = LoadingScreen(
self.winfo_toplevel(),
message=TRANSLATIONS[self.language].get('moving_bin', 'Moving to position...'),
dark_mode=self.dark_mode,
language=self.language
)
def perform_rotation():
try:
if self._destroyed:
return
# Calculate target position
target_position = self.turntable.positions[bin_id]
# Calculate and execute movement
steps, direction = self.turntable._calculate_steps(target_position)
self.turntable._move_motor(steps, direction)
self.turntable.current_position = target_position
# Close loading screen after movement completes
if not self._destroyed:
self.after(500, loading_screen.close)
except Exception as e:
print(f"Error during rotation: {e}")
if not self._destroyed:
self.after(0, loading_screen.close)
# Run rotation in separate thread
thread = threading.Thread(target=perform_rotation, daemon=True)
thread.start()Editor is loading...
Leave a Comment