本文整理汇总了Python中qtpy.QtWidgets.QFileDialog类的典型用法代码示例。如果您正苦于以下问题:Python QFileDialog类的具体用法?Python QFileDialog怎么用?Python QFileDialog使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QFileDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, parent):
QFileDialog.__init__(self, parent)
self.setFileMode(QFileDialog.AnyFile)
self.setAcceptMode(QFileDialog.AcceptSave)
# Widgets
self._chk_tight = QCheckBox('Tight layout')
self._txt_dpi = QSpinBox()
self._txt_dpi.setRange(1, 10000)
self._txt_dpi.setSingleStep(50)
self._txt_dpi.setSuffix('dpi')
self._txt_dpi.setValue(100)
# Layouts
layout = self.layout()
lyt_extras = QHBoxLayout()
lyt_extras.addWidget(QLabel('Extra options'))
lyt_extras.addWidget(self._chk_tight)
lyt_extras.addWidget(QLabel('Resolution'))
lyt_extras.addWidget(self._txt_dpi)
layout.addLayout(lyt_extras, layout.rowCount(), 0, 1, layout.columnCount())
self.setLayout(layout)
示例2: select_manual_output_folder
def select_manual_output_folder(self):
# _current_folder = self.main_window.current_folder
dlg = QFileDialog(parent=self.main_window,
caption="Select or Define Output Directory")
dlg.setFileMode(QFileDialog.Directory)
if dlg.exec_():
output_folder_name = str(dlg.selectedFiles()[0])
self.main_window.autonom_ui.manual_output_folder_field.setText(output_folder_name)
示例3: _export
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")
示例4: do_export_selected_scans
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()
示例5: output_dir_button_clicked
def output_dir_button_clicked(self):
_output_folder = QFileDialog.getExistingDirectory(caption="Select Output Folder ...",
directory=self.parent.output_folder,
options=QFileDialog.ShowDirsOnly)
if _output_folder:
self.ui.output_dir_label.setText(str(_output_folder))
self.parent.output_folder = str(_output_folder)
示例6: cache_dir_button_clicked
def cache_dir_button_clicked(self):
_cache_folder = QFileDialog.getExistingDirectory(caption="Select Cache Folder ...",
directory=self.parent.cache_folder,
options=QFileDialog.ShowDirsOnly)
if _cache_folder:
self.ui.cache_dir_label.setText(str(_cache_folder))
self.parent.cache_folder = str(_cache_folder)
示例7: request_config_file_name
def request_config_file_name(self, open_flag=True):
_caption = 'Select or Define a Configuration File Name'
_current_folder = self.parent.configuration_folder
if open_flag:
_file = QFileDialog.getOpenFileName(parent=self.parent,
filter='config (*.cfg)',
caption=_caption,
directory=_current_folder)
if isinstance(_file, tuple):
_file = _file[0]
else:
_file, _ = get_save_file(parent=self.parent,
filter={'config (*.cfg)':'cfg'},
caption=_caption,
directory=_current_folder)
if not _file:
self.filename = ''
return
_new_path = os.path.dirname(_file)
self.parent.configuration_folder = _new_path
o_file_handler = FileHandler(filename=_file)
o_file_handler.check_file_extension(ext_requested='cfg')
self.filename = o_file_handler.filename
示例8: browse_file
def browse_file(self, type='calibration'):
if type == 'calibration':
_current_folder = self.parent.calibration_folder
_filter = "calib (*.h5);;all (*.*)"
_caption = "Select Calibration File"
_output_ui = self.parent.ui.mantid_calibration_value
else:
_current_folder = self.parent.characterization_folder
_filter = "characterization (*-rietveld.txt);;all (*.*)"
_caption = "Select Characterization File"
_output_ui = self.parent.ui.mantid_characterization_value
_file = QFileDialog.getOpenFileName(parent=self.parent,
filter=_filter,
caption=_caption,
directory=_current_folder)
if not _file:
return
if isinstance(_file, tuple):
_file = _file[0]
_output_ui.setText(str(_file))
_path = os.path.dirname(str(_file))
if type == 'calibration':
self.parent.calibration_current_folder = _path
else:
self.parent.characterization_current_folder = _path
示例9: open_file
def open_file(self):
# todo: when more file types are added this should
# live in its own type
filepath, _ = QFileDialog.getOpenFileName(self, "Open File...", "", "Python (*.py)")
if not filepath:
return
self.editor.open_file_in_new_tab(filepath)
示例10: _save_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()
示例11: open_file_dialog
def open_file_dialog(line_edit, filter_text, directory):
file_name = QFileDialog.getOpenFileName(None, 'Open', directory, filter_text)
if not file_name:
return
if isinstance(file_name, tuple):
file_name = file_name[0]
line_edit.setText(file_name)
示例12: _on_load_from_file
def _on_load_from_file(self):
filename = QFileDialog.getOpenFileName(
self, caption='Load Model',
filter=SPECVIZ_MODEL_FILE_FILTER)[0]
if not filename:
return
self._load_model_from_file(filename)
示例13: grouping_button
def grouping_button(self, key=None, grouping_type='input'):
message = "Select {} grouping".format(grouping_type)
ext = 'Grouping (*.txt);;All (*.*)'
file_name = QFileDialog.getOpenFileName(self.main_window,
message,
self.main_window.calibration_folder,
ext)
if file_name is None:
return
示例14: _savedir_browse
def _savedir_browse(self):
save_dir = QFileDialog.getExistingDirectory(self, "Output Directory - Choose a directory",
os.path.expanduser('~'),
QFileDialog.ShowDirsOnly
| QFileDialog.DontResolveSymlinks)
if not save_dir:
return
if isinstance(save_dir, tuple):
save_dir = save_dir[0]
self._content.savedir_edit.setText(save_dir)
示例15: get_directory_name_for_saving
def get_directory_name_for_saving(self):
"""
Pops up a directory selection dialogue
:return : The path to the directory
"""
# Note that the native dialog does not always show the files
# in the directory on Linux, but using the non-native dialog
# is not very pleasant on Windows or Mac
directory = QFileDialog.getExistingDirectory(caption='Select folder for exported plots')
return directory