#!/usr/bin/env python
from iv import *
from qt import *
import os
import sys
class InventorMainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(
self, None, 'SoQt Main Window Example', Qt.WDestructiveClose)
# Since SoQt widgets are not derived from QWidget,
# it is sometimes usefull to give them a empty shell QWidget as parent:
shell = QWidget(self)
self.viewer = SoQtExaminerViewer(shell)
# and now
self.setCentralWidget(shell)
# instead of self.setCentralWidget(self.viewer) which raises an error.
fileMenu = QPopupMenu(self)
self.menuBar().insertItem('&File', fileMenu)
fileMenu.insertItem(
'&Open...', self.openFile, Qt.CTRL + Qt.Key_O)
fileMenu.insertItem(
'&Quit', qApp, SLOT('closeAllWindows()'), Qt.CTRL + Qt.Key_Q)
self.statusBar().message('Ready', 5000)
self.resize(600, 400)
# __init__()
def openFile(self):
name = QFileDialog.getOpenFileName(
os.path.join(os.pardir, 'data'), 'Inventor files (*.iv)', self)
if not name:
self.statusBar().message('Reading aborted', 5000);
return
input = SoInput()
# str(name), since name is a QString which is not accepted by
# SoInput.openFile()
if not input.openFile(str(name)):
self.statusBar().message('Failed to open %s' % name, 5000)
scene = SoDB.readAll(input)
self.viewer.setSceneGraph(scene)
# openFile()
# class InventorMainWindow
def main():
app = QApplication(sys.argv)
SoQt.init(None)
demo = InventorMainWindow()
demo.show()
app.connect(app, SIGNAL('lastWindowClosed()'), app, SLOT('quit()'))
SoQt.mainLoop()
# main()
if __name__ == '__main__':
main()
# Local Variables: ***
# mode: python ***
# End: ***