1 """
2 Overview
3 ========
4 This submodule provides specific implementations of L{DockWidget<client.Widget.DockWidget>}s for functions in Basin's Cosmology package.
5
6 There are currently three functions in the Cosmology package for basin that require a DockWidget. They differ
7 greatly from each other, so unlike other package submodules, there is no abstract version of a Cosmology DockWidget.
8 """
9
10 from PyQt4.QtGui import *
11 from PyQt4.QtCore import *
12
13 import re
14
15 import Constants
16 import DataGuesser
17 import Widget
18 import Holders
19
20 -class Hubble (Widget.DockWidget):
22 self._type = "Cosmology"
23 self._displayName = "Hubble Constant"
24 self._displayIcon = QIcon (Constants.ICON_DIR + "/cosmology/hubble.png")
25 self._description = "You may either supply a float or an attribute of floats. " + \
26 "Your result will reflect the type of input you supplied."
27 Widget.DockWidget.__init__ (self, parent, bridge)
28
30 box = QGroupBox ("Commands")
31 layout = QHBoxLayout (box)
32
33 self._action = Constants.BQPushButton ("Execute", layout)
34 QObject.connect (self._action, SIGNAL ("clicked ()"), self.Execute)
35
36 clearButton = Constants.BQPushButton ("Clear", layout)
37 QObject.connect (clearButton, SIGNAL ("clicked ()"), self.clear)
38
39 return box
40
42 self._in = AttributeHolder (self._bridge, self)
43 self._in.setReadOnly (False)
44 self._out = Holders.NameHolder ("hubble")
45
46 self._dataType = QComboBox ()
47 self._dataType.addItems (["Float", "Attribute"])
48 QObject.connect (self._dataType, \
49 SIGNAL ("currentIndexChanged (const QString&)"), self.changeType)
50
51 outline = QGroupBox ("Data Selection")
52 boxLayout = QGridLayout ()
53 outline.setLayout (boxLayout)
54 boxLayout.addWidget (QLabel (QString ("In/Out Type")), 0, 0, 1, 2, Qt.AlignRight)
55 boxLayout.addWidget (self._dataType, 0, 2, 1, 2, Qt.AlignLeft)
56 boxLayout.addWidget (QLabel (QString ("In:")), 1, 0, Qt.AlignRight)
57 boxLayout.addWidget (self._in, 1, 1, Qt.AlignLeft)
58 boxLayout.addWidget (QLabel (QString ("Out:")), 1, 2, Qt.AlignRight)
59 boxLayout.addWidget (self._out, 1, 3, Qt.AlignLeft)
60
61 return outline
62
66
68 self._in.clear ()
69 current = self._dataType.currentIndex ()
70 if self._dataType.itemText (current) == "Attribute":
71 self._in.setReadOnly (True)
72 elif self._dataType.itemText (current) == "Float":
73 self._in.setReadOnly (False)
74
76 if not ( self._bridge._connected == True and self._bridge._parallel == True):
77 return False
78 if self._in._shellAccess == None or self._out.text () == "":
79 return
80
81 commands = []
82 commands.append (str (self._out.text ()) + \
83 " = COSMOLOGY.hubble (" + self._in._shellAccess + ")")
84 self._bridge._ipyShell.BatchCommands (commands, True)
85
86 self._in.clear ()
87 self._out.clear ()
88
90 if attr == None:
91 attr = self._bridge._regionViewer.getSingleSelectedItem ()
92
93 if attr.Type () == "ALIAS":
94 attr = attr._item
95
96 current = self._dataType.currentIndex ()
97 if (attr.Type () == "ATTRIBUTE" or (attr.Type () == "VALUE" and \
98 attr._type == "_basin.Attribute")) and self._dataType.itemText (current) == "Attribute":
99 self._in._name = attr._name
100 self._in._shellAccess = attr._shellAccess
101 self._in.setText (attr._name)
102
103
106 self._type = "Cosmology"
107 self._displayName = "Redshift To Distance"
108 self._displayIcon = QIcon (Constants.ICON_DIR + "/cosmology/rdist.png")
109 self._description = "some description here..."
110 Widget.DockWidget.__init__ (self, parent, bridge)
111
113 box = QGroupBox ("Commands")
114 layout = QHBoxLayout (box)
115
116 self._action = Constants.BQPushButton ("Execute", layout)
117 QObject.connect (self._action, SIGNAL ("clicked ()"), self.Execute)
118
119 clearButton = Constants.BQPushButton ("Clear", layout)
120 QObject.connect (clearButton, SIGNAL ("clicked ()"), self.clear)
121
122 return box
123
125 box = QGroupBox ("Modes")
126 layout = QHBoxLayout (box)
127
128 self.pref = QCheckBox ("Execute in Place")
129 QObject.connect (self.pref, SIGNAL ("stateChanged (int)"), self.setOutput)
130 layout.addWidget (self.pref)
131
132 return box
133
135 box = QGroupBox ("Modes")
136 layout = QVBoxLayout (box)
137
138 distLabel = QLabel ("Distance Type:")
139 self._distanceType = QComboBox ()
140 self._distanceType.addItems (["Comoving", "Proper", "Angular Diameter", "Luminosity"])
141 distLayout = Constants.BQHBoxLayout (layout)
142 distLayout.addWidget (distLabel)
143 distLayout.addWidget (self._distanceType)
144
145 hLabel = QLabel ("h Result:")
146 self._hType = QComboBox ()
147 self._hType.addItems (["h^-1 Mpc", "h Mpc"])
148 hLayout = Constants.BQHBoxLayout (layout)
149 hLayout.addWidget (hLabel)
150 hLayout.addWidget (self._hType)
151
152 return box
153
155 self.list = Holders.ParentListHolder (self._bridge, ["redshift"], ["distance"])
156 innerLayout = self.list.layout
157
158 box = QGroupBox ("Data Selection")
159 box.setLayout (innerLayout)
160 return box
161
164
166 if self._bridge._inPlace:
167 self.pref.setCheckState (Qt.Checked)
168 else:
169 self.pref.setCheckState (Qt.Unchecked)
170
175
177 if state == 0:
178 self.list.setEnabled (False)
179 elif state == 2:
180 self.list.setEnabled (True)
181
183 if not ( self._bridge._connected == True and self._bridge._parallel == True):
184 return False
185
186 distFlag = self._distanceType.currentIndex ()
187 hFlag = self._hType.currentIndex ()
188
189 commands = []
190 if self.pref.checkState () == Qt.Unchecked:
191 inAttribute = ""
192 result = self.list.getInAccesses ()
193 if result == False:
194 return
195 for attr in result:
196 inAttribute += str (attr)
197 outAttribute = ""
198 result = self.list.getOutNames ()
199 if result == False:
200 return
201 for attr in result:
202 outAttribute += str (attr)
203
204 commands.append (outAttribute + \
205 " = COSMOLOGY.redshift_to_distance (" + str (inAttribute) + \
206 ", " + str (distFlag) + ", " + str (hFlag) + ")")
207
208 elif self.pref.checkState () == Qt.Checked:
209 inAttribute = ""
210 result = self.list.getInNames ()
211 if result == False:
212 return
213 for attr in result:
214 inAttribute += ", \"" + str (attr) + "\""
215 outAttribute = ""
216 result = self.list.getOutNames ()
217 if result == False:
218 return
219 for attr in result:
220 outAttribute += ", \"" + str (attr) + "\""
221
222 commands.append ("COSMOLOGY.redshift_to_distance (" + \
223 str (self.list._shellAccess) + str (inAttribute) + \
224 str (outAttribute) + ", " + str (distFlag) + ", " + str (hFlag) + ")")
225 self._bridge._ipyShell.BatchCommands (commands, True)
226
227 for holder in self.list._inList:
228 holder.clear ()
229 for holder in self.list._outList:
230 holder.clear ()
231 self.list.clear ()
232
234 if attr == None:
235 attr = self._bridge._regionViewer.getSingleSelectedItem ()
236
237 if attr.Type () == "ALIAS":
238 attr = attr._item
239
240 if attr.Type () == "ATTRIBUTE" or (attr.Type () == "VALUE" \
241 and attr._type == "_basin.Attribute"):
242 for holder in self.list._inList:
243 if holder.SetItem (attr, clobber = False) == True:
244 return
245 elif attr.Type () == "LIST":
246 if self.list.text () == "None":
247 self.list.setText (attr.text (0))
248 self.list._shellAccess = attr._shellAccess
249
250
253 self._type = "Cosmology"
254 self._displayName = "Redshift To Growth"
255 self._displayIcon = QIcon (Constants.ICON_DIR + "/cosmology/rgrowth.png")
256 self._description = "some description here..."
257 Widget.DockWidget.__init__ (self, parent, bridge)
258
260 box = QGroupBox ("Modes")
261 layout = QHBoxLayout (box)
262
263 self.pref = QCheckBox ("Execute in Place")
264 QObject.connect (self.pref, SIGNAL ("stateChanged (int)"), self.setOutput)
265 layout.addWidget (self.pref)
266
267 return box
268
269
271 self.list = Holders.ParentListHolder (self._bridge, ["redshift"], ["growth"])
272 innerLayout = self.list.layout
273
274 box = QGroupBox ("Data Selection")
275 box.setLayout (innerLayout)
276 return box
277
279 box = QGroupBox ("Commands")
280 layout = QHBoxLayout (box)
281
282 self._action = Constants.BQPushButton ("Execute", layout)
283 QObject.connect (self._action, SIGNAL ("clicked ()"), self.Execute)
284
285 clearButton = Constants.BQPushButton ("Clear", layout)
286 QObject.connect (clearButton, SIGNAL ("clicked ()"), self.clear)
287
288 return box
289
292
294 if self._bridge._inPlace:
295 self.pref.setCheckState (Qt.Checked)
296 else:
297 self.pref.setCheckState (Qt.Unchecked)
298
303
305 if state == 0:
306 self.list.setEnabled (False)
307 elif state == 2:
308 self.list.setEnabled (True)
309
311 if not ( self._bridge._connected == True and self._bridge._parallel == True):
312 return False
313
314 commands = []
315 if self.pref.checkState () == Qt.Unchecked:
316 inAttribute = ""
317 result = self.list.getInAccesses ()
318 if result == False:
319 return
320 for attr in result:
321 inAttribute += str (attr)
322 outAttribute = ""
323 result = self.list.getOutNames ()
324 if result == False:
325 return
326 for attr in result:
327 outAttribute += str (attr)
328
329 commands.append (outAttribute + " = COSMOLOGY.redshift_to_growth (" +
330 str (inAttribute) + ")")
331
332 elif self.pref.checkState () == Qt.Checked:
333 inAttribute = ""
334 result = self.list.getInNames ()
335 if result == False:
336 return
337 for attr in result:
338 inAttribute += ", \"" + str (attr) + "\""
339 outAttribute = ""
340 result = self.list.getOutNames ()
341 if result == False:
342 return
343 for attr in result:
344 outAttribute += ", \"" + str (attr) + "\""
345
346 commands.append ("COSMOLOGY.redshift_to_growth (" + \
347 str (self.list._shellAccess) + str (inAttribute) + \
348 str (outAttribute) + ")")
349 self._bridge._ipyShell.BatchCommands (commands, True)
350
351 for holder in self.list._inList:
352 holder.clear ()
353 for holder in self.list._outList:
354 holder.clear ()
355 self.list.clear ()
356
358 if attr == None:
359 attr = self._bridge._regionViewer.getSingleSelectedItem ()
360
361 if attr.Type () == "ALIAS":
362 attr = attr._item
363
364 if attr.Type () == "ATTRIBUTE" or (attr.Type () == "VALUE" \
365 and attr._type == "_basin.Attribute"):
366 for holder in self.list._inList:
367 if holder.SetItem (attr, clobber = False) == True:
368 return
369 elif attr.Type () == "LIST":
370 if self.list.text () == "None":
371 self.list.setText (attr.text (0))
372 self.list._shellAccess = attr._shellAccess
373
374
377 QLineEdit.__init__ (self, QString ("None"))
378 self.parent = parent
379 self._bridge = bridge
380 self.setReadOnly (True)
381 self.setAcceptDrops (True)
382 self._name = None
383 self._shellAccess = None
384 QObject.connect (self, SIGNAL ("textEdited (const QString&)"), self.set)
385
386 - def set (self, text):
387 self._name = str (text)
388 self._shellAccess = str (text)
389
391 self.setText ("None")
392 self._name = None
393 self._shellAccess = None
394
396 data = self._bridge.PopDrugItem ()
397 if not data:
398 return
399 if data.Type () == "ALIAS":
400 data = data._item
401
402 current = self.parent._dataType.currentIndex ()
403 if self.parent._dataType.itemText (current) == "Attribute":
404 if data.Type () == "ATTRIBUTE":
405 self._name = data._name
406 self._shellAccess = data._shellAccess
407 self.setText (self._name)
408 ev.setDropAction (Qt.LinkAction)
409 ev.accept ()
410 elif data.Type () == "VALUE" and data._type == "_basin.Attribute":
411 self._name = data._name
412 self._shellAccess = data._name
413 self.setText (self._name)
414 ev.setDropAction (Qt.LinkAction)
415 ev.accept ()
416 else:
417 ev.ignore ()
418 elif self.parent._dataType.itemText (current) == "Float":
419 if data.Type () == "VALUE" and data._type == "float":
420 self._name = data._name
421 self._shellAccess = data._name
422 self.setText (self._name)
423 ev.setDropAction (Qt.LinkAction)
424 ev.accept ()
425
427 if ev.mimeData ().hasFormat ("text/plain"):
428 ev.setDropAction (Qt.LinkAction)
429 ev.accept ()
430 else:
431 ev.ignore ()
432