Skip to content

Commit 0cffd19

Browse files
committedMay 31, 2018
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)
1 parent 9fcee52 commit 0cffd19

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
 

‎python/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from builtins import zip
2727
import os
28+
import sys
2829

2930

3031
def setupenv():
@@ -69,3 +70,20 @@ def setupenv():
6970

7071

7172
from qgis.PyQt import QtCore
73+
74+
# monkey patching custom widgets in case we are running on a local install
75+
# this should fix import errors such as "ModuleNotFoundError: No module named qgsfilewidget"
76+
# ("from qgsfilewidget import QgsFileWidget")
77+
# In a complete install, this is normally avoided and rather imports "qgis.gui"
78+
# (thanks to uic/widget-plugins/qgis_customwidgets.py)
79+
try:
80+
import qgis.gui
81+
widget_list = dir(qgis.gui)
82+
# remove widgets that are not allowed as customwidgets (they need to be manually promoted)
83+
skip_list = ['QgsScrollArea']
84+
for widget in widget_list:
85+
if widget.startswith('Qgs') and widget not in skip_list:
86+
sys.modules[widget.lower()] = qgis.gui
87+
except ImportError:
88+
# gui might not be built
89+
pass

0 commit comments

Comments
 (0)
Please sign in to comment.