<s> from atom . api import Int , Typed <EOL> from enaml . widgets . file_dialog_ex import ProxyFileDialogEx <EOL> from . QtGui import QFileDialog <EOL> from . qt_toolkit_dialog import QtToolkitDialog <EOL> ACCEPT_MODE = { <EOL> '<STR_LIT>' : QFileDialog . AcceptOpen , <EOL> '<STR_LIT>' : QFileDialog . AcceptSave , <EOL> } <EOL> FILE_MODE = { <EOL> '<STR_LIT>' : QFileDialog . AnyFile , <EOL> '<STR_LIT>' : QFileDialog . ExistingFile , <EOL> '<STR_LIT>' : QFileDialog . ExistingFiles , <EOL> '<STR_LIT>' : QFileDialog . Directory , <EOL> } <EOL> PATH_GUARD = <NUM_LIT> <EOL> FILTER_GUARD = <NUM_LIT> <EOL> class QtFileDialogEx ( QtToolkitDialog , ProxyFileDialogEx ) : <EOL> """<STR_LIT>""" <EOL> widget = Typed ( QFileDialog ) <EOL> _guard = Int ( <NUM_LIT:0> ) <EOL> def create_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> self . widget = QFileDialog ( self . parent_widget ( ) ) <EOL> def init_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( QtFileDialogEx , self ) . init_widget ( ) <EOL> d = self . declaration <EOL> self . set_accept_mode ( d . accept_mode ) <EOL> self . set_file_mode ( d . file_mode ) <EOL> self . set_show_dirs_only ( d . show_dirs_only ) <EOL> self . set_current_path ( d . current_path ) <EOL> self . set_name_filters ( d . name_filters ) <EOL> self . set_selected_name_filter ( d . selected_name_filter ) <EOL> widget = self . widget <EOL> widget . currentChanged . connect ( self . on_current_changed ) <EOL> widget . filesSelected . connect ( self . on_files_selected ) <EOL> widget . filterSelected . connect ( self . on_filter_selected ) <EOL> def get_default_title ( self ) : <EOL> """<STR_LIT>""" <EOL> widget = self . widget <EOL> if widget . acceptMode ( ) == QFileDialog . AcceptOpen : <EOL> if widget . fileMode ( ) == QFileDialog . Directory : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' <EOL> def on_current_changed ( self , path ) : <EOL> """<STR_LIT>""" <EOL> d = self . declaration <EOL> if d is not None : <EOL> self . _guard |= PATH_GUARD <EOL> try : <EOL> d . current_path = path <EOL> finally : <EOL> self . _guard &= ~ PATH_GUARD <EOL> def on_files_selected ( self , paths ) : <EOL> """<STR_LIT>""" <EOL> d = self . declaration <EOL> if d is not None : <EOL> d . selected_paths = paths <EOL> def on_filter_selected ( self , selected ) : <EOL> """<STR_LIT>""" <EOL> d = self . declaration <EOL> if d is not None : <EOL> self . _guard |= FILTER_GUARD <EOL> try : <EOL> d . selected_name_filter = selected <EOL> finally : <EOL> self . _guard &= ~ FILTER_GUARD <EOL> def set_accept_mode ( self , mode ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setAcceptMode ( ACCEPT_MODE [ mode ] ) <EOL> def set_file_mode ( self , mode ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setFileMode ( FILE_MODE [ mode ] ) <EOL> def set_show_dirs_only ( self , show ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setOption ( QFileDialog . ShowDirsOnly , show ) <EOL> def set_current_path ( self , path ) : <EOL> """<STR_LIT>""" <EOL> if not self . _guard & PATH_GUARD : <EOL> self . widget . selectFile ( path ) <EOL> def set_name_filters ( self , filters ) : <EOL> """<STR_LIT>""" <EOL> self . widget . setNameFilters ( filters ) <EOL> def set_selected_name_filter ( self , selected ) : <EOL> """<STR_LIT>""" <EOL> if not self . _guard & FILTER_GUARD : <EOL> self . widget . selectNameFilter ( selected ) <EOL> def exec_native ( self ) : <EOL> """<STR_LIT>""" <EOL> d = self . declaration <EOL> path = d . current_path <EOL> caption = d . title <EOL> filters = '<STR_LIT>' . join ( d . name_filters ) <EOL> selected_filter = d . selected_name_filter <EOL> parent = self . parent_widget ( ) <EOL> if d . file_mode == '<STR_LIT>' : <EOL> path = QFileDialog . getExistingDirectory ( parent , caption , path ) <EOL> paths = [ path ] if path else [ ] <EOL> elif d . accept_mode == '<STR_LIT>' : <EOL> path , selected_filter = QFileDialog . getSaveFileNameAndFilter ( <EOL> parent , caption , path , filters , selected_filter <EOL> ) <EOL> paths = [ path ] if path else [ ] <EOL> elif d . file_mode == '<STR_LIT>' : <EOL> paths , selected_filter = QFileDialog . getOpenFileNamesAndFilter ( <EOL> parent , caption , path , filters , selected_filter <EOL> ) <EOL> else : <EOL> path , selected_filter = QFileDialog . getOpenFileNameAndFilter ( <EOL> parent , caption , path , filters , selected_filter <EOL> ) <EOL> paths = [ path ] if path else [ ] <EOL> if paths : <EOL> self . on_current_changed ( paths [ <NUM_LIT:0> ] ) <EOL> self . on_filter_selected ( selected_filter ) <EOL> self . on_files_selected ( paths ) <EOL> d . _proxy_finished ( bool ( paths ) ) </s>
