1 import PyQt4.QtCore
2 import PyQt4.QtGui
3
4 import Constants
5 import DataGuesser
6 import Widget
7 import Holders
8
13
15 box = PyQt4.QtGui.QGroupBox ("Commands")
16 layout = PyQt4.QtGui.QHBoxLayout ()
17 box.setLayout (layout)
18
19 executeButton = Constants.BQPushButton ("Execute", layout)
20 PyQt4.QtCore.QObject.connect (executeButton, PyQt4.QtCore.SIGNAL ("clicked ()"), self.Execute)
21
22 clearButton = Constants.BQPushButton ("Clear", layout)
23 PyQt4.QtCore.QObject.connect (clearButton, PyQt4.QtCore.SIGNAL ("clicked ()"), self.clear)
24
25 return box
26
28 self._in = AttributeHolder (self._bridge, self)
29 self._out = NewAttributeHolder (self._defaultOutName)
30
31 outline = PyQt4.QtGui.QGroupBox ("Data Selection")
32 self.rightLayout = PyQt4.QtGui.QGridLayout ()
33 self.rightLayout.addWidget (PyQt4.QtGui.QLabel ("in:"), 0, 0)
34 self.rightLayout.addWidget (self._in, 0 ,1)
35 self.rightLayout.addWidget (PyQt4.QtGui.QLabel ("out:"), 0, 2)
36 self.rightLayout.addWidget (self._out, 0, 3)
37 outline.setLayout (self.rightLayout)
38
39 return outline
40
42 if not ( self._bridge._connected == True and self._bridge._parallel == True):
43 return False
44
45 commands = []
46 commands.append (self._out.text () + " = " + self._functionName + " (" + self._in._shellAccess + ")")
47 self._bridge._ipyShell.BatchCommands (commands, True)
48
49 self.clear ()
50
52 if attr == None:
53 return
54
55 if attr.Type () == "ALIAS":
56 attr = attr._item
57
58 if attr.Type () == "ATTRIBUTE" or (attr.Type () == "VALUE" and attr._type == "_basin.Attribute"):
59 self._in.setText (attr._name)
60 self._in._name = attr._name
61 self._in._shellAccess = attr._shellAccess
62
64 self._in.clear ()
65 self._out.clear ()
66 return
67
68
69 -class Sort (AbstractFunction):
71 self._functionName = "sort"
72 self._displayName = "Sort"
73 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/sort.png")
74 self._description = "This function takes an Attribute in, sorts it, then sets that to the out " + \
75 "Attribute."
76 self._defaultOutName = "sorted"
77 AbstractFunction.__init__ (self, parent, bridge)
78
79
82 self._functionName = "index_sort"
83 self._displayName = "Index Sort"
84 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/sortindex.png")
85 self._description = "This function takes an Attribute in, sorts it by index, then sets that to " + \
86 "the out Attribute."
87 self._defaultOutName = "sorted"
88 AbstractFunction.__init__ (self, parent, bridge)
89
90
93 self._functionName = "abs"
94 self._displayName = "Absolute Value"
95 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/absval.png")
96 self._description = "This function takes an Attribute in, takes its absolute value, then sets " + \
97 "that to the out Attribute."
98 self._defaultOutName = "abs_out"
99 AbstractFunction.__init__ (self, parent, bridge)
100
101
102 -class Log (AbstractFunction):
104 self._functionName = "log"
105 self._displayName = "Natural Log"
106 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/log.png")
107 self._description = "This function takes an Attribute in, takes its natural log, then sets " + \
108 "that to the out Attribute."
109 self._defaultOutName = "log_out"
110 AbstractFunction.__init__ (self, parent, bridge)
111
112
113 -class Log10 (AbstractFunction):
115 self._functionName = "log10"
116 self._displayName = "Log 10"
117 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/log10.png")
118 self._description = "This function takes an Attribute in, takes its log base 10, then sets " + \
119 "that to the out Attribute."
120 self._defaultOutName = "log_out"
121 AbstractFunction.__init__ (self, parent, bridge)
122
123
124 -class Exp (AbstractFunction):
126 self._functionName = "exp"
127 self._displayName = "Natural Exponential"
128 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/exp.png")
129 self._description = "This function takes an Attribute in, takes it as the exponent of e, then " + \
130 "sets that to the out Attribute."
131 self._defaultOutName = "exp_out"
132 AbstractFunction.__init__ (self, parent, bridge)
133
134
135 -class Exp10 (AbstractFunction):
137 self._functionName = "exp10"
138 self._displayName = "Exponential 10"
139 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/exp10.png")
140 self._description = "This function takes an Attribute in, takes it as the exponent of 10, then " + \
141 "sets that to the out Attribute."
142 self._defaultOutName = "exp_out"
143 AbstractFunction.__init__ (self, parent, bridge)
144
145
148 self._functionName = "sqrt"
149 self._displayName = "Square Root"
150 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/squareroot.png")
151 self._description = "This function takes an Attribute in, takes its square root, then sets that " + \
152 "to the out Attribute."
153 self._defaultOutName = "sqrt_out"
154 AbstractFunction.__init__ (self, parent, bridge)
155
156
157 -class Sin (AbstractFunction):
159 self._functionName = "sin"
160 self._displayName = "Sin"
161 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/sin.png")
162 self._description = "This function takes an Attribute in, takes its sin, then sets that to " + \
163 "the out Attribute."
164 self._defaultOutName = "sin_out"
165 AbstractFunction.__init__ (self, parent, bridge)
166
167
168 -class Cos (AbstractFunction):
170 self._functionName = "cos"
171 self._displayName = "Cos"
172 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/cos.png")
173 self._description = "This function takes an Attribute in, takes its cos, then sets that to " + \
174 "the out Attribute."
175 self._defaultOutName = "cos_out"
176 AbstractFunction.__init__ (self, parent, bridge)
177
178
179 -class Cosh (AbstractFunction):
181 self._functionName = "cosh"
182 self._displayName = "Cosh"
183 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/cosh.png")
184 self._description = "This function takes an Attribute in, takes its cosh, then sets that to " + \
185 "the out Attribute."
186 self._defaultOutName = "cosh_out"
187 AbstractFunction.__init__ (self, parent, bridge)
188
189
190 -class Sinh (AbstractFunction):
192 self._functionName = "sinh"
193 self._displayName = "Sinh"
194 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/sinh.png")
195 self._description = "This function takes an Attribute in, takes its sinh, then sets that to " + \
196 "the out Attribute."
197 self._defaultOutName = "sinh_out"
198 AbstractFunction.__init__ (self, parent, bridge)
199
200
201 -class Acos (AbstractFunction):
203 self._functionName = "acos"
204 self._displayName = "Acos"
205 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/arccos.png")
206 self._description = "This function takes an Attribute in, takes its acos, then sets that to " + \
207 "the out Attribute."
208 self._defaultOutName = "acos_out"
209 AbstractFunction.__init__ (self, parent, bridge)
210
211
212 -class Asin (AbstractFunction):
214 self._functionName = "asin"
215 self._displayName = "Asin"
216 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/arcsin.png")
217 self._description = "This function takes an Attribute in, takes its asin, then sets that to " + \
218 "the out Attribute."
219 self._defaultOutName = "asin_out"
220 AbstractFunction.__init__ (self, parent, bridge)
221
222
223 -class Acosh (AbstractFunction):
225 self._functionName = "acosh"
226 self._displayName = "Acosh"
227 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/acosh.png")
228 self._description = "This function takes an Attribute in, takes its acosh, then sets that to " + \
229 "the out Attribute."
230 self._defaultOutName = "acosh_out"
231 AbstractFunction.__init__ (self, parent, bridge)
232
233
234 -class Asinh (AbstractFunction):
236 self._functionName = "asinh"
237 self._displayName = "Asinh"
238 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/asinh.png")
239 self._description = "This function takes an Attribute in, takes its asinh, then sets that to " + \
240 "the out Attribute."
241 self._defaultOutName = "asinh_out"
242 AbstractFunction.__init__ (self, parent, bridge)
243
244
245 -class Atan (AbstractFunction):
247 self._functionName = "atan"
248 self._displayName = "Atan"
249 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/atan.png")
250 self._description = "This function takes an Attribute in, takes its atan, then sets that to " + \
251 "the out Attribute."
252 self._defaultOutName = "atan_out"
253 AbstractFunction.__init__ (self, parent, bridge)
254
255
256 -class Pow (AbstractFunction):
258 self._functionName = "pow"
259 self._displayName = "Pow"
260 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/pow.png")
261 self._description = "This function takes an Attribute in, takes it to the nth power, then sets " + \
262 "that to the out Attribute."
263 self._defaultOutName = "pow_out"
264 AbstractFunction.__init__ (self, parent, bridge)
265
266 self._exp = PyQt4.QtGui.QSpinBox ()
267 self._exp.setRange (0, 100)
268 self._exp.setSingleStep (1)
269 self.rightLayout.addWidget (PyQt4.QtGui.QLabel ("Exponent:"), 1, 0, 1, 2, PyQt4.QtCore.Qt.AlignRight)
270 self.rightLayout.addWidget (self._exp, 1, 2, 1, 2, PyQt4.QtCore.Qt.AlignLeft)
271
273 if not ( self._bridge._connected == True and self._bridge._parallel == True):
274 return False
275
276 commands = []
277 commands.append (self._out.text () + " = " + self._functionName + " (" +
278 self._in._shellAccess + ", " + str (self._exp.value ()) + ")")
279 self._bridge._ipyShell.BatchCommands (commands, True)
280
281 self.clear ()
282
283
284 -class Real (AbstractFunction):
286 self._functionName = "real"
287 self._displayName = "Real"
288 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/real.png")
289 self._description = "This function takes an Attribute in, takes its real part, then sets that " + \
290 "to the out Attribute."
291 self._defaultOutName = "real_out"
292 AbstractFunction.__init__ (self, parent, bridge)
293
294
297 self._functionName = "imag"
298 self._displayName = "Imaginary"
299 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/imaginary.png")
300 self._description = "This function takes an Attribute in, takes it's imaginary part, then sets " + \
301 "that to the out Attribute."
302 self._defaultOutName = "imag_out"
303 AbstractFunction.__init__ (self, parent, bridge)
304
305
308 PyQt4.QtGui.QLineEdit.__init__ (self, "None")
309 self.setReadOnly (True)
310 self._shellAccess = None
311 self._name = None
312 self._bridge = bridge
313 self._parent = parent
314
316 self.setText ("None")
317 self._shellAccess = None
318 self._name = None
319
321
322 data = self._bridge.PopDrugItem ()
323 if not data:
324 return
325
326 if data.Type () == "ATTRIBUTE" or (data.Type () == "VALUE" and data._type == "_basin.Attribute"):
327 self.setText (data._name)
328 self._name = data._name
329 self._shellAccess = data._shellAccess
330 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction)
331 ev.accept ()
332
333 else:
334 ev.ignore ()
335
337 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction)
338 ev.accept ()
339
342 PyQt4.QtGui.QLineEdit.__init__ (self, default)
343 self._default = default
344
346 self.setText (self._default)
347
350
353
354
357 self._displayName = "Constant Attribute"
358 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/constant.png")
359 self._description = "Choose the number of elements of your new attribute. Also " + \
360 "choose a seed. Note that if always use the same seed, you always get the " + \
361 "same attribute back."
362 AbstractFunction.__init__ (self, parent, bridge)
363
365 self._num = PyQt4.QtGui.QSpinBox ()
366 self._num.setRange (1, 999999999)
367 self._num.setSingleStep (1)
368 self._value = PyQt4.QtGui.QDoubleSpinBox ()
369 self._value.setRange (-999999999.9, 999999999.9)
370 self._value.setValue (0.0)
371 self._value.setSingleStep (1)
372 self._out = NewAttributeHolder ("const_out")
373
374 outline = PyQt4.QtGui.QGroupBox ("Data Selection")
375 rightLayout = PyQt4.QtGui.QGridLayout ()
376 rightLayout.addWidget (PyQt4.QtGui.QLabel ("Size:"), 0, 0)
377 rightLayout.addWidget (self._num, 0, 1)
378 rightLayout.addWidget (PyQt4.QtGui.QLabel ("Value:"), 1, 0)
379 rightLayout.addWidget (self._value, 1, 1)
380 rightLayout.addWidget (PyQt4.QtGui.QLabel ("Out Attribute:"), 2, 0)
381 rightLayout.addWidget (self._out, 2, 1)
382 outline.setLayout (rightLayout)
383
384 return outline
385
387 self._num.setValue (1)
388 self._value.setValue (1)
389 self._out.clear ()
390
392 if not ( self._bridge._connected == True and self._bridge._parallel == True):
393 return False
394
395 self._bridge._ipyShell.Command (self._out.text () + " = Attribute (" +
396 str (self._num.value ()) + ", " + str (self._value.value ()) + ")")
397
398 self.clear ()
399
401 if attr == None:
402 return
403
404 if attr.Type () == "ALIAS":
405 attr = attr._item
406
407 if attr.Type () == "ATTRIBUTE" or (attr.Type () == "VALUE" and attr._type == "_basin.Attribute"):
408 self._in.setText (attr._name)
409 self._in._name = attr._name
410 self._in._shellAccess = attr._shellAccess
411
412
415 self._type = "General Function"
416 self._displayName = "Attribute Index"
417 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DEFAULT)
418 self._description = "This function will return an attribute the same size as your " + \
419 "input. It the attribute it returns will provide indices into your input " + \
420 "data."
421 Widget.DockWidget.__init__ (self, parent, bridge)
422
424 box = PyQt4.QtGui.QGroupBox ("Commands")
425 layout = PyQt4.QtGui.QHBoxLayout ()
426 box.setLayout (layout)
427
428 executeButton = Constants.BQPushButton ("Execute", layout)
429 PyQt4.QtCore.QObject.connect (executeButton, PyQt4.QtCore.SIGNAL ("clicked ()"), self.Execute)
430
431 clearButton = Constants.BQPushButton ("Clear", layout)
432 PyQt4.QtCore.QObject.connect (clearButton, PyQt4.QtCore.SIGNAL ("clicked ()"), self.clear)
433
434 return box
435
437 box = PyQt4.QtGui.QGroupBox ("Data Selection")
438 layout = PyQt4.QtGui.QVBoxLayout ()
439 box.setLayout (layout)
440
441 outLayout = PyQt4.QtGui.QHBoxLayout ()
442 outLabel = PyQt4.QtGui.QLabel ("out:")
443 outLabel.setAlignment (PyQt4.QtCore.Qt.AlignVCenter | PyQt4.QtCore.Qt.AlignRight)
444 self._out = PyQt4.QtGui.QLineEdit ("index_out")
445 outLayout.addWidget (outLabel)
446 outLayout.addWidget (self._out)
447 layout.addLayout (outLayout)
448
449 self._data = Holders.GenericInputHolder (self._bridge, layout, "data", \
450 ["ATTRIBUTE"], ["_basin.Attribute", "list"])
451 PyQt4.QtCore.QObject.connect (self._data, PyQt4.QtCore.SIGNAL ("textChanged (const QString&)"), self.checkOrder)
452 PyQt4.QtCore.QObject.connect (self._data, PyQt4.QtCore.SIGNAL ("textChanged (const QString&)"), self.checkDims)
453
454 dirLayout = PyQt4.QtGui.QHBoxLayout ()
455 dirLabel = PyQt4.QtGui.QLabel ("dir:")
456 dirLabel.setAlignment (PyQt4.QtCore.Qt.AlignVCenter | PyQt4.QtCore.Qt.AlignRight)
457 self._dir = PyQt4.QtGui.QComboBox ()
458 dirLayout.addWidget (dirLabel)
459 dirLayout.addWidget (self._dir)
460
461 orderLayout = PyQt4.QtGui.QHBoxLayout ()
462 orderLabel = PyQt4.QtGui.QLabel ("order:")
463 orderLabel.setAlignment (PyQt4.QtCore.Qt.AlignVCenter | PyQt4.QtCore.Qt.AlignRight)
464 self._order = PyQt4.QtGui.QComboBox ()
465 self._order.setEnabled (False)
466 self._order.addItem ("Normal", PyQt4.QtCore.QVariant ("0"))
467 self._order.addItem ("FFT Half Hermitian", PyQt4.QtCore.QVariant ("1"))
468 orderLayout.addWidget (orderLabel)
469 orderLayout.addWidget (self._order)
470
471 layout.addLayout (dirLayout)
472 layout.addLayout (orderLayout)
473 return box
474
476
477 text = str (text)
478 if text != "None":
479 type = self._data.type ()
480 if type == "<type 'list'>":
481 self._order.setEnabled (True)
482 return
483 self._order.setEnabled (False)
484
486
487 self._dir.clear ()
488 text = str (text)
489 if text != "None":
490 size = self._data.size ()
491 for i in xrange (size):
492 self._dir.addItem (str (i))
493
494
496 self._data.clear ()
497 self._out.setText ("index_out")
498
500 if not ( self._bridge._connected == True and self._bridge._parallel == True):
501 return False
502
503 order = ""
504 if self._order.isEnabled ():
505 order += ", " + str (self._order.currentText ())
506
507 self._bridge._ipyShell.Command (self._out.text () + " = attribute_index (" + \
508 self._data._item._shellAccess + ", " + str (self._dir.currentText ()) + \
509 order + ")", True)
510 self.clear ()
511
513 if attr == None:
514 return
515
516 if attr.Type () == "ALIAS":
517 attr = attr._item
518
519 if attr.Type () == "ATTRIBUTE" or (attr.Type () == "VALUE" and attr._type == "_basin.Attribute") \
520 or (attr.Type () == "VALUE" and attr._type == "list"):
521 self._data.SetItem (attr, False)
522
523
526 self._displayName = "Random Attribute"
527 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/general_functions/random.png")
528 self._description = "Choose the number of elements of your new attribute. Also " + \
529 "choose a seed. Note that if always use the same seed, you " + \
530 "always get the same attribute back."
531 AbstractFunction.__init__ (self, parent, bridge)
532
534 self._num = PyQt4.QtGui.QSpinBox ()
535 self._num.setRange (1, 999999999)
536 self._num.setSingleStep (1)
537 self._seed = PyQt4.QtGui.QSpinBox ()
538 self._seed.setRange (1, 999999999)
539 self._seed.setSingleStep (1)
540 self._out = NewAttributeHolder ("rand_out")
541
542 outline = PyQt4.QtGui.QGroupBox ("Data Selection")
543 rightLayout = PyQt4.QtGui.QGridLayout ()
544 rightLayout.addWidget (PyQt4.QtGui.QLabel ("Size:"), 0, 0)
545 rightLayout.addWidget (self._num, 0, 1)
546 rightLayout.addWidget (PyQt4.QtGui.QLabel ("Seed:"), 1, 0)
547 rightLayout.addWidget (self._seed, 1, 1)
548 rightLayout.addWidget (PyQt4.QtGui.QLabel ("Out Attribute:"), 2, 0)
549 rightLayout.addWidget (self._out, 2, 1)
550 outline.setLayout (rightLayout)
551
552 return outline
553
555 self._num.setValue (1)
556 self._seed.setValue (1)
557 self._out.clear ()
558
560 if not ( self._bridge._connected == True and self._bridge._parallel == True):
561 return False
562
563 commands = []
564 commands.append (self._out.text () + " = attribute_random" +
565 " (" + str (self._num.value ()) + ", " + str (self._seed.value ()) + ")")
566 self._bridge._ipyShell.BatchCommands (commands, True)
567
568 self.clear ()
569
571 if attr == None:
572 return
573
574 if attr.Type () == "ALIAS":
575 attr = attr._item
576
577 if attr.Type () == "ATTRIBUTE" or (attr.Type () == "VALUE" and attr._type == "_basin.Attribute"):
578 self._in.setText (attr._name)
579 self._in._name = attr._name
580 self._in._shellAccess = attr._shellAccess
581