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

Source Code for Module client.Dock.LinearAlgebra

  1  import PyQt4.QtCore 
  2  import PyQt4.QtGui 
  3   
  4  import Constants 
  5  import Widget 
  6  import Holders 
  7   
8 -class AbstractLinearAlgebra (Widget.DockWidget):
9 - def __init__ (self, parent, bridge):
10 self._type = "Linear Algebra" 11 Widget.DockWidget.__init__ (self, parent, bridge)
12
13 - def _addCommands (self):
14 box = PyQt4.QtGui.QGroupBox ("Commands") 15 layout = PyQt4.QtGui.QHBoxLayout (box) 16 17 executeButton = Constants.BQPushButton ("Execute", layout) 18 executeButton.setDefault (True) 19 PyQt4.QtCore.QObject.connect (executeButton, PyQt4.QtCore.SIGNAL ("clicked ()"), self.execute) 20 21 clearButton = Constants.BQPushButton ("Clear", layout) 22 PyQt4.QtCore.QObject.connect (clearButton, PyQt4.QtCore.SIGNAL ("clicked ()"), self.clear) 23 24 return box
25
26 - def _addDataSelection (self):
27 self._inHolders = [] 28 self._outHolder = "" 29 30 outline = PyQt4.QtGui.QGroupBox ("Data Selection") 31 dataLayout = PyQt4.QtGui.QVBoxLayout (outline) 32 for input in self._inList: 33 holder = Holders.GenericInputHolder (self._bridge, dataLayout, input, [], ["_basin.matrix"]) 34 35 dataLayout.addSpacing (10) 36 37 output = self._outList 38 tempLayout = Constants.BQHBoxLayout (dataLayout) 39 label = PyQt4.QtGui.QLabel (output + ":") 40 label.setAlignment (PyQt4.QtCore.Qt.AlignRight | PyQt4.QtCore.Qt.AlignVCenter) 41 tempLayout.addWidget (label) 42 holder = Holders.OutputHolder (output, self._bridge) 43 self._outHolder = holder 44 tempLayout.addWidget (holder) 45 46 return outline
47
48 - def clear (self):
49 for holder in self._inHolders: 50 holder.clear () 51 self._outHolder.clear ()
52
53 - def DoubleClicked (self, matrix = None):
54 if matrix == None: 55 return 56 57 if matrix.Type () == "VALUE" and matrix._type == "_basin.matrix": 58 for holder in self._inHolders: 59 if holder._item == None: 60 holder.SetItem (matrix, False) 61 return True 62 return False
63
64 - def execute (self):
65 if not ( self._bridge._connected == True and self._bridge._parallel == True): 66 return False 67 if self._outHolder == "": 68 return False 69 70 inString = "" 71 for holder in self._inHolders: 72 inString += holder._item._shellAccess + ", " 73 inString = inString[:-2] 74 75 commands = [] 76 commands.append (self._outHolder.text () + " = " + self._functionName + " (" + inString + ")") 77 self._bridge._ipyShell.BatchCommands (commands, True) 78 79 self.clear ()
80 81
82 -class MatrixInvert (AbstractLinearAlgebra):
83 - def __init__ (self, parent, bridge):
84 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/linear_algebra/matrixinvert.png") 85 self._displayName = "Invert Matrix" 86 self._functionName = "matrix_invert" 87 self._description = "This function will invert a square matrix." 88 self._inList = ["matrix"] 89 self._outList = "inverse" 90 AbstractLinearAlgebra.__init__ (self, parent, bridge)
91 92
93 -class MatrixMult (AbstractLinearAlgebra):
94 - def __init__ (self, parent, bridge):
95 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/linear_algebra/matrixmult.png") 96 self._displayName = "Multiply Matrices" 97 self._functionName = "matrix_mult" 98 self._description = "This function will multiply two different matrices." 99 self._inList = ["a", "b"] 100 self._outList = "product" 101 AbstractLinearAlgebra.__init__ (self, parent, bridge)
102 103
104 -class MatrixCreate (AbstractLinearAlgebra):
105 - def __init__ (self, parent, bridge):
106 self._type = "Linear Algebra" 107 self._displayName = "Create Matrix" 108 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/linear_algebra/matrixcreate.png") 109 self._description = "Supply a python list and the dimensions to create a matrix." 110 AbstractLinearAlgebra.__init__ (self, parent, bridge)
111
112 - def _addDataSelection (self):
113 outline = PyQt4.QtGui.QGroupBox ("Data Selection") 114 dataLayout = PyQt4.QtGui.QVBoxLayout (outline) 115 116 self._dataHolder = Holders.GenericInputHolder (self._bridge, dataLayout, "data", [], ["_basin.matrix"]) 117 118 dimMLayout = Constants.BQHBoxLayout (dataLayout) 119 dimMLabel = PyQt4.QtGui.QLabel ("m:") 120 dimMLabel.setAlignment (PyQt4.QtCore.Qt.AlignRight | PyQt4.QtCore.Qt.AlignVCenter) 121 self._dimM = PyQt4.QtGui.QSpinBox () 122 self._dimM.setRange (1,999999999) 123 dimMLayout.addWidget (dimMLabel) 124 dimMLayout.addWidget (self._dimM) 125 126 dimNLayout = Constants.BQHBoxLayout (dataLayout) 127 dimNLabel = PyQt4.QtGui.QLabel ("n:") 128 dimNLabel.setAlignment (PyQt4.QtCore.Qt.AlignRight | PyQt4.QtCore.Qt.AlignVCenter) 129 self._dimN = PyQt4.QtGui.QSpinBox () 130 self._dimN.setRange (1,999999999) 131 dimNLayout.addWidget (dimNLabel) 132 dimNLayout.addWidget (self._dimN) 133 134 dataLayout.addSpacing (10) 135 output = "out" 136 tempLayout = Constants.BQHBoxLayout (dataLayout) 137 label = PyQt4.QtGui.QLabel (output + ":") 138 label.setAlignment (PyQt4.QtCore.Qt.AlignRight | PyQt4.QtCore.Qt.AlignVCenter) 139 tempLayout.addWidget (label) 140 holder = Holders.OutputHolder (output, self._bridge) 141 self._outHolder = holder 142 tempLayout.addWidget (holder) 143 144 return outline
145
146 - def clear (self):
147 self._dimM.setValue (1) 148 self._dimN.setValue (1) 149 self._dataHolder.clear () 150 self._outHolder.clear ()
151
152 - def DoubleClicked (self, list = None):
153 if list == None: 154 return 155 156 if list.Type () == "VALUE" and list._type == "list": 157 holder = self._dataHolder 158 if holder._item == None: 159 holder.SetItem (list, False) 160 return True 161 return False
162
163 - def execute (self):
164 if not ( self._bridge._connected == True and self._bridge._parallel == True): 165 return False 166 if self._outHolder == "": 167 return False 168 169 m, n = self._dimM.value (), self._dimN.value () 170 dataLength = self._dataHolder.getLength () 171 if (m * n) != dataLength and self._dataHolder._item != None: 172 self._bridge._statusBar.showTimed ("Dimensions provided don't fit data! (" + \ 173 str (dataLength) + " != " + str (m) + " * " + str (n) + ")", STATUS_WAIT) 174 return False 175 176 data = "" 177 if self._dataHolder._item != None: 178 data = self._dataHolder._item._shellAccess + ", " 179 180 commands = [] 181 commands.append (self._outHolder.text () + " = matrix (" + data + str (m) + ", " + str (n) + ")") 182 self._bridge._ipyShell.BatchCommands (commands, True) 183 184 self.clear ()
185 186
187 -class IdentityMatrixCreate (AbstractLinearAlgebra):
188 - def __init__ (self, parent, bridge):
189 self._type = "Linear Algebra" 190 self._displayName = "Create Identity Matrix" 191 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/linear_algebra/identitymatrixcreate.png") 192 self._description = "Supply the square dimension of the identity matrix." 193 AbstractLinearAlgebra.__init__ (self, parent, bridge)
194
195 - def _addDataSelection (self):
196 outline = PyQt4.QtGui.QGroupBox ("Data Selection") 197 dataLayout = PyQt4.QtGui.QVBoxLayout (outline) 198 199 dimLayout = Constants.BQHBoxLayout (dataLayout) 200 dimLabel = PyQt4.QtGui.QLabel ("dim:") 201 dimLabel.setAlignment (PyQt4.QtCore.Qt.AlignRight | PyQt4.QtCore.Qt.AlignVCenter) 202 self._dim = PyQt4.QtGui.QSpinBox () 203 self._dim.setRange (1,999999999) 204 dimLayout.addWidget (dimLabel) 205 dimLayout.addWidget (self._dim) 206 207 dataLayout.addSpacing (10) 208 output = "out" 209 tempLayout = Constants.BQHBoxLayout (dataLayout) 210 label = PyQt4.QtGui.QLabel (output + ":") 211 label.setAlignment (PyQt4.QtCore.Qt.AlignRight | PyQt4.QtCore.Qt.AlignVCenter) 212 tempLayout.addWidget (label) 213 holder = Holders.OutputHolder (output, self._bridge) 214 self._outHolder = holder 215 tempLayout.addWidget (holder) 216 217 return outline
218
219 - def clear (self):
220 self._dim.setValue (1) 221 self._outHolder.clear ()
222
223 - def DoubleClicked (self, list = None):
224 return
225
226 - def execute (self):
227 if not ( self._bridge._connected == True and self._bridge._parallel == True): 228 return False 229 if self._outHolder == "": 230 return False 231 232 commands = [] 233 commands.append (self._outHolder.text () + " = matrix (" + str (self._dim.value ()) + ")") 234 self._bridge._ipyShell.BatchCommands (commands, True) 235 236 self.clear ()
237