我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用PyQt5.QtWidgets.QFileDialog.AcceptSave()。
def save_as_filter(parent,my_filter): selected_filter = "" dialog = QFileDialog(parent) dialog.setWindowTitle(_("Save as")) dialog.setNameFilter(my_filter) dialog.setAcceptMode(QFileDialog.AcceptSave) if dialog.exec_() == QDialog.Accepted: filename = dialog.selectedFiles()[0] s=dialog.selectedNameFilter() if s.count("(*")==1: s=s.split("(*")[1] s=s[:-1] if filename.endswith(s)==False: filename=filename+s else: filename=filename return filename else: return None
def slot_save(self): buf = self.editor.toPlainText() # ???? ??? ?? ???? fdial = QFileDialog(self) fdial.setAcceptMode(QFileDialog.AcceptSave) file_name = self.filename if not self.filename: file_name = fdial.getSaveFileName(self, self.tr("Save File"), filter='*.txt')[0] if not file_name: return False fd = open(file_name, 'w') fd.write(buf) fd.close() self.filename = file_name self.menu.act_save_file.setEnabled(False) self.set_window_title() return True
def dlg_export(parent): dialog = QFileDialog(parent) dialog.setWindowTitle(_("Export the simulation as")) dialog.setAcceptMode(QFileDialog.AcceptSave) types=[] types.append(_("gpvdm archive input+output files")+" (*.gpvdm)") types.append(_("gpvdm archive input files")+" (*.gpvdm)") types.append(_("optical materials database")+" (*.zip)") types.append(_("pdf file")+" (*.pdf)") types.append(_("jpg image")+" (*.jpg)") types.append(_("tex file")+" (*.tex)") types.append(_("Excel file")+" (*.xlsx)") dialog.setNameFilters(types) dialog.setFileMode(QFileDialog.ExistingFile) dialog.setAcceptMode(QFileDialog.AcceptSave) if dialog.exec_() == QDialog.Accepted: file_name = dialog.selectedFiles()[0] print(dialog.selectedNameFilter()) if dialog.selectedNameFilter()==_("gpvdm archive input+output files")+" (*.gpvdm)": export_archive(file_name,True) elif dialog.selectedNameFilter()==_("gpvdm archive input files")+" (*.gpvdm)": export_archive(file_name,False) elif dialog.selectedNameFilter()==_("optical materials database")+" (*.zip)": export_materials(file_name) elif dialog.selectedNameFilter()==_("pdf file")+" (*.pdf)" or dialog.selectedNameFilter()==_("jpg image")+" (*.jpg)" or dialog.selectedNameFilter()==_("tex file")+" (*.tex)": export_as(file_name) elif dialog.selectedNameFilter()==_("Excel file")+" (*.xlsx)": gen_workbook(get_sim_path(),set_file_ext(file_name,".xlsx"))
def save_as_gpvdm(parent): dialog = QFileDialog(parent) dialog.setWindowTitle(_("Save a the simulation as")) dialog.setNameFilter(_("Directory")) dialog.setAcceptMode(QFileDialog.AcceptSave) dialog.setOption(QFileDialog.ShowDirsOnly, True) if dialog.exec_() == QDialog.Accepted: filename = dialog.selectedFiles()[0] filename = to_native_path(filename) return filename else: return None
def saveTrace(self,checked): #diag = QFileDialog.getSaveFileName(self, "Select destination", "./", "Comma Separated Values (*.csv)"); diag = QFileDialog(self); diag.setAcceptMode(QFileDialog.AcceptSave) #Save file, not open one diag.setNameFilter("Comma Separated Values (*.csv);;Space separated Values (*.csv)"); diag.setDefaultSuffix("csv"); # Make sure selected files end in .csv diag.exec(); try: filename = diag.selectedFiles()[0]; except IndexError: filename = ''; user_filter = diag.selectedNameFilter(); if (user_filter == "Space separated Values (*.csv)"): delimiter = " "; else: delimiter = ","; if (filename != '' and not os.path.isdir(filename)): npzfile = self.last_result; t = npzfile["t"]; cos2 = npzfile["cos2"]; cos2d = npzfile["cos2d"]; extra_header = []; extra_columns = []; if ('Javg' in npzfile.keys()): Javg = npzfile["Javg"]; std = npzfile["std"]; percentile_999 = npzfile["percentile_999"]; extra_header = ["<J>","std(J)","J_99.9%"]; extra_columns = [Javg,std,percentile_999]; utils.save_to_csv(filename,t,cos2,cos2d,extra_header,extra_columns,delimiter);
def get_save_file_name(initial_name: str, wav_only=False, caption="Save signal"): global RECENT_PATH if caption == "Save signal": name_filter = "Complex files (*.complex);;Complex16 files (2 unsigned int8) " \ "(*.complex16u);;Complex16 files (2 signed int8) (*.complex16s);;" \ "Compressed complex files (*.coco);;wav files (*.wav);;all files (*)" if wav_only: name_filter = "wav files (*.wav);;all files (*)" elif caption == "Save fuzz profile": name_filter = "Fuzzfiles (*.fuzz.xml *.fuzz);;All files (*)" elif caption == "Save encoding": name_filter = "" else: name_filter = "Protocols (*.proto.xml *.proto);;All files (*)" filename = None dialog = QFileDialog() dialog.setFileMode(QFileDialog.AnyFile) dialog.setNameFilter(name_filter) dialog.setViewMode(QFileDialog.Detail) dialog.setDirectory(RECENT_PATH) dialog.setLabelText(QFileDialog.Accept, "Save") dialog.setWindowTitle(caption) dialog.setAcceptMode(QFileDialog.AcceptSave) dialog.selectFile(initial_name) if dialog.exec(): filename = dialog.selectedFiles()[0] if filename: RECENT_PATH = os.path.split(filename)[0] return filename
def _save_plot(self, target, plot_name): if not target.confirm_on_empty(plot_name): return None dialog = QFileDialog(self) dialog.setAcceptMode(QFileDialog.AcceptSave) dialog.setFileMode(QFileDialog.AnyFile) formats = self._mpl_output_formats(self._pmi) dialog.setNameFilters(["Matplotlib Formats " + formats, "All Files (*)"]) if dialog.exec(): target.save_plot(dialog.selectedFiles()[0])