File: init_menubar.py

package info (click to toggle)
openstructure 2.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 205,228 kB
  • sloc: cpp: 188,129; python: 35,361; ansic: 34,298; fortran: 3,275; sh: 286; xml: 146; makefile: 29
file content (120 lines) | stat: -rw-r--r-- 4,608 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#------------------------------------------------------------------------------
# This file is part of the OpenStructure project <www.openstructure.org>
#
# Copyright (C) 2008-2020 by the OpenStructure authors
#
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3.0 of the License, or (at your option)
# any later version.
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#------------------------------------------------------------------------------

import sys
from ost import gui
from ost import gfx
import ost

from PyQt5 import QtCore, QtGui
from ost.gui import FileLoader
from ost.gui.init_splash import _InitSplash
from ost.gui.dng import termuse
class InitMenuBar(QtCore.QObject):
  def __init__(self, menu_bar=None):
    QtCore.QObject.__init__(self, menu_bar)
    
    persp=gui.GostyApp.Instance().perspective
    file=persp.GetMenu("File")
    options=persp.GetMenu("Options")
    window=persp.GetMenu("Window")
    help=persp.GetMenu("Help")
    
    load = QtGui.QAction(QtGui.QIcon('icons/open.png'), '&Open', self)
    load.setStatusTip('Load a file')
    load.setShortcut('Ctrl+O')
    self.connect(load, QtCore.SIGNAL('triggered()'), self.Load)
    file.addAction(load)

    webpage = QtGui.QAction('&Documentation', self)
    webpage.setStatusTip('Documentation')
    webpage.setShortcut('Ctrl+D')
    self.connect(webpage, QtCore.SIGNAL('triggered()'), self.OpenDocs)
    help.addAction(webpage)
    if sys.platform=='darwin':
      install_ctl=QtGui.QAction('Install Command Line Tool', self)    
      self.connect(install_ctl, QtCore.SIGNAL('triggered()'), 
                   termuse.InstallTerminalPrograms)
      help.addAction(install_ctl)
    about = QtGui.QAction('&About', self)
    about.setStatusTip('About')
    about.setShortcut('Ctrl+A')
    self.connect(about, QtCore.SIGNAL('triggered()'), self.About)
    help.addAction(about)
    
        
    window.addMenu(persp.panels.menu)
    gl_win = QtGui.QAction('&GL Window', self)
    gl_win.setStatusTip('Display gl windows')
    gl_win.setShortcut('Ctrl+G')
    self.connect(gl_win, QtCore.SIGNAL('triggered()'), self.ShowGLWin)
    window.addAction(gl_win)
    
    reset = QtGui.QAction('Reset View', self)
    reset.setStatusTip('Reset the Panels and Widgets')
    self.connect(reset, QtCore.SIGNAL('triggered()'), self.ResetView)
    window.addAction(reset)
    
  def Exit(self):
    reply = QtGui.QMessageBox()
    reply.addButton(QtGui.QMessageBox.Yes)
    

  def Load(self):
    filename = QtGui.QFileDialog.getOpenFileName(None, 'Open file','')
    if(QtCore.QFileInfo(filename).isFile()):
      FileLoader.LoadObject(str(filename))

  def OpenDocs(self):
    QtGui.QDesktopServices.openUrl(QtCore.QUrl("http://www.openstructure.org/docs/"))
    
  def About(self):
    _InitSplash()
  
  def ShowGLWin(self):
    gosty=gui.GostyApp.Instance()
    gl_win=gosty.GetGLWin()
    if gl_win and gl_win.qobject.isHidden():
      gl_win.Show()
  
  def ResetView(self):
    msg_box = QtGui.QMessageBox()
    msg_box.setWindowTitle("Reset the Panels and Widget");
    msg_box.setIcon(QtGui.QMessageBox.Question)
    msg_box.setText("Do you really want to reset the Panels and Widgets?");
    msg_box.setStandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel);
    msg_box.setDefaultButton(QtGui.QMessageBox.Cancel);
    ret = msg_box.exec_();
    if(ret == QtGui.QMessageBox.Yes):
      settings = QtCore.QSettings()
      settings.setValue("restore_settings",QtCore.QVariant(False))
      info_box = QtGui.QMessageBox()
      info_box.setStandardButtons(QtGui.QMessageBox.Ok)
      info_box.setIcon(QtGui.QMessageBox.Information)
      info_box.setWindowTitle("Restart OpenStructure")
      info_box.setText("You must restart OpenStructure for the changes to take effect!");
      info_box.exec_();
            
def _InitMenuBar(app):
  #InitMenuBar(app.perspective.menubar)
  pass
## \example 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.