本文整理汇总了Python中qtpy.QtWidgets.QFileDialog.exec_方法的典型用法代码示例。如果您正苦于以下问题:Python QFileDialog.exec_方法的具体用法?Python QFileDialog.exec_怎么用?Python QFileDialog.exec_使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QFileDialog
的用法示例。
在下文中一共展示了QFileDialog.exec_方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: select_manual_output_folder
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import exec_ [as 别名]
def select_manual_output_folder(self):
# _current_folder = self.main_window.current_folder
dlg = QFileDialog(parent=self.main_window,
caption="Select or Define Output Directory")
dlg.setFileMode(QFileDialog.Directory)
if dlg.exec_():
output_folder_name = str(dlg.selectedFiles()[0])
self.main_window.autonom_ui.manual_output_folder_field.setText(output_folder_name)
示例2: open_a_file_dialog
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import exec_ [as 别名]
def open_a_file_dialog(parent=None, default_suffix=None, directory=None, file_filter=None, accept_mode=None,
file_mode=None):
"""
Open a dialog asking for a file location and name to and return it
:param parent: QWidget; The parent QWidget of the created dialog
:param default_suffix: String; The default suffix to be passed
:param directory: String; Directory to which the dialog will open
:param file_filter: String; The filter name and file type e.g. "Python files (*.py)"
:param accept_mode: enum AcceptMode; Defines the AcceptMode of the dialog, check QFileDialog Class for details
:param file_mode: enum FileMode; Defines the FileMode of the dialog, check QFileDialog Class for details
:return: String; The filename that was selected, it is possible to return a directory so look out for that
"""
global _LAST_SAVE_DIRECTORY
dialog = QFileDialog(parent)
# It is the intention to only save the user's last used directory until workbench is restarted similar to other
# applications (VSCode, Gedit etc)
if _LAST_SAVE_DIRECTORY is not None and directory is None:
dialog.setDirectory(_LAST_SAVE_DIRECTORY)
elif directory is not None:
dialog.setDirectory(directory)
else:
dialog.setDirectory(os.path.expanduser("~"))
if file_filter is not None:
dialog.setFilter(QDir.Files)
dialog.setNameFilter(file_filter)
if default_suffix is not None:
dialog.setDefaultSuffix(default_suffix)
if file_mode is not None:
dialog.setFileMode(file_mode)
if accept_mode is not None:
dialog.setAcceptMode(accept_mode)
# Connect the actual filename setter
dialog.fileSelected.connect(_set_last_save)
# Wait for dialog to finish before allowing continuation of code
if dialog.exec_() == QDialog.Rejected:
return None
filename = _LAST_SAVE_DIRECTORY
# Make sure that the _LAST_SAVE_DIRECTORY is set as a directory
if _LAST_SAVE_DIRECTORY is not None and not os.path.isdir(_LAST_SAVE_DIRECTORY):
# Remove the file for last directory
_LAST_SAVE_DIRECTORY = os.path.dirname(os.path.abspath(_LAST_SAVE_DIRECTORY))
return filename
示例3: openDirDialog
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import exec_ [as 别名]
def openDirDialog(self):
dialog = QFileDialog(self)
dialog.setFileMode(QFileDialog.DirectoryOnly)
if dialog.exec_():
directory = dialog.selectedFiles()[0]
self.openDir(directory)