[Qgis-developer] Compiling ui files with custom widgets creates wrong imports

Lauri Kajan lauri.kajan at gmail.com
Thu Sep 24 07:08:50 PDT 2015


Hi Denis,

Unfortunately this seems not to be enough.
If pythonpath is set pyuic4 still produces wrong import.

Here's my environment and command to compile ui file
with QgsMapLayerComboBox.
------------------
C:\OSGeo4W64>echo %PATH%
C:\OSGEO4~1\apps\qgis-dev\bin;C:\OSGEO4~1\apps\Python27\Scripts;C:\OSGEO4~1\bin;
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\WBem;C:\OSGEO4~1\apps\msys\bin

C:\OSGeo4W64>echo %PYTHONPATH%
C:\OSGEO4~1\apps\qgis-dev\python

C:\OSGeo4W64>pyuic4 test_widget.ui -o test_widget.py
-----------------

In the compiled test_widget.py there's still a line:
from qgsmaplayercombobox import QgsMapLayerComboBox


Paths should be set correctly because importing qgis.gui works ok from
python started from the same environment.


PyQt and pyuic4 reads custom witget definitions
from C:\OSGeo4W64\apps\Python27\Lib\site-packages\PyQt4\uic\widget-plugins.
I think that PyQt is not aware
of C:\OSGeo4W64\apps\qgis-dev\python\PyQt4\uic\widget-plugins folder.


This is not a problem of only pyuic4.
Also all plugins that use custom qgis widgets and try to import ui files
directly in their code using the uic.loadUiType() function crashes on
windows!



-Lauri

On Tue, Sep 22, 2015 at 8:05 AM, Denis Rouzaud <denis.rouzaud at gmail.com>
wrote:

> Hi all,
>
>
> The path that must be specified as PYTHONPATH is
> QGIS_PREFIX_PATH/share/qgis/python
>
> All the custom widgets have their classes in qgis gui. Therefore, you
> just need to add the QGIS python path to PYTHONPATH to be able to define
> properly their import.
>
> As Jürgen said there might be several versions of QGIS installed (i.e.
> different versions of the custom widgets library), hence the PYTHONPATH
> can't be set automatically.
>
> Denis
>
>
>
> On 09/19/2015 03:16 PM, Lauri Kajan wrote:
> > Hi Jürgen!
> >
> > I think that this can't be fixed by just setting the PYTHONPATH.
> >
> > If I have understood right the problem is that PyQt and its uic module
> > can't find qgis_customwidgets.py or better said
> > 'qgis-dev\python\PyQt4\uic\widget-plugins' directory because it is not
> > told to do so. It is not that some module can't be imported because it
> > is not in pythonpath. Please correct me if I'm wrong.
> >
> > Directories that are searched for widget plugins by PyQt4 are defined in
> > uic.widgetPluginPath. I have not found any environment variable where
> > this list can be altered.
> > After I appended
> > "C:\OSGeo4W64\apps\qgis-dev\python\PyQt4\uic\widget-plugins" to the
> > widgetPluginPath list I'm able to use uic.loadUiType function inside
> > python. Still that doesn't solve the problem with pyuic4 because
> > widgetPluginPath can't be set externally.
> >
> >
> > -Lauri
> >
> >
> >
> > On Sat, Sep 19, 2015 at 12:47 PM, Jürgen E. <jef at norbit.de
> > <mailto:jef at norbit.de>> wrote:
> >
> >     Hi Lauri,
> >
> >     On Sat, 19. Sep 2015 at 12:11:11 +0300, Lauri Kajan wrote:
> >     > The actual problem might be that
> >     >
> C:\OSGeo4W64\apps\qgis-dev\python\PyQt4\uic\widget-plugins\qgis_customwidgets.py
> >     > file is not found by pyuic4.
> >     > After I copied that file
> >     > to
> C:\OSGeo4W64\apps\Python27\Lib\site-packages\PyQt4\uic\widget-plugins
> >     > everything works ok.
> >     >
> >     > Is this a osgeo4w bug or could this be fixed by us?
> >
> >     > Should the qgis postinstall bat copy qgis_customwidgets.py file to
> the
> >     > right place?
> >
> >     No, qgis-dev might not be the only installed version - so you have
> >     to setup the
> >     PYTHONPATH to use the version you target.
> >
> >
> >     Jürgen
> >
> >     --
> >     Jürgen E. Fischer           norBIT GmbH             Tel.
> >     +49-4931-918175-31 <tel:%2B49-4931-918175-31>
> >     Dipl.-Inf. (FH)             Rheinstraße 13          Fax.
> >     +49-4931-918175-50 <tel:%2B49-4931-918175-50>
> >     Software Engineer           D-26506 Norden
> >      http://www.norbit.de
> >     QGIS release manager (PSC)  Germany                    IRC: jef on
> >     FreeNode
> >
> >     _______________________________________________
> >     Qgis-developer mailing list
> >     Qgis-developer at lists.osgeo.org <mailto:
> Qgis-developer at lists.osgeo.org>
> >     http://lists.osgeo.org/mailman/listinfo/qgis-developer
> >
> >
> >
> >
> > _______________________________________________
> > Qgis-developer mailing list
> > Qgis-developer at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/qgis-developer
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150924/be575e1e/attachment.html>


More information about the Qgis-developer mailing list