添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Code: Select all

In PyQt5, you don't need sys.exit() at all. app.exec_() or app.exec() alone is enough and it works normally. They fixed some things in PyQt5 under the hood so that you don't need that sys.exit() anymore. If you want your code to run on PyQt4, then have sys.exit() there. Also, app.exec_() and app.exec() are interchangable, so you can use whichever you like. If you want your code to run on PyQt4 as well, then stick with app.exec_(). So, the bottom line is: for your code to work properly on PyQt5 and PyQt4, use sys.exit(app.exec_())
I think that is the answer
if I do the program run.
if someone try I can get same feedback
thank you
vocx wrote: Thu Jan 30, 2020 5:36 am This Dialog creation page that you are reading is "developer documentation". Unfortunately, this documentation is pretty old, and hasn't been updated thoroughly in a while. For example, it still has references to Qt4 and PyQt4, which are no longer used in FreeCAD.
all macro run in FC 0.18 (official) just corrected 1 macro (unicode error)
@sibelius
i have python 3.6 and PyQt5-5.6 installed and pyuic5.exe is located in " C:\Python36\Scripts " directory
and my batch file as the wiki (adapted for pyuic5.exe):

Code: Select all

@"C:\Python36\Scripts\pyuic5.exe" -x %1.ui -o%1.py
give the code :

Code: Select all

# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Connect_And_Sweep_05_COMPLET_02.ui'
# Created by: PyQt5 UI code generator 5.12.1
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
...........
...........
if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
for use it in FreeCAD you must change (PyQt5 to PySide) and delete the (sys... and line contend it):
result:

Code: Select all

# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Connect_And_Sweep_05_COMPLET_02.ui'
# Created by: PyQt5 UI code generator 5.12.1
# WARNING! All changes made in this file will be lost!
from PySide2 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
...........
...........
if __name__ == "__main__":
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
sibelius wrote: Fri Jan 31, 2020 10:36 am I think I solved the problem; I followed this link to install PySide2 https://wiki.qt.io/Qt_for_Python and then I went in my python38 latest version and I follow again the procedure i did for python27.... By the way, this is completely unnecessary, and I'm afraid you may leave your system in a strange state.
I started reading this thread under the assumption that you have a running FreeCAD system. Where did you install it from? The Windows package in Download?
If this is the case, your system should already contain Python 3, and the necessary versions of Qt5 and PySide2. You don't have to manually install them. They are necessary to run the graphical interface so these libraries should already be included. If you externally install another version of Python 3, and another version of Qt5 and PySide2, that may cause collisions at some point in the future that will be difficult to troubleshoot.
So, if you want my opinion, I suggest you remove everything you installed, FreeCAD, Python, PySide, etc. Make sure your system is clean. Then install only FreeCAD, and then try the examples with the Python console included in FreeCAD.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
hi everyone.
I don't remember were I download freeCAD 0.19; I think I did from https://github.com/FreeCAD/FreeCAD/rele ... g/0.19_pre.
in this version of FreeCAd PySide2 wasn't in.
I have this two version of freeCAd; 0.18 and 0.19.
I realize that I need PySide to convert files ui into files py.
also I read that PySide war override by PySide2, so basically what I did was to install PySide2 for my python3.6.8 witch is the version I have on my freeCAD 0.19.
after that I created a file batch witch allowed me to give a simple line command to do the conversion (it's not necessary, just easy).
at this point I can convert any file I like just give this command and have as a result a py file compatible with the version of the python running in my freeCAD 0.19.
as above before getting to that I repeat the entire procedure for python2.7 (even if I don't have any FreeCAD running under that Python version, I just try to see where I was landing; at this point my goal was to understaind how to install PySide--also at this point I didn't realize that PySyde was obsolete). anyway I was able to install PySide for Python2.7 and then in the same way I created my file batch to convert from ui to py.
now after installing PYSide for Python2.7 I realize that I was running freeCAD 0.19 under Python 3.6.8 and my thought was: the py file I get is a py done by Python2.7 by PySide (the obsolete version, not the PySide2) and the code inside this py was a Python 2 and not Python 3 (at this point I'm still writing without knowledge among the difference between the two Python versions) and in consequence of that I repeat this entire procedure installing the PySide2 as I explained at the beginning of the message.

Code: Select all

@"C:\Python27\python" "C:\Python27\Lib\site-packages\PySide\scripts\uic.py" %1.ui > %1.py
this is the file batch to run PySide (useless in my case)

Code: Select all

@"C:\Python36\python" "C:\Python36\scripts\pyside2-uic.exe" %1.ui > %1.py
this is the file batch to run PySide2 (that's what I use); finally to operate the conversion you can use one of the following command line

Code: Select all

compSide2 myfilename ui 
or

Code: Select all

pyside2-uic myfilename.ui > myfilename.py
now at this point I have to understaind a bit of Python3 coding because as Mario52 pointed out in his example there are changes between Pythons versions.
anyway time permitting I'm still learning.
thank you very much for your help
I was just trying to put this two code in freeCAD Python consolle and both seems working ; the second one tell me to exit as well.

Code: Select all

from PySide2.QtWidgets import QApplication, QLabel
if __name__ == "__main__":
    label = QLabel("Hello World")
    label.show() 
first code

Code: Select all

import sys
from PySide2.QtWidgets import QApplication, QLabel
if __name__ == "__main__":
    app = QApplication(sys.argv)
    label = QLabel("Hello World")
    label.show() 
    sys.exit(app.exec_())
second code
sibelius wrote: Fri Jan 31, 2020 9:38 pm hi everyone.
I don't remember were I download freeCAD 0.19; I think I did from https://github.com/FreeCAD/FreeCAD/rele ... g/0.19_pre.
in this version of FreeCAd PySide2 wasn't in.... No, you are mistaken. PySide2 is included with FreeCAD 0.19, as long as you are using the Qt5 version.
However, in FreeCAD you should use the PySide module. This module is a fake module which will import the PySide2 classes. This is done so you can use the same PySide module with Qt4 or Qt5.
So, in FreeCAD

Code: Select all

PySide2.QtCore.SomeClass -> PySide.QtCore.SomeClass
PySide2.QtGui.SomeClass2 -> PySide.QtGui.SomeClass2
PySide2.QtWidgets.SomeClass3 -> PySide.QtGui.SomeClass3
The only weird thing is that all classes from PySide2.QtWidgets are contained inside the PySide.QtGui namespace.

Code: Select all

import sys
from PySide.QtGui import QApplication, QLabel
# from PySide2.QtWidgets import QApplication, QLabel # it's the same
if __name__ == "__main__":
    app = QApplication(sys.argv)
    label = QLabel("Hello World")
    label.show() 
    sys.exit(app.exec_())
									
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
thanks for your correction; tell you the truth at this point I'm not sure if PySide2 was or not inside freeCAd 0.19.
because my skills are so poor on this matter the unique thing I can do is to read, test and ask; so if you said PySide2 was in, for me was in too.
anyway thanks for your examples.
PS reading again your examples make things a bit clear now (still a long way to go for me)