本文整理汇总了Python中qtpy.QtWidgets.QFileDialog.getSaveFileName方法的典型用法代码示例。如果您正苦于以下问题:Python QFileDialog.getSaveFileName方法的具体用法?Python QFileDialog.getSaveFileName怎么用?Python QFileDialog.getSaveFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QFileDialog
的用法示例。
在下文中一共展示了QFileDialog.getSaveFileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _save_as
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def _save_as(self):
"""
Present a file dialog to the user and saves the content of
the UI in XML format.
"""
if self._filename is not None:
fname = self._filename
else:
fname = self._instrument + '_'
fname = QFileDialog.getSaveFileName(self, "Reduction settings - Save settings",
self._last_directory + '/' + fname,
"Settings files (*.xml)")
if not fname:
return
if isinstance(fname, tuple):
fname = fname[0]
fname = str(QFileInfo(fname).filePath())
if not fname.endswith('.xml'):
fname += ".xml"
if fname in self._recent_files:
self._recent_files.remove(fname)
self._recent_files.insert(0,fname)
while len(self._recent_files) > 10:
self._recent_files.pop()
self._last_directory = QFileInfo(fname).path()
self._filename = fname
self._save()
示例2: _export
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def _export(self):
"""
Exports the current content of the UI to a python script that can
be run within MantidPlot
"""
if self._interface is None:
return
fname = QFileDialog.getSaveFileName(self, "Mantid Python script - Save script",
self._last_export_directory,
"Python script (*.py)")
if not fname:
return
if isinstance(fname, tuple):
fname = fname[0]
fname = str(fname)
if not fname.endswith('.py'):
fname += ".py"
(folder, file_name) = os.path.split(fname)
self._last_export_directory = folder
script = self._interface.export(fname)
if script is not None:
self.statusBar().showMessage("Saved as %s" % fname)
else:
self.statusBar().showMessage("Could not save file")
示例3: do_export_selected_scans
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def do_export_selected_scans(self):
"""
export selected scans to a file
:return:
"""
# get the scans
scans_list = self._myParent.ub_matrix_processing_table.get_selected_scans()
scans_list.sort()
# form the output string
output_str = '# Exp = {0}.\n'.format(self._myParent.current_exp_number)
for scan in scans_list:
output_str += '{0}, '.format(scan)
# trim the last
output_str = output_str[:-2]
# get the output file name
file_filter = 'Text Files (*.dat);;All Files (*.*)'
file_name = QFileDialog.getSaveFileName(self, 'File to export selected scans',
self._myParent.working_directory, file_filter)
if not file_name:
return
if isinstance(file_name, tuple):
file_name = file_name[0]
# write file
out_file = open(file_name, 'w')
out_file.write(output_str)
out_file.close()
示例4: saveText
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def saveText(self):
"""
Saves the generated text to a file (opens file dialog).
"""
fname = QFileDialog.getSaveFileName(self, 'Open file', '')
if isinstance(fname, tuple):
fname = fname[0]
fid = open(fname, 'w')
fid.write(self.genText())
fid.close()
示例5: show_savecfg_dlg
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def show_savecfg_dlg(self):
filename, _ = QFileDialog.getSaveFileName(
self, self.tr("Save configuration file..."),
directory=os.path.expanduser("~"),
filter="Json file (*.json)"
)
if filename:
self.filename = filename
self.save_file()
示例6: get_save_file
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def get_save_file(parent, directory=None, caption=None, filter=dict()):
'''
This is operating under the assumption that the file_filters parameter is a dict of filter:extension
The filename will have the file extension appended if one isn't already found on it
It returns a pair (<filename with extension>, <extension>). In the case of user cancelling, the filename
returned is None
'''
# convert defaults into something useful
if not directory:
# try to get it from the parent
if parent:
try:
directory = parent._currWorkDir
except:
pass
# just give up and use the current working directory
if not directory:
directory = os.getcwd()
if not caption:
caption = 'Save File'
if filter:
dialogfilter = ';;'.join(filter.keys())
else:
dialogfilter = ''
result = QFileDialog.getSaveFileName(parent=parent, directory=directory, caption=caption,
filter=dialogfilter)
# qt4/qt5 return slightly different things
if isinstance(result, tuple):
filename, filefilter = result
else:
filename = result
filefilter = None
# check if the user canceled
if not filename:
return None, filefilter
# determine the type and add the extension
extension = os.path.splitext(str(filename))[-1]
filetype = filter.get(filefilter, None)
if filetype is None:
filetype = extension.replace('.', '')
elif not extension:
# implementation ties filetype to the extension
filename = '{}.{}'.format(filename, filetype)
return filename, filetype
示例7: _writeToFile
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def _writeToFile(out_model_dict, model_directory, parent):
fname = QFileDialog.getSaveFileName(parent, 'Save to file', model_directory)[0]
if len(fname) > 0:
# enforce correct suffix.
if not fname.endswith(".yaml"):
fname += ".yaml"
f = open(fname, "w")
yaml.dump(out_model_dict, f,default_flow_style=False)
f.close()
示例8: get_file_name_for_saving
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def get_file_name_for_saving(self, extension):
"""
Pops up a file selection dialog with the filter set to the
extension type
:param extension: The file extension to use which defines the
export type
:return absolute_path: The absolute path to save to
"""
# Returns a tuple containing the filename and extension
absolute_path = QFileDialog.getSaveFileName(caption='Select filename for exported plot',
filter='*{}'.format(extension))
return absolute_path[0]
示例9: _writeToFile
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def _writeToFile(expression_string, model_directory, parent, header):
fname = QFileDialog.getSaveFileName(parent, 'Export to .py file', model_directory)[0]
if len(fname) > 0:
# enforce correct suffix.
if not fname.endswith(".py"):
fname += ".py"
f = open(fname, 'w')
f.write(header)
f.write(expression_string)
f.close()
示例10: do_export_plot
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def do_export_plot(self):
"""
export plot
:return:
"""
# get directory
file_name = QFileDialog.getSaveFileName(self, caption='File to save the plot',
directory=self._work_dir,
filter='Data File(*.dat);;All Files(*.*')
if not file_name:
return
if isinstance(file_name, tuple):
file_name = file_name[0]
self.ui.graphicsView_plotView.save_current_plot(None, file_name)
示例11: data_save_dialog
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def data_save_dialog(self, data_type=None, title=None):
"""
Pop up a save file dialog box.
@param data_type: string used to filter the files
@param title: string to use as title
"""
if data_type is None:
data_type = self._data_type
if title is None:
title = "Save file - Set a location and name"
fname = QFileDialog.getSaveFileName(self, title,
self._settings.data_path,
data_type)
if isinstance(fname, tuple):
fname = fname[0]
return QFileInfo(fname).filePath()
示例12: save_list_to_file
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def save_list_to_file(self):
filename, filters = QFileDialog.getSaveFileName(self,
"Save connection list",
"",
"Text Files (*.txt)")
try:
with open(filename, "w") as f:
for conn in self.table_view.model().connections:
f.write(
"{p}://{a}\n".format(p=conn.protocol, a=conn.address))
self.save_status_label.setText("File saved to {}".format(filename))
except Exception as e:
msgBox = QMessageBox()
msgBox.setText("Couldn't save connection list to file.")
msgBox.setInformativeText("Error: {}".format(str(e)))
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec_()
示例13: export_csv
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def export_csv(self):
filename, _ = QFileDialog.getSaveFileName(
self, QCoreApplication.applicationName(),
filter="CSV files(*.csv);;All files (*.*)"
)
if filename == "":
return
# get current dataframe and export to csv
df = self.recordWidget.dataframe
decimal = self.settings.get(DECIMAL_SETTING)
df = df.applymap(lambda x: str(x).replace(".", decimal))
df.to_csv(
filename, index_label="time",
sep=self.settings.get(SEPARATOR_SETTING)
)
示例14: _on_save_model
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def _on_save_model(self, interactive=True):
model_editor_model = self.hub.data_item.model_editor_model
# There are no models to save
if not model_editor_model.fittable_models:
QMessageBox.warning(self,
'No model available',
'No model exists to be saved.')
return
default_name = os.path.join(os.path.curdir, 'new_model.smf')
outfile = QFileDialog.getSaveFileName(
self, caption='Save Model', directory=default_name,
filter=SPECVIZ_MODEL_FILE_FILTER)[0]
# No file was selected; the user hit "Cancel"
if not outfile:
return
self._save_models(outfile)
QMessageBox.information(self,
'Model saved',
'Model successfully saved to {}'.format(outfile))
示例15: ask_for_filename
# 需要导入模块: from qtpy.QtWidgets import QFileDialog [as 别名]
# 或者: from qtpy.QtWidgets.QFileDialog import getSaveFileName [as 别名]
def ask_for_filename(self):
filename, _ = QFileDialog.getSaveFileName(self.editor, "Choose filename...")
return filename