本文整理汇总了Python中PyQt5.QtWidgets.QFileDialog.getOpenFileName方法的典型用法代码示例。如果您正苦于以下问题:Python QFileDialog.getOpenFileName方法的具体用法?Python QFileDialog.getOpenFileName怎么用?Python QFileDialog.getOpenFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QFileDialog
的用法示例。
在下文中一共展示了QFileDialog.getOpenFileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _open_img
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def _open_img(self):
'''
打开图片
'''
self.path_img,_=QFileDialog.getOpenFileName(self.centralWidget,'打开图片文件','./','Image Files(*.png *.jpg *.bmp)')
if self.path_img and os.path.exists(self.path_img):
print(self.path_img)
self.im_bgr,self.temp_bgr,self.faces=self.mu.read_and_mark(self.path_img)
self.im_ori,self.previous_bgr=self.im_bgr.copy(),self.im_bgr.copy()
self._set_statu(self.bg_edit,True)
self._set_statu(self.bg_op,True)
self._set_statu(self.bg_result,True)
self._set_statu(self.sls,True)
self._set_img()
else:
QMessageBox.warning(self.centralWidget,'无效路径','无效路径,请重新选择!')
示例2: __import_presets
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def __import_presets(self):
archive, _ = QFileDialog.getOpenFileName(self, filter='*.presets')
if archive != '':
try:
if import_has_conflicts(archive):
answer = QMessageBox.question(
self,
translate('Presets', 'Presets'),
translate('Presets', 'Some presets already exists, '
'overwrite?'),
buttons=QMessageBox.Yes | QMessageBox.Cancel)
if answer != QMessageBox.Yes:
return
import_presets(archive)
self.__populate()
except PresetImportError as e:
QDetailedMessageBox.dcritical(
translate('Presets', 'Presets'),
translate('Presets', 'Cannot import correctly.'),
str(e),
parent=self
)
示例3: set_xls_BH
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def set_xls_BH(self):
# Ask the user to select a .xlsx file to load
load_path = str(
QFileDialog.getOpenFileName(
self,
self.tr("Load file"),
split(abs_file_path(self.mat.path, is_check=False))[0],
"Excel (*.xlsx *.xls)",
)[0]
)
if load_path is not None:
self.mat.mag.BH_curve = ImportMatrixXls(
file_path=rel_file_path(load_path, "MATLIB_DIR"),
sheet="BH",
is_transpose=False,
skiprows=0,
usecols=None,
)
self.in_BH_file.setText(split(load_path)[1])
self.b_plot.setEnabled(True)
示例4: gui_fname
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def gui_fname(dir=None):
"""
Select a file via a dialog and return the file name.
"""
try:
from PyQt5.QtWidgets import QApplication, QFileDialog
except ImportError:
try:
from PyQt4.QtGui import QApplication, QFileDialog
except ImportError:
from PySide.QtGui import QApplication, QFileDialog
if dir is None:
dir = './'
app = QApplication([dir])
fname = QFileDialog.getOpenFileName(None, "Select a file...",
dir, filter="All files (*)")
if isinstance(fname, tuple):
return fname[0]
else:
return str(fname)
示例5: open_file
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def open_file(self):
if in_pyqt5:
_DataFilePath=str(QFileDialog.getOpenFileName(filter="*.h5")[0])
if in_pyqt4:
_DataFilePath=str(QFileDialog.getOpenFileName(filter="*.h5"))
if _DataFilePath:
self.DATA.DataFilePath = _DataFilePath
self.h5file= h5py.File(self.DATA.DataFilePath,mode='r')
self.DATA.filename = self.h5file.filename.split(os.path.sep)[-1]
self.populate_data_list()
self.h5file.close()
s = (self.DATA.DataFilePath.split(os.path.sep)[-5:])
self.statusBar().showMessage((os.path.sep).join(s for s in s))
title = "Qviewkit: %s"%(self.DATA.DataFilePath.split(os.path.sep)[-1:][0][:6])
self.setWindowTitle(title)
示例6: load_image
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def load_image(self):
'''
加载原图
'''
try:
im_path,_=QFileDialog.getOpenFileName(self,'打开图片文件','./','Image Files(*.png *.jpg *.bmp)')
if not os.path.exists(im_path):
return
self.im_path=im_path
self.statu_text.append('打开图片文件:'+self.im_path)
if not self.swapper:
self.swapper=Coupleswapper([self.im_path])
elif not self.im_path== self.cur_im_path:
self.swapper.load_heads([self.im_path])
self.img_ori=self.swapper.heads[os.path.split(self.im_path)[-1]][0]
cv2.imshow('Origin',self.img_ori)
except (TooManyFaces,NoFace):
self.statu_text.append(traceback.format_exc()+'\n人脸定位失败,请重新选择!保证照片中有两张可识别的人脸。')
return
示例7: on_pbTessExec_clicked
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def on_pbTessExec_clicked(self):
fileFilter = self.tr("All files (*);;")
if sys.platform == "win32":
fileFilter = self.tr("Executables (*.exe);;") + fileFilter
getFileName = QFileDialog.getOpenFileName
filename = getFileName(self,
self.tr("Select tesseract-ocr executable..."),
self.ui.lnTessExec.text(),
fileFilter)
if not filename:
return
else:
print('fileFilter', fileFilter)
print('filename', type(filename), filename)
self.ui.lnTessExec.setText(filename[0])
示例8: load
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def load(self, path=None):
if self.unsavedCheck():
if path is None:
path = QFileDialog.getOpenFileName(None, 'Load motor', '', 'Motor Files (*.ric)')[0]
if path != '': # If they cancel the dialog, path will be an empty string
try:
res = loadFile(path, fileTypes.MOTOR)
if res is not None:
motor = motorlib.motor.Motor()
motor.applyDict(res)
self.startFromMotor(motor, path)
return True
except Exception as exc:
self.app.outputException(exc, "An error occurred while loading the file: ")
return False # If no file is loaded, return false
# Return the recent end of the motor history
示例9: on_loadfile_model_released
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def on_loadfile_model_released(self):
pwd = os.getcwd()
self.corr_file6, _ = (QFileDialog.getOpenFileName(
self, "Choose *.nd", pwd,"Model file (*.nd);;"))
if not self.corr_file6:
return
if self.corr_file6.endswith('.nd'):
self.ui.label_58.setText(os.path.basename(self.corr_file6))
filename7 = DIR2 + '/input_files/model_file.nd'
shutil.copy2(self.corr_file6,filename7)
else:
raise IOError('unknown file type *.%s' %
self.corr_file6.split('.')[-1])
################################################################
# TOOLS FOR TIME
################################################################
示例10: on_loadfile_spec_released
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def on_loadfile_spec_released(self):
pwd = os.getcwd()
self.spectre_file, _ = (QFileDialog.getOpenFileName(
self, "Choose *.xyz", pwd,"Map file (*.xyz);;"))
if not self.spectre_file:
return
if self.spectre_file.endswith('.xyz'):
self.ui.label_31.setText(os.path.basename(self.spectre_file))
filename6 = DIR2 + '/input_files/map_file.xyz'
shutil.copy2(self.spectre_file,filename6)
else:
raise IOError('unknown file type *.%s' %
self.spectre_file.split('.')[-1])
################################################################
# TOOLS FOR CORRELATION
################################################################
示例11: getFile
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def getFile(self, lineEdit):
lineEdit.setText(QFileDialog.getOpenFileName()[0])
示例12: loadEquations
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def loadEquations(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
fileName, _ = QFileDialog.getOpenFileName(self, "Add Custom Equations", "", "All Files (*);;Visma Files (*.vis)", options=options)
if os.path.isfile(fileName):
if os.path.getsize(fileName) == 0:
return self.workSpace.warning("Input equations file is empty!")
if self.workSpace.equations[0][0] == "No equations stored":
self.workSpace.equations.pop(0)
with open(fileName) as fileobj:
for line in fileobj:
line = line.replace(' ', '').replace('\n', '')
if not any(line in item for item in self.workSpace.equations) and not (line.isspace() or line == ''):
self.workSpace.equations.insert(0, ('Equation No.' + str(len(self.workSpace.equations) + 1), line))
self.workSpace.addEquation()
示例13: on_btnDLL_clicked
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def on_btnDLL_clicked(self):
dllpath, filter = QFileDialog.getOpenFileName(caption='JLink_x64.dll路径', filter='动态链接库文件 (*.dll)', directory=self.linDLL.text())
if dllpath != '':
self.linDLL.setText(dllpath)
示例14: changeAria2Path
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def changeAria2Path(self, button):
cwd = sys.argv[0]
cwd = os.path.dirname(cwd)
f_path, filters = QFileDialog.getOpenFileName(
self, 'Select aria2 path', cwd)
# if path is correct:
if os.path.isfile(str(f_path)):
self.aria2_path_lineEdit.setText(str(f_path))
else:
self.aria2_path_checkBox.setChecked(False)
示例15: dialog_open_lattice
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def dialog_open_lattice(self):
"""Read lattice from file"""
filename = QFileDialog.getOpenFileName(self.mw, 'Open Lattice', '', "Python Files (*.py);;All Files (*)", options=QFileDialog.DontUseNativeDialog)[0]
if filename == '':
return 0
self.mw.lattice = GUILattice()
# executing opened file
loc_dict = {}
try:
exec(open(filename).read(), globals(), loc_dict)
except Exception as err:
self.mw.error_window('Open Lattice File Error', str(err))
# parsing sequences and create elements list from cell
if 'cell' in loc_dict:
self.mw.lattice.cell = deepcopy(loc_dict['cell'])
lp = Parser()
self.mw.lattice.elements = lp.get_elements(self.mw.lattice.cell)
else:
self.mw.error_window('Open Lattice File Error', 'NO secuence named "cell"')
# parsing method
if 'method' in loc_dict:
self.mw.lattice.method = deepcopy(loc_dict['method'])
# parsing beam
if 'beam' in loc_dict:
self.mw.lattice.beam = deepcopy(loc_dict['beam'])
# parsing tws0
if 'tws0' in loc_dict:
self.mw.lattice.tws0 = deepcopy(loc_dict['tws0'])
self.mw.menu_edit.edit_lattice()