Package client
[hide private]
[frames] | no frames]

Source Code for Package client

  1  #!/usr/bin/env python 
  2   
  3  import sys 
  4  import PyQt4.QtGui 
  5  import PyQt4.QtCore 
  6   
  7  import Constants 
  8  import IPythonShell 
  9   
 10  import Actions 
 11  import Bridge 
 12  import Dock 
 13  import MenuBar 
 14  import StatusBar 
 15  import ToolBar 
 16  import Viewers 
 17   
18 -class BasinBody (PyQt4.QtGui.QWidget):
19 """ 20 Overview 21 ======== 22 This class in a convenience class which inherits from I{QWidget}. It bundles the layout and instantiation 23 of the main components of the central body widget during construction. In every other aspect it behaves 24 as a normal QWidget. 25 """ 26
27 - def __init__ (self, parent, bridge):
28 """ 29 Overview 30 ======== 31 This constructor creates the central widget for the I{Basin Client} User Interface. It 32 is everything between the menu bar and status bar. It will set up the following components: 33 - L{BasinViewer<client.Viewers.BasinViewer>} 34 - L{VariableViewer<client.Viewers.VariableViewer>} 35 - L{Dock<client.Dock.Dock>} 36 - L{IPythonView<client.IPythonShell.IPythonView>} 37 38 @param parent: This is the main window which this body will be inserted into as the central component. 39 @type parent: BasinWindow 40 41 @param bridge: This is the instance of the bridge, the abstract component linking the 42 interactive components 43 @type bridge: Bridge 44 """ 45 46 # setup the widget object and its layout 47 PyQt4.QtGui.QWidget.__init__ (self, parent) 48 self.layout = PyQt4.QtGui.QHBoxLayout (self) 49 splitter = PyQt4.QtGui.QSplitter () 50 self.layout.addWidget (splitter) 51 52 # make a sub-layout of the left-hand side 53 # which consists of the region & variable viewers 54 leftSplitter = PyQt4.QtGui.QSplitter () 55 leftSplitter.setOrientation (PyQt4.QtCore.Qt.Vertical) 56 self._regionViewer = Viewers.BasinViewer (leftSplitter, self, bridge) 57 self._varViewer = Viewers.VariableViewer (leftSplitter, bridge) 58 splitter.addWidget (leftSplitter) 59 60 # right-hand layout, the dock and ipython shell 61 rightSplitter = PyQt4.QtGui.QSplitter () 62 rightSplitter.setOrientation (PyQt4.QtCore.Qt.Vertical) 63 self._dock = Dock.Dock (rightSplitter, bridge) 64 self._ipyShell = IPythonShell.IPythonView (rightSplitter, bridge) 65 splitter.addWidget (rightSplitter) 66 67 # makes it so this created layout goes on the widget, 68 # which becomes the main centeral widget 69 self.setLayout (self.layout) 70 parent.setCentralWidget (self)
71 72
73 -class BasinWindow (PyQt4.QtGui.QMainWindow):
74 """ 75 Overview 76 ======== 77 This is simply a convenience class which inherits from I{QMainWindow}. In every other way it behaves 78 like a normal QMainWindow should. The purpose of it is to wrap the necessary components 79 of the I{Basin Client} User Interace into the window. The window must be comprised of these elements, 80 so it is fitting for them to be bundled into this class. 81 """ 82
83 - def __init__ (self, app):
84 """ 85 Overview 86 ======== 87 This constructor will create the entire main window for the I{Basin Client}. 88 It takes care of creating all the layouts and widgets for the entire application. 89 It will not take care of showing and executing the main window, so the calling 90 function should handle this. 91 92 First, the parent class' constructor is called. Then constructor sets the Basin title and icon. 93 After this it instantiates the following components (order is important here): 94 1. L{Bridge<client.Bridge.Bridge>} 95 2. L{StatusBar<client.StatusBar.StatusBar>} 96 3. L{BasinBody<client.BasinBody>} 97 4. L{Actions<client.Actions.Actions>} 98 5. L{ToolBar<client.ToolBar.ToolBar>} 99 6. L{MenuBar<client.MenuBar.MenuBar>} 100 101 @param app: This is the application for which you want this main window applied to. 102 @type app: PyQt4.QtGui.QApplication 103 """ 104 105 # Normal setup of a QMainWindow with an icon and title 106 PyQt4.QtGui.QMainWindow.__init__ (self) 107 self.setWindowIcon (PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/basin.png")) 108 self.setWindowTitle ("BASIN") 109 110 # The main parts of the main window, 111 # I'll go into detail on their individual objects... 112 self._bridge = Bridge.Bridge (app, self) 113 self._status = StatusBar.StatusBar (self, self._bridge) 114 self._body = BasinBody (self, self._bridge) 115 self._actions = Actions.Actions (self._bridge) 116 117 # Note that ToolBar and MenuBar depends on BasinActions, 118 # They must be initialized AFTER the bridge. 119 self._tool = ToolBar.ToolBar (self, self._bridge) 120 self._menu = MenuBar.MenuBar (self, self._bridge)
121 122
123 -def main (args):
124 """ 125 Overview 126 ======== 127 This simple main function creates the entire I{Basin Client} application. When creating the 128 instance of a QApplication, it currently does not make use of the command line arguments which 129 are passed to this function. Currently they have would have no context. The function creates 130 a working window for the application, shows the window and executes the application. 131 132 @param args: This is a list of the command line arguments specified when running this script. 133 @type args: list 134 """ 135 # The actual application object 136 app = PyQt4.QtGui.QApplication ([], 1) 137 138 # Set up the main window within the application 139 win = BasinWindow (app) 140 141 # win.show () for non-maximized appearance 142 win.showMaximized () 143 144 # Starts main event loop 145 app.exec_()
146 147 148 if __name__ == "__main__": 149 main (sys.argv) 150