[PyQt] loadUiType and resources_rc.py in another folder

Denis Rouzaud denis.rouzaud at gmail.com
Fri Jan 17 13:58:33 GMT 2020


Hi Ludovic,

Thanks for the help.

I tried to add this in my resources_rc.py in the same path than the dialog
py file without success.
I also tried in the __init__.py

Where is it meant to live?

Cheers,
Denis

Le ven. 17 janv. 2020 à 14:27, Ludovic Bellière <
belliere.ludovic at proximus.be> a écrit :

> Hello Denis,
>
> The compiled resources_rc.py has a bit of code that will inject the
> different resources into Qt's database at the time of import. To achieve
> that, you need to do the import this way:
>
> `from .. import resources_rc`
>
> On 16/01/20 11:29, Denis Rouzaud wrote:
> > Hi list,
> >
> > I have this tree structure:
> > - gui
> >   |- dialog.py
> > - ui
> >   |- dialog.ui
> > - resources_rc.py
> >
> > I am trying to use uic.loadUiType with the ui file having a resources
> > file defined integrated with:
> >
> > <iconset resource="../resources.qrc">
> >
>  <normaloff>:/plugins/qfieldsync/visibility.svg</normaloff>:/plugins/qfieldsync/visibility.svg</iconset>
> > </property>
> >
> >
> >
> > I have this error:
> >
> >   File "/Users/denis/Library/Application
> >
> Support/QGIS/QGIS3/profiles/default/python/plugins/qfieldsync/gui/project_configuration_dialog.py",
> > line 36, in
> >     os.path.join(os.path.dirname(__file__),
> > '../ui/project_configuration_dialog.ui'),
> >   File
> >
> "/Applications/QGIS3.11.app/Contents/MacOS/../Resources/python/qgis/PyQt/uic/__init__.py",
> > line 36, in __loadUiType
> >     return __PyQtLoadUiType(*args, **kwargs)
> >   File
> >
> "/Applications/QGIS3.11.app/Contents/MacOS/../Resources/python/PyQt5/uic/__init__.py",
> > line 201, in loadUiType
> >     exec(code_string.getvalue(), ui_globals)
> >   File "", line 182, in
> >   File
> >
> "/Applications/QGIS3.11.app/Contents/MacOS/../Resources/python/qgis/utils.py",
> > line 737, in _import
> >     mod = _builtin_import(name, globals, locals, fromlist, level)
> > ModuleNotFoundError: No module named 'resources_rc'
> >
> >
> >
> >
> > I tried to add a resources_rc.py in the gui folder with:
> >
> > from ..resources_rc import *
> >
> > but this doesn't help.
> >
> >
> > And if I use the option from_imports=True (in loadUiType), I am getting:
> >
> > line 37, in
> >     from_imports=True
> >   File
> >
> "/Applications/QGIS3.11.app/Contents/MacOS/../Resources/python/qgis/PyQt/uic/__init__.py",
> > line 36, in __loadUiType
> >     return __PyQtLoadUiType(*args, **kwargs)
> >   File
> >
> "/Applications/QGIS3.11.app/Contents/MacOS/../Resources/python/PyQt5/uic/__init__.py",
> > line 201, in loadUiType
> >     exec(code_string.getvalue(), ui_globals)
> >   File "", line 182, in
> >   File
> >
> "/Applications/QGIS3.11.app/Contents/MacOS/../Resources/python/qgis/utils.py",
> > line 737, in _import
> >     mod = _builtin_import(name, globals, locals, fromlist, level)
> > KeyError: "'__name__' not in globals"
> >
> >
> >
> >
> >
> > How am I suppose to handle this?
> > Thanks,
> >
> > Denis
> >
> >
> > _______________________________________________
> > PyQt mailing list    PyQt at riverbankcomputing.com
> > https://www.riverbankcomputing.com/mailman/listinfo/pyqt
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200117/58bd92ce/attachment.html>


More information about the PyQt mailing list