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