Thursday 14 June 2018

pyqgis - Missing qgis icon resources for symbology dialog


I'm trying to call QgsRendererV2PropertiesDialog from a standalone Qgis python script. It mostly works, except there's some "unknown error" messages related to SVG files when I trigger the dialog:


Cannot open file ':/images/themes/default/sort.svg', because: Unknown error
Cannot open file ':/images/themes/default/sort.svg', because: Unknown error
Cannot open file ':/images/themes/default/symbologyAdd.svg', because: Unknown error
Cannot open file ':/images/themes/default/symbologyAdd.svg', because: Unknown error
[etc]

and the relevant buttons that should have those icons are blank. The dialog looks fine with no missing buttons when I run Qgis itself.


Here's a test script that fires up a symbology dialog that produces the error for me, and one line after it that also produces the error when trying to load an icon. The missing icons are under the symbology layer list, with functions like new layer, lock colour, move layer up/down etc:



from qgis.core import *
from qgis.gui import *
import sys
sys.path.append("/usr/share/qgis/python/plugins")
from PyQt4.QtCore import *
from PyQt4.QtGui import *

app = QgsApplication([], True)
app.setPrefixPath("/usr", True)
app.setThemeName("default")

app.initQgis()
print QgsApplication.showSettings()

layer = QgsVectorLayer("point","point","memory")
if not layer.isValid():
raise ValueError,"Layer not valid"

canvas=QgsMapCanvas()
dialog = QgsRendererV2PropertiesDialog(layer, QgsStyleV2.defaultStyle(), embedded=False)
dialog.exec_()


print QIcon(QgsApplication.iconPath( "symbologyAdd.svg" ) )

app.exitQgis()

Note that the settings printed out by QgsApplication.showSettings() are the same in this script and in Qgis. I'm thinking there's some app initialisation that I've not done. I can't find the resource file that has those icons in it. The icon path is the same in my script, namely: ":/images/themes/default/symbologyAdd.svg".


So, any solution?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...