[Qgis-developer] Including style on a Qgis plugin
Xavier Barnada
xbarnada at gisce.net
Thu Oct 13 23:38:56 PDT 2016
Hi,
Sorry y hadn't been enought specific. The problem was on the images URLs.
I fixed it with this function:
def fix_qml_rel_urls(self, url):
"""
Replaces the QML URLs with plugin relative URLs
:return:
"""
plugin_dir = os.path.dirname(os.path.realpath(__file__))
with open(url, 'r') as fd:
data = fd.read()
f = etree.fromstring(data)
for r in f.xpath('//qgis/renderer-v2/symbols/symbol/layer/prop[@k="
name"]'):
val = r.get('v')
parent = r.getparent()
parent.remove(r)
rel_url = os.path.join(plugin_dir, val)
r.set('v', rel_url)
parent.append(r)
t = etree.tostring(f, pretty_print=True)
tmp_url = tempfile.NamedTemporaryFile(suffix='.qml', delete=False)
tmp_url.write(t)
tmp_url.close()
return tmp_url.name
I'm sure that this don't work on all the types of symbols but perhaps is
useful for someone
After patch the style I loaded it.
Best reggards.
Xavier Barnada
2016-10-13 14:27 GMT+02:00 Tom Chadwin <tom.chadwin at nnpa.org.uk>:
> Hi Xavier
>
> This should give you the path to your plugin's installation folder:
>
> os.path.dirname(os.path.realpath(__file__))
>
> Hope this is what you need.
>
> Tom
>
>
>
> -----
> Buy Pie Spy: Adventures in British pastry 2010-11 on Amazon
> --
> View this message in context: http://osgeo-org.1560.x6.
> nabble.com/Including-style-on-a-Qgis-plugin-tp5290553p5290560.html
> Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20161014/54534735/attachment.html>
More information about the Qgis-developer
mailing list