Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
3nids committed May 31, 2018
1 parent 9fcee52 commit 0cffd19
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions python/__init__.py
Expand Up @@ -25,6 +25,7 @@

from builtins import zip
import os
import sys


def setupenv():
Expand Down Expand Up @@ -69,3 +70,20 @@ def setupenv():


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

0 comments on commit 0cffd19

Please sign in to comment.