1 import PyQt4.QtGui
2 import PyQt4.QtCore
3
4 import string
5 import re
6
7 import Actions
8 import Constants
9
10 -class Region (PyQt4.QtGui.QTreeWidgetItem):
11 """
12 Overview
13 ========
14 This object is the graphical representation of one sub-Region
15 under the RegionTree. For top-level Regions, a derived class
16 TopRegion is used, which is mostly just named in a
17 different manner.
18
19 To constitute a valid Region, it must have a name and
20 shellAccess. The shellAccess is a string of the ipython command
21 needed to access the object. Since these are not variables,
22 their names aren't their access. Generally speaking, their
23 shellAccess will be a traceback up the tree, with the appropriate
24 calls. The exception to this rule is with top-level regions
25 where their name is indeed a shellAccess, where both object
26 attributes still exist with the same value.
27
28 Any abstract object, including this one, may have an alias. An
29 alias is nothing more than setting a variable to an Abstract object.
30 The point being that some arbitrarily deep buried object might have
31 an obscene shellAccess, but the user can assign it to a variable
32 and the GUI will realize this and accomdate for it.
33
34 These objects are created by having passed it a list of strings that
35 identify the entire tree structure. Rather than just the information
36 specific to this tree branch, every node linearly "under" and including
37 this node is listed. It will find its current depth, and only generate
38 tree items based on that depth (and tree structure "deeper"), until
39 it has no more. All mutations to the list of strings are permanent,
40 so once a line generates a tree item, it disposes of itself.
41 """
42
43 - def __init__ (self, parent, parentShellAccess, info):
44 """
45 """
46
47 self._parent = parent
48 PyQt4.QtGui.QTreeWidgetItem.__init__ (self)
49 parent.addChild (self)
50
51 background = PyQt4.QtGui.QColor (230, 230, 255)
52 gradient1 = PyQt4.QtGui.QLinearGradient (PyQt4.QtCore.QPointF(0, 0), PyQt4.QtCore.QPointF(33, 0))
53 gradient1.setColorAt (0, PyQt4.QtCore.Qt.white)
54 gradient1.setColorAt (1, background)
55 brush1 = PyQt4.QtGui.QBrush (gradient1)
56 gradient2 = PyQt4.QtGui.QLinearGradient (PyQt4.QtCore.QPointF(0, 0), PyQt4.QtCore.QPointF(100, 0))
57 gradient2.setColorAt (0, background)
58 gradient2.setColorAt (1, PyQt4.QtCore.Qt.white)
59 brush2 = PyQt4.QtGui.QBrush (gradient2)
60
61 self.setBackground (0, brush1)
62 self.setBackgroundColor (1, background)
63 self.setBackgroundColor (2, background)
64 self.setBackground (3, brush2)
65 self._alias = None
66 currentDepth = info[0].count ("^")
67
68 self.nameMe (parentShellAccess, info)
69 info.pop (0)
70
71 while len (info) > 0 and info[0].count ("^") > currentDepth:
72 regexpList = re.compile ("\^*LIST:.*")
73 regexpGrid = re.compile ("\^*GRID:.*")
74 regexpChild = re.compile ("\^*REGION:.*")
75
76
77 if regexpList.match (info[0]):
78 List (self, self._shellAccess, info)
79 elif regexpGrid.match (info[0]):
80 Grid (self, self._shellAccess, info)
81 elif regexpChild.match (info[0]):
82 Region (self, self._shellAccess, info)
83
84 self.Display ()
85 self.setExpanded (True)
86
88 """
89 Overview
90 ========
91 This function actually sets the text to screen. It will display the name, the fact
92 that it is a Region, and if it exists, the alias name. Notably, this is only 3
93 columns where the RegionTree has 4 columns. This is because no Regions have dimensions.
94 """
95
96 self.setText (0, PyQt4.QtCore.QString (self._name))
97 self.setText (1, PyQt4.QtCore.QString ("Region"))
98 self.setTextAlignment (0, PyQt4.QtCore.Qt.AlignLeft | PyQt4.QtCore.Qt.AlignVCenter)
99 self.setTextAlignment (1, PyQt4.QtCore.Qt.AlignRight | PyQt4.QtCore.Qt.AlignVCenter)
100 if self._alias:
101 self.setText (3, PyQt4.QtCore.QString (str (self._alias._name)))
102 else:
103 self.setText (3, PyQt4.QtCore.QString ("None"))
104
105 - def nameMe (self, parentShellAccess, info):
106 """
107 @param parentShellAccess: Obviously the parent's shell access which directly contributes to the
108 child's shellAccess.
109 @type parentShellAccess: string
110
111 @param info: This is the formatted list of strings that describes the entire makeup
112 of the tree.Information needed to determine the name is extracted from
113 this list, and then destroyed from this list.
114 @type info: list <string>
115 """
116
117 if self.isTop () == False:
118 regexp = re.compile ("\^*REGION:.*")
119 if not regexp.match (info[0]):
120 return
121 self._name = info[0][info[0].index (":") + 1:]
122 self._shellAccess = str (parentShellAccess) + ".get_child (\"" + self._name + "\")"
123
125 """
126 @return: For sub-Regions this will always return False.
127 """
128
129 return False
130
132 """
133 @return: For Regions, this will always return "REGION".
134 """
135 return "REGION"
136
138 """
139 Overview
140 ========
141 This method will take a given alias and set keep track of its reference to this Region. No checks are
142 made currently, as this is assumed to be done in the calling function. This should only
143 really be done from the L{VariableViewer<client.Viewers.VariableViewer>} when the alias has
144 been established.
145
146 @param alias: The alias which references this object.
147 @type alias: L{Alias<client.Viewers.Items.Alias>}
148 """
149
150 self._alias = alias
151 self.Display ()
152
154 """
155 Overview
156 ========
157 This method will create a dialog that simply verifies that the user wishes to delete this region.
158 Note, this deletes the actual data object behind the abstract model. The data can't be recovered
159 after performing this action.
160 """
161
162 dialog = Actions.DeleteDialog (self.treeWidget ()._bridge._mainWindow, self._name)
163 result = dialog.result ()
164 if result == 1:
165 result = self.treeWidget ()._bridge._ipyShell.Command (str (self.parent () \
166 ._shellAccess) + ".delete_child (" + self._shellAccess + ")", True)
167 if result.find ("rror") != -1:
168 self._bridge.Error ("BASIN_region_viewer.py", "Region",
169 "Delete", result)
170 return
171 self.treeWidget ()._bridge.Update ()
172
174 """
175 Overview
176 ========
177 This action assumes something has been copied. Infact it only becomes available if something
178 has been copied. The copied abstract object is stored on the RegionTree. Regions may have other
179 Regions, Lists, or Grids under them. If an attribute was copied, nothing will happen. After a
180 Paste occurs, the copied object is no longer on the "clipboard".
181 """
182
183 if self.treeWidget ()._copy and self.treeWidget ()._copy.Type () == "REGION":
184 if self.treeWidget ()._copy == self: return
185 result = self.treeWidget ()._bridge._ipyShell.Command (str (self._shellAccess) +
186 ".add_child (" + self.treeWidget ()._copy._shellAccess + ")")
187 elif self.treeWidget ()._copy and self.treeWidget ()._copy.Type () == "GRID":
188 result = self.treeWidget ()._bridge._ipyShell.Command (str (self._shellAccess) +
189 ".add_grid (\"" + self.treeWidget ()._copy._name + "\", " +
190 self.treeWidget ()._copy._shellAccess + ")")
191 elif self.treeWidget ()._copy and self.treeWidget ()._copy.Type () == "LIST":
192 result = self.treeWidget ()._bridge._ipyShell.Command (str (self._shellAccess) +
193 ".add_list (\"" + self.treeWidget ()._copy._name + "\", " +
194 self.treeWidget ()._copy._shellAccess + ")")
195 if result.find ("rror") != -1:
196 self.treeWidget ()._bridge.Error ("BASIN_region_viewer.py", "Region", "Paste", result)
197
199 """
200 Overview
201 ========
202 Just adds this object to the "clipboard", located on the RegionTree. Doing so will allow Pastes
203 to occur in the menu system.
204 """
205
206 self.treeWidget ()._copy = self
207
209 """
210 Overview
211 ========
212 This will prompt the user for a name. If a valid name is given, and the dialog wasn't cancelled,
213 this method will create an empty Region as a child of the region being represented by this
214 abstract region.
215 """
216
217 item = self.treeWidget ().getSingleSelectedItem ()
218 if item == None:
219 return
220
221 dialog = Actions.NameDialog (self.treeWidget ()._bridge._mainWindow, "Create Region...", PyQt4.QtGui.QIcon (Constants.ICON_DIR + \
222 "/misc/createregion.png"))
223 result = dialog.result ()
224 if result == 1 and dialog.name.text () != "":
225 shell = self.treeWidget ()._bridge._ipyShell
226 commands = []
227 shell.Command (str (dialog.name.text ()) + " = Region ()", False)
228
229 shell.removeTopLevelRegion (str (dialog.name.text ()))
230 commands.append (str (dialog.name.text ()) + ".set_name (\"" +
231 str (dialog.name.text ()) + "\")")
232 commands.append (str (item._shellAccess) + ".add_child (" +
233 str (dialog.name.text ()) + ")")
234 shell.BatchCommands (commands, True)
235
237 """
238 Overview
239 ========
240 This will prompt the user for a name. If a valid name is given, and the dialog wasn't
241 cancelled, this method will create an empty Grid as a child of the region being represented
242 by this abstract region.
243 """
244
245 item = self.treeWidget ().getSingleSelectedItem ()
246 if item == None:
247 return
248
249 dialog = Actions.NameDialog (self.treeWidget ()._bridge._mainWindow, "Create Grid...", PyQt4.QtGui.QIcon (Constants.ICON_DIR + \
250 "/misc/creategrid.png"))
251 name = str (dialog.name.text ())
252 result = dialog.result ()
253 if result == 1 and name != "":
254 commands = []
255 commands.append (name + " = Grid ()")
256 commands.append (str (item._shellAccess) + ".add_grid (\"" +
257 str (dialog.name.text ()) + "\", " + name + ")")
258 self.treeWidget ()._bridge._ipyShell.BatchCommands (commands)
259
260
262 """
263 Overview
264 ========
265 This will prompt the user for a name. If a valid name is given, and the dialog wasn't
266 cancelled, this method will create an empty List as a child of the region being represented
267 by this abstract region.
268 """
269 item = self.treeWidget ().getSingleSelectedItem ()
270 if item == None:
271 return
272
273 dialog = Actions.NameDialog (self.treeWidget ()._bridge._mainWindow, "Create List...", PyQt4.QtGui.QIcon (Constants.ICON_DIR + \
274 "/misc/createlist.png"))
275 name = str (dialog.name.text ())
276 result = dialog.result ()
277 if result == 1 and name != "":
278 commands = []
279 commands.append (name + " = List ()")
280 commands.append (str (item._shellAccess) + ".add_list (\"" +
281 str (dialog.name.text ()) + "\", " + name + ")")
282 self.treeWidget ()._bridge._ipyShell.BatchCommands (commands, False)
283
284
286 """
287 Overview
288 ========
289 This object is the graphical representation of one top-level Region under the RegionTree.
290 To constitute a valid TopRegion, it must have a name and shellAccess. The shellAccess is
291 a string of the ipython command needed to access the object. Their name is a shellAccess,
292 where both object attributes still exist with the same value, since TopRegions are both
293 basin objects and variables.
294
295 Any abstract object, including this one, may have an alias. An
296 alias is nothing more than setting a variable to an Abstract object.
297 The point being that some arbitrarily deep buried object might have
298 an obscene shellAccess, but the user can assign it to a variable
299 and the GUI will realize this and accomdate for it. Essentially
300 top-level Regions are aliases themselves, but you are welcome
301 to give it another alias name if you wish.
302
303 These objects are created by having passed it a list of strings that
304 identify the entire tree structure. Rather than just the information
305 specific to this tree branch, every node linearly "under" and including
306 this node is listed. It will find its current depth, and only generate
307 tree items based on that depth (and tree structure "deeper"), until
308 it has no more. All mutations to the list of strings are permanent,
309 so once a line generates a tree item, it disposes of itself.
310 """
311 - def __init__ (self, parent, info, name):
312 self._parent = parent
313 self._name = name
314 self._shellAccess = name
315 Region.__init__ (self, parent, name, info)
316 self.Display ()
317
319 """
320 TopRegion.isTop (self)
321
322 For top-level Regions this will always return True.
323 """
324 return True
325
327 """
328 TopRegion.Delete (self)
329
330 This method will create a dialog that simply verifies
331 that the user wishes to delete this region. Note, this
332 deletes the actual data object behind the abstract model.
333 The data can't be recovered after performing this action.
334 """
335 dialog = Actions.DeleteDialog (self.treeWidget ()._bridge._mainWindow, self._name)
336 result = dialog.result ()
337 if result == 1:
338 self.treeWidget ()._bridge._ipyShell.removeTopLevelRegion (str (self._name))
339 self.treeWidget ()._bridge._ipyShell.removeFreeVariable (str (self._name))
340 commands = []
341 commands.append ("del (" + self._shellAccess + ")")
342 self.treeWidget ()._bridge._ipyShell.BatchCommands (commands, True)
343 self.treeWidget ()._bridge.Update ()
344
345
346 -class Grid (PyQt4.QtGui.QTreeWidgetItem):
347 - def __init__ (self, parent, parentShellAccess, info):
348 PyQt4.QtGui.QTreeWidgetItem.__init__ (self)
349 parent.addChild (self)
350 self._parent = parent
351
352 background = PyQt4.QtGui.QColor (230, 255, 230)
353 gradient1 = PyQt4.QtGui.QLinearGradient (PyQt4.QtCore.QPointF(0, 0), PyQt4.QtCore.QPointF (33, 0))
354 gradient1.setColorAt (0, PyQt4.QtCore.Qt.white)
355 gradient1.setColorAt (1, background)
356 brush1 = PyQt4.QtGui.QBrush (gradient1)
357 gradient2 = PyQt4.QtGui.QLinearGradient (PyQt4.QtCore.QPointF(0, 0), PyQt4.QtCore.QPointF (100, 0))
358 gradient2.setColorAt (0, background)
359 gradient2.setColorAt (1, PyQt4.QtCore.Qt.white)
360 brush2 = PyQt4.QtGui.QBrush (gradient2)
361
362 self.setBackground (0, brush1)
363 self.setBackgroundColor (1, background)
364 self.setBackgroundColor (2, background)
365 self.setBackground (3, brush2)
366 self._alias = None
367
368 currentDepth = info[0].count ("^")
369 self.nameMe (parentShellAccess, info)
370 info.pop (0)
371
372 while len (info) > 0 and info[0].count ("^") > currentDepth:
373 regexp = re.compile ("\^*ATTRIBUTE:.*")
374 if regexp.match (info[0]):
375 Attribute (self, self._shellAccess, info)
376
377 self.Display ()
378 self.setExpanded (True)
379
380 - def nameMe (self, parentShellAccess, info):
381 regexp = re.compile ("\^*GRID:.*")
382 if not regexp.match (info[0]):
383 return
384 self._name = info[0][info[0].index (":") + 1:]
385 self._shellAccess = str (parentShellAccess) + ".get_grid (\"" + self._name + "\")"
386
388 self.setText (0, PyQt4.QtCore.QString (str (self._name)))
389 self.setText (1, PyQt4.QtCore.QString ("Grid"))
390 self.setTextAlignment (0, PyQt4.QtCore.Qt.AlignLeft | PyQt4.QtCore.Qt.AlignVCenter)
391 self.setTextAlignment (1, PyQt4.QtCore.Qt.AlignRight | PyQt4.QtCore.Qt.AlignVCenter)
392 if self._alias:
393 self.setText (3, PyQt4.QtCore.QString (str (self._alias._name)))
394 else:
395 self.setText (3, PyQt4.QtCore.QString ("None"))
396
399
401 self._alias = alias
402 self.Display ()
403
405 dialog = Actions.DeleteDialog (self.treeWidget ()._bridge._mainWindow, self._name)
406 result = dialog.result ()
407 if result == 1:
408 commands = []
409 commands.append (str (self.parent () \
410 ._shellAccess) + ".delete_grid (\"" + self._name + "\")")
411 self.treeWidget ()._bridge._ipyShell.BatchCommands (commands, True)
412 self.treeWidget ()._bridge.Update ()
413
415 if self.treeWidget ()._copy and self.treeWidget ()._copy.Type () == "ATTRIBUTE":
416 commands = []
417 commands.append (str (self._shellAccess) +
418 ".add_attribute (\"" + self.treeWidget ()._copy._name + "\", " +
419 self.treeWidget ()._copy._shellAccess + ")")
420 self.treeWidget ()._copy = None
421 self.treeWidget ()._bridge._ipyShell.BatchCommands (commands, True)
422
424 self.treeWidget ()._copy = self
425
426
427 -class List (PyQt4.QtGui.QTreeWidgetItem):
428 - def __init__ (self, parent, parentShellAccess, info):
429 PyQt4.QtGui.QTreeWidgetItem.__init__ (self)
430 parent.addChild (self)
431 self._parent = parent
432
433 background = PyQt4.QtGui.QColor (255, 230, 230)
434 gradient1 = PyQt4.QtGui.QLinearGradient (PyQt4.QtCore.QPointF(0, 0), PyQt4.QtCore.QPointF (33, 0))
435 gradient1.setColorAt (0, PyQt4.QtCore.Qt.white)
436 gradient1.setColorAt (1, background)
437 brush1 = PyQt4.QtGui.QBrush (gradient1)
438 gradient2 = PyQt4.QtGui.QLinearGradient (PyQt4.QtCore.QPointF(0, 0), PyQt4.QtCore.QPointF (100, 0))
439 gradient2.setColorAt (0, background)
440 gradient2.setColorAt (1, PyQt4.QtCore.Qt.white)
441 brush2 = PyQt4.QtGui.QBrush (gradient2)
442
443 self.setBackground (0, brush1)
444 self.setBackgroundColor (1, background)
445 self.setBackgroundColor (2, background)
446 self.setBackground (3, brush2)
447 self._alias = None
448
449 currentDepth = info[0].count ("^")
450 self.nameMe (parentShellAccess, info)
451 info.pop (0)
452
453 while len (info) > 0 and info[0].count ("^") > currentDepth:
454 regexp = re.compile ("\^*ATTRIBUTE:.*")
455 if regexp.match (info[0]):
456 Attribute (self, self._shellAccess, info)
457
458 self.setExpanded (True)
459 self.Display ()
460
461 - def nameMe (self, parentShellAccess, info):
462 regexp = re.compile ("\^*LIST:.*")
463 if not regexp.match (info[0]):
464 return
465 self._name = info[0][info[0].index (":") + 1:]
466 self._shellAccess = str (parentShellAccess) + ".get_list (\"" + self._name + "\")"
467
469 self.setText (0, PyQt4.QtCore.QString (str (self._name)))
470 self.setText (1, PyQt4.QtCore.QString ("List"))
471 self.setTextAlignment (0, PyQt4.QtCore.Qt.AlignLeft | PyQt4.QtCore.Qt.AlignVCenter)
472 self.setTextAlignment (1, PyQt4.QtCore.Qt.AlignRight | PyQt4.QtCore.Qt.AlignVCenter)
473 if self._alias:
474 self.setText (3, PyQt4.QtCore.QString (str (self._alias._name)))
475 else:
476 self.setText (3, PyQt4.QtCore.QString ("None"))
477
480
482 self._alias = alias
483 self.Display ()
484
486 dialog = Actions.DeleteDialog (self.treeWidget ()._bridge._mainWindow, self._name)
487 result = dialog.result ()
488 if result == 1:
489 commands = []
490 commands.append (str (self.parent ()._shellAccess) +
491 ".delete_list (\"" + self._name + "\")")
492 self.treeWidget ()._bridge._ipyShell.BatchCommands (commands, True)
493 self.treeWidget ()._bridge.Update ()
494
496 if self.treeWidget ()._copy and self.treeWidget ()._copy.Type () == "ATTRIBUTE":
497 commands = []
498 commands.append (str (self._shellAccess) +
499 ".add_attribute (\"" + self.treeWidget ()._copy._name + "\", " +
500 self.treeWidget ()._copy._shellAccess + ")")
501 self.treeWidget ()._copy = None
502 self.treeWidget ()._bridge._ipyShell.BatchCommands (commands, True)
503
505 self.treeWidget ()._copy = self
506
507
508 -class Attribute (PyQt4.QtGui.QTreeWidgetItem):
509
510
511 - def __init__ (self, parent, parentShellAccess, info):
512 PyQt4.QtGui.QTreeWidgetItem.__init__ (self)
513 parent.addChild (self)
514 self._parent = parent
515
516 background = PyQt4.QtGui.QColor (230, 230, 230)
517 gradient1 = PyQt4.QtGui.QLinearGradient (PyQt4.QtCore.QPointF(0, 0), PyQt4.QtCore.QPointF(33, 0))
518 gradient1.setColorAt (0, PyQt4.QtCore.Qt.white)
519 gradient1.setColorAt (1, background)
520 brush1 = PyQt4.QtGui.QBrush (gradient1)
521 gradient2 = PyQt4.QtGui.QLinearGradient (PyQt4.QtCore.QPointF(0, 0), PyQt4.QtCore.QPointF(100, 0))
522 gradient2.setColorAt (0, background)
523 gradient2.setColorAt (1, PyQt4.QtCore.Qt.white)
524 brush2 = PyQt4.QtGui.QBrush (gradient2)
525
526 self.setBackground (0, brush1)
527 self.setBackgroundColor (1, background)
528 self.setBackgroundColor (2, background)
529 self.setBackground (3, brush2)
530 self._alias = None
531
532 currentDepth = info[0].count ("^")
533 self.nameMe (parentShellAccess, info)
534 info.pop (0)
535
536 self.getDims (info)
537 info.pop (0)
538
539 self.Display ()
540
541
542
543
545 self.setText (0, PyQt4.QtCore.QString (str (self._name)))
546 self.setText (1, PyQt4.QtCore.QString ("Attribute"))
547 self.setText (2, PyQt4.QtCore.QString (str (self._dims)))
548 if self._alias:
549 self.setText (3, PyQt4.QtCore.QString (str (self._alias._name)))
550 else:
551 self.setText (3, PyQt4.QtCore.QString ("None"))
552 self.setTextAlignment (0, PyQt4.QtCore.Qt.AlignLeft | PyQt4.QtCore.Qt.AlignVCenter)
553 self.setTextAlignment (1, PyQt4.QtCore.Qt.AlignRight | PyQt4.QtCore.Qt.AlignVCenter)
554 self.setTextAlignment (2, PyQt4.QtCore.Qt.AlignRight | PyQt4.QtCore.Qt.AlignVCenter)
555
556
557
558
559 - def nameMe (self, parentShellAccess, info):
560 regexp = re.compile ("\^*ATTRIBUTE:.*")
561 if not regexp.match (info[0]):
562 return
563 self._name = info[0][info[0].index (":") + 1:]
564 self._shellAccess = str (parentShellAccess) + ".get_attribute (\"" + self._name + "\")"
565
566
568 regexp = re.compile ("\^*DIMENSION:.*")
569 if not regexp.match (info[0]):
570 return
571 self._dims = info[0][info[0].index (":") + 1:]
572
573
574
575
578
579
580
581
583 self._alias = alias
584 self.Display ()
585
586
588 dialog = Actions.DeleteDialog (self.treeWidget ()._bridge._mainWindow, self._name)
589 result = dialog.result ()
590 if result == 1:
591
592
593 commands = []
594 commands.append (str (self.parent ()._shellAccess) +
595 ".delete_attribute (\"" + self._name + "\")")
596 self.treeWidget ()._bridge._ipyShell.BatchCommands (commands, True)
597 self.treeWidget ()._bridge.Update ()
598
600 self.treeWidget ()._copy = self
601
602
603 -class Alias (PyQt4.QtGui.QTreeWidgetItem):
604 - def __init__ (self, parent, name, access):
605 PyQt4.QtGui.QTreeWidgetItem.__init__ (self, parent)
606
607 background = PyQt4.QtGui.QColor (255, 228, 181)
608 gradient1 = PyQt4.QtGui.QLinearGradient (PyQt4.QtCore.QPointF(0, 0), PyQt4.QtCore.QPointF(33, 0))
609 gradient1.setColorAt (0, PyQt4.QtCore.Qt.white)
610 gradient1.setColorAt (1, background)
611 brush1 = PyQt4.QtGui.QBrush (gradient1)
612 gradient2 = PyQt4.QtGui.QLinearGradient (PyQt4.QtCore.QPointF(0, 0), PyQt4.QtCore.QPointF(100, 0))
613 gradient2.setColorAt (0, background)
614 gradient2.setColorAt (1, PyQt4.QtCore.Qt.white)
615 brush2 = PyQt4.QtGui.QBrush (gradient2)
616
617 self.setBackground (0, brush1)
618 self.setBackgroundColor (1, background)
619 self.setBackground (2, brush2)
620 self.setText (0, PyQt4.QtCore.QString (str (name)))
621 self.setText (1, PyQt4.QtCore.QString ("Alias"))
622 self._shellAccess = str (access)
623 self._item = None
624 self._name = name
625 self.findReference ()
626
629
631 iter = PyQt4.QtGui.QTreeWidgetItemIterator (self.treeWidget ()._bridge._regionViewer)
632 while iter.value ():
633 if iter.value ().text (0) != "BASIN":
634 if self._shellAccess.replace (" ", "") == \
635 iter.value ()._shellAccess.replace (" ", ""):
636 self.setText (2, PyQt4.QtCore.QString (str (iter.value ()._name)))
637 iter.value ().setAlias (self)
638 self._item = iter.value ()
639 return True
640 iter += 1
641 return False
642
644 if self._item.Type () == "REGION" and self._item.isTop ():
645
646 self._item.Delete ()
647 else:
648 self.treeWidget ()._bridge._ipyShell.removeFreeVariable (self._name)
649 self.treeWidget ()._bridge.Update ()
650
651
652 -class Value (PyQt4.QtGui.QTreeWidgetItem):
654 PyQt4.QtGui.QTreeWidgetItem.__init__ (self, parent)
655
656 background = PyQt4.QtGui.QColor (152, 251, 152)
657 gradient1 = PyQt4.QtGui.QLinearGradient (PyQt4.QtCore.QPointF(0, 0), PyQt4.QtCore.QPointF (33, 0))
658 gradient1.setColorAt (0.0, PyQt4.QtCore.Qt.white)
659 gradient1.setColorAt (1.0, background)
660 brush1 = PyQt4.QtGui.QBrush (gradient1)
661 gradient2 = PyQt4.QtGui.QLinearGradient (PyQt4.QtCore.QPointF(0, 0), PyQt4.QtCore.QPointF (100, 0))
662 gradient2.setColorAt (0.0, background)
663 gradient2.setColorAt (1.0, PyQt4.QtCore.Qt.white)
664 brush2 = PyQt4.QtGui.QBrush (gradient2)
665
666 self.setBackground (0, brush1)
667 self.setBackgroundColor (1, background)
668 self.setBackground (2, brush2)
669 self.setText (0, PyQt4.QtCore.QString (str (name)))
670
671
672
673 self._item = self
674 self._name = name
675 self._shellAccess = name
676 self._type = self.getRealType ()
677 self.setText (1, PyQt4.QtCore.QString (str (self._type)))
678
681
683 result = self.treeWidget ()._bridge._ipyShell.ControllerCommand \
684 ("print str (type (" + self._name + "))")
685 if result.find ("Error") != -1:
686 self.treeWidget ()._bridge.Error ("BASIN_variable_viewer.py", \
687 "VariableValue", "getRealType", result)
688 return "#Error"
689 begin = result.find ("'")
690 close = result.rfind ("'")
691 return result[begin + 1:close]
692
694 dialog = Actions.DeleteDialog (self.treeWidget ()._bridge._mainWindow, self._name)
695 result = dialog.result ()
696 if result == 1:
697 self.treeWidget ()._bridge._ipyShell.removeFreeVariable (str (self._name))
698 commands = []
699 commands.append ("del (" + self._shellAccess + ")")
700 self.treeWidget ()._bridge._ipyShell.BatchCommands (commands, True)
701 self.treeWidget ()._bridge.Update ()
702