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