OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
init_menubar.py
Go to the documentation of this file.
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 
20 import sys
21 from ost import gui
22 import sip
23 from ost import gfx
24 import ost
25 
26 from PyQt4 import QtCore, QtGui
27 from ost.gui import FileLoader
28 from ost.gui.scene.file_loader import GenericLoader
29 from ost.gui.scene.loader_manager_widget import LoaderManagerWidget
30 from ost.gui.init_splash import _InitSplash
31 from ost.gui.dng import termuse
32 class InitMenuBar(QtCore.QObject):
33  def __init__(self, menu_bar=None):
34  QtCore.QObject.__init__(self, menu_bar)
35 
36  persp=gui.GostyApp.Instance().perspective
37  file=persp.GetMenu("File")
38  options=persp.GetMenu("Options")
39  window=persp.GetMenu("Window")
40  help=persp.GetMenu("Help")
41 
42  load = QtGui.QAction(QtGui.QIcon('icons/open.png'), '&Open', self)
43  load.setStatusTip('Load a file')
44  load.setShortcut('Ctrl+O')
45  self.connect(load, QtCore.SIGNAL('triggered()'), self.Load)
46  file.addAction(load)
47 
48  webpage = QtGui.QAction('&Documentation', self)
49  webpage.setStatusTip('Documentation')
50  webpage.setShortcut('Ctrl+D')
51  self.connect(webpage, QtCore.SIGNAL('triggered()'), self.OpenDocs)
52  help.addAction(webpage)
53  if sys.platform=='darwin':
54  install_ctl=QtGui.QAction('Install Command Line Tool', self)
55  self.connect(install_ctl, QtCore.SIGNAL('triggered()'),
56  termuse.InstallTerminalPrograms)
57  help.addAction(install_ctl)
58  about = QtGui.QAction('&About', self)
59  about.setStatusTip('About')
60  about.setShortcut('Ctrl+A')
61  self.connect(about, QtCore.SIGNAL('triggered()'), self.About)
62  help.addAction(about)
63 
64 
65  window.addMenu(persp.panels.menu)
66  gl_win = QtGui.QAction('&GL Window', self)
67  gl_win.setStatusTip('Display gl windows')
68  gl_win.setShortcut('Ctrl+G')
69  self.connect(gl_win, QtCore.SIGNAL('triggered()'), self.ShowGLWin)
70  window.addAction(gl_win)
71 
72  reset = QtGui.QAction('Reset View', self)
73  reset.setStatusTip('Reset the Panels and Widgets')
74  self.connect(reset, QtCore.SIGNAL('triggered()'), self.ResetView)
75  window.addAction(reset)
76 
77  #Options
78  #Add file loader to menu
79  loader_manager = QtGui.QAction('File &Loader', self)
80  loader_manager.setStatusTip('Loader Manager')
81  self.connect(loader_manager, QtCore.SIGNAL('triggered()'), self.LoaderManager)
82  options.addAction(loader_manager)
83 
85 
86  def Exit(self):
87  reply = QtGui.QMessageBox()
88  reply.addButton(QtGui.QMessageBox.Yes)
89 
90 
91  def Load(self):
92  filename = QtGui.QFileDialog.getOpenFileName(None, 'Open file','')
93  if(QtCore.QFileInfo(filename).isFile()):
94  FileLoader.LoadObject(str(filename))
95 
96  def LoaderManager(self):
97  self.loader_manager.exec_()
98 
99  def OpenDocs(self):
100  QtGui.QDesktopServices.openUrl(QtCore.QUrl("http://www.openstructure.org/docs/"))
101 
102  def About(self):
103  _InitSplash()
104 
105  def ShowGLWin(self):
106  gosty=gui.GostyApp.Instance()
107  gl_win=gosty.GetGLWin()
108  if gl_win and gl_win.qobject.isHidden():
109  gl_win.Show()
110 
111  def ResetView(self):
112  msg_box = QtGui.QMessageBox()
113  msg_box.setWindowTitle("Reset the Panels and Widget");
114  msg_box.setIcon(QtGui.QMessageBox.Question)
115  msg_box.setText("Do you really want to reset the Panels and Widgets?");
116  msg_box.setStandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel);
117  msg_box.setDefaultButton(QtGui.QMessageBox.Cancel);
118  ret = msg_box.exec_();
119  if(ret == QtGui.QMessageBox.Yes):
120  settings = QtCore.QSettings()
121  settings.setValue("restore_settings",QtCore.QVariant(False))
122  info_box = QtGui.QMessageBox()
123  info_box.setStandardButtons(QtGui.QMessageBox.Ok)
124  info_box.setIcon(QtGui.QMessageBox.Information)
125  info_box.setWindowTitle("Restart OpenStructure")
126  info_box.setText("You must restart OpenStructure for the changes to take effect!");
127  info_box.exec_();
128 
129 def _InitMenuBar(app):
130  #InitMenuBar(app.perspective.menubar)
131  pass
132 ## \example menubar_example.py
133 #
134 # Shows how to use PyQt to add a menu from within Python and interact
135 # with the currently selected objects in the scene menu.