<s> from pyface . qt import QtCore , QtGui <EOL> from traits . api import Bool , Dict , Enum , Instance , provides , Unicode <EOL> from pyface . i_confirmation_dialog import IConfirmationDialog , MConfirmationDialog <EOL> from pyface . constant import CANCEL , YES , NO <EOL> from pyface . image_resource import ImageResource <EOL> from . dialog import Dialog , _RESULT_MAP <EOL> @ provides ( IConfirmationDialog ) <EOL> class ConfirmationDialog ( MConfirmationDialog , Dialog ) : <EOL> """<STR_LIT>""" <EOL> cancel = Bool ( False ) <EOL> default = Enum ( NO , YES , CANCEL ) <EOL> image = Instance ( ImageResource ) <EOL> message = Unicode <EOL> informative = Unicode <EOL> detail = Unicode <EOL> no_label = Unicode <EOL> yes_label = Unicode <EOL> _button_result_map = Dict ( ) <EOL> def _create_contents ( self , parent ) : <EOL> pass <EOL> def _create_control ( self , parent ) : <EOL> dlg = QtGui . QMessageBox ( parent ) <EOL> dlg . setWindowTitle ( self . title ) <EOL> dlg . setText ( self . message ) <EOL> dlg . setInformativeText ( self . informative ) <EOL> dlg . setDetailedText ( self . detail ) <EOL> if self . image is None : <EOL> dlg . setIcon ( QtGui . QMessageBox . Warning ) <EOL> else : <EOL> dlg . setIconPixmap ( self . image . create_image ( ) ) <EOL> if self . yes_label : <EOL> btn = dlg . addButton ( self . yes_label , QtGui . QMessageBox . YesRole ) <EOL> else : <EOL> btn = dlg . addButton ( QtGui . QMessageBox . Yes ) <EOL> self . _button_result_map [ btn ] = YES <EOL> if self . default == YES : <EOL> dlg . setDefaultButton ( btn ) <EOL> if self . no_label : <EOL> btn = dlg . addButton ( self . no_label , QtGui . QMessageBox . NoRole ) <EOL> else : <EOL> btn = dlg . addButton ( QtGui . QMessageBox . No ) <EOL> self . _button_result_map [ btn ] = NO <EOL> if self . default == NO : <EOL> dlg . setDefaultButton ( btn ) <EOL> if self . cancel : <EOL> if self . cancel_label : <EOL> btn = dlg . addButton ( self . cancel_label , QtGui . QMessageBox . RejectRole ) <EOL> else : <EOL> btn = dlg . addButton ( QtGui . QMessageBox . Cancel ) <EOL> self . _button_result_map [ btn ] = CANCEL <EOL> if self . default == CANCEL : <EOL> dlg . setDefaultButton ( btn ) <EOL> return dlg <EOL> def _show_modal ( self ) : <EOL> self . control . setWindowModality ( QtCore . Qt . ApplicationModal ) <EOL> retval = self . control . exec_ ( ) <EOL> if self . control is None : <EOL> if self . cancel : <EOL> return CANCEL <EOL> return self . default <EOL> clicked_button = self . control . clickedButton ( ) <EOL> if clicked_button in self . _button_result_map : <EOL> retval = self . _button_result_map [ clicked_button ] <EOL> else : <EOL> retval = _RESULT_MAP [ retval ] <EOL> return retval </s>
