Skip to content

Commit 986bd1c

Browse files
committed
[processing] add "Save as" functionality to History dialog (fix #10086)
1 parent e3f630a commit 986bd1c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

python/plugins/processing/core/ProcessingLog.py

+8
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ def clearLog():
134134
os.unlink(ProcessingLog.logFilename())
135135
ProcessingLog.startLogging()
136136

137+
@staticmethod
138+
def saveLog(fileName):
139+
entries = ProcessingLog.getLogEntries()
140+
with codecs.open(fileName, 'w', encoding='utf-8') as f:
141+
for k, v in entries.iteritems():
142+
for entry in v:
143+
f.write('%s|%s|%s\n' % (k, entry.date, entry.text))
144+
137145

138146
class LogEntry:
139147

python/plugins/processing/gui/HistoryDialog.py

+17
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@ def __init__(self):
5151
self.clearButton.setToolTip(self.tr('Clear history and log'))
5252
self.buttonBox.addButton(self.clearButton, QDialogButtonBox.ActionRole)
5353

54+
self.saveButton = QPushButton(self.tr('Save As...'))
55+
self.saveButton.setToolTip(self.tr('Save history and log'))
56+
self.buttonBox.addButton(self.saveButton, QDialogButtonBox.ActionRole)
57+
5458
self.tree.doubleClicked.connect(self.executeAlgorithm)
5559
self.tree.currentItemChanged.connect(self.changeText)
5660
self.clearButton.clicked.connect(self.clearLog)
61+
self.saveButton.clicked.connect(self.saveLog)
5762

5863
self.tree.setContextMenuPolicy(Qt.CustomContextMenu)
5964
self.tree.customContextMenuRequested.connect(self.showPopupMenu)
@@ -70,6 +75,18 @@ def clearLog(self):
7075
ProcessingLog.clearLog()
7176
self.fillTree()
7277

78+
def saveLog(self):
79+
fileName = QFileDialog.getSaveFileName(self,
80+
self.tr('Save file'), '.', 'Log files (*.log *.LOG)')
81+
82+
if fileName == '':
83+
return
84+
85+
if not fileName.lower().endswith('.log'):
86+
fileName += '.log'
87+
88+
ProcessingLog.saveLog(fileName)
89+
7390
def fillTree(self):
7491
self.tree.clear()
7592
elements = ProcessingLog.getLogEntries()

0 commit comments

Comments
 (0)