[docs]classConfirmScreen(ModalScreen[bool]):"""Ask before an irreversible action and default to declining it."""DEFAULT_CSS=_CONFIRM_DIALOG_CSSBINDINGS:ClassVar=[Binding("escape","decline","",show=False),Binding("y","confirm","",show=False)]def__init__(self,*,title:str,message:str,confirm_label:str,cancel_label:str)->None:"""Store the localized confirmation copy."""super().__init__()self._title=titleself._message=messageself._confirm_label=confirm_labelself._cancel_label=cancel_label
[docs]defon_mount(self)->None:"""Focus the safe declining action first."""self.query_one("#btn-confirm-cancel",Button).focus()
[docs]defon_button_pressed(self,event:Button.Pressed)->None:"""Dismiss with the selected confirmation state."""self.dismiss(event.button.id=="btn-confirm-accept")
[docs]defaction_decline(self)->None:"""Dismiss without approving the action."""self.dismiss(False)
[docs]defaction_confirm(self)->None:"""Dismiss with explicit approval."""self.dismiss(True)