本文整理汇总了Python中AnyQt.QtWidgets.QFileDialog.selectNameFilter方法的典型用法代码示例。如果您正苦于以下问题:Python QFileDialog.selectNameFilter方法的具体用法?Python QFileDialog.selectNameFilter怎么用?Python QFileDialog.selectNameFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QFileDialog
的用法示例。
在下文中一共展示了QFileDialog.selectNameFilter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_save_filename
# 需要导入模块: from AnyQt.QtWidgets import QFileDialog [as 别名]
# 或者: from AnyQt.QtWidgets.QFileDialog import selectNameFilter [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