Skip to content

Commit

Permalink
[Processing] Fix when iface is None
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Apr 20, 2016
1 parent 46ff59b commit e765bb6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion python/plugins/processing/core/GeoAlgorithm.py
Expand Up @@ -386,7 +386,8 @@ def setOutputCRS(self):
return
try:
from qgis.utils import iface
self.crs = iface.mapCanvas().mapSettings().destinationCrs()
if iface is not None:

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Apr 20, 2016

Member

Wasn't that caught by the exception already?

This comment has been minimized.

Copy link
@rldhont

rldhont Apr 20, 2016

Author Contributor

I don't exactly know what the try is for. I think it is much more the from ... import

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Apr 20, 2016

Member

The way it currently stands it will catch any error. But it's bad practice to use a generic except, so you have a point there :)

self.crs = iface.mapCanvas().mapSettings().destinationCrs()
except:
pass

Expand Down
7 changes: 4 additions & 3 deletions python/plugins/processing/modeler/ModelerAlgorithm.py
Expand Up @@ -385,9 +385,10 @@ def prepareAlgorithm(self, alg):
if param.name in alg.params:
value = self.resolveValue(alg.params[param.name])
else:
iface.messageBar().pushMessage(self.tr("Warning"),
self.tr("Parameter %s in algorithm %s in the model is run with default value! Edit the model to make sure that this is correct.") % (param.name, alg.name),
QgsMessageBar.WARNING, 4)
if iface is not None:
iface.messageBar().pushMessage(self.tr("Warning"),
self.tr("Parameter %s in algorithm %s in the model is run with default value! Edit the model to make sure that this is correct.") % (param.name, alg.name),
QgsMessageBar.WARNING, 4)

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Apr 20, 2016

Member

In general, wouldn't it be nice to send signals for such things which are connected to messagebar on desktop and to other means somewhere else?
No critics on this particular commit, more a general thought.

This comment has been minimized.

Copy link
@rldhont

rldhont Apr 20, 2016

Author Contributor

It is for server side where iface is None and messageBar does not exist.

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Apr 20, 2016

Member

That's exactly my point, in this case it should go to e.g. a logfile. Hardcoding the message target in here is bad practice.
Your fix basically works around the assumption that a model is always run in a QGIS desktop context.

value = None
if value is None and isinstance(param, ParameterExtent):
value = self.getMinCoveringExtent()
Expand Down

0 comments on commit e765bb6

Please sign in to comment.