2

I created a QGIS (2.14.8 LTR) plugin gui with QtDesigner and I would like to use a QgsMapLayerComboBox, cp. screenshot below (selected widget, settings at the right).

enter image description here

At QGIS startup, when loading the plugins I get the following traceback:

2016-11-02T15:27:40 1   Traceback (most recent call last):
          File "C:/OSGEO4~1/apps/qgis-ltr/./python\qgis\utils.py", line 306, in startPlugin
            plugins[packageName] = package.classFactory(iface)
          File "C:/Users/Jochen/.qgis2/python/plugins\ALBeDa\__init__.py", line 34, in classFactory
            from .al_ba import AlBA
          File "C:/OSGEO4~1/apps/qgis-ltr/./python\qgis\utils.py", line 572, in _import
            mod = _builtin_import(name, globals, locals, fromlist, level)
          File "C:/Users/Jochen/.qgis2/python/plugins\ALBeDa\al_ba.py", line 29, in <module>
            from al_ba_dockwidget import AlBADockWidget
          File "C:/OSGEO4~1/apps/qgis-ltr/./python\qgis\utils.py", line 572, in _import
            mod = _builtin_import(name, globals, locals, fromlist, level)
          File "C:/Users/Jochen/.qgis2/python/plugins\ALBeDa\al_ba_dockwidget.py", line 43, in <module>
            os.path.dirname(__file__), 'al_ba_dockwidget_base.ui'))
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\__init__.py", line 210, in loadUiType
            winfo = compiler.UICompiler().compileUi(uifile, code_string, from_imports, resource_suffix)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\Compiler\compiler.py", line 139, in compileUi
            w = self.parse(input_stream, resource_suffix)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 933, in parse
            actor(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 772, in createUserInterface
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 224, in createWidget
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 461, in createLayout
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 504, in handleItem
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 461, in createLayout
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 504, in handleItem
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 224, in createWidget
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 224, in createWidget
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 461, in createLayout
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 504, in handleItem
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 461, in createLayout
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 504, in handleItem
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 224, in createWidget
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 224, in createWidget
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 461, in createLayout
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 504, in handleItem
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 461, in createLayout
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 504, in handleItem
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 461, in createLayout
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 504, in handleItem
            self.traverseWidgetTree(elem)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 750, in traverseWidgetTree
            handler(self, child)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 215, in createWidget
            self.stack.push(self.setupObject(widget_class, parent, elem))
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 177, in setupObject
            self.wprops.setProperties(obj, branch)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\properties.py", line 418, in setProperties
            prop_value = self.convert(prop, widget)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\properties.py", line 383, in convert
            return func(prop[0], **args)
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\properties.py", line 116, in _set
            expr = [self._pyEnumMember(v) for v in prop.text.split('|')]
          File "C:\OSGEO4~1\apps\Python27\lib\site-packages\PyQt4\uic\properties.py", line 111, in _pyEnumMember
            raise AttributeError("unknown enum %s" % cpp_name)
        AttributeError: unknown enum QgsMapLayerProxyModel::PolygonLayer

Do I miss something in the configuration or do I not use this as intented? One explanation might be that there are no map layers at QGIS startup, but then how to use this at all (is the QgsMapLayerComboBox widget updated when adding layers or opening a new project)?

  • 1
    It might be an issue with dependencies because I couldn't reproduce the problem on a GNU/Linux machine. If it helps somehow, have a look at my installed QGIS packages. – Germán Carrillo Nov 2 '16 at 15:28
  • 1
    I believe there's an issue with accessing the Qgs* widgets under windows, from plugins anyway - it affected one of my plugins. In my case, though, I was able to revert to the standard Qt widget. This issue and the associated dev mailing list thread might be of interest – Steven Kay Nov 2 '16 at 18:05
1

I faced the same bug and I managed to solve it copying qgis_customwidgets.py file in the right place during plugin initialization appending to __init__ function the following lines:

    import shutils        

    #check for qgis_customwidgets.py
    qgis_loc = os.path.abspath(os.environ["QGIS_PREFIX_PATH"])
    bad_loc =  os.path.abspath(os.path.join(qgis_loc,"python","PyQt4","uic","widget-plugins","qgis_customwidgets.py"))
    right_loc =  os.path.abspath(os.path.join(qgis_loc,"..","Python27","Lib","site-packages","PyQt4","uic","widget-plugins","qgis_customwidgets.py"))
    if os.path.exists(bad_loc) and not os.path.exists(right_loc):
        shutil.copyfile(bad_loc,right_loc)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.