From 0cffd19e5f54e22f27797fcfd0a7e8e04a755da0 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Thu, 31 May 2018 12:03:40 -0400 Subject: [PATCH] monkey path custom widgets this will add module to the system to avoid missing modules when running on a local install (uic widget-plugin not installed) --- python/__init__.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/python/__init__.py b/python/__init__.py index b0efd4a6288..5f19de3634c 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -25,6 +25,7 @@ __revision__ = '$Format:%H$' from builtins import zip import os +import sys def setupenv(): @@ -69,3 +70,20 @@ if os.name == 'nt': from qgis.PyQt import QtCore + +# monkey patching custom widgets in case we are running on a local install +# this should fix import errors such as "ModuleNotFoundError: No module named qgsfilewidget" +# ("from qgsfilewidget import QgsFileWidget") +# In a complete install, this is normally avoided and rather imports "qgis.gui" +# (thanks to uic/widget-plugins/qgis_customwidgets.py) +try: + import qgis.gui + widget_list = dir(qgis.gui) + # remove widgets that are not allowed as customwidgets (they need to be manually promoted) + skip_list = ['QgsScrollArea'] + for widget in widget_list: + if widget.startswith('Qgs') and widget not in skip_list: + sys.modules[widget.lower()] = qgis.gui +except ImportError: + # gui might not be built + pass