Utiliser Freecad dans Q widget pyqt5

Forum destiné aux questions et discussions en français
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
Tonio16
Posts: 3
Joined: Thu Oct 10, 2019 9:28 pm

Utiliser Freecad dans Q widget pyqt5

Post by Tonio16 »

Bonjour
J ai crée un logiciel en Python 3.6 à l'aide de pyqt5 pour la GUI
Je voulais savoir s'il était possible d introduire ou ancrer Freecad dans Q widget de mon appli
C est juste pour faire un Viewer dans mon appli (charger des steps, déplacer des objets utiliser les outils de mesures de Freecad)
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Utiliser Freecad dans Q widget pyqt5

Post by openBrain »

Bonjour Tonio, bienvenue.

La complexité de la solution dépendra de la profondeur d'intégration que tu veux entre FC et ton appli.
Mais si tu veux juste afficher FC dans ton appli, tu peux utiliser QWindow.fromWinId(). ;)

Exemples ici et ici
Tonio16
Posts: 3
Joined: Thu Oct 10, 2019 9:28 pm

Re: Utiliser Freecad dans Q widget pyqt5

Post by Tonio16 »

Merci de votre réponse
Je vais étudier cette piste et je posterai la solution quand ça sera opérationnelle
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Utiliser Freecad dans Q widget pyqt5

Post by openBrain »

Au passage, si jamais tu souhaites refaire ce genre de chose, je te conseille plutôt Qt for Python (autrement dit PySide2) que PyQt.
Comme c'est maintenant soutenu par Qt directement, c'est plus complet et plus à jour. ;)
Tonio16
Posts: 3
Joined: Thu Oct 10, 2019 9:28 pm

Re: Utiliser Freecad dans Q widget pyqt5

Post by Tonio16 »

Ci joint un exemple de code pour intégrer FreeCad dans un widget

Code: Select all

import subprocess
import sys
import time
import win32gui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import (QWidget, QApplication,
                             QVBoxLayout)
class Main(QWidget):
    """Classe représentant les options de configuration de GRUB"""

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        # create a process
        exePath = "C:\\xxx\\FreeCAD 0.18\\bin\\FreeCAD.exe"
        subprocess.Popen (exePath)

        # Temps démarrage FreeCad
        time.sleep (10)

        hwnd = win32gui.FindWindowEx (0, 0, 0, "FreeCAD 0.18")

        window = QWindow.fromWinId (hwnd)
        self.container = self.createWindowContainer (window)
        self.setGeometry (500, 500, 800, 800)

        layout = QVBoxLayout (self)
        layout.addWidget (self.container)

        self.show()

if __name__ == "__main__":

    app = QApplication(sys.argv)

    win = Main()
    win.setWindowTitle("Test FreeCAD")

    sys.exit(app.exec_())
User avatar
rockn
Veteran
Posts: 1791
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Re: Utiliser Freecad dans Q widget pyqt5

Post by rockn »

Excellent Tonio16, merci beaucoup pour le partage :mrgreen:
Formations - Assistance - Développement : https://freecad-france.com
mea08kw
Posts: 82
Joined: Sun Oct 09, 2022 6:22 am

Re: Utiliser Freecad dans Q widget pyqt5

Post by mea08kw »

openBrain wrote: Fri Oct 11, 2019 2:57 pm Bonjour Tonio, bienvenue.

La complexité de la solution dépendra de la profondeur d'intégration que tu veux entre FC et ton appli.
Mais si tu veux juste afficher FC dans ton appli, tu peux utiliser QWindow.fromWinId(). ;)

Exemples ici et ici
Hi

First of all, sorry about that I can only speak English here.

What if I want to display an App inside FreeCAD, I had a try, but I cound't import win32gui.

Is there any way to fix it?

Many thanks.

Best Regards,

Mea08kw
mea08kw
Posts: 82
Joined: Sun Oct 09, 2022 6:22 am

Re: Utiliser Freecad dans Q widget pyqt5

Post by mea08kw »

Tonio16 wrote: Sun Oct 27, 2019 10:29 am Ci joint un exemple de code pour intégrer FreeCad dans un widget

Code: Select all

import subprocess
import sys
import time
import win32gui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import (QWidget, QApplication,
                             QVBoxLayout)
class Main(QWidget):
    """Classe représentant les options de configuration de GRUB"""

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        # create a process
        exePath = "C:\\xxx\\FreeCAD 0.18\\bin\\FreeCAD.exe"
        subprocess.Popen (exePath)

        # Temps démarrage FreeCad
        time.sleep (10)

        hwnd = win32gui.FindWindowEx (0, 0, 0, "FreeCAD 0.18")

        window = QWindow.fromWinId (hwnd)
        self.container = self.createWindowContainer (window)
        self.setGeometry (500, 500, 800, 800)

        layout = QVBoxLayout (self)
        layout.addWidget (self.container)

        self.show()

if __name__ == "__main__":

    app = QApplication(sys.argv)

    win = Main()
    win.setWindowTitle("Test FreeCAD")

    sys.exit(app.exec_())
Hi

First of all, sorry about that I can only speak English here.

What if I want to display an App inside FreeCAD, I had a try, but I cound't import win32gui.

Is there any way to fix it?

Many thanks.

Best Regards,

Mea08kw
User avatar
flachyjoe
Veteran
Posts: 1869
Joined: Sat Mar 31, 2012 12:00 pm
Location: Limoges, France

Re: Utiliser Freecad dans Q widget pyqt5

Post by flachyjoe »

Hi @mea08kw,
please use a translator to post in French in this sub-forum.

Pour embarquer une fenêtre d'une autre application dans FreeCAD, regarde :
To embed an external app window in FreeCAD, see:
- Flachy Joe -
Image
Post Reply