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

Denis Rouzaud denis.rouzaud at gmail.com
Thu Sep 24 07:53:46 PDT 2015


Hi Lauri, hi Jürgen,

I think you're right and
\apps\qgis-dev\python\PyQt4\uic\widget-plugins\qgis_customwidgets.py
should be moved to
\apps\Python27\Lib\site-packages\PyQt4\uic\widget-plugins.

This file is not intended to change over QGIS versions and is totally
generic.
In fact, it will load the qgis version depending on the PYTHONPATH.

Jürgen, are you ok with this and can you do so?

Cheers,

Denis


PS: here is the content of qgis_customwidgets.py









On 09/24/2015 04:08 PM, Lauri Kajan wrote:
> 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
> <mailto: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>
>     > <mailto: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>
>     <tel:%2B49-4931-918175-31>
>     >     Dipl.-Inf. (FH)             Rheinstraße 13          Fax.
>     >     +49-4931-918175-50 <tel:%2B49-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>
>     <mailto: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 <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
> 


More information about the Qgis-developer mailing list