import tkinter as tk from tkinter import ttk from shared_libs.wp_app_config import Msg class TunnelList(ttk.Frame): def __init__(self, container, selection_callback, **kwargs): super().__init__(container, **kwargs) self.list_frame = ttk.LabelFrame(self, text=Msg.STR["tunnels"]) self.list_frame.grid( column=0, row=0, sticky="nsew", padx=(10, 0), pady=(0, 8)) self.list_box = tk.Listbox(self.list_frame, selectmode="single") self.list_box.config( relief="flat", font=("Ubuntu", 12, "bold"), ) self.list_box.grid(column=0, row=0, sticky="nsew") self.list_box.event_add("<>", "") self.list_box.bind("<>", selection_callback) self.scrollbar = ttk.Scrollbar( self.list_frame, orient="vertical", command=self.list_box.yview ) self.scrollbar.grid(column=1, row=0, sticky="ns") self.list_box.configure(yscrollcommand=self.scrollbar.set) self.columnconfigure(0, weight=5) self.rowconfigure(0, weight=5) self.list_frame.columnconfigure(0, weight=5) self.list_frame.rowconfigure(0, weight=5) def populate(self, tunnels): self.list_box.delete(0, tk.END) for tunnel in tunnels: self.list_box.insert("end", tunnel) self.list_box.update() def get_selected(self): selection_indices = self.list_box.curselection() if not selection_indices: return None return self.list_box.get(selection_indices[0]) def get_size(self): return self.list_box.size() def set_selection(self, index): self.list_box.selection_clear(0, tk.END) self.list_box.selection_set(index) def delete_selected(self): selection_indices = self.list_box.curselection() if selection_indices: self.list_box.delete(selection_indices[0])