""" App Selection Frame UI component for selecting an app registration. """ import customtkinter as ctk from typing import List, Dict, Callable, Optional from ui.components import UnifiedDropdown class AppSelectionFrame(ctk.CTkFrame): """Frame for app registration selection.""" def __init__(self, parent, on_app_selected: Callable = None): """ Initialize the app selection frame. Args: parent: Parent widget on_app_selected: Callback function when an app is selected """ super().__init__(parent) self.on_app_selected = on_app_selected # Configure frame self.configure(corner_radius=10, border_width=2) # Create unified dropdown self.dropdown = UnifiedDropdown( self, title="App Registration Selection", on_selection_changed=self._on_app_selected, show_count=True, display_key='display_name', max_dropdown_height=400 ) self.dropdown.grid(row=0, column=0, sticky="ew") self.dropdown.set_placeholder("Please connect to Azure first") # Configure grid self.grid_columnconfigure(0, weight=1) def set_apps(self, apps: List[Dict[str, str]]): """ Set the list of applications. Args: apps: List of app dictionaries with 'id', 'app_id', and 'display_name' """ self.dropdown.set_items(apps) def _on_app_selected(self, app: Dict): """ Handle app selection. Args: app: The selected app dictionary """ if self.on_app_selected: self.on_app_selected(app) def get_selected_app(self) -> Optional[Dict[str, str]]: """ Get the currently selected app. Returns: Dict: Selected app or None """ return self.dropdown.get_selected() def set_enabled(self, enabled: bool): """ Enable or disable the frame. Args: enabled: Whether to enable the frame """ self.dropdown.set_enabled(enabled) def set_loading(self, loading: bool): """ Set loading state. Args: loading: Whether currently loading """ self.dropdown.set_loading(loading)