10 examples of 'pyqt save file dialog' in Python

Every line of 'pyqt save file dialog' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
114def _save_file_dialog(self):
115 return open_a_file_dialog(accept_mode=QFileDialog.AcceptSave, file_mode=QFileDialog.AnyFile,
116 file_filter="Project files ( *" + self.project_file_ext + ")")
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

2748def save_project_file_dialog(self):
2749 filters = "Prusa (*.prusa *.PRUSA)"
2750 title = 'Save project file'
2751 open_at = self.settings.value("project_path", "")
2752 data = QFileDialog.getSaveFileName(None, title, open_at, filters)
2753 if data:
2754 self.settings.setValue("project_path", QFileInfo(data).absolutePath())
2755 if data == '':
2756 return data
2757
2758 return data
102def fileSave(self):
103 """ callback for File->Save
104
105 """
106 self.saveIt()
70def saveAs(self):
71 """
72 Open an SaveAs File dialog.
73 """
74 # TODO: think about export in different formats
75 labelSaveAs = self.tr("Save As")
76 fileDialog = QtGui.QFileDialog(self.parentWidget, labelSaveAs, self.directory, self.fileDescription + " (*" + str(self.fileExtension) + ")" )
77
78 fileDialog.setHistory(World.settings.value("SaveAsHistory").toStringList())
79 fileDialog.setDirectory(self.directory)
80 fileDialog.setLabelText ( QtGui.QFileDialog.Accept, labelSaveAs)
81 fileDialog.setAcceptMode(QtGui.QFileDialog.AcceptSave)
82 fileDialog.setConfirmOverwrite(True)
83
84 # perform save as only when there is filename
85 if (fileDialog.exec_()):
86 files = fileDialog.selectedFiles()
87 if (not files.isEmpty()):
88 fileForSave = files.first()
89 if (not fileForSave.endsWith(self.fileExtension, QtCore.Qt.CaseInsensitive)):
90 # add extension according to existing open file
91 fileForSave.append(self.fileExtension)
92 self.filename = fileForSave
93 self.emitFileToSave(self.filename)
94
95 history = fileDialog.history()
96 newHistory = QtCore.QStringList()
97 while (not history.isEmpty() and newHistory.count() < self.MaxRecentHistory):
98 newHistory.append(history.first())
99 history.removeAll(history.first())
100 World.settings.setValue("SaveAsHistory", QtCore.QVariant(newHistory))
101
102 else:
103 QtGui.QMessageBox.information(self.parentWidget, self.tr("Information") , self.tr("Please specify the filename to save to"))
104 self.saveAs()
35def save_file_as(parent, title, fn_filter):
36 return QtGui.QFileDialog.getSaveFileName(parent, title, filter=fn_filter)[0]
152def _save_file_as(self):
153 if self._guiprovider.controller.is_empty():
154 self._guiprovider.controller._outputView.write_line("No data to save.")
155 return
156
157 preferences = self._guiprovider.create_uipreferences()
158 filename = tkfd.asksaveasfilename(parent=self,
159 title='Save File',
160 initialdir=preferences.get_savefile_initialdir())
161 if filename and self._guiprovider.controller.save_file_as(filename):
162 preferences.add_recent_file(filename)
163 preferences.set_savefile_initialdir(os.path.dirname(filename))
164 preferences.save()
161def save(self):
162 fn = str(pg.QtGui.QFileDialog.getSaveFileName(self, "Save State..", "untitled.cfg", "Config Files (*.cfg)"))
163 if fn == '':
164 return
165 state = self.params.saveState()
166 pg.configfile.writeConfigFile(state, fn)
28def saveFile(self):
29 if not self.filename:
30 self.filename, ok = QtWidgets.QFileDialog.getSaveFileName(
31 self, "Choose a file name", DESKTOP, "UTF-8 (*.txt)")
32
33 if not ok:
34 return
35
36 if not self.filename:
37 return
38
39 writer = QtGui.QTextDocumentWriter(self.filename)
40 success = writer.write(self.document())
41
42 if success:
43 return self.filename
44 else:
45 QtWidgets.QMessageBox.question(
46 self, 'Cancel', 'Saving Failed', QtWidgets.QMessageBox.Yes)
16def file_save_dialog(title):
17 dialog_style = wx.FD_SAVE
18
19 dialog = wx.FileDialog(
20 None, message=title,
21 defaultDir=os.getcwd(),
22 defaultFile='', style=dialog_style)
23
24 return dialog
121def saveFile(self):
122 filename, _ = QFileDialog.getSaveFileName(self,
123 "Choose a file name", '.', "UTF-8 (*.txt)")
124 if not filename:
125 return
126
127 file = QFile(filename+'.txt')
128 if not file.open(QFile.WriteOnly | QFile.Text):
129 QMessageBox.warning(self, "Dock Widgets",
130 "Cannot write file %s:\n%s." % (filename, file.errorString()))
131 return
132
133 out = QTextStream(file)
134 out.setCodec("UTF-8")
135 QApplication.setOverrideCursor(Qt.WaitCursor)
136 out << self.editor.toPlainText()
137 QApplication.restoreOverrideCursor()
138
139 self.statusBar().showMessage("Saved '%s'" % filename, 2000)

Related snippets