OpenStructure
Loading...
Searching...
No Matches
menubar_example.py

Shows how to use PyQt to add a menu from within Python and interact with the currently selected objects in the scene menu.

Shows how to use PyQt to add a menu from within Python and interact with the currently selected objects in the scene menu.

1#------------------------------------------------------------------------------
2# This file is part of the OpenStructure project <www.openstructure.org>
3#
4# Copyright (C) 2008-2020 by the OpenStructure authors
5#
6# This library is free software; you can redistribute it and/or modify it under
7# the terms of the GNU Lesser General Public License as published by the Free
8# Software Foundation; either version 3.0 of the License, or (at your option)
9# any later version.
10# This library is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13# details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this library; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18#------------------------------------------------------------------------------
19from ost import gui
20from ost.gui import FileLoader
21
22from PyQt5 import QtCore, QtGui, QtWidgets
23
24class InitMenuBar(QtCore.QObject):
25 def __init__(self, menu_bar=None):
26 QtCore.QObject.__init__(self, menu_bar)
27 self.scene_selection_ = gui.SceneSelection.Instance()
28
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)
33
34 test = menu_bar.addMenu('&Test')
35 test.addAction(test_action)
36
37 def TestMethod(self):
38 reply = QtWidgets.QMessageBox()
39
40 node_count = self.scene_selection_.GetActiveNodeCount()
41 if(node_count > 0):
42 string = "";
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)
47 else:
48 reply.setText("This is a test!")
49 reply.addButton(QtWidgets.QMessageBox.Yes)
50 reply.exec_()
51
52menu_bar=gui.GostyApp.Instance().perspective.GetMenuBar()
53InitMenuBar(menu_bar)