Package client :: Package Dock :: Module Widget
[hide private]
[frames] | no frames]

Source Code for Module client.Dock.Widget

  1  """ 
  2  Overview 
  3  ======== 
  4  This submodule provides a common interface for Dock Widgets with default implementations. 
  5  Dock Widgets are those components in the upper right corner of the Basin Client's central widget. 
  6  They are the menus that are seemingly dynamically swapped out when their button is clicked. 
  7  """ 
  8   
  9  import PyQt4.QtCore 
 10  import PyQt4.QtGui 
 11   
12 -class DockWidget (PyQt4.QtGui.QWidget):
13 """ 14 This class provides an interface for DockWidgets in an effort to make their appearance consistent. 15 16 Overview 17 ======== 18 This is the only class within the DockWidget submodule. It provides an interface for all 19 Dock Widgets with default implementations. The private methods provided all create different 20 sections of the layout. They are intended to give a consistent feel to all Dock Widgets. Currently 21 there are two categories of private methods for this class: 22 23 Implemented 24 ----------- 25 These methods will have a default behavior that will generally assume that the instance 26 of DockWidget (or any inherited classes) has certain private variables instantiated. If 27 such private variables are not found, then a blank implementation is assumed. These methods 28 are not intended to be overridden as they provide a common feel among all Dock Widgets. See 29 specific private methods for what variables they require. 30 31 Unimplemented 32 ------------- 33 These methods are unimplemented for one of two reasons: 34 1. They were optional sections 35 2. They are meant to be very specific for the particular Dock Widget 36 37 That being said, you never have to implement them, in which case the space they would have taken 38 will be filled by the other sections. 39 40 Important 41 ========= 42 These private methods are for internal use only. You should only ever override their implementations, 43 never explicity call them. They are called in the constructor once for a reason. 44 """ 45
46 - def __init__ (self, parent, bridge):
47 """ 48 This constructor for a DockWidget will create a consistent look and feel for the entire DockWidget. 49 50 The constructor will create the following sections of a DockWidget based on 51 1. Pre-existing Private Variables 52 2. Reimplementation of _add* methods 53 54 These are the sections of a DockWidget. Please note that they are all optional, and if you don't 55 want them to appear, overload the corresponding _add* methods to return None. 56 - Header 57 - Description 58 - Commands 59 - Modes 60 - Options 61 - Data Selection 62 """ 63 64 PyQt4.QtGui.QWidget.__init__ (self) 65 self.setVisible (False) 66 self._bridge = bridge 67 bridge._dock.layout.addWidget (self) 68 69 overallLayout = PyQt4.QtGui.QVBoxLayout () 70 self.setLayout (overallLayout) 71 mainLayout = PyQt4.QtGui.QHBoxLayout () 72 73 # Add the Header 74 tempLayout = self._addHeader () 75 if tempLayout: 76 overallLayout.addLayout (tempLayout) 77 overallLayout.setAlignment (tempLayout, PyQt4.QtCore.Qt.AlignCenter) 78 79 overallLayout.addLayout (mainLayout) 80 81 # Sets up the left-hand side 82 leftLayout = PyQt4.QtGui.QVBoxLayout () 83 mainLayout.addLayout (leftLayout) 84 mainLayout.setStretchFactor (leftLayout, 1) 85 86 # Add the Description 87 tempLayout = self._addDescription () 88 if tempLayout: 89 leftLayout.addWidget (tempLayout) 90 91 # Add the Options 92 tempLayout = self._addOptions () 93 if tempLayout: 94 leftLayout.addWidget (tempLayout) 95 96 # Add the Commands 97 tempLayout = self._addCommands () 98 if tempLayout: 99 leftLayout.addWidget (tempLayout) 100 101 # Sets up the right-hand side 102 rightLayout = PyQt4.QtGui.QVBoxLayout () 103 mainLayout.addLayout (rightLayout) 104 mainLayout.setStretchFactor (rightLayout, 1) 105 106 # Add the Modes 107 tempLayout = self._addModes () 108 if tempLayout: 109 rightLayout.addWidget (tempLayout) 110 111 # Add the Data Selection 112 tempLayout = self._addDataSelection () 113 if tempLayout: 114 rightLayout.addWidget (tempLayout)
115 116
117 - def _addHeader (self):
118 """ 119 This method provides the DockWidget a consistent look for a header. 120 121 Overview 122 ======== 123 This method will provide the consistent header of a DockWidget. If any of the three 124 required variables do not appear, the constructor will ignore making the header. 125 126 Pre-existing Private Variables 127 ============================== 128 - self._displayIcon = QIcon (icon of the function) 129 - self._displayName = string (name of the function) 130 - self._type = string (name of the package) 131 132 @return: This function may return 1 of 2 things: 133 1. QLayout 134 2. None 135 """ 136 137 try: 138 picLabel = PyQt4.QtGui.QLabel () 139 picLabel.setPixmap (self._displayIcon.pixmap (PyQt4.QtCore.QSize (22, 22))) 140 header = PyQt4.QtGui.QLabel ("<big><b>" + self._displayName + "</b> (" + self._type + ")</big>") 141 header.setTextFormat (PyQt4.QtCore.Qt.RichText) 142 143 layout = PyQt4.QtGui.QHBoxLayout () 144 layout.addWidget (picLabel) 145 layout.addWidget (header) 146 layout.setAlignment (picLabel, PyQt4.QtCore.Qt.AlignVCenter | PyQt4.QtCore.Qt.AlignRight) 147 layout.setAlignment (header, PyQt4.QtCore.Qt.AlignVCenter | PyQt4.QtCore.Qt.AlignLeft) 148 return layout 149 except (AttributeError): 150 # if self._type, self._displayName, or self._displayIcon weren't found 151 # then return nothing 152 return
153
154 - def _addDescription (self):
155 """ 156 This method provides the DockWidget with a consistent look for the function description 157 158 Overview 159 ======== 160 This method will provide a description for the DockWidget contingent on it finding the 161 single required variable. In the event that the variable is not found, the constructor 162 calling the method will ignore making a description. 163 164 Pre-existing Private Variable 165 ============================= 166 - self._description = string (verbose description of the function) 167 168 @return: This function may return 1 of 2 things: 169 1. QWidget 170 2. None 171 """ 172 173 try: 174 box = PyQt4.QtGui.QGroupBox ("Description") 175 layout = PyQt4.QtGuiQHBoxLayout (box) 176 description = PyQt4.QtGuiQLabel (self._description) 177 description.setWordWrap (True) 178 layout.addWidget (description) 179 return box 180 except (AttributeError): 181 # if self._description wasn't found then return nothing 182 return
183
184 - def _addCommands (self):
185 """ 186 The purpose of this method is to create a consistent look and feel for a DockWidget's command buttons. 187 188 Overview 189 ======== 190 This method has no default implementation since the commands vary between DockWidgets. While 191 you are able to put anything into this reimplementation, it is recommended that it remains 192 consistent with the rest of the Basin Client. Generally speaking, commands are buttons that 193 will execute the function belonging to the DockWidget. Please note that this simply sets up 194 the buttons and their actions, it does not perform the action of the commands. 195 196 @return: This function may return 1 of 2 things: 197 1. QWidget 198 2. None 199 """ 200 201 pass
202
203 - def _addModes (self):
204 """ 205 The purpose of this method is to create a consistent look and feel for DockWidgets who need modes. 206 207 Overview 208 ======== 209 This method has no default implementation since not all DockWidgets will require a mode. 210 While you are able to put anything into the reimplementation of this method, it is recommended 211 that they remain consistent with the rest of the Basin Client. Generally speaking, modes 212 are drawn up as a horizontal layout of QRadioButtons. Again, while not required, the point of 213 the modes is to swap out the I{Data Selection} for a different mode. 214 215 @return: This function may return 1 of 2 things: 216 1. QWidget 217 2. None 218 """ 219 220 pass
221
222 - def _addOptions (self):
223 """ 224 The purpose of this method is to create a consistent look and feel for options contained in DockWidgets. 225 226 Overview 227 ======== 228 This method has no default implementation since not all DockWidgets will require options. 229 While you are able to put anything into the reimplementation of this method, it is recommended 230 that tehy remain consistent wit hthe rest of the Basin Client. Generally speaking, options 231 are drawn up as a vertical layout of QCheckBoxes. Options are considered to be minor changes to the 232 overall purpose of the function. 233 234 @return: This function may return 1 of 2 things: 235 1. QWidget 236 2. None 237 """ 238 239 pass
240
241 - def _addDataSelection (self):
242 """ 243 The purpose of the method is to create a place for any DockWidget to place the guts of the function. 244 245 Overview 246 ======== 247 This method has no default implementation since it would be unique for any DockWidget. There is no 248 real default layout for any function's data selection. Bearing that in mind, this is the place where 249 the actual data that the function intends to utilize should go. Utilize the L{Holders<Holders>} 250 submodule for this. 251 252 @return: This function may return 1 of 2 things: 253 1. QWidget 254 2. None 255 """ 256 257 pass
258