本文整理汇总了Python中PyQt5.QtWidgets.QFileDialog.getSaveFileName方法的典型用法代码示例。如果您正苦于以下问题:Python QFileDialog.getSaveFileName方法的具体用法?Python QFileDialog.getSaveFileName怎么用?Python QFileDialog.getSaveFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QFileDialog
的用法示例。
在下文中一共展示了QFileDialog.getSaveFileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dialog_save_lattice
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def dialog_save_lattice(self):
"""Save lattice to file"""
filename = QFileDialog.getSaveFileName(self.mw, 'Save Lattice', '', "Python Files (*.py);;All Files (*)", options=QFileDialog.DontUseNativeDialog)
if filename[0] == '':
return 0
lp = Parser()
lines = lp.gui_lattice2input(self.mw.lattice, split=True)
if filename[1] == 'Python Files (*.py)' and filename[0][-3:] != '.py':
filename = filename[0] + '.py'
else:
filename = filename[0]
with open(filename, 'w') as fp:
fp.writelines(lines)
示例2: new_project
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def new_project(self, src_imgdir):
'''
create new project directory from src image directory to dst
'''
imgdir = src_imgdir.toLocalFile()
p = Path(imgdir)
default_projdir = str(
p.with_name( consts.default_proj_name(p.name) )
)
projdir,_ = QFileDialog.getSaveFileName(
caption=consts.config["new_project_dialog"]["caption"],
directory=default_projdir,
filter=consts.config["new_project_dialog"]["filter"]
)
new_projdir = state.new_project(imgdir, projdir)
if new_projdir:
self.set_project(new_projdir)
return new_projdir
#---------------------------------------------------
示例3: __export_presets
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def __export_presets(self):
names = [item.text() for item in self.presetsList.selectedItems()]
archive, _ = QFileDialog.getSaveFileName(
self,
directory='archive.presets',
filter='*.presets'
)
if archive != '':
if not archive.endswith('.presets'):
archive += '.presets'
try:
export_presets(names, archive)
except PresetExportError as e:
QDetailedMessageBox.dcritical(
translate('Presets', 'Presets'),
translate('Presets', 'Cannot export correctly.'),
str(e),
parent=self
)
示例4: save
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def save(self):
"""Save log to file."""
home = str(Path.home())
self.output = ""
self.output = QFileDialog.getSaveFileName(self,
'Save file',
home,
"ReST files (*.rst)")
if self.output[0] is not "":
with open(self.output[0], 'w') as f:
f.write(self.te.toPlainText())
btMessage = f'File saved as {self.output[0]}.'
else:
btMessage = "Can't save. No file specified."
self.systemtray_icon.showMessage(
APP_NAME, btMessage, QIcon(ICON_PATH), 5000)
self.statusBar().showMessage(btMessage)
示例5: on_save_log
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def on_save_log(self):
file_name, _ = QFileDialog.getSaveFileName( # second return value contains the used file type filter.
self.window(),
"Save log file",
"",
"" # TODO: File type filter. Maybe "*.log"?
)
del _ # We are only interested in the selected file name
if file_name:
list_widget = self.listWidget # type: QListWidget
item_texts = (list_widget.item(row).text() for row in range(list_widget.count()))
log_text = "\n".join(item_texts) + "\n"
try:
with open(file_name, "w") as log_file:
log_file.write(log_text)
except IOError:
logger.exception("Error saving log file")
else:
self.on_clear_log() # Error log saved, so clear the previously saved entries
示例6: dump_memory
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def dump_memory(self, file_path=None, ptr=0, length=0):
if ptr == 0:
ptr, inp = InputDialog.input_pointer(self._app_window)
if ptr > 0:
if length == 0:
accept, length = InputDialog.input(
self._app_window, hint='insert length', placeholder='1024')
if not accept:
return
try:
if length.startswith('0x'):
length = int(length, 16)
else:
length = int(length)
except:
return
if file_path is None:
r = QFileDialog.getSaveFileName(self._app_window, caption='Save binary dump to file')
if len(r) == 0 or len(r[0]) == 0:
return
file_path = r[0]
data = self.read_memory(ptr, length)
if data is not None and len(data) > 1:
with open(file_path, 'wb') as f:
f.write(data[1])
示例7: on_pushButton_10_clicked
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def on_pushButton_10_clicked(self):
"""
恢复
"""
ori_img = self.my_recovery_parameter.get('ori_img',None)
attacked_img = self.my_recovery_parameter.get('attacked_img',None)
if not ori_img:
QMessageBox.warning(self,"警告",'未读取原图',QMessageBox.Ok)
elif not attacked_img:
QMessageBox.warning(self,"警告",'未读取受到攻击的图片',QMessageBox.Ok)
else:
outfile_path,_ = QFileDialog.getSaveFileName(self, '恢复图片', self.my_bwm_parameter.get('work_path','./'),"PNG (*.png);;All Files (*)")
if outfile_path:
rate = self.doubleSpinBox_3.value()
self.recovery_thread = recovery(ori_img,attacked_img,outfile_path,rate)
self.recovery_thread.finished.connect(self.recovery_thread.deleteLater)
self.recovery_thread.num_of_good.connect(self.show_recovery)
self.recovery_thread.start()
示例8: on_pbLog_clicked
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def on_pbLog_clicked(self):
""" Select file for logging error/output of Lector
"""
fileFilter = self.tr("Log files (*.log);;All files (*);;")
init_filename = self.ui.lnLog.text()
if not init_filename:
if (os.path.split(sys.executable)[1]).lower().startswith('python'):
logPath = os.path.abspath(os.path.dirname(__file__))
else:
logPath = os.path.abspath(os.path.dirname(sys.executable))
init_filename = os.path.join(logPath, "lector.log")
filename = str(QFileDialog.getSaveFileName(self,
self.tr("Select file for log output..."),
init_filename,
fileFilter))
if not filename:
return
else:
self.ui.lnLog.setText(filename)
示例9: _export_plaintext_recovery
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def _export_plaintext_recovery(self, gateway):
dest, _ = QFileDialog.getSaveFileName(
self.parent,
"Select a destination",
os.path.join(
os.path.expanduser("~"), gateway.name + " Recovery Key.json"
),
)
if not dest:
return
try:
gateway.export(dest, include_rootcap=True)
except Exception as e: # pylint: disable=broad-except
error(self.parent, "Error exporting Recovery Key", str(e))
return
self.done.emit(dest)
示例10: _save_button_clicked
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def _save_button_clicked(self):
anchor_positions = self._data_model.get_anchor_postions()
data = {}
for id, pos in anchor_positions.items():
data[id] = {'x': pos[0], 'y': pos[1], 'z': pos[2]}
names = QFileDialog.getSaveFileName(self, 'Save file',
self._current_folder,
"*.yaml;;*.*")
if names[0] == '':
return
self._current_folder = os.path.dirname(names[0])
if not names[0].endswith(".yaml") and names[0].find(".") < 0:
filename = names[0] + ".yaml"
else:
filename = names[0]
f = open(filename, 'w')
with f:
yaml.dump(data, f)
示例11: saveOperation
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def saveOperation(self):
filename = QFileDialog.getSaveFileName(self, 'Save file', './screenshot.png', '*.png;;*.jpg')
if len(filename[0]) == 0:
return
else:
self.saveScreenshot(False, filename[0], filename[1][2:])
self.close()
示例12: s_save
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def s_save(self):
"""Slot for saving the current machine to a json file
Parameters
----------
self : DMachineSetup
A DMachineSetup object
"""
# Ask the user to select a .m file to save
if self.machine.name in ["", None]:
save_file_path = QFileDialog.getSaveFileName(
self, self.tr("Save file"), self.machine_path, "Json (*.json)"
)[0]
else:
def_path = join(self.machine_path, self.machine.name + ".json")
save_file_path = QFileDialog.getSaveFileName(
self, self.tr("Save file"), def_path, "Json (*.json)"
)[0]
# Avoid bug due to user closing the popup witout selecting a file
if save_file_path != "":
# Set the machine name to match the file name
self.machine.name = str(basename(str(save_file_path)))[:-5]
# Save the machine file
self.machine.save(save_file_path)
# To update the machine name field (if first page)
self.set_nav(self.nav_step.currentRow())
# Update the machine path to remember the last used folder
self.machine_path = dirname(save_file_path)
# Notify the project GUI that the machine has changed
self.machineChanged.emit()
self.is_save_needed = False
return True
return False
示例13: on_btnRead_finished
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def on_btnRead_finished(self):
binpath, filter = QFileDialog.getSaveFileName(caption=u'将读取到的数据保存到文件', filter=u'程序文件 (*.bin)')
if binpath:
with open(binpath, 'wb') as f:
f.write(bytes(self.buff))
self.jlk.reset()
self.setEnabled(True)
self.prgInfo.setVisible(False)
示例14: _export2JqkaAct
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def _export2JqkaAct(self):
data = {}
if not DyStockTableSelectDlg(data, '{0}导出到同花顺'.format(self.getUniqueName())).exec_():
return
defaultFileName = '{0}.sel' if data['all'] else '{0}_高亮.sel'
defaultFileName = defaultFileName.format(self.getUniqueName())
defaultDir = DyCommon.createPath('Stock/User/Save/Strategy/同花顺')
fileName, _ = QFileDialog.getSaveFileName(None, '导出到同花顺', os.path.join(defaultDir, defaultFileName), "同花顺files (*.sel);;all files(*.*)", options=QFileDialog.DontUseNativeDialog)
if fileName:
self.export2Jqka(fileName)
示例15: _saveAsAct
# 需要导入模块: from PyQt5.QtWidgets import QFileDialog [as 别名]
# 或者: from PyQt5.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def _saveAsAct(self):
data = {}
if not DyStockTableSelectDlg(data, '{0}保存'.format(self.getUniqueName())).exec_():
return
defaultFileName = '{0}.json' if data['all'] else '{0}_高亮.json'
defaultFileName = defaultFileName.format(self.getUniqueName())
defaultDir = DyCommon.createPath('Stock/User/Save/Strategy')
fileName, _ = QFileDialog.getSaveFileName(None, '保存股票表', os.path.join(defaultDir, defaultFileName), "JSON files (*.json);;all files(*.*)", options=QFileDialog.DontUseNativeDialog)
if fileName:
self._saveAs(fileName, data['all'])