[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] loadUiType and resources_rc.py in another folder
From:       Denis Rouzaud <denis.rouzaud () gmail ! com>
Date:       2020-01-20 8:51:41
Message-ID: CAMtsY+Zn+Ect36b9JkhVN0_snWHYaBBsdBbHfkQoUw9aOJYZzQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Ludovic,

I am not modifying the built resources_rc.py but the import one I am using
in the same directory than the dialog file.
This resources_rc.py only contains the import statement, I have
successfully used this when using pyuic in the past, but it doesn't seem to
work when using loadUiType.

More generally, I am wondering what is the approach when the
resources_rc.py, the ui and the dialog py files are all 3 in
distinct directories.

Cheers,
Denis

Le ven. 17 janv. 2020 à 15:34, Ludovic Bellière <
belliere.ludovic@proximus.be> a écrit :

> Hello Denis,
> 
> The resources_rc.py is supposed to be generated with pyrcc5, and
> shouldn't be edited. The structure of your application is weird, and
> apparently the loader is unable to find your resources_rc.py, which
> means you didn't put it where it needs to be. I don't know where it
> needs to be, it depends on the structure of your code, and files within
> your project.
> 
> Do you know how python imports works? You see confused on that subject.
> Did you consider building a test PyQt5 app using a flat format, and then
> expand from there?
> 
> Cheers,
> Ludovic
> 
> PS: sorry about the previous direct e-mail. Still figuring ML stuff out.
> 
> On 17/01/20 14:58, Denis Rouzaud wrote:
> > 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@proximus.be <mailto:belliere.ludovic@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@riverbankcomputing.com
> > <mailto:PyQt@riverbankcomputing.com>
> > > https://www.riverbankcomputing.com/mailman/listinfo/pyqt
> > > 
> > 
> 


[Attachment #5 (text/html)]

<div dir="ltr">Hi Ludovic,<div><br></div><div>I am not modifying the built \
resources_rc.py but the import one I am using in the same directory than the dialog \
file.</div><div>This resources_rc.py only contains the import statement, I have \
successfully  used this when using pyuic in the past, but it doesn&#39;t seem to work \
when using loadUiType.</div><div><br></div><div>More generally, I am wondering what \
is the approach when the resources_rc.py, the ui and the dialog py files are all 3 in \
distinct  directories.</div><div><br></div><div>Cheers,</div><div>Denis</div></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">Le  ven. 17 janv. 2020 Ã   \
15:34, Ludovic Bellière &lt;<a \
href="mailto:belliere.ludovic@proximus.be">belliere.ludovic@proximus.be</a>&gt; a \
écrit  :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello Denis,<br> <br>
The resources_rc.py is supposed to be generated with pyrcc5, and<br>
shouldn&#39;t be edited. The structure of your application is weird, and<br>
apparently the loader is unable to find your resources_rc.py, which<br>
means you didn&#39;t put it where it needs to be. I don&#39;t know where it<br>
needs to be, it depends on the structure of your code, and files within<br>
your project.<br>
<br>
Do you know how python imports works? You see confused on that subject.<br>
Did you consider building a test PyQt5 app using a flat format, and then<br>
expand from there?<br>
<br>
Cheers,<br>
Ludovic<br>
<br>
PS: sorry about the previous direct e-mail. Still figuring ML stuff out.<br>
<br>
On 17/01/20 14:58, Denis Rouzaud wrote:<br>
&gt; Hi Ludovic,<br>
&gt; <br>
&gt; Thanks for the help.<br>
&gt; <br>
&gt; I tried to add this in my resources_rc.py in the same path than the<br>
&gt; dialog py file without  success.<br>
&gt; I also tried in the __init__.py<br>
&gt; <br>
&gt; Where is it meant to live?<br>
&gt; <br>
&gt; Cheers,<br>
&gt; Denis<br>
&gt; <br>
&gt; Le  ven. 17 janv. 2020 à  14:27, Ludovic Bellière<br>
&gt; &lt;<a href="mailto:belliere.ludovic@proximus.be" \
target="_blank">belliere.ludovic@proximus.be</a> &lt;mailto:<a \
href="mailto:belliere.ludovic@proximus.be" \
target="_blank">belliere.ludovic@proximus.be</a>&gt;&gt; a<br> &gt; écrit  :<br>
&gt; <br>
&gt;        Hello Denis,<br>
&gt; <br>
&gt;        The compiled resources_rc.py has a bit of code that will inject the<br>
&gt;        different resources into Qt&#39;s database at the time of import. To \
achieve<br> &gt;        that, you need to do the import this way:<br>
&gt; <br>
&gt;        `from .. import resources_rc`<br>
&gt; <br>
&gt;        On 16/01/20 11:29, Denis Rouzaud wrote:<br>
&gt;        &gt; Hi list,<br>
&gt;        &gt;<br>
&gt;        &gt; I have this tree structure:<br>
&gt;        &gt; - gui<br>
&gt;        &gt;    |- dialog.py<br>
&gt;        &gt; - ui<br>
&gt;        &gt;    |- dialog.ui<br>
&gt;        &gt; - resources_rc.py<br>
&gt;        &gt;<br>
&gt;        &gt; I am trying to use uic.loadUiType with the ui file having a \
resources<br> &gt;        &gt; file defined integrated with:<br>
&gt;        &gt;<br>
&gt;        &gt; &lt;iconset resource=&quot;../resources.qrc&quot;&gt;<br>
&gt;        &gt;  <br>
&gt;          &lt;normaloff&gt;:/plugins/qfieldsync/visibility.svg&lt;/normaloff&gt;:/plugins/qfieldsync/visibility.svg&lt;/iconset&gt;<br>
 &gt;        &gt; &lt;/property&gt;<br>
&gt;        &gt;<br>
&gt;        &gt;<br>
&gt;        &gt;<br>
&gt;        &gt; I have this error:<br>
&gt;        &gt;<br>
&gt;        &gt;    File &quot;/Users/denis/Library/Application<br>
&gt;        &gt;<br>
&gt;        Support/QGIS/QGIS3/profiles/default/python/plugins/qfieldsync/gui/project_configuration_dialog.py&quot;,<br>
 &gt;        &gt; line 36, in<br>
&gt;        &gt;       os.path.join(os.path.dirname(__file__),<br>
&gt;        &gt; &#39;../ui/project_configuration_dialog.ui&#39;),<br>
&gt;        &gt;    File<br>
&gt;        &gt;<br>
&gt;        &quot;/Applications/QGIS3.11.app/Contents/MacOS/../Resources/python/qgis/PyQt/uic/__init__.py&quot;,<br>
 &gt;        &gt; line 36, in __loadUiType<br>
&gt;        &gt;       return __PyQtLoadUiType(*args, **kwargs)<br>
&gt;        &gt;    File<br>
&gt;        &gt;<br>
&gt;        &quot;/Applications/QGIS3.11.app/Contents/MacOS/../Resources/python/PyQt5/uic/__init__.py&quot;,<br>
 &gt;        &gt; line 201, in loadUiType<br>
&gt;        &gt;       exec(code_string.getvalue(), ui_globals)<br>
&gt;        &gt;    File &quot;&quot;, line 182, in<br>
&gt;        &gt;    File<br>
&gt;        &gt;<br>
&gt;        &quot;/Applications/QGIS3.11.app/Contents/MacOS/../Resources/python/qgis/utils.py&quot;,<br>
 &gt;        &gt; line 737, in _import<br>
&gt;        &gt;       mod = _builtin_import(name, globals, locals, fromlist, \
level)<br> &gt;        &gt; ModuleNotFoundError: No module named \
&#39;resources_rc&#39;<br> &gt;        &gt;<br>
&gt;        &gt;<br>
&gt;        &gt;<br>
&gt;        &gt;<br>
&gt;        &gt; I tried to add a resources_rc.py in the gui folder with:<br>
&gt;        &gt;<br>
&gt;        &gt; from ..resources_rc import *<br>
&gt;        &gt;<br>
&gt;        &gt; but this doesn&#39;t help.<br>
&gt;        &gt;<br>
&gt;        &gt;<br>
&gt;        &gt; And if I use the option from_imports=True (in loadUiType), I am<br>
&gt;        getting:<br>
&gt;        &gt;<br>
&gt;        &gt; line 37, in<br>
&gt;        &gt;       from_imports=True<br>
&gt;        &gt;    File<br>
&gt;        &gt;<br>
&gt;        &quot;/Applications/QGIS3.11.app/Contents/MacOS/../Resources/python/qgis/PyQt/uic/__init__.py&quot;,<br>
 &gt;        &gt; line 36, in __loadUiType<br>
&gt;        &gt;       return __PyQtLoadUiType(*args, **kwargs)<br>
&gt;        &gt;    File<br>
&gt;        &gt;<br>
&gt;        &quot;/Applications/QGIS3.11.app/Contents/MacOS/../Resources/python/PyQt5/uic/__init__.py&quot;,<br>
 &gt;        &gt; line 201, in loadUiType<br>
&gt;        &gt;       exec(code_string.getvalue(), ui_globals)<br>
&gt;        &gt;    File &quot;&quot;, line 182, in<br>
&gt;        &gt;    File<br>
&gt;        &gt;<br>
&gt;        &quot;/Applications/QGIS3.11.app/Contents/MacOS/../Resources/python/qgis/utils.py&quot;,<br>
 &gt;        &gt; line 737, in _import<br>
&gt;        &gt;       mod = _builtin_import(name, globals, locals, fromlist, \
level)<br> &gt;        &gt; KeyError: &quot;&#39;__name__&#39; not in \
globals&quot;<br> &gt;        &gt;<br>
&gt;        &gt;<br>
&gt;        &gt;<br>
&gt;        &gt;<br>
&gt;        &gt;<br>
&gt;        &gt; How am I suppose to handle this?<br>
&gt;        &gt; Thanks,<br>
&gt;        &gt;<br>
&gt;        &gt; Denis<br>
&gt;        &gt;<br>
&gt;        &gt;<br>
&gt;        &gt; _______________________________________________<br>
&gt;        &gt; PyQt mailing list      <a href="mailto:PyQt@riverbankcomputing.com" \
target="_blank">PyQt@riverbankcomputing.com</a><br> &gt;        &lt;mailto:<a \
href="mailto:PyQt@riverbankcomputing.com" \
target="_blank">PyQt@riverbankcomputing.com</a>&gt;<br> &gt;        &gt; <a \
href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" \
target="_blank">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br> &gt; \
&gt;<br> &gt; <br>
</blockquote></div>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic