Hi Sebastian,

Im not sure if thats possible with SimpleGui at the moment (correct me if im 
wrong) without hacking it a bit.
(one) problem is that init_display() creates the QApplication, there can be 
only one instance of this class.

SimpleGui (as the name says) is only aimed for simple viewing of you geometry. 
but it should be too much work to take the simpleGui code and adapt it:

you only need the qt part of SimpleGui (code with comments below, see 
comments), http://stackoverflow.com/questions/1442128/multiple-windows-in-pyqt4 
is a good example i think.

as for executing code, its not possible after start_display(), but you can 
register methods to be added to a dropdown menu with add_function_to_menu. 

Good luck,

Henrik

from qtDisplay import qtViewer3d
        class MainWindow(QtGui.QMainWindow): #Should inherit from another 
window class (QDialog for example)
            def __init__(self, *args):
                apply(QtGui.QMainWindow.__init__,(self,)+args)
                self.canva = qtViewer3d(self)
                self.setWindowTitle("pythonOCC-%s 3d viewer ('qt' 
backend)"%VERSION)
                self.resize(1024,768)
                self.canva = qtViewer3d(self)
                self.setCentralWidget(self.canva)
                self.menuBar = self.menuBar()
                self._menus = {}
                self._menu_methods = {}

            def add_menu(self, menu_name):
                _menu = self.menuBar.addMenu("&"+menu_name)
                self._menus[menu_name]=_menu
            def add_function_to_menu(self, menu_name, _callable):
                assert callable(_callable), 'the function supplied is not 
callable'
                try:
                    _action = QtGui.QAction(_callable.__name__.replace('_', ' 
').lower(), self)
                    self.connect(_action, QtCore.SIGNAL("triggered()"), 
_callable)
                    self._menus[menu_name].addAction(_action)
                except KeyError:
                    raise ValueError, 'the menu item %s does not exist' % 
(menu_name)

        #this call should only be made once
        app = QtGui.QApplication(sys.argv) 
        

        win = MainWindow()
        win.show()
        win.canva.InitDriver()
        display = win.canva._display
        display.SetBackgroundImage(get_bg_abs_filename())        
        def add_menu(*args, **kwargs):
            win.add_menu(*args, **kwargs)
        def add_function_to_menu(*args, **kwargs):
            win.add_function_to_menu(*args, **kwargs)
        def start_display():
           
            #no code is executed in this thread after this call
            app.exec_()



On Apr 21, 2010, at 8:05 PM, Sebastian Barthmes wrote:

> Hi there!
> 
> I'd like to open multiple windows (with qt backend) for 3D display. Here's a 
> simple example:
> 
> 
> ###############
> 
> import OCC.Display.SimpleGui
> 
> #Open the first Window
> OCC.Display.SimpleGui.set_backend('qt')
> display, start_display, add_menu, add_function_to_menu = 
> OCC.Display.SimpleGui.init_display()
> start_display()
> 
> #Make sure the old object are destroyed:
> del display
> del start_display
> 
> #Now do the same thing again after the old window is closed, this one throws 
> an exception:
> OCC.Display.SimpleGui.set_backend('qt')
> display, start_display, add_menu, add_function_to_menu = 
> OCC.Display.SimpleGui.init_display()
> start_display()
> 
> ###############
> 
> 
> The Exception which is thrown now:
> QWidget: Must construct a QApplication before a QPaintDevice
> Aborted (Speicherabzug geschrieben)
> 
> 
> How can I get this to work? 
> 
> Further I'd like to know whether it is possible to open the window for 
> display but let the code continue.
> 
> Thanks in advance for your help!
> 
> 
> Sebastian
> 
> 
> _______________________________________________
> Pythonocc-users mailing list
> Pythonocc-users@gna.org
> https://mail.gna.org/listinfo/pythonocc-users


_______________________________________________
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users

Reply via email to