Skip to content
Permalink
Browse files

[processing] Use c++ recent algorithm log, remove python log

Indirectly fixes #19218
  • Loading branch information
nyalldawson committed Jul 4, 2018
1 parent d232cde commit 6c014b46babf8f22bcd0208fbd6043ddbfd6d0da
@@ -42,7 +42,7 @@
QgsProject,
QgsMessageLog,
QgsProcessingOutputLayerDefinition)
from qgis.gui import QgsEncodingFileDialog
from qgis.gui import QgsEncodingFileDialog, QgsGui
from qgis.utils import OverrideCursor

from processing.core.ProcessingConfig import ProcessingConfig
@@ -240,6 +240,7 @@ def accept(self):

context = dataobjects.createContext()
ProcessingLog.addToLog(self.alg.asPythonCommand(parameters, context))
QgsGui.instance().processingRecentAlgorithmLog().push(self.alg.id())

self.executed, results = execute(self.alg, parameters, context, self.feedback)
self.setPercentage(0)
@@ -56,7 +56,6 @@ class ProcessingConfig:
USE_FILENAME_AS_LAYER_NAME = 'USE_FILENAME_AS_LAYER_NAME'
KEEP_DIALOG_OPEN = 'KEEP_DIALOG_OPEN'
SHOW_DEBUG_IN_DIALOG = 'SHOW_DEBUG_IN_DIALOG'
RECENT_ALGORITHMS = 'RECENT_ALGORITHMS'
PRE_EXECUTION_SCRIPT = 'PRE_EXECUTION_SCRIPT'
POST_EXECUTION_SCRIPT = 'POST_EXECUTION_SCRIPT'
SHOW_CRS_DEF = 'SHOW_CRS_DEF'
@@ -136,10 +135,6 @@ def initialize():
ProcessingConfig.POST_EXECUTION_SCRIPT,
ProcessingConfig.tr('Post-execution script'), '',
valuetype=Setting.FILE))
ProcessingConfig.addSetting(Setting(
ProcessingConfig.tr('General'),
ProcessingConfig.RECENT_ALGORITHMS,
ProcessingConfig.tr('Recent algorithms'), '', hidden=True))
ProcessingConfig.addSetting(Setting(
ProcessingConfig.tr('General'),
ProcessingConfig.MODELS_SCRIPTS_REPO,
@@ -38,7 +38,6 @@
class ProcessingLog:

DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
recentAlgs = []

@staticmethod
def logFilename():
@@ -63,14 +62,6 @@ def addToLog(msg):
with codecs.open(ProcessingLog.logFilename(), 'a',
encoding='utf-8') as logfile:
logfile.write(line)
algname = msg[len('processing.run("'):]
algname = algname[:algname.index('"')]
if algname not in ProcessingLog.recentAlgs:
ProcessingLog.recentAlgs.append(algname)
recentAlgsString = ';'.join(ProcessingLog.recentAlgs[-6:])
ProcessingConfig.setSettingValue(
ProcessingConfig.RECENT_ALGORITHMS,
recentAlgsString)
except:
pass

@@ -95,16 +86,6 @@ def getLogEntries():

return entries

@staticmethod
def getRecentAlgorithms():
recentAlgsSetting = ProcessingConfig.getSetting(
ProcessingConfig.RECENT_ALGORITHMS)
try:
ProcessingLog.recentAlgs = recentAlgsSetting.split(';')
except:
pass
return ProcessingLog.recentAlgs

@staticmethod
def clearLog():
os.unlink(ProcessingLog.logFilename())
@@ -44,7 +44,8 @@
QgsProcessingParameterFeatureSink,
QgsProcessingParameterRasterDestination,
QgsProcessingAlgorithm)
from qgis.gui import (QgsMessageBar,
from qgis.gui import (QgsGui,
QgsMessageBar,
QgsProcessingAlgorithmDialogBase)
from qgis.utils import iface

@@ -188,6 +189,7 @@ def accept(self):
command = self.algorithm().asPythonCommand(parameters, context)
if command:
ProcessingLog.addToLog(command)
QgsGui.instance().processingRecentAlgorithmLog().push(self.algorithm().id())
self.cancelButton().setEnabled(self.algorithm().flags() & QgsProcessingAlgorithm.FlagCanCancel)

def on_complete(ok, results):
@@ -35,7 +35,8 @@
from qgis.utils import iface
from qgis.core import (QgsApplication,
QgsProcessingAlgorithm)
from qgis.gui import QgsDockWidget
from qgis.gui import (QgsGui,
QgsDockWidget)

from processing.gui.Postprocessing import handleAlgorithmResults
from processing.core.ProcessingLog import ProcessingLog
@@ -107,6 +108,7 @@ def openSettings(url):

QgsApplication.processingRegistry().providerRemoved.connect(self.removeProvider)
QgsApplication.processingRegistry().providerAdded.connect(self.addProvider)
QgsGui.instance().processingRecentAlgorithmLog().changed.connect(self.addRecentAlgorithms)
settingsWatcher.settingsChanged.connect(self.fillTree)

def showDisabled(self):
@@ -349,11 +351,6 @@ def executeAlgorithm(self):
except:
pass
canvas.setMapTool(prevMapTool)
if dlg.wasExecuted():
showRecent = ProcessingConfig.getSetting(
ProcessingConfig.SHOW_RECENT_ALGORITHMS)
if showRecent:
self.addRecentAlgorithms(True)
else:
feedback = MessageBarProgress()
context = dataobjects.createContext(feedback)
@@ -366,11 +363,11 @@ def fillTree(self):
self.fillTreeUsingProviders()
self.addRecentAlgorithms(False)

def addRecentAlgorithms(self, updating):
def addRecentAlgorithms(self, updating=True):
showRecent = ProcessingConfig.getSetting(
ProcessingConfig.SHOW_RECENT_ALGORITHMS)
if showRecent:
recent = ProcessingLog.getRecentAlgorithms()
recent = QgsGui.instance().processingRecentAlgorithmLog().recentAlgorithmIds()
if len(recent) != 0:
found = False
if updating:
@@ -382,8 +379,8 @@ def addRecentAlgorithms(self, updating):

recentItem = QTreeWidgetItem()
recentItem.setText(0, self.tr('Recently used'))
for algname in recent:
alg = QgsApplication.processingRegistry().createAlgorithmById(algname)
for algorithm_id in recent:
alg = QgsApplication.processingRegistry().createAlgorithmById(algorithm_id)
if alg is not None:
algItem = TreeAlgorithmItem(alg)
recentItem.addChild(algItem)

0 comments on commit 6c014b4

Please sign in to comment.
You can’t perform that action at this time.