# File menu file_menu = tk.Menu(menubar, tearoff=0) menubar.add_cascade(label="File", menu=file_menu) file_menu.add_command(label="Refresh Ports", command=lambda: app.port_combo.configure(values=app.get_serial_ports())) file_menu.add_separator() file_menu.add_command(label="Exit", command=root.quit)
def disconnect_printer(self): """Disconnect from printer""" if self.serial_port and self.serial_port.is_open: self.serial_port.close() self.connected = False self.serial_port = None self.status_label.config(text="● Disconnected", foreground="red") self.connect_btn.config(state=tk.NORMAL) self.disconnect_btn.config(state=tk.DISABLED) self.reset_pad_btn.config(state=tk.DISABLED) self.reset_all_btn.config(state=tk.DISABLED) self.log_message("Disconnected from printer") Epson L4150 L4160 L4170 Resetter Adjustment Program
def __init__(self, parent): self.parent = parent self.serial_port = None self.current_model = None self.connected = False self.setup_ui() def setup_ui(self): """Setup the main user interface""" self.parent.title("Epson Resetter Adjustment Program v2.0") self.parent.geometry("800x600") self.parent.resizable(True, True) # Set style style = ttk.Style() style.theme_use('clam') # Main container main_frame = ttk.Frame(self.parent, padding="10") main_frame.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S)) # Connection Frame conn_frame = ttk.LabelFrame(main_frame, text="Printer Connection", padding="10") conn_frame.grid(row=0, column=0, columnspan=2, sticky=(tk.W, tk.E), pady=5) ttk.Label(conn_frame, text="COM Port:").grid(row=0, column=0, sticky=tk.W) self.port_combo = ttk.Combobox(conn_frame, values=self.get_serial_ports(), width=15) self.port_combo.grid(row=0, column=1, padx=5) ttk.Label(conn_frame, text="Baud Rate:").grid(row=0, column=2, sticky=tk.W, padx=(20,0)) self.baud_combo = ttk.Combobox(conn_frame, values=[9600, 19200, 38400, 115200], width=10) self.baud_combo.set(9600) self.baud_combo.grid(row=0, column=3, padx=5) self.connect_btn = ttk.Button(conn_frame, text="Connect", command=self.connect_printer) self.connect_btn.grid(row=0, column=4, padx=10) self.disconnect_btn = ttk.Button(conn_frame, text="Disconnect", command=self.disconnect_printer, state=tk.DISABLED) self.disconnect_btn.grid(row=0, column=5) # Status indicator self.status_label = ttk.Label(conn_frame, text="● Disconnected", foreground="red") self.status_label.grid(row=0, column=6, padx=(20,0)) # Printer Info Frame info_frame = ttk.LabelFrame(main_frame, text="Printer Information", padding="10") info_frame.grid(row=1, column=0, columnspan=2, sticky=(tk.W, tk.E), pady=5) ttk.Label(info_frame, text="Model:").grid(row=0, column=0, sticky=tk.W) self.model_var = tk.StringVar() ttk.Label(info_frame, textvariable=self.model_var, font=("Arial", 10, "bold")).grid(row=0, column=1, sticky=tk.W) ttk.Label(info_frame, text="Firmware:").grid(row=0, column=2, sticky=tk.W, padx=(20,0)) self.firmware_var = tk.StringVar() ttk.Label(info_frame, textvariable=self.firmware_var).grid(row=0, column=3, sticky=tk.W) ttk.Label(info_frame, text="Serial:").grid(row=1, column=0, sticky=tk.W) self.serial_var = tk.StringVar() ttk.Label(info_frame, textvariable=self.serial_var).grid(row=1, column=1, sticky=tk.W) # Counter Display Frame counter_frame = ttk.LabelFrame(main_frame, text="Waste Ink Counters", padding="10") counter_frame.grid(row=2, column=0, columnspan=2, sticky=(tk.W, tk.E, tk.N, tk.S), pady=5) # Create treeview for counters columns = ('Counter', 'Current Value', 'Maximum', 'Percentage') self.counter_tree = ttk.Treeview(counter_frame, columns=columns, show='headings', height=5) for col in columns: self.counter_tree.heading(col, text=col) self.counter_tree.column(col, width=150) scrollbar = ttk.Scrollbar(counter_frame, orient=tk.VERTICAL, command=self.counter_tree.yview) self.counter_tree.configure(yscrollcommand=scrollbar.set) self.counter_tree.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S)) scrollbar.grid(row=0, column=1, sticky=(tk.N, tk.S)) ttk.Button(counter_frame, text="Refresh Counters", command=self.get_counters).grid(row=1, column=0, pady=10) # Reset Actions Frame reset_frame = ttk.LabelFrame(main_frame, text="Reset Operations", padding="10") reset_frame.grid(row=3, column=0, columnspan=2, sticky=(tk.W, tk.E), pady=5) # Reset buttons self.reset_pad_btn = ttk.Button(reset_frame, text="Reset Waste Ink Pad Counter", command=self.reset_pad_counter, state=tk.DISABLED, style="Danger.TButton") self.reset_pad_btn.grid(row=0, column=0, padx=5, pady=5) self.reset_all_btn = ttk.Button(reset_frame, text="Reset All Counters", command=self.reset_all_counters, state=tk.DISABLED) self.reset_all_btn.grid(row=0, column=1, padx=5, pady=5) # Progress bar self.progress = ttk.Progressbar(main_frame, mode='indeterminate') self.progress.grid(row=4, column=0, columnspan=2, sticky=(tk.W, tk.E), pady=10) # Log Frame log_frame = ttk.LabelFrame(main_frame, text="Operation Log", padding="10") log_frame.grid(row=5, column=0, columnspan=2, sticky=(tk.W, tk.E, tk.N, tk.S), pady=5) self.log_text = tk.Text(log_frame, height=10, wrap=tk.WORD) scroll_log = ttk.Scrollbar(log_frame, orient=tk.VERTICAL, command=self.log_text.yview) self.log_text.configure(yscrollcommand=scroll_log.set) self.log_text.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S)) scroll_log.grid(row=0, column=1, sticky=(tk.N, tk.S)) # Configure grid weights self.parent.columnconfigure(0, weight=1) self.parent.rowconfigure(0, weight=1) main_frame.columnconfigure(0, weight=1) main_frame.rowconfigure(2, weight=1) main_frame.rowconfigure(5, weight=1) counter_frame.columnconfigure(0, weight=1) counter_frame.rowconfigure(0, weight=1) log_frame.columnconfigure(0, weight=1) log_frame.rowconfigure(0, weight=1) # Create custom styles style.configure("Danger.TButton", foreground="red") def get_serial_ports(self): """Get list of available serial ports""" ports = serial.tools.list_ports.comports() return [port.device for port in ports] # File menu file_menu = tk