OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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.

1 #------------------------------------------------------------------------------
2 # This file is part of the OpenStructure project <www.openstructure.org>
3 #
4 # Copyright (C) 2008-2011 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 #------------------------------------------------------------------------------
19 from ost import gui
20 from ost.gui import FileLoader
21 
22 from PyQt4 import QtCore, QtGui
23 
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()
28 
29  test_action = QtGui.QAction('Test Menu Point', self)
30  test_action.setStatusTip('Print Hello World')
31  test_action.setShortcut('Ctrl+T')
32 
33  self.connect(test_action, QtCore.SIGNAL('triggered()'), self.TestMethod)
34 
35  test = menu_bar.addMenu('&Test')
36  test.addAction(test_action)
37 
38  def TestMethod(self):
39  reply = QtGui.QMessageBox()
40 
41  node_count = self.scene_selection_.GetActiveNodeCount()
42  if(node_count > 0):
43  string = "";
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)
48  else:
49  reply.setText("This is a test!")
50  reply.addButton(QtGui.QMessageBox.Yes)
51  reply.exec_()
52 
53 menu_bar=gui.GostyApp.Instance().perspective.GetMenuBar()
54 InitMenuBar(menu_bar)