本文整理汇总了Python中AnyQt.QtWidgets.QFileDialog.setOption方法的典型用法代码示例。如果您正苦于以下问题:Python QFileDialog.setOption方法的具体用法?Python QFileDialog.setOption怎么用?Python QFileDialog.setOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QFileDialog
的用法示例。
在下文中一共展示了QFileDialog.setOption方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_save_filename
# 需要导入模块: from AnyQt.QtWidgets import QFileDialog [as 别名]
# 或者: from AnyQt.QtWidgets.QFileDialog import setOption [as 别名]
def get_save_filename(self): # pragma: no cover
if sys.platform == "darwin":
def remove_star(filt):
return filt.replace(" (*.", " (.")
else:
def remove_star(filt):
return filt
no_ext_filters = {remove_star(f): f for f in self._valid_filters()}
filename = self._initial_start_dir()
while True:
dlg = QFileDialog(
None, "Save File", filename, ";;".join(no_ext_filters))
dlg.setAcceptMode(dlg.AcceptSave)
dlg.selectNameFilter(remove_star(self._default_valid_filter()))
dlg.setOption(QFileDialog.DontConfirmOverwrite)
if dlg.exec() == QFileDialog.Rejected:
return "", ""
filename = dlg.selectedFiles()[0]
selected_filter = no_ext_filters[dlg.selectedNameFilter()]
filename = self._replace_extension(
filename, self._extension_from_filter(selected_filter))
if not os.path.exists(filename) or QMessageBox.question(
self, "Overwrite file?",
f"File {os.path.split(filename)[1]} already exists.\n"
"Overwrite?") == QMessageBox.Yes:
return filename, selected_filter
示例2: __runOpenDialog
# 需要导入模块: from AnyQt.QtWidgets import QFileDialog [as 别名]
# 或者: from AnyQt.QtWidgets.QFileDialog import setOption [as 别名]
def __runOpenDialog(self):
startdir = os.path.expanduser("~/")
if self.recent_paths:
startdir = os.path.dirname(self.recent_paths[0].abspath)
if OWImportImages.Modality == Qt.WindowModal:
dlg = QFileDialog(
self, "Select Top Level Directory", startdir,
acceptMode=QFileDialog.AcceptOpen,
modal=True,
)
dlg.setFileMode(QFileDialog.Directory)
dlg.setOption(QFileDialog.ShowDirsOnly)
dlg.setDirectory(startdir)
dlg.setAttribute(Qt.WA_DeleteOnClose)
@dlg.accepted.connect
def on_accepted():
dirpath = dlg.selectedFiles()
if dirpath:
self.setCurrentPath(dirpath[0])
self.start()
dlg.open()
else:
dirpath = QFileDialog.getExistingDirectory(
self, "Select Top Level Directory", startdir
)
if dirpath:
self.setCurrentPath(dirpath)
self.start()