Open hdd opened 8 years ago
wondering, if the tool has to work on more than one (eg: PySide/PySide2) ... should resource should be compiled for both ?
checking now, but should be compatible, so is matter of having some logic on when we compile the resource files.
ok looks like is not, as in the compiled resouce file we end up (eg: pyside) with from
PySide import QtCore
There isn't any wrapper at the moment, but one could potentially be built in.
I reckon that if the resulting resources can't be used in all bindings, then there probably isn't much point in wrapping it.
If you were to provide a wrapper, it could get tested on each supported platform and each supported binding via Travis and the pull request. Have a look at the currently ongoing pull request for load_ui for example.
To my knowledge, pysideuic
is its own module and is not part of PySide
or PySide2
. So far, we haven't attempted to map modules which aren't part of the actual bindings but I can't see why this could not be done.
How would such a module be imported though? Perhaps something like this:
from Qt import pysideuic
But then you'd probably just be better off handling this yourself since there's no equivalent in PyQt land...?
from Qt import __binding__
if __binding__ in ('PySide', 'PySide2'):
import pysideuic
do_pyside_stuff()
elif __binding__ in ('PyQt4', 'PyQt5'):
import uic
do_pyqt_stuff()
Oh, wait, are we talking about the standalone executables such as pyside-uic.exe
?
Thinking of fixing this in the various setup.py which are doing the compilation of the resources, replacing in the compiled resource :
Thinking of fixing this in the various setup.py which are doing the compilation of the resources, replacing in the compiled resource
Possible to show an example of this?
Sure, so when you compile an py from an rcc file, the first lines of the compiled one looks like this:
# -*- coding: utf-8 -*-
# Resource object code
#
# Created: Fri Aug 5 10:17:32 2016
# by: The Resource Compiler for PySide (Qt v4.8.5)
#
# WARNING! All changes made in this file will be lost!
from PySide import QtCore
qt_resource_data = "......................."
This should be changed after the compilation as :
# -*- coding: utf-8 -*-
# Resource object code
#
# Created: Fri Aug 5 10:17:32 2016
# by: The Resource Compiler for PySide (Qt v4.8.5)
#
# WARNING! All changes made in this file will be lost!
from Qt import QtCore
qt_resource_data = "......................."
I'll give this a shot and let you know. This way we should be able to provide backward compatibility.
so, in the setup.py of the tool I'm working in at the moment, I've been adding a post processing call which does pretty much this, which seems to be working fine :
import fileinput
filepath = '/home/efesto/Desktop/resource.py'
replace = 'from Qt import QtCore'
for line in fileinput.input(filepath, inplace=True):
if 'import QtCore' in line:
print line.replace(line, replace)
else:
print line
here it is in action: https://gitlab.com/4degrees/riffle/merge_requests/4/diffs#8e2edce0d507e1297474f25c00cae94258db38d8_53_54
wondering, does worth providing a wrapper with popen which kicks the compilation and replace ? it could be retained in a /bin folder under the project as qt-rcc
let me know. Cheers. L
Interesting. I haven't used these features myself, so I'll have to rely on your experiences.
I'm a bit blurry on how the setup.py comes in to play. Are you saying that you distribute your software with a PyQt or PySide compiled resource file, and re-map it when setup.py is used? That is, during installation?
Could you show a small runnable example?
To cut to the chase, what I'm looking for is the tests for this feature, before we start talking about an implementation.
The tests will more or less be the minimal, yet complete, examples that you come up with. Once there are tests, it will be more easily understood what your end game is and how we can reach it.
For example.
def test_compile_resources():
import Qt
Qt.compile_resources(sourcedir="/path/to/resources", targetfile="/path/to/my_resources.py")
assert os.path.isfile("path/to/my_resources.py"), "nothing written"
This tells us, in just a few lines:
The tests could also include importing this file and asserting some of its content, like (1) the variable in which the data resides and (2) the header comment and (3) the use of Qt instead of PySide etc.
How about this for support coming from Qt.py?
PyQt
or PySide
with Qt
and write a new fileThat way, developers can work natively and Qt.py doesn't have to wrap any functionality, whilst still being able to provide support for all bindings. Win-win-win.
The interface could look something like this.
$ pyside-uic my_resources # writes my_resources.py
$ python -m Qt --convert my_resources.py # writes my_resources_qt.py
I wonder if they produce identical results though? If so, I agree this is a win-win-win 😉
isn't it a bit inconsistent as you are providing wrappers for loading the ui ? This two step process doesn't make much sense, either is done from within the code (Qt.compile_resource(in, out) ), or for me , simply worth keeping it on the various setup.py
simply worth keeping it on the various setup.py
Fair enough. Let's make it part of the docs on how to do that, and we're done.
cool, then please remember to add this also for the uic files, otherwise people will be having all sorts of issues.
Cheers. L.
then please remember to add this also for the uic files
What uic files? Sorry, I don't follow.
Ui (uic) files are created through designer-qt4 and the can be compiled (similarly to resources) to py using pyside-uic
This, usually, allow to load the ui faster than through the load ui command.
I see, ok. Would you be up for writing this part of the README?
@hdd please have a look at the latest release which implements the alpha feature --convert: https://github.com/mottosso/Qt.py/releases/tag/0.5.0
I think Lorenzo is asking about compiling resources, such as png's and jpeg's, into a .py file. --convert
only handles .ui files.
Oh 😮 allright 😄
Hi , is there any wrapped command for things like : pyside-rcc and pyside-uic , so does pick up the right one depending on the framework in use ?