7

We already know that we can convert from ui to py easily with pyuic4.

Is possible to convert .py (that only contains pyqt ui related stuff) code back to .ui.

Ali
  • 335
  • 1
  • 3
  • 12
  • 1
    Why do you want to do this? – abarnert Apr 04 '13 at 22:32
  • it is a long story, but let me try to explain it. I saw someone was able to implement matplotlib into pyqt ui. A canvas has been assigned to the figurecanvas inside ui part of the py code. i wonder how this looks like in pyqt ui. Technically, we can't just drag and drop matlabplotlib canvas into a pyqt canvas using qt designer, can we? – Ali Apr 05 '13 at 01:00
  • It's possible—in fact, easy—to create PyQt code that doesn't map to any possibly .ui file, in a variety of different ways. Unless that someone was creating the UI by generating a .ui file and running pyuic4 on it, what you're trying to do isn't even meaningful, much less possible. – abarnert Apr 05 '13 at 01:05

2 Answers2

11

I can give you an example of why such a thing: when you inherited a project and the original developer didn't place the ui files in the repository (only left there the generated by pyuic4). True, that is a very particular example and that's also my reason why I'm trying to find something (is not a matter of one single ui file).

In a more generic way I can imagine that this would had happen to the previous developer in case of a disk fail.

Yes, I'm completely agreed that such a tool is not a normal thing to be provided like pyuic4...

srgblnch
  • 323
  • 3
  • 11
  • 1
    If we wanted to extend the existing .py file with additional buttons / features, then it will be time saving to include these new features in .ui file rather than .py file. So I still feel the necessity to convert .py to .ui. If my question is silly andiIf there are any other better methods, please suggest me. – user8162 Feb 15 '16 at 20:40
  • 1
    I've lost .ui files before... – Alex Jan 27 '21 at 11:36
0

Qt/PyQt doesn't come with a tool for that, and AFAIK nobody's written one.

And it's hard to imagine why you'd need it. Just keep the .ui file around, and never edit the generated .py file (or even use the .ui file dynamically at runtime with uic), and you'll never need to reverse-convert.

Meanwhile, if you've got some random PyQt4 code that generates a GUI that wasn't even created by pyuic4, there's no guarantee that any .ui could possibly generate the code. (In fact, most of the PyQt samples you'll find online don't do things the same way pyuic4 would, and most likely any other code generator will similarly not do things the same way pyuic4 does.)

abarnert
  • 354,177
  • 51
  • 601
  • 671