<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import os <EOL> import sys <EOL> import collections <EOL> from winpython . qt . QtGui import QFileDialog <EOL> from winpython . py3compat import is_text_string , to_text_string , TEXT_TYPES <EOL> PYQT_API_1 = False <EOL> if os . environ [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> import sip <EOL> try : <EOL> PYQT_API_1 = sip . getapi ( '<STR_LIT>' ) == <NUM_LIT:1> <EOL> except AttributeError : <EOL> PYQT_API_1 = True <EOL> def to_qvariant ( pyobj = None ) : <EOL> """<STR_LIT>""" <EOL> if PYQT_API_1 : <EOL> from PyQt4 . QtCore import QVariant <EOL> return QVariant ( pyobj ) <EOL> else : <EOL> return pyobj <EOL> def from_qvariant ( qobj = None , convfunc = None ) : <EOL> """<STR_LIT>""" <EOL> if PYQT_API_1 : <EOL> assert isinstance ( convfunc , collections . Callable ) <EOL> if convfunc in TEXT_TYPES or convfunc is to_text_string : <EOL> return convfunc ( qobj . toString ( ) ) <EOL> elif convfunc is bool : <EOL> return qobj . toBool ( ) <EOL> elif convfunc is int : <EOL> return qobj . toInt ( ) [ <NUM_LIT:0> ] <EOL> elif convfunc is float : <EOL> return qobj . toDouble ( ) [ <NUM_LIT:0> ] <EOL> else : <EOL> return convfunc ( qobj ) <EOL> else : <EOL> return qobj <EOL> else : <EOL> def to_qvariant ( obj = None ) : <EOL> """<STR_LIT>""" <EOL> return obj <EOL> def from_qvariant ( qobj = None , pytype = None ) : <EOL> """<STR_LIT>""" <EOL> return qobj <EOL> def getexistingdirectory ( parent = None , caption = '<STR_LIT>' , basedir = '<STR_LIT>' , <EOL> options = QFileDialog . ShowDirsOnly ) : <EOL> """<STR_LIT>""" <EOL> if sys . platform == "<STR_LIT:win32>" : <EOL> _temp1 , _temp2 = sys . stdout , sys . stderr <EOL> sys . stdout , sys . stderr = None , None <EOL> try : <EOL> result = QFileDialog . getExistingDirectory ( parent , caption , basedir , <EOL> options ) <EOL> finally : <EOL> if sys . platform == "<STR_LIT:win32>" : <EOL> sys . stdout , sys . stderr = _temp1 , _temp2 <EOL> if not is_text_string ( result ) : <EOL> result = to_text_string ( result ) <EOL> return result <EOL> def _qfiledialog_wrapper ( attr , parent = None , caption = '<STR_LIT>' , basedir = '<STR_LIT>' , <EOL> filters = '<STR_LIT>' , selectedfilter = '<STR_LIT>' , options = None ) : <EOL> if options is None : <EOL> options = QFileDialog . Options ( <NUM_LIT:0> ) <EOL> try : <EOL> from winpython . qt . QtCore import QString <EOL> except ImportError : <EOL> QString = None <EOL> tuple_returned = True <EOL> try : <EOL> func = getattr ( QFileDialog , attr + '<STR_LIT>' ) <EOL> except AttributeError : <EOL> func = getattr ( QFileDialog , attr ) <EOL> if QString is not None : <EOL> selectedfilter = QString ( ) <EOL> tuple_returned = False <EOL> if sys . platform == "<STR_LIT:win32>" : <EOL> _temp1 , _temp2 = sys . stdout , sys . stderr <EOL> sys . stdout , sys . stderr = None , None <EOL> try : <EOL> result = func ( parent , caption , basedir , <EOL> filters , selectedfilter , options ) <EOL> except TypeError : <EOL> result = func ( parent , caption , basedir , filters , options ) <EOL> finally : <EOL> if sys . platform == "<STR_LIT:win32>" : <EOL> sys . stdout , sys . stderr = _temp1 , _temp2 <EOL> if tuple_returned : <EOL> output , selectedfilter = result <EOL> else : <EOL> output = result <EOL> if QString is not None : <EOL> selectedfilter = to_text_string ( selectedfilter ) <EOL> if isinstance ( output , QString ) : <EOL> output = to_text_string ( output ) <EOL> else : <EOL> output = [ to_text_string ( fname ) for fname in output ] <EOL> return output , selectedfilter <EOL> def getopenfilename ( parent = None , caption = '<STR_LIT>' , basedir = '<STR_LIT>' , filters = '<STR_LIT>' , <EOL> selectedfilter = '<STR_LIT>' , options = None ) : <EOL> """<STR_LIT>""" <EOL> return _qfiledialog_wrapper ( '<STR_LIT>' , parent = parent , <EOL> caption = caption , basedir = basedir , <EOL> filters = filters , selectedfilter = selectedfilter , <EOL> options = options ) <EOL> def getopenfilenames ( parent = None , caption = '<STR_LIT>' , basedir = '<STR_LIT>' , filters = '<STR_LIT>' , <EOL> selectedfilter = '<STR_LIT>' , options = None ) : <EOL> """<STR_LIT>""" <EOL> return _qfiledialog_wrapper ( '<STR_LIT>' , parent = parent , <EOL> caption = caption , basedir = basedir , <EOL> filters = filters , selectedfilter = selectedfilter , <EOL> options = options ) <EOL> def getsavefilename ( parent = None , caption = '<STR_LIT>' , basedir = '<STR_LIT>' , filters = '<STR_LIT>' , <EOL> selectedfilter = '<STR_LIT>' , options = None ) : <EOL> """<STR_LIT>""" <EOL> return _qfiledialog_wrapper ( '<STR_LIT>' , parent = parent , <EOL> caption = caption , basedir = basedir , <EOL> filters = filters , selectedfilter = selectedfilter , <EOL> options = options ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from winpython . utils . qthelpers import qapplication <EOL> _app = qapplication ( ) <EOL> print ( repr ( getexistingdirectory ( ) ) ) <EOL> print ( repr ( getopenfilename ( filters = '<STR_LIT>' ) ) ) <EOL> print ( repr ( getopenfilenames ( filters = '<STR_LIT>' ) ) ) <EOL> print ( repr ( getsavefilename ( filters = '<STR_LIT>' ) ) ) <EOL> sys . exit ( ) </s>
