本文整理汇总了Python中AnyQt.QtWidgets.QFileDialog.getOpenFileName方法的典型用法代码示例。如果您正苦于以下问题:Python QFileDialog.getOpenFileName方法的具体用法?Python QFileDialog.getOpenFileName怎么用?Python QFileDialog.getOpenFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QFileDialog
的用法示例。
在下文中一共展示了QFileDialog.getOpenFileName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open_report
# 需要导入模块: from AnyQt.QtWidgets import QFileDialog [as 别名]
# 或者: from AnyQt.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def open_report(self):
filename, _ = QFileDialog.getOpenFileName(
self, "Open Report", self.open_dir, "Report (*.report)")
if not filename:
return
self.report_changed = False
self.open_dir = os.path.dirname(filename)
self.saveSettings()
try:
report = self.load(filename)
except (IOError, AttributeError, pickle.UnpicklingError) as e:
message_critical(
self.tr("Could not load an Orange Report file"),
title=self.tr("Error"),
informative_text=self.tr("Error occurred "
"while loading '{}'.").format(filename),
exc_info=True,
parent=self)
log.error(str(e), exc_info=True)
return
self.set_instance(report)
self = report
self._build_html()
self.table.selectRow(0)
self.show()
self.raise_()
示例2: main
# 需要导入模块: from AnyQt.QtWidgets import QFileDialog [as 别名]
# 或者: from AnyQt.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def main(argv=sys.argv):
if len(argv) == 1:
filename = None
else:
if argv[1] in ["-h", "--help"]:
usage(argv)
return 0
else:
filename = argv[1]
app = QApplication(argv)
app.setAttribute(Qt.AA_EnableHighDpiScaling)
app.setAttribute(Qt.AA_UseHighDpiPixmaps)
if filename is None:
filename, _ = QFileDialog.getOpenFileName(
None, "Image file", os.path.expanduser("~/Documents"),
"Image (*.png)")
if not filename:
return 1
print(filename)
form = MainForm(filename=filename)
rect = QApplication.desktop().availableGeometry()
form.show()
form.raise_()
return app.exec_()
示例3: onAddScriptFromFile
# 需要导入模块: from AnyQt.QtWidgets import QFileDialog [as 别名]
# 或者: from AnyQt.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def onAddScriptFromFile(self, *args):
filename, _ = QFileDialog.getOpenFileName(
self, 'Open Python Script',
os.path.expanduser("~/"),
'Python files (*.py)\nAll files(*.*)'
)
if filename:
name = os.path.basename(filename)
contents = open(filename, "rb").read().decode("utf-8", errors="ignore")
self.libraryList.append(Script(name, contents, 0, filename))
self.setSelectedScript(len(self.libraryList) - 1)
示例4: browse
# 需要导入模块: from AnyQt.QtWidgets import QFileDialog [as 别名]
# 或者: from AnyQt.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def browse(self):
"""Select a filename using an open file dialog."""
if self.filename is None:
startdir = stdpaths.Documents
else:
startdir = os.path.dirname(self.filename)
filename, _ = QFileDialog.getOpenFileName(
self, self.tr("Open"), directory=startdir, filter=self.FILTER)
if filename:
self.load(filename)
示例5: onAddScriptFromFile
# 需要导入模块: from AnyQt.QtWidgets import QFileDialog [as 别名]
# 或者: from AnyQt.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def onAddScriptFromFile(self, *args):
filename, _ = QFileDialog.getOpenFileName(
self, 'Open Python Script',
os.path.expanduser("~/"),
'Python files (*.py)\nAll files(*.*)'
)
if filename:
name = os.path.basename(filename)
# TODO: use `tokenize.detect_encoding`
with open(filename, encoding="utf-8") as f:
contents = f.read()
self.libraryList.append(Script(name, contents, 0, filename))
self.setSelectedScript(len(self.libraryList) - 1)
示例6: browse_file
# 需要导入模块: from AnyQt.QtWidgets import QFileDialog [as 别名]
# 或者: from AnyQt.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def browse_file(self):
"""
Open the file dialog and open the chosen file.
"""
start_path = self.last_path() or os.path.expanduser("~")
filename, _ = QFileDialog.getOpenFileName(
None, "Open File", start_path, 'All Files (*.*)')
if not filename:
return
self.closeContext()
self.add_path(filename)
self.openContext(filename)
self.open_file()
示例7: browse_file
# 需要导入模块: from AnyQt.QtWidgets import QFileDialog [as 别名]
# 或者: from AnyQt.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def browse_file(self, in_demos=False):
if in_demos:
start_file = get_sample_datasets_dir()
if not os.path.exists(start_file):
QMessageBox.information(
None, "File",
"Cannot find the directory with documentation data sets")
return
else:
start_file = self.last_path() or os.path.expanduser("~/")
filename, _ = QFileDialog.getOpenFileName(
self, 'Open Distance File', start_file, "(*.dst)")
if not filename:
return
self.add_path(filename)
self.open_file()
示例8: browse_file
# 需要导入模块: from AnyQt.QtWidgets import QFileDialog [as 别名]
# 或者: from AnyQt.QtWidgets.QFileDialog import getOpenFileName [as 别名]
def browse_file(self, in_demos=False):
if in_demos:
start_file = get_sample_datasets_dir()
if not os.path.exists(start_file):
QMessageBox.information(
None, "File",
"Cannot find the directory with documentation data sets")
return
else:
start_file = self.last_path() or os.path.expanduser("~/")
filename, _ = QFileDialog.getOpenFileName(
self, 'Open Orange Data File', start_file, dialog_formats())
if not filename:
return
self.add_path(filename)
self.source = self.LOCAL_FILE
self.load_data()