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

Source Code for Module client.Dock.Holders

  1  import PyQt4.QtCore 
  2  import PyQt4.QtGui 
  3  from PyQt4.QtCore import * 
  4  from PyQt4.QtGui import * 
  5   
  6  import re 
  7   
  8  import Constants 
  9   
10 -class ParentHolder (PyQt4.QtGui.QLineEdit):
11 - def __init__ (self, bridge, inList, outList = []):
12 PyQt4.QtGui.QLineEdit.__init__ (self, "None") 13 self._bridge = bridge 14 self._item = None 15 self.setReadOnly (True) 16 self.setAcceptDrops (True) 17 self._inList = [] 18 self._outList = [] 19 20 self.layout = PyQt4.QtGui.QGridLayout () 21 if outList == []: 22 self.layout.addWidget (PyQt4.QtGui.QLabel (self._typeDisplay + ": "), \ 23 0, 0, PyQt4.QtCore.Qt.AlignRight) 24 self.layout.addWidget (self, 0, 1, PyQt4.QtCore.Qt.AlignLeft) 25 else: 26 self.layout.addWidget (PyQt4.QtGui.QLabel (self._typeDisplay + ": "), \ 27 0, 0, 1, 2, PyQt4.QtCore.Qt.AlignRight) 28 self.layout.addWidget (self, 0, 2, 1, 2, PyQt4.QtCore.Qt.AlignLeft) 29 30 count = 0 31 for inStr in inList: 32 self._inList.append (ChildAttributeHolder (bridge, self)) 33 self.layout.addWidget (PyQt4.QtGui.QLabel (str (inStr) + ": "), \ 34 (count + 1), 0, PyQt4.QtCore.Qt.AlignRight) 35 self.layout.addWidget (self._inList[count], (count + 1), 1, PyQt4.QtCore.Qt.AlignLeft) 36 count += 1 37 38 count = 0 39 for outStr in outList: 40 self._outList.append (OutputHolder (str (outStr), bridge)) 41 self.layout.addWidget (PyQt4.QtGui.QLabel (str (outStr) + ": "), \ 42 (count + 1), 2, PyQt4.QtCore.Qt.AlignRight) 43 self.layout.addWidget (self._outList[count], (count + 1), 3, PyQt4.QtCore.Qt.AlignLeft) 44 count += 1
45
46 - def isInFull (self):
47 if len (self._inList) == self.getNumberOfIns (): 48 return True 49 return False
50
51 - def getNumberOfIns (self):
52 result = 0 53 for holder in self._inList: 54 if holder._item: 55 result += 1 56 return result
57
58 - def getInNames (self, careful = True):
59 result = [] 60 for holder in self._inList: 61 if holder._item: 62 result.append (holder.text ()) 63 elif careful == True: 64 return False 65 return result
66
67 - def getInAccesses (self, careful = True):
68 result = [] 69 for holder in self._inList: 70 if holder._item: 71 result.append (holder._item._shellAccess) 72 elif careful == True: 73 return False 74 return result
75
76 - def getOutNames (self, careful = True):
77 result = [] 78 for holder in self._outList: 79 if holder.text () != "": 80 result.append (holder.text ()) 81 elif careful == True: 82 return False 83 return result
84
85 - def clear (self):
86 self.setText ("None") 87 self._item = None
88
89 - def SetItem (self, item, clobber = True):
90 if item.Type () == self._type and ((clobber == False and self._item != None) \ 91 or clobber == True): 92 self._item = item 93 self.setText (item._name) 94 self._shellAccess = item._shellAccess 95 self.PurgeIncorrectChildren ()
96
97 - def PurgeIncorrectChildren (self):
98 for holder in self._inList: 99 if holder._item and holder._item.parent ()._shellAccess != self._item._shellAccess: 100 holder.clear ()
101
102 - def dropEvent (self, ev):
103 if ev.mimeData ().hasFormat ("text/plain"): 104 data = self._bridge.PopDrugItem () 105 if data.Type () == "ALIAS": 106 data = data._item 107 if data.Type () == self._type: 108 self.SetItem (data, clobber = True) 109 self.setFocus () 110 111 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction) 112 ev.accept () 113 else: 114 ev.ignore ()
115
116 - def dragEnterEvent (self, ev):
117 if ev.mimeData ().hasFormat ("text/plain"): 118 if ev.source () == self._bridge._regionViewer: 119 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction) 120 ev.accept () 121 else: 122 ev.acceptProposedAction () 123 else: 124 ev.ignore ()
125
126 -class ParentListHolder (ParentHolder):
127 - def __init__ (self, bridge, inList, outList = []):
128 self._type = "LIST" 129 self._typeDisplay = "List" 130 ParentHolder.__init__ (self, bridge, inList, outList) 131 self.setStatusTip ("List Holder") 132 self.setToolTip ("Place List Here")
133
134 -class ParentGridHolder (ParentHolder):
135 - def __init__ (self, bridge, inList, outList = []):
136 self._type = "GRID" 137 self._typeDisplay = "Grid" 138 ParentHolder.__init__ (self, bridge, inList, outList) 139 self.setStatusTip ("Grid Holder") 140 self.setToolTip ("Place Grid Here")
141
142 -class ChildAttributeHolder (PyQt4.QtGui.QLineEdit):
143 - def __init__ (self, bridge, list):
144 PyQt4.QtGui.QLineEdit.__init__ (self, "None") 145 self._bridge = bridge 146 self._list = list 147 self._item = None 148 self.setReadOnly (True) 149 self.setAcceptDrops (True) 150 self.setStatusTip ("Attribute Holder") 151 self.setToolTip ("Place Attribute Here")
152
153 - def clear (self):
154 self.setText ("None") 155 self.setStatusTip ("Empty"); 156 self._item = None
157
158 - def SetItem (self, item, clobber = True):
159 if item.Type () == "ATTRIBUTE" and (item.parent ().Type () == self._list._type \ 160 or self._list._type == "FREE") and ((clobber == False and self._item == None) \ 161 or clobber == True): 162 self._item = item 163 self.setText (item._name) 164 if self._list._item == None or \ 165 item.parent ()._shellAccess != self._list._item._shellAccess: 166 self._list.SetItem (item.parent (), clobber = True) 167 self.setStatusTip (makeBreadCrumb (item._shellAccess)); 168 # True signifies that an Item has been set, or cannot be set in the current condition 169 return True 170 elif item.Type () == "VALUE" and item._type == "_basin.Attribute" \ 171 and ((clobber == False and self._item == None) or clobber == True): 172 if self._list._type == "FREE" or self._list.isEnabled () == False: 173 self._item = item 174 self.setText (item._name) 175 self.setStatusTip (makeBreadCrumb (item._shellAccess)); 176 else: 177 self._list._bridge._statusBar.showTimed ("You cannot add this for an 'In Place' action...", STATUS_WAIT) 178 # True signifies that an Item has been set, or cannot be set in the current condition 179 return True 180 # False signifies that it should continue looking for available holders 181 return False
182
183 - def dropEvent (self, ev):
184 # Get the drug item and then make sure something is indeed there 185 data = self._bridge.PopDrugItem () 186 if not data: 187 return 188 if data.Type () == "ALIAS": 189 data = data._item 190 # If its already an attribute, go ahead and drop it 191 if data.Type () == "ATTRIBUTE": 192 self.SetItem (data, clobber = True) 193 self.setFocus () 194 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction) 195 ev.accept () 196 # If its a free floating value, check to atleast make sure its a basin attribute 197 elif data.Type () == "VALUE" and data._type == "_basin.Attribute": 198 if self._list._type == "FREE": 199 self.SetItem (data, clobber = True) 200 self.setFocus () 201 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction) 202 ev.accept () 203 elif self._list.isEnabled () == False: 204 self.SetItem (data, clobber = True) 205 self.setFocus () 206 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction) 207 ev.accept () 208 # otherwise just ignore the action 209 else: 210 self._bridge._statusBar.showTimed ("You may only drop attributes here!", STATUS_WAIT) 211 ev.ignore () 212 # otherwise just ignore the action 213 else: 214 self._bridge._statusBar.showTimed ("You may only drop attributes here!", STATUS_WAIT) 215 ev.ignore ()
216
217 - def dragEnterEvent (self, ev):
218 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction) 219 ev.accept ()
220
221 -class ChildListHolder (PyQt4.QtGui.QLineEdit):
222 - def __init__ (self, bridge, parent):
223 PyQt4.QtGui.QLineEdit.__init__ (self, "None") 224 self._bridge = bridge 225 self._item = None 226 self._parent = parent 227 self.setReadOnly (True) 228 self.setAcceptDrops (True) 229 self.setStatusTip ("List Holder")
230
231 - def clear (self):
232 self.setText ("None") 233 self.setStatusTip ("Empty"); 234 self._item = None
235
236 - def SetItem (self, item, clobber = True):
237 if item.Type () == "VALUE" and item._type == "list" \ 238 and ((clobber == False and self._item == None) or clobber == True): 239 if self._parent._type == "FREE": 240 self._item = item 241 self.setText (item._name) 242 self.setStatusTip (makeBreadCrumb (item._shellAccess)); 243 elif self._parent.isEnabled () == False: 244 self._item = item 245 self.setText (item._name) 246 self.setStatusTip (makeBreadCrumb (item._shellAccess)); 247 # True signifies that an Item has been set, or cannot be set in the current condition 248 return True 249 # False signifies that it should continue looking for available holders 250 return False
251
252 - def dropEvent (self, ev):
253 # Get the drug item and then make sure something is indeed there 254 data = self._bridge.PopDrugItem () 255 if not data: 256 return 257 if data.Type () == "ALIAS": 258 data = data._item 259 # If its a free floating value, check to atleast make sure its a basin attribute 260 if data.Type () == "VALUE" and data._type == "list": 261 if self._parent._type == "FREE": 262 self.SetItem (data, clobber = True) 263 self.setFocus () 264 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction) 265 ev.accept () 266 elif self._parent.isEnabled () == False: 267 self.SetItem (data, clobber = True) 268 self.setFocus () 269 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction) 270 ev.accept () 271 # otherwise just ignore the action 272 else: 273 self._bridge._statusBar.showTimed ("You may only drop float lists here!", STATUS_WAIT) 274 ev.ignore () 275 # otherwise just ignore the action 276 else: 277 self._bridge._statusBar.showTimed ("You may only drop float lists here!", STATUS_WAIT) 278 ev.ignore ()
279
280 - def dragEnterEvent (self, ev):
281 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction) 282 ev.accept ()
283 284
285 -class OutputHolder (PyQt4.QtGui.QLineEdit):
286 - def __init__ (self, default, bridge):
287 PyQt4.QtGui.QLineEdit.__init__ (self, default) 288 self._bridge = bridge 289 self.setReadOnly (False) 290 self.setAcceptDrops (False) 291 self._default = default 292 regexp = QRegExp ("[A-Za-z_][0-9A-Za-z_]*") 293 valid = QRegExpValidator (regexp, self) 294 self.setValidator (valid) 295 self.setStatusTip ("Output") 296 self.setToolTip ("Output Name")
297
298 - def clear (self):
299 self.setText (self._default)
300 301
302 -class FreeHolderGroup:
303 - def __init__ (self, bridge, inList, outList = []):
304 self._bridge = bridge 305 self._item = None 306 self._inList = [] 307 self._outList = [] 308 self._type = "FREE" 309 310 self.layout = PyQt4.QtGui.QGridLayout () 311 count = 0 312 for inStr in inList: 313 self._inList.append (ChildAttributeHolder (bridge, self)) 314 self.layout.addWidget (PyQt4.QtGui.QLabel (str (inStr) + ": "), count, 0, PyQt4.QtCore.Qt.AlignRight) 315 self.layout.addWidget (self._inList[count], count, 1, PyQt4.QtCore.Qt.AlignLeft) 316 count += 1 317 318 count = 0 319 for outStr in outList: 320 self._outList.append (OutputHolder (str (outStr), bridge)) 321 self.layout.addWidget (PyQt4.QtGui.QLabel (str (outStr) + ": "), \ 322 count, 2, PyQt4.QtCore.Qt.AlignRight) 323 self.layout.addWidget (self._outList[count], count, 3, PyQt4.QtCore.Qt.AlignLeft) 324 count += 1
325
326 - def isInFull (self):
327 if len (self._inList) == self.getNumberOfIns (): 328 return True 329 return False
330
331 - def getNumberOfIns (self):
332 result = 0 333 for holder in self._inList: 334 if holder._item: 335 result += 1 336 return result
337
338 - def getInNames (self, careful = True):
339 result = [] 340 for holder in self._inList: 341 if holder._item: 342 result.append (holder.text ()) 343 elif careful == True: 344 return False 345 return result
346
347 - def getInAccesses (self, careful = True):
348 result = [] 349 for holder in self._inList: 350 if holder._item: 351 result.append (holder._item._shellAccess) 352 elif careful == True: 353 return False 354 return result
355
356 - def getOutNames (self, careful = True):
357 result = [] 358 for holder in self._outList: 359 if holder.text () != "": 360 result.append (holder.text ()) 361 elif careful == True: 362 return False 363 return result
364
365 - def clear (self):
366 for holder in self._inList: 367 holder.clear () 368 for holder in self._outList: 369 holder.clear ()
370
371 - def SetItem (self, item, clobber = True):
372 return
373
374 -class GenericGroupHolder:
375 - def __init__ (self, bridge, parent, name, inputs, inputOrder, outputs):
376 """ 377 @param bridge: The bridge object which connects all interactive components together. 378 @type bridge: L{Bridge<client.BASIN_bridge.Bridge>} 379 380 @param parent: The first list contains strings of valid basin types. The second list contains 381 strings of valid python types. There must be exactly two outter lists, the inner 382 lists may vary from being empty to any number of strings. 383 @type parent: [list <string>, list <string>] 384 385 @param name: A string name of the parent 386 @type name: 387 388 @param inputs: A dictionary of string names for inputs, to a 2 element list of lists, similar to 389 the type from `parent` 390 @type inputs: [list <string>, list <string>] 391 392 @param inputOrder: A list of string names for inputs. These should correspond to the keys of C{inputs}. 393 @type inputOrder: list <string> 394 395 @param outputs: A list of string names for outputs. 396 @type outputs: list <string> 397 """ 398 self._layout = QVBoxLayout () 399 self._inputTypes = inputs 400 self._inputHolders = [] 401 self._outputHolders = [] 402 403 topLayout = Constants.BQHBoxLayout (self._layout) 404 bottomLayout = Constants.BQHBoxLayout (self._layout) 405 406 self._parent = GenericInputHolder (bridge, topLayout, name, parent[0], parent[1]) 407 408 inputLayout = Constants.BQVBoxLayout (bottomLayout) 409 for key in inputOrder: 410 GenericChildHolder (bridge, self, inputLayout, key, inputs[key][0], inputs[key][1]) 411 412 outputLayout = Constants.BQVBoxLayout (bottomLayout) 413 count = 0 414 for output in outputs: 415 tempLayout = Constants.BQHBoxLayout (outputLayout) 416 tempLabel = PyQt4.QtGui.QLabel (output + ":") 417 tempLabel.setAlignment (PyQt4.QtCore.Qt.AlignVCenter | PyQt4.QtCore.Qt.AlignRight) 418 tempLayout.addWidget (tempLabel) 419 self._outputHolders.append (OutputHolder (str (output), bridge)) 420 tempLayout.addWidget (self._outputHolders[count]) 421 count += 1
422
423 - def setEnabled (self, enable):
424 """ 425 Overview 426 ======== 427 This method allows you to switch make the group's parent holder usable or unusable. This can be 428 useful when you want to be able to "switch" between a group of holders with a parent, and without. 429 430 An example of this is in the L{AbstractTransform<client.Dock.Transforms.AbstractTransform>} where 431 a checkbox is used to determine if the function's output should be directed to the parent list 432 (in which case we'd want this function to enable the parent holder). Otherwise the function 433 will direct its output to the free variables (in which case we'd want the function to disable 434 the parent holder). 435 436 @param enable: If true, will allow the group's parent holder to be accessable, false if not. 437 @type enable: boolean 438 439 return: none 440 """ 441 442 self._parent.setEnabled (enable)
443
444 - def isInFull (self):
445 """ 446 Overview 447 ======== 448 This method will return either True or False depending on whether all of the input holders have 449 been filled in. 450 451 It utilizes L{getNumberOfIns<client.Dock.Holders.GenericGroupHolder.getNumberOfIns>} and compares 452 it to the length of self._inputHolders. 453 454 @return: boolean, whether or not all of the input holders have been filled 455 """ 456 if len (self._inputHolders) == self.getNumberOfIns (): 457 return True 458 return False
459
460 - def getNumberOfIns (self):
461 """ 462 Overview 463 ======== 464 This method will returnthe number of input holders which have a _item member. The method does not 465 take in to account the total number of holders. 466 467 @return: integer, the number of items found in the input holders 468 """ 469 result = 0 470 for holder in self._inputHolders: 471 if holder._item: 472 result += 1 473 return result
474
475 - def getInNames (self, careful = True):
476 """ 477 GenericGroupHolder.getInNames (self, careful = True) 478 479 This method will generalls return a list of the names 480 on items in the input holders. 481 482 If careful is True, then it will return False if it ever 483 encounters an empty holder. It defaults to this. 484 485 If careful is False, then it will always return a list 486 of strings, and if an input holder has no _item member, 487 then it won't append anything to the result list. 488 """ 489 result = [] 490 for holder in self._inputHolders: 491 if holder._item: 492 result.append (holder.text ()) 493 elif careful == True: 494 return False 495 return result
496
497 - def getInAccesses (self, careful = True):
498 """ 499 GenericGroupHolder.getInAccesses (self, careful = True) 500 501 This method will generalls return a list of the ipython 502 shell access strings on items in the input holders. 503 504 If careful is True, then it will return False if it ever 505 encounters an empty holder. It defaults to this. 506 507 If careful is False, then it will always return a list 508 of strings, and if an input holder has no _item member, 509 then it won't append anything to the result list. 510 """ 511 result = [] 512 for holder in self._inputHolders: 513 if holder._item: 514 result.append (holder._item._shellAccess) 515 elif careful == True: 516 return False 517 return result
518
519 - def getOutNames (self, careful = True):
520 """ 521 GenericGroupHolder.getOutNames (self, careful = True) 522 523 This method will generalls return a list of the names 524 on items in the output holders. 525 526 If careful is True, then it will return False if it ever 527 encounters an empty holder. It defaults to this. 528 529 If careful is False, then it will always return a list 530 of strings, and if an output holder has no _item member, 531 then it won't append anything to the result list. 532 """ 533 result = [] 534 for holder in self._outputHolders: 535 if holder.text () != "": 536 result.append (holder.text ()) 537 elif careful == True: 538 return False 539 return result
540
541 - def clear (self):
542 """ 543 Overview 544 ======== 545 This is a convenience method which simply calls the C{clear ()} method on: 546 1. C{self._parent} 547 2. all holders in C{self._inputHolders} 548 3. all holders in C{self._outputHolders} 549 550 return: none 551 """ 552 553 self._parent.clear () 554 for holder in self._inputHolders: 555 holder.clear () 556 for holder in self._outputHolders: 557 holder.clear ()
558
559 - def PurgeIncorrectChildren (self):
560 """ 561 Overview 562 ======== 563 This method will run through all of the input holders and check if their parent item is the 564 current parent item. If any of the input holders don't meet that condition, then their clear 565 method is called individually, effectively purging it from the group. 566 567 return: none 568 """ 569 570 for holder in self._inputHolders: 571 if holder._item and holder._item.parent ()._shellAccess != self._parent._shellAccess: 572 holder.clear ()
573 574
575 -class GenericInputHolder (PyQt4.QtGui.QLineEdit):
576 - def __init__ (self, bridge, parentLayout, name, basinTypes, pythonTypes):
577 PyQt4.QtGui.QLineEdit.__init__ (self, "None") 578 self._bridge = bridge 579 self._item = None 580 self._name = name 581 self._size = None 582 self._type = None 583 self._basinTypes = basinTypes 584 self._pythonTypes = pythonTypes 585 self.setReadOnly (True) 586 self.setAcceptDrops (True) 587 588 layout = Constants.BQHBoxLayout (parentLayout) 589 label = PyQt4.QtGui.QLabel (self._name + ":") 590 label.setAlignment (PyQt4.QtCore.Qt.AlignVCenter | PyQt4.QtCore.Qt.AlignRight) 591 layout.addWidget (label) 592 layout.addWidget (self)
593
594 - def type (self):
595 # No sense in going through a server command if its already been done 596 if self._type: 597 return self._type 598 599 result = self._bridge._ipyShell.SilentCommand ("print \"\\n\" + str (type (" + \ 600 self._item._shellAccess + "))", False) 601 result = result.split ("\n")[3] 602 603 # Save and return result 604 self._type = result 605 return self._type
606
607 - def size (self):
608 # No sense in going through a server command if its already been done 609 if self._size: 610 return self._size 611 612 result = "" 613 type = self.type () 614 if type == "<type 'list'>": 615 result = self._bridge._ipyShell.SilentCommand ("print \"\\n\" + str (len (" + \ 616 self._item._shellAccess + "))").split ("\n")[3] 617 elif type == "<class '_basin.Attribute'>": 618 result = self._bridge._ipyShell.SilentCommand ("print \"\\n\" + str (len (" + \ 619 self._item._shellAccess + ".get_dims ()))").split ("\n")[3] 620 self._size = int (result) 621 return self._size
622
623 - def clear (self):
624 self.setText ("None") 625 self._item = None 626 self._type = None 627 self._size = None 628 self.setStatusTip ("Empty")
629
630 - def SetItem (self, item, clobber = True):
631 for type in self._basinTypes: 632 if item.Type () == type and ((clobber == False and self._item == None) \ 633 or clobber == True): 634 self._item = item 635 self._type = None 636 self._size = None 637 self.setText (item._name) 638 self.setStatusTip (makeBreadCrumb (self._item._shellAccess)); 639 # True signifies that an Item has been set, or cannot be set in the current condition 640 return True 641 642 for type in self._pythonTypes: 643 if item.Type () == "VALUE" and item._type == type \ 644 and ((clobber == False and self._item == None) or clobber == True): 645 self._item = item 646 self._type = None 647 self._size = None 648 self.setText (item._name) 649 self.setStatusTip (makeBreadCrumb (self._item._shellAccess)); 650 # True signifies that an Item has been set, or cannot be set in the current condition 651 return True 652 653 # False signifies that it should continue looking for available holders 654 return False
655
656 - def dropEvent (self, ev):
657 # Get the drug item and then make sure something is indeed there 658 data = self._bridge.PopDrugItem () 659 if not data: 660 return 661 if data.Type () == "ALIAS": 662 data = data._item 663 664 # Attempt to add the data of any valid basin types 665 for type in self._basinTypes: 666 if data.Type () == type: 667 self.SetItem (data, clobber = True) 668 self.setFocus () 669 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction) 670 ev.accept () 671 return 672 673 # Attempt to add the data of any valid python types 674 for type in self._pythonTypes: 675 if data.Type () == "VALUE" and data._type == type: 676 self.SetItem (data, clobber = True) 677 self.setFocus () 678 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction) 679 ev.accept () 680 return 681 682 self._bridge._statusBar.showTimed ("You may not drop that type here!", Constants.STATUS_WAIT) 683 ev.ignore ()
684
685 - def dragEnterEvent (self, ev):
686 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction) 687 ev.accept ()
688 689
690 -class GenericChildHolder (GenericInputHolder):
691 """ 692 Overview 693 ======== 694 This class of objects is a simple addition to L{GenericInputHolders<GenericInputHolder>} such that it 695 will also contain a reference to a parent. This is so that a group holder may contain children holders 696 and the children holders are aware that they have a parent. 697 """
698 - def __init__ (self, bridge, parent, parentLayout, name, basinTypes, pythonTypes):
699 """ 700 @param bridge: The interlinking bridge class. 701 @type bridge: L{Bridge<client.Bridge>} 702 703 @param parent: This is the group holder which will own this holder. 704 @type parent: L{GenericGroupHolder<GenericGroupHolder>} 705 706 @param parentLayout: The layout of the parent for which this holder will be inserted into. 707 @type parentLayout: PyQt4.QtGui.QLayout 708 709 @param name: This will be the name of the holder, signified by a PyQt4.QtGui.QLabel. 710 @type name: string 711 712 @param basinTypes: This strings in this list are the allowable Basin types that this holder will be 713 able to take as input. They are one of these: 714 - "REGION" 715 - "GRID" 716 - "LIST" 717 - "ATTRIBUTE" 718 @type basinTypes: list <string> 719 720 @param pythonTypes: The strings in this list are the allowable python types that this holder will be 721 able to take as input. Calling the global python function I{type (object)} on an 722 object will show you the string for the object's type. 723 (Generally module_name.class_name) 724 @type pythonTypes: list <string> 725 """ 726 727 GenericInputHolder.__init__ (self, bridge, parentLayout, name, basinTypes, pythonTypes) 728 self._parent = parent._parent 729 parent._inputHolders.append (self)
730 731
732 -class NameHolder (PyQt4.QtGui.QLineEdit):
733 """ 734 Overview 735 ======== 736 This holder is a simple implementation of a PyQt4.QtGui.QLineEdit which has a default value. The purpose of the default 737 value is that when the holder is cleared, instead of an empty string the default value appears. This is used 738 for the naming of data which has yet to be created. In that sense the NameHolder is different from other 739 holders since it doesn't represent data, just a name for future data. 740 """ 741
742 - def __init__ (self, text):
743 """ 744 Overview 745 ======== 746 This simple constructor will create a PyQt4.QtGui.QLineEdit and set its default value and initial value. 747 748 @param text: This will become the initial text of the PyQt4.QtGui.QLineEdit, as well as the default value for it. 749 @type text: string 750 """ 751 752 PyQt4.QtGui.QLineEdit.__init__ (self, text) 753 self._default = text
754
755 - def clear (self):
756 """ 757 Overview 758 ======== 759 This overrides the normal implementation of clear so that instead of setting its text to an empty 760 string, it is reset to the default value. 761 """ 762 763 self.setText (self._default)
764
765 - def dropEvent (self, ev):
766 """ 767 Overview 768 ======== 769 This method handles the dropping of objects into the PyQt4.QtGui.QLineEdit. It will essentially take the displayed 770 name of objects from the basin object tree and set the text of the PyQt4.QtGui.QLineEdit to that. 771 772 @param ev: This is the event object for dropping an object into the PyQt4.QtGui.QLineEdit. It must have a mime data 773 type that is plain text. 774 @type ev: QDropEvent 775 """ 776 777 if ev.mimeData ().hasFormat ("text/plain"): 778 data = self._bridge.PopDrugItem () 779 if data != None: 780 self.setText (data._name) 781 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction) 782 ev.accept () 783 else: 784 ev.ignore ()
785
786 - def dragEnterEvent (self, ev):
787 """ 788 Overview 789 ======== 790 This method simply allows objects to be dragged over the PyQt4.QtGui.QLineEdit. Without the ability to be drug over 791 this object, an object could not be dropped into it. 792 793 @param ev: 794 @type ev: QDragEnterEvent 795 """ 796 797 ev.setDropAction (PyQt4.QtCore.Qt.LinkAction) 798 ev.accept ()
799 800
801 -def makeBreadCrumb (text):
802 """ 803 Overview 804 ======== 805 This function will take the shell access from an abstract basin object (from the Basin Objects tree) and transform it into a more readable bread crumb string. This is useful since the name displayed in a holder is not necessarily unique, however, the bread crumb of any object is unique. Currently this is taken and displayed in the Status Bar, but this function doesn't take care of that. 806 807 @param text: This is a string that must be in the form of a the _shellAccess variable of an abstract 808 basin object from the basin object tree. The format of it will not be verified, and no 809 errors should arise if it is not of that format, but the return will be meaningless. 810 @type text: string 811 812 @return: string 813 """ 814 815 return "Region: " + text.replace ("get_attribute", " - Attribute:").replace ("get_list", " - List:").replace ("get_grid", " - Grid:").replace ("get_child", " - Region:").replace (".", "").replace ("(", "").replace (")", "").replace ("\"", "")
816