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 PyQt5
import QtCore, QtGui, QtWidgets
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 = QtWidgets.QAction(
'Test Menu Point', self)
30 test_action.setStatusTip(
'Print Hello World')
31 test_action.setShortcut(
'Ctrl+T')
32 test_action.triggered.connect(self.TestMethod)
34 test = menu_bar.addMenu(
'&Test')
35 test.addAction(test_action)
38 reply = QtWidgets.QMessageBox()
40 node_count = self.scene_selection_.GetActiveNodeCount()
43 for i
in range(node_count):
44 entity = self.scene_selection_.GetActiveNode(i)
45 string=string + entity.GetName()
46 reply.setText(
"Oh, there are selected entities: %s" % string)
48 reply.setText(
"This is a test!")
49 reply.addButton(QtWidgets.QMessageBox.Yes)
52 menu_bar=gui.GostyApp.Instance().perspective.GetMenuBar()