1

I was wondering if there might be something similar to loadUiType for the resource file. Of course one can use pyrcc5 example.qrc -o example_rc.py but than I have to do this step every time something is changed. Using:

from PyQt5.uic import loadUiType
Ui_MainWindow, QMainwindo = loadUiType('~/example.ui')

renders the usage of the pyuic5-step unnecessary, which eases the application building process a bit.

How would one do that with the resource file?

cheers, Christian

camaro
  • 118
  • 12
  • There is [QResource](http://doc.qt.io/qt-4.8/qresource.html), but the resources still have to be compiled with an external tool before they can be loaded. Personally, I use a makefile with generic targets for pyuic and pyrcc. Then, during development, I use a simple wrapper script that does `make pyuic pyrcc` before running/testing the application. – ekhumoro Jun 24 '15 at 16:34
  • Then it doesn't help. `loadUiType` really saves that compiling stepand the additional file, which normaly is created. There are definetly advantages in creating an additional file with pyuic5, especially when it comes to huge files where one could get lost in all those policy statements, but for prototyping it can get a pain in the ass. For rcc which just holds all the resources one once would provide, it doesn't seem that handy but it would ease up things pretty much because one could use it in the same breath as `loadUiType`. – camaro Jun 25 '15 at 01:10
  • Anyway, `make` has it's value but `scons` has features that charm python in a way I haven't found any equivalents in `make`. But I think that is a little bit overkill and it doesn't save that step at all. On the contrary! It adds further occupation because one has to set up those tools properly and can't recycle from project to project. – camaro Jun 25 '15 at 01:17
  • Using `loadUiType` doesn't save anything. It compiles the module using exactly the same code as `pyuic`. The only difference is that is does it all at runtime, and then imports the module with `exec`. Importing a pre-compiled module is much more efiicient, and I find it helpful to be able to view the contents of the file. As for `make` (or whatever equivalent tool you prefer): I use the same makefile and run script for all my applications. It's only about twenty lines of code in all, and it's very easy to adapt it for each project. – ekhumoro Jun 25 '15 at 15:09
  • Ok, let's say it doesn't 'save' this step but I don't have to do it manually, which is an improvement anyway. Let me draw the attention back to the problem: Is there anything similar? If not please write an official answer so I can credit it. If I have to compile the resource file by hand than having `scons` or `make` in use is an option because it reduces further up coming issues to just one automated step. That's where you're right. – camaro Jun 26 '15 at 07:32
  • Yes, my `pyuic` and `pyrcc` make targets are just part of an installer that is re-purposed during the development process. I think this `loadUi` vs `pyuic` thing mostly comes down to personal taste and how you normally structure your projects. You do have a point regarding `pyrcc` - there probably should be an `rcc` module to match the `uic` one for developers who'd prefer runtime loading. But at the moment, there just isn't one (see my answer, below). – ekhumoro Jun 26 '15 at 20:39

1 Answers1

1

At one time, both pyuic and pyrcc were pure commandline tools written in C++. But the pyuic tool was ported to python for PyQt4 (I think as a student project by Thorsten Marek), and now has a separate uic module of it's own.

I don't think anyone has ever suggested porting pyrcc to python. A brief skim of the code (it's quite short), suggests this might be feasible, but it probably wouldn't be straightforward.

As stated in the comments, there is a QResource class that allows resources to be registered at runtime. But it still requires pre-compilation using the external rcc tool. Since PyQt generally follows the Qt APIs quite closely, this probably explains why it also doesn't have a way to directly compile and load resources at runtime.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • Thx, I can live with that answer. So, if I want to use the resource stuff further efforts have to be taken and having scons doing compiling job – camaro Jun 29 '15 at 09:19