我在ipython / jupyter浏览器单元格中有以下代码段。 当我第一次运行这个单元格时,我正确打开了PySide QT文件对话框 但是,当我第二次运行此单元格时,文件对话框将显示在浏览器窗口下。
-thanks提前
from PySide import QtGui, QtCore
def file_select(dir=None, dirSelect=False, parent=None):
"""
Select a file via a dialog and return the file name.
"""
if dir is None:
dir = './'
app = QtGui.QApplication.instance()
if not app:
app = QtGui.QApplication([dir])
retVal=None
try:
dlgTitle = 'Select Directory' if dirSelect else 'Select File'
dialog = QtGui.QFileDialog(parent, dlgTitle)
if dirSelect:
dialog.setFileMode(QtGui.QFileDialog.Directory)
dialog.setOption(QtGui.QFileDialog.ShowDirsOnly, True)
if dialog.exec_():
fileNames = dialog.selectedFiles()
selected_file = fileNames[0]
retVal = str(selected_file)
finally:
pass
return retVal
file_select('./', dirSelect= True)
其他细节,
pip list
给出
backports-abc (0.4)
backports.shutil-get-terminal-size (1.0.0)
backports.ssl-match-hostname (3.5.0.1)
certifi (2016.2.28)
cffi (1.6.0)
configparser (3.3.0.post2)
cryptography (1.3.2)
cycler (0.10.0)
decorator (4.0.9)
entrypoints (0.2.1)
enum34 (1.1.4)
filelock (2.0.6)
functools32 (3.2.3.post2)
futures (3.0.5)
h5py (2.6.0)
idna (2.1)
ipaddress (1.0.16)
ipykernel (4.3.1)
ipyparallel (5.0.1)
ipython (4.2.0)
ipython-genutils (0.1.0)
ipywidgets (5.1.3)
Jinja2 (2.8)
jsonschema (2.5.1)
jupyter (1.0.0)
jupyter-client (4.2.2)
jupyter-console (4.1.1)
jupyter-core (4.1.0)
MarkupSafe (0.23)
matplotlib (1.5.1)
mistune (0.7.2)
nbconvert (4.2.0)
nbformat (4.0.1)
ndg-httpsclient (0.4.0)
nose (1.3.7)
notebook (4.2.0)
numpy (1.11.0)
pathlib2 (2.1.0)
pexpect (4.0.1)
pickleshare (0.7.2)
pip (8.1.1)
protobuf (2.6.1)
psutil (4.1.0)
ptyprocess (0.5.1)
pyasn1 (0.1.9)
pycparser (2.14)
Pygments (2.1.3)
pyOpenSSL (16.0.0)
pyparsing (2.1.1)
PySide (1.2.4)
Python-contrib-nbextensions (alpha)
python-dateutil (2.5.3)
pytz (2016.4)
PyYAML (3.11)
pyzmq (15.2.0)
qtconsole (4.2.1)
setuptools (21.0.0)
simplegeneric (0.8.1)
singledispatch (3.4.0.3)
six (1.10.0)
terminado (0.6)
tornado (4.3)
traitlets (4.2.1)
wheel (0.29.0)
widgetsnbextension (1.2.2)