Shows how to use PyQt to add a menu from within Python and interact with the currently selected objects in the scene menu.
22 from PyQt4
import QtCore, QtGui
24 class InitMenuBar(QtCore.QObject):
25 def __init__(self, menu_bar=None):
26 QtCore.QObject.__init__(self, menu_bar)
27 self.scene_selection_ = gui.SceneSelection.Instance()
29 test_action = QtGui.QAction(
'Test Menu Point', self)
30 test_action.setStatusTip(
'Print Hello World')
31 test_action.setShortcut(
'Ctrl+T')
33 self.connect(test_action, QtCore.SIGNAL(
'triggered()'), self.TestMethod)
35 test = menu_bar.addMenu(
'&Test')
36 test.addAction(test_action)
39 reply = QtGui.QMessageBox()
41 node_count = self.scene_selection_.GetActiveNodeCount()
44 for i
in range(node_count):
45 entity = self.scene_selection_.GetActiveNode(i)
46 string=string + entity.GetName()
47 reply.setText(
"Oh, there are selected entities: %s" % string)
49 reply.setText(
"This is a test!")
50 reply.addButton(QtGui.QMessageBox.Yes)
53 menu_bar=gui.GostyApp.Instance().perspective.GetMenuBar()