Skip to content
Permalink
Browse files

[Processing] Fix when iface is None

  • Loading branch information
rldhont committed Apr 20, 2016
1 parent 46ff59b commit e765bb6dd1686ca86d7930069cda03db946f71ff
@@ -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

@@ -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()

0 comments on commit e765bb6

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