IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques tierces Python Discussion :

Afficher pythonocc dans une fenetre pyside


Sujet :

Bibliothèques tierces Python

  1. #1
    Candidat au Club
    Inscrit en
    Mars 2005
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 4
    Points : 3
    Points
    3
    Par défaut Afficher pythonocc dans une fenetre pyside
    Bonjour à tous,

    Débutant avec pythonocc je n'arrive pas a intégrer un rendu pythonocc dans une page pyside.

    J'ai bien fait une recherche sur internet et trouvé 2 exemples, mais impossible de les faire tourner.

    Est-ce que quelqu'un aurai un exemple minimaliste qui fonctionne ?

    Par avance merci.

    Laurent

  2. #2
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Salut,

    Je ne connais pas pythonocc mais sur leur page d'exemple il semble que l'on peut faire un rendu à afficher dans un browser.

    Qu'est-ce que tu as essayé ? Tu as les liens des deux exemples dont tu parles ?


    Ça a l'air pas mal foutu pythonocc, si ça peut s'intégrer à Qt ce serait parfait.

  3. #3
    Candidat au Club
    Inscrit en
    Mars 2005
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 4
    Points : 3
    Points
    3
    Par défaut
    Merci pour ton intérêt

    Je n'ai pas essayé d'afficher dans un navigateur, mais avec le système d'affichage ça marche sans bien.



    En théorie ça devrait marché avec PySide ou QT mais en pratique, il me manque quelque chose pour y arriver.

    Si tu veux essayer, n'oublie pas qu'il faut installer avant openCascade et avoir un python 32bit (2.x ou 3.X)

  4. #4
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Testé sur Ubuntu 14.04

    J'ai ajouté QtOpenGL qui n'est pas installé par défaut avec PyQt4 ensuite j'ai essayé le script simpleGui.py

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    Traceback (most recent call last):
      File "sample.py", line 180, in <module>
        display, start_display, add_menu, add_function_to_menu = init_display()
      File "sample.py", line 109, in init_display
        from OCC.Display.qtDisplay import qtViewer3d, get_qt_modules
    ImportError: No module named qtDisplay
    Vérification faites, le module s'appelle pyqt4Display

    Après cette correction, j'ai obtenu la fenêtre avec un affichage correcte des deux primitives, la perspective me semble un peu étrange mais les mouvements 3D sont fluides.

    Si tu as des erreurs au lancement du code, copie ici le contenu intégral des messages d'erreurs.

  5. #5
    Candidat au Club
    Inscrit en
    Mars 2005
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 4
    Points : 3
    Points
    3
    Par défaut
    Merci pour ta réponse,

    Effectivement ça marche bien avec pyside, en fait je me rend compte que je m'étais mal exprimé.

    En fait ce que je n'arrive pas a faire, c'est intégrer cet affichage, dans un container de QMainWindow, pour pouvoir ajouter entre autre un menu et des QToolBox.

    En fait je voudrais faire quelque chose comme :

    monOcc = QPythonOcc(self, ... )
    et ajouter monOcc à ma QMainWindows

  6. #6
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Un exemple fonctionnel.

    pyocc.py
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
    # -*- coding: utf-8 -*-
     
    import sys
    from mainui import MainUi
     
    from PyQt4 import QtGui
     
    from OCC.BRepPrimAPI import BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeBox
     
    class Main(object):
        def __init__(self):
            self.ui = MainUi(self)
            self.ui.show()
            self.ui.glview.InitDriver()
            self.display = self.ui.glview._display
            self.display.set_bg_gradient_color(206, 215, 222, 128, 128, 128)
            self.display.display_trihedron()
     
        def build_cube(self, event=None):
            self.display.DisplayShape(BRepPrimAPI_MakeBox(1, 1, 1).Shape(), update=True)
     
        def build_sphere(self, event=None):
            self.display.DisplayShape(BRepPrimAPI_MakeSphere(100).Shape(), update=True)
     
     
    if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        main = Main()
        sys.exit(app.exec_())
    mainui.py
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
     
    # -*- coding: utf-8 -*-
     
    from PyQt4 import QtCore, QtGui
    from OCC.Display.pyqt4Display import qtViewer3d
     
    class MainUi(QtGui.QMainWindow):
        def __init__(self, main):
            super(MainUi, self).__init__()
            self.main = main
            self.resize(720, 500)
            self.setWindowTitle("pythonocc")
            self.centralwidget = QtGui.QWidget(self)
            self.gridLayout = QtGui.QGridLayout(self.centralwidget)
            self.horizontalLayout_4 = QtGui.QHBoxLayout()
            self.groupBox = QtGui.QGroupBox(self.centralwidget)
            self.groupBox.setTitle("Tools")
            self.verticalLayout_3 = QtGui.QVBoxLayout(self.groupBox)
            self.verticalLayout_2 = QtGui.QVBoxLayout()
            self.pushButton = QtGui.QPushButton("Tool 1", self.groupBox)
            self.verticalLayout_2.addWidget(self.pushButton)
            self.pushButton_2 = QtGui.QPushButton("Tool 2", self.groupBox)
            self.verticalLayout_2.addWidget(self.pushButton_2)
            self.label = QtGui.QLabel("Parameters", self.groupBox)
            self.verticalLayout_2.addWidget(self.label)
            self.horizontalLayout = QtGui.QHBoxLayout()
            self.label_2 = QtGui.QLabel("X:", self.groupBox)
            self.horizontalLayout.addWidget(self.label_2)
            self.doubleSpinBox_2 = QtGui.QDoubleSpinBox(self.groupBox)
            self.horizontalLayout.addWidget(self.doubleSpinBox_2)
            self.verticalLayout_2.addLayout(self.horizontalLayout)
            self.horizontalLayout_2 = QtGui.QHBoxLayout()
            self.label_3 = QtGui.QLabel("Y:", self.groupBox)
            self.horizontalLayout_2.addWidget(self.label_3)
            self.doubleSpinBox = QtGui.QDoubleSpinBox(self.groupBox)
            self.horizontalLayout_2.addWidget(self.doubleSpinBox)
            self.verticalLayout_2.addLayout(self.horizontalLayout_2)
            self.horizontalLayout_3 = QtGui.QHBoxLayout()
            self.label_4 = QtGui.QLabel("Z:", self.groupBox)
            self.horizontalLayout_3.addWidget(self.label_4)
            self.doubleSpinBox_3 = QtGui.QDoubleSpinBox(self.groupBox)
            self.horizontalLayout_3.addWidget(self.doubleSpinBox_3)
            self.verticalLayout_2.addLayout(self.horizontalLayout_3)
            spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, 
                                            QtGui.QSizePolicy.Expanding)
            self.verticalLayout_2.addItem(spacerItem)
            self.verticalLayout_3.addLayout(self.verticalLayout_2)
            self.horizontalLayout_4.addWidget(self.groupBox)
     
            self.glview = qtViewer3d(self)
            self.glview.setMinimumSize(650, 450)
            self.horizontalLayout_4.addWidget(self.glview)
     
            self.gridLayout.addLayout(self.horizontalLayout_4, 0, 0, 1, 1)
            self.setCentralWidget(self.centralwidget)
            self.menubar = QtGui.QMenuBar(self)
            self.menubar.setGeometry(QtCore.QRect(0, 0, 713, 24))
            self.menuPrimitives = QtGui.QMenu(self.menubar)
            self.menuPrimitives.setTitle("&Primitives")
            self.setMenuBar(self.menubar)
            self.statusbar = QtGui.QStatusBar(self)
            self.setStatusBar(self.statusbar)
            self.actionCube = QtGui.QAction("&Cube", self)
            self.actionSphere = QtGui.QAction("&Sphere", self)
            self.menuPrimitives.addAction(self.actionCube)
            self.menuPrimitives.addAction(self.actionSphere)
            self.menubar.addAction(self.menuPrimitives.menuAction())
            self.actionCube.triggered.connect(self.main.build_cube)
            self.actionSphere.triggered.connect(self.main.build_sphere)
    J'ai repris la façon de faire de leur exemple mais tu peux aussi directement, dans l'interface, insérer le QGLWidget à la place de leur qtViewer3d.

    Tu le lances avec Il y a probablement du code à modifier selon l'os, moi j'ai testé sous Linux.

  7. #7
    Candidat au Club
    Inscrit en
    Mars 2005
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 4
    Points : 3
    Points
    3
    Par défaut
    MERCI VinsS ! merci BEAUCOUP !

    c'est exactement ce dont j'avais besoin ! ça marche nickel !

    Je suis aussi sous linux : aucune modification de code nécessaire.

    pour ceux que ça intéresse, le même exemple fonctionnel version PySide :

    installer python-pyside.qtopengl (synaptic)

    creer les deux fichiers :

    mainui.py :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
     
    # -*- coding: utf-8 -*-
     
    from PySide import QtCore, QtGui
    from OCC.Display.pysideDisplay import qtViewer3d
     
    class MainUi(QtGui.QMainWindow):
        def __init__(self, main):
            super(MainUi, self).__init__()
            self.main = main
            self.resize(720, 500)
            self.setWindowTitle("pythonocc")
            self.centralwidget = QtGui.QWidget(self)
            self.gridLayout = QtGui.QGridLayout(self.centralwidget)
            self.horizontalLayout_4 = QtGui.QHBoxLayout()
            self.groupBox = QtGui.QGroupBox(self.centralwidget)
            self.groupBox.setTitle("Tools")
            self.verticalLayout_3 = QtGui.QVBoxLayout(self.groupBox)
            self.verticalLayout_2 = QtGui.QVBoxLayout()
            self.pushButton = QtGui.QPushButton("Tool 1", self.groupBox)
            self.verticalLayout_2.addWidget(self.pushButton)
            self.pushButton_2 = QtGui.QPushButton("Tool 2", self.groupBox)
            self.verticalLayout_2.addWidget(self.pushButton_2)
            self.label = QtGui.QLabel("Parameters", self.groupBox)
            self.verticalLayout_2.addWidget(self.label)
            self.horizontalLayout = QtGui.QHBoxLayout()
            self.label_2 = QtGui.QLabel("X:", self.groupBox)
            self.horizontalLayout.addWidget(self.label_2)
            self.doubleSpinBox_2 = QtGui.QDoubleSpinBox(self.groupBox)
            self.horizontalLayout.addWidget(self.doubleSpinBox_2)
            self.verticalLayout_2.addLayout(self.horizontalLayout)
            self.horizontalLayout_2 = QtGui.QHBoxLayout()
            self.label_3 = QtGui.QLabel("Y:", self.groupBox)
            self.horizontalLayout_2.addWidget(self.label_3)
            self.doubleSpinBox = QtGui.QDoubleSpinBox(self.groupBox)
            self.horizontalLayout_2.addWidget(self.doubleSpinBox)
            self.verticalLayout_2.addLayout(self.horizontalLayout_2)
            self.horizontalLayout_3 = QtGui.QHBoxLayout()
            self.label_4 = QtGui.QLabel("Z:", self.groupBox)
            self.horizontalLayout_3.addWidget(self.label_4)
            self.doubleSpinBox_3 = QtGui.QDoubleSpinBox(self.groupBox)
            self.horizontalLayout_3.addWidget(self.doubleSpinBox_3)
            self.verticalLayout_2.addLayout(self.horizontalLayout_3)
            spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, 
                                            QtGui.QSizePolicy.Expanding)
            self.verticalLayout_2.addItem(spacerItem)
            self.verticalLayout_3.addLayout(self.verticalLayout_2)
            self.horizontalLayout_4.addWidget(self.groupBox)
     
            self.glview = qtViewer3d(self)
            self.glview.setMinimumSize(650, 450)
            self.horizontalLayout_4.addWidget(self.glview)
     
            self.gridLayout.addLayout(self.horizontalLayout_4, 0, 0, 1, 1)
            self.setCentralWidget(self.centralwidget)
            self.menubar = QtGui.QMenuBar(self)
            self.menubar.setGeometry(QtCore.QRect(0, 0, 713, 24))
            self.menuPrimitives = QtGui.QMenu(self.menubar)
            self.menuPrimitives.setTitle("&Primitives")
            self.setMenuBar(self.menubar)
            self.statusbar = QtGui.QStatusBar(self)
            self.setStatusBar(self.statusbar)
            self.actionCube = QtGui.QAction("&Cube", self)
            self.actionSphere = QtGui.QAction("&Sphere", self)
            self.menuPrimitives.addAction(self.actionCube)
            self.menuPrimitives.addAction(self.actionSphere)
            self.menubar.addAction(self.menuPrimitives.menuAction())
            self.actionCube.triggered.connect(self.main.build_cube)
            self.actionSphere.triggered.connect(self.main.build_sphere)
    pyocc.py
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
    # -*- coding: utf-8 -*-
     
    import sys
    from mainui import MainUi
     
    from PySide import QtGui
     
    from OCC.BRepPrimAPI import BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeBox
     
    class Main(object):
        def __init__(self):
            self.ui = MainUi(self)
            self.ui.show()
            self.ui.glview.InitDriver()
            self.display = self.ui.glview._display
            self.display.set_bg_gradient_color(206, 215, 222, 128, 128, 128)
            self.display.display_trihedron()
     
        def build_cube(self, event=None):
            self.display.DisplayShape(BRepPrimAPI_MakeBox(1, 1, 1).Shape(), update=True)
     
        def build_sphere(self, event=None):
            self.display.DisplayShape(BRepPrimAPI_MakeSphere(100).Shape(), update=True)
     
     
    if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        main = Main()
        sys.exit(app.exec_())
    lancer :

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Afficher resultat dans une fenetre
    Par snake52200 dans le forum MATLAB
    Réponses: 1
    Dernier message: 28/05/2010, 11h44
  2. afficher un tableau dans une fenetre
    Par igor24 dans le forum AWT/Swing
    Réponses: 17
    Dernier message: 30/04/2006, 09h51
  3. afficher un tableau 2 dimensions dans une fenetre
    Par igor24 dans le forum AWT/Swing
    Réponses: 1
    Dernier message: 29/04/2006, 13h50
  4. Réponses: 13
    Dernier message: 09/03/2006, 18h17
  5. afficher de l'opengl dans une fenetre web
    Par soubre dans le forum OpenGL
    Réponses: 7
    Dernier message: 16/09/2005, 18h16

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo