-
Notifications
You must be signed in to change notification settings - Fork 95
/
tree_node.py
2398 lines (1879 loc) · 86.9 KB
/
tree_node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#------------------------------------------------------------------------------
#
# Copyright (c) 2005, Enthought, Inc.
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in enthought/LICENSE.txt and may be redistributed only
# under the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
#
# Author: David C. Morrill
# Date: 12/03/2004
#
#------------------------------------------------------------------------------
""" Defines the tree node descriptor used by the tree editor and tree editor
factory classes.
"""
#-------------------------------------------------------------------------------
# Imports:
#-------------------------------------------------------------------------------
from __future__ import absolute_import
from traits.api import (AdaptedTo, Adapter, Any, Bool, Callable, Either,
HasPrivateTraits, Instance, Interface, List, Property, Str, cached_property)
from traits.trait_base import SequenceTypes, get_resource_path, xgetattr, xsetattr
from .ui_traits import AView
#-------------------------------------------------------------------------------
# 'TreeNode' class:
#-------------------------------------------------------------------------------
class TreeNode ( HasPrivateTraits ):
""" Represents a tree node. Used by the tree editor and tree editor factory
classes.
"""
#---------------------------------------------------------------------------
# Trait definitions:
#---------------------------------------------------------------------------
# Name of trait containing children (if '', the node is a leaf).
children = Str
# Either the name of a trait containing a label, or a constant label, if
# the string starts with '='.
label = Str
# The name of a trait containing a list of labels for any columns.
column_labels = Str
# Either the name of a trait containing a tooltip, or constant tooltip, if
# the string starts with '='.
tooltip = Str
# Name to use for a new instance
name = Str
# Can the object's children be renamed?
rename = Bool( True )
# Can the object be renamed?
rename_me = Bool( True )
# Can the object's children be copied?
copy = Bool( True )
# Can the object's children be deleted?
delete = Bool( True )
# Can the object be deleted (if its parent allows it)?
delete_me = Bool( True )
# Can children be inserted (vs. appended)?
insert = Bool( True )
# Should tree nodes be automatically opened (expanded)?
auto_open = Bool( False )
# Automatically close sibling tree nodes?
auto_close = Bool( False )
# List of object classes than can be added or copied
add = List( Any )
# List of object classes that can be moved
move = List( Any )
# List of object classes and/or interfaces that the node applies to
node_for = List( Any )
# Tuple of object classes that the node applies to
node_for_class = Property( depends_on = 'node_for' )
# List of object interfaces that the node applies to
node_for_interface = Property( depends_on = 'node_for' )
# Function for formatting the label
formatter = Callable
# Functions for formatting the other columns.
column_formatters = List(Either(None, Callable))
# Function for formatting the tooltip
tooltip_formatter = Callable
# Function for handling selecting an object
on_select = Callable
# Function for handling clicking an object
on_click = Callable
# Function for handling double-clicking an object
on_dclick = Callable
# Function for handling activation of an object
# (double-click or Enter key press when node is in focus)
on_activated = Callable
# View to use for editing the object
view = AView
# Right-click context menu. The value can be one of:
#
# - Instance( Menu ): Use this menu as the context menu
# - None: Use the default context menu
# - False: Do not display a context menu
menu = Any
# Name of leaf item icon
icon_item = Str( '<item>' )
# Name of group item icon
icon_group = Str( '<group>' )
# Name of opened group item icon
icon_open = Str( '<open>' )
# Resource path used to locate the node icon
icon_path = Str
# Selector or name for background color
background = Any
# Selector or name for foreground color
foreground = Any
# fixme: The 'menu' trait should really be defined as:
# Instance( 'traitsui.menu.MenuBar' ), but it doesn't work
# right currently.
#---------------------------------------------------------------------------
# Initializes the object:
#---------------------------------------------------------------------------
def __init__ ( self, **traits ):
super( TreeNode, self ).__init__( **traits )
if self.icon_path == '':
self.icon_path = get_resource_path()
#-- Property Implementations -----------------------------------------------
@cached_property
def _get_node_for_class ( self ):
return tuple( [ klass for klass in self.node_for
if not issubclass( klass, Interface ) ] )
@cached_property
def _get_node_for_interface ( self ):
return [ klass for klass in self.node_for
if issubclass( klass, Interface ) ]
#-- Overridable Methods: ---------------------------------------------------
#---------------------------------------------------------------------------
# Returns whether chidren of this object are allowed or not:
#---------------------------------------------------------------------------
def allows_children ( self, object ):
""" Returns whether this object can have children.
"""
return (self.children != '')
#---------------------------------------------------------------------------
# Returns whether or not the object has children:
#---------------------------------------------------------------------------
def has_children ( self, object ):
""" Returns whether the object has children.
"""
return (len( self.get_children( object ) ) > 0)
#---------------------------------------------------------------------------
# Gets the object's children:
#---------------------------------------------------------------------------
def get_children ( self, object ):
""" Gets the object's children.
"""
return getattr( object, self.children )
#---------------------------------------------------------------------------
# Gets the object's children identifier:
#---------------------------------------------------------------------------
def get_children_id ( self, object ):
""" Gets the object's children identifier.
"""
return self.children
#---------------------------------------------------------------------------
# Appends a child to the object's children:
#---------------------------------------------------------------------------
def append_child ( self, object, child ):
""" Appends a child to the object's children.
"""
getattr( object, self.children ).append( child )
#---------------------------------------------------------------------------
# Inserts a child into the object's children:
#---------------------------------------------------------------------------
def insert_child ( self, object, index, child ):
""" Inserts a child into the object's children.
"""
getattr( object, self.children )[ index: index ] = [ child ]
#---------------------------------------------------------------------------
# Confirms that a specified object can be deleted or not:
# Result = True: Delete object with no further prompting
# = False: Do not delete object
# = other: Take default action (may prompt user to confirm delete)
#---------------------------------------------------------------------------
def confirm_delete ( self, object ):
""" Checks whether a specified object can be deleted.
Returns
-------
* **True** if the object should be deleted with no further prompting.
* **False** if the object should not be deleted.
* Anything else: Caller should take its default action (which might
include prompting the user to confirm deletion).
"""
return None
#---------------------------------------------------------------------------
# Deletes a child at a specified index from the object's children:
#---------------------------------------------------------------------------
def delete_child ( self, object, index ):
""" Deletes a child at a specified index from the object's children.
"""
del getattr( object, self.children )[ index ]
#---------------------------------------------------------------------------
# Sets up/Tears down a listener for 'children replaced' on a specified
# object:
#---------------------------------------------------------------------------
def when_children_replaced ( self, object, listener, remove ):
""" Sets up or removes a listener for children being replaced on a
specified object.
"""
object.on_trait_change( listener, self.children, remove = remove,
dispatch = 'fast_ui' )
#---------------------------------------------------------------------------
# Sets up/Tears down a listener for 'children changed' on a specified
# object:
#---------------------------------------------------------------------------
def when_children_changed ( self, object, listener, remove ):
""" Sets up or removes a listener for children being changed on a
specified object.
"""
object.on_trait_change( listener, self.children + '_items',
remove = remove, dispatch = 'fast_ui' )
#---------------------------------------------------------------------------
# Gets the label to display for a specified object:
#---------------------------------------------------------------------------
def get_label ( self, object ):
""" Gets the label to display for a specified object.
"""
label = self.label
if label[:1] == '=':
return label[1:]
label = xgetattr( object, label, '' )
if self.formatter is None:
return label
return self.formatter( object, label )
#---------------------------------------------------------------------------
# Sets the label for a specified object:
#---------------------------------------------------------------------------
def set_label ( self, object, label ):
""" Sets the label for a specified object.
"""
label_name = self.label
if label_name[:1] != '=':
xsetattr( object, label_name, label )
#---------------------------------------------------------------------------
# Sets up/Tears down a listener for 'label changed' on a specified object:
#---------------------------------------------------------------------------
def when_label_changed ( self, object, listener, remove ):
""" Sets up or removes a listener for the label being changed on a
specified object.
"""
label = self.label
if label[:1] != '=':
object.on_trait_change( listener, label, remove = remove,
dispatch = 'ui' )
def get_column_labels(self, object):
""" Get the labels for any columns that have been defined.
"""
trait = self.column_labels
labels = xgetattr(object, trait, [])
formatted = []
for formatter, label in map(None, self.column_formatters, labels):
# If the list of column formatters is shorter than the list of
# labels, then map(None) will extend it with Nones. Just pass the label
# as preformatted. Similarly, explicitly using None in the list will
# pass through the item.
if formatter is None:
formatted.append(label)
else:
formatted.append(formatter(label))
return formatted
def when_column_labels_change(self, object, listener, remove):
""" Sets up or removes a listener for the column labels being changed on
a specified object.
This will fire when either the list is reassigned or when it is
modified. I.e., it listens both to the trait change event and the
trait_items change event. Implement the listener appropriately to handle
either case.
"""
trait = self.column_labels
if trait != '':
object.on_trait_change(listener, trait, remove=remove, dispatch='ui')
object.on_trait_change(listener, trait+'_items', remove=remove, dispatch='ui')
#---------------------------------------------------------------------------
# Gets the tooltip to display for a specified object:
#---------------------------------------------------------------------------
def get_tooltip ( self, object ):
""" Gets the tooltip to display for a specified object.
"""
tooltip = self.tooltip
if tooltip == '':
return tooltip
if tooltip[:1] == '=':
return tooltip[1:]
tooltip = xgetattr( object, tooltip, '' )
if self.tooltip_formatter is None:
return tooltip
return self.tooltip_formatter( object, tooltip )
#---------------------------------------------------------------------------
# Returns the icon for a specified object:
#---------------------------------------------------------------------------
def get_icon ( self, object, is_expanded ):
""" Returns the icon for a specified object.
"""
if not self.allows_children( object ):
return self.icon_item
if is_expanded:
return self.icon_open
return self.icon_group
#---------------------------------------------------------------------------
# Returns the path used to locate an object's icon:
#---------------------------------------------------------------------------
def get_icon_path ( self, object ):
""" Returns the path used to locate an object's icon.
"""
return self.icon_path
#---------------------------------------------------------------------------
# Returns the name to use when adding a new object instance (displayed in
# the 'New' submenu):
#---------------------------------------------------------------------------
def get_name ( self, object ):
""" Returns the name to use when adding a new object instance
(displayed in the "New" submenu).
"""
return self.name
#---------------------------------------------------------------------------
# Gets the View to use when editing an object:
#---------------------------------------------------------------------------
def get_view ( self, object ):
""" Gets the view to use when editing an object.
"""
return self.view
#---------------------------------------------------------------------------
# Returns the right-click context menu for an object:
#---------------------------------------------------------------------------
def get_menu ( self, object ):
""" Returns the right-click context menu for an object.
"""
return self.menu
def get_background(self, object) :
background = self.background
if isinstance(background, basestring) :
background = getattr(object, background, background)
return background
def get_foreground(self, object) :
foreground = self.foreground
if isinstance(foreground, basestring) :
foreground = getattr(object, foreground, foreground)
return foreground
#---------------------------------------------------------------------------
# Returns whether or not the object's children can be renamed:
#---------------------------------------------------------------------------
def can_rename ( self, object ):
""" Returns whether the object's children can be renamed.
"""
return self.rename
#---------------------------------------------------------------------------
# Returns whether or not the object can be renamed:
#---------------------------------------------------------------------------
def can_rename_me ( self, object ):
""" Returns whether the object can be renamed.
"""
return self.rename_me
#---------------------------------------------------------------------------
# Returns whether or not the object's children can be copied:
#---------------------------------------------------------------------------
def can_copy ( self, object ):
""" Returns whether the object's children can be copied.
"""
return self.copy
#---------------------------------------------------------------------------
# Returns whether or not the object's children can be deleted:
#---------------------------------------------------------------------------
def can_delete ( self, object ):
""" Returns whether the object's children can be deleted.
"""
return self.delete
#---------------------------------------------------------------------------
# Returns whether or not the object can be deleted:
#---------------------------------------------------------------------------
def can_delete_me ( self, object ):
""" Returns whether the object can be deleted.
"""
return self.delete_me
#---------------------------------------------------------------------------
# Returns whether or not the object's children can be inserted (or just
# appended):
#---------------------------------------------------------------------------
def can_insert ( self, object ):
""" Returns whether the object's children can be inserted (vs.
appended).
"""
return self.insert
#---------------------------------------------------------------------------
# Returns whether or not the object's children should be auto-opened:
#---------------------------------------------------------------------------
def can_auto_open ( self, object ):
""" Returns whether the object's children should be automatically
opened.
"""
return self.auto_open
#---------------------------------------------------------------------------
# Returns whether or not the object's children should be auto-closed:
#---------------------------------------------------------------------------
def can_auto_close ( self, object ):
""" Returns whether the object's children should be automatically
closed.
"""
return self.auto_close
#---------------------------------------------------------------------------
# Returns whether or not this is the node that should handle a specified
# object:
#---------------------------------------------------------------------------
def is_node_for ( self, object ):
""" Returns whether this is the node that handles a specified object.
"""
return (isinstance( object, self.node_for_class ) or
object.has_traits_interface( *self.node_for_interface ))
#---------------------------------------------------------------------------
# Returns whether a given 'add_object' can be added to an object:
#---------------------------------------------------------------------------
def can_add ( self, object, add_object ):
""" Returns whether a given object is droppable on the node.
"""
klass = self._class_for( add_object )
if self.is_addable( klass ):
return True
for item in self.move:
if type( item ) in SequenceTypes:
item = item[0]
if issubclass( klass, item ):
return True
return False
#---------------------------------------------------------------------------
# Returns the list of classes that can be added to the object:
#---------------------------------------------------------------------------
def get_add ( self, object ):
""" Returns the list of classes that can be added to the object.
"""
return self.add
#---------------------------------------------------------------------------
# Returns the 'draggable' version of a specified object:
#---------------------------------------------------------------------------
def get_drag_object ( self, object ):
""" Returns a draggable version of a specified object.
"""
return object
#---------------------------------------------------------------------------
# Returns a droppable version of a specified object:
#---------------------------------------------------------------------------
def drop_object ( self, object, dropped_object ):
""" Returns a droppable version of a specified object.
"""
klass = self._class_for( dropped_object )
if self.is_addable( klass ):
return dropped_object
for item in self.move:
if type( item ) in SequenceTypes:
if issubclass( klass, item[0] ):
return item[1]( object, dropped_object )
elif issubclass( klass, item ):
return dropped_object
return dropped_object
#---------------------------------------------------------------------------
# Handles an object being selected:
#---------------------------------------------------------------------------
def select ( self, object ):
""" Handles an object being selected.
"""
if self.on_select is not None:
self.on_select( object )
return None
return True
#---------------------------------------------------------------------------
# Handles an object being clicked:
#---------------------------------------------------------------------------
def click ( self, object ):
""" Handles an object being clicked.
"""
if self.on_click is not None:
self.on_click( object )
return None
return True
#---------------------------------------------------------------------------
# Handles an object being double-clicked:
#---------------------------------------------------------------------------
def dclick ( self, object ):
""" Handles an object being double-clicked.
"""
if self.on_dclick is not None:
self.on_dclick( object )
return None
return True
#---------------------------------------------------------------------------
# Handles an object being activated:
#---------------------------------------------------------------------------
def activated ( self, object ):
""" Handles an object being activated.
"""
if self.on_activated is not None:
self.on_activated( object )
return None
return True
#---------------------------------------------------------------------------
# Returns whether or not a specified object class can be added to the node:
#---------------------------------------------------------------------------
def is_addable ( self, klass ):
""" Returns whether a specified object class can be added to the node.
"""
for item in self.add:
if type( item ) in SequenceTypes:
item = item[0]
if issubclass( klass, item ):
return True
return False
#---------------------------------------------------------------------------
# Returns the class of an object:
#---------------------------------------------------------------------------
def _class_for ( self, object ):
""" Returns the class of an object.
"""
if isinstance( object, type ):
return object
return object.__class__
#-------------------------------------------------------------------------------
# 'ITreeNode' class
#-------------------------------------------------------------------------------
class ITreeNode ( Interface ):
def allows_children ( self ):
""" Returns whether this object can have children.
"""
def has_children ( self ):
""" Returns whether the object has children.
"""
def get_children ( self ):
""" Gets the object's children.
"""
def get_children_id ( self ):
""" Gets the object's children identifier.
"""
def append_child ( self, child ):
""" Appends a child to the object's children.
"""
def insert_child ( self, index, child ):
""" Inserts a child into the object's children.
"""
def confirm_delete ( self ):
""" Checks whether a specified object can be deleted.
Returns
-------
* **True** if the object should be deleted with no further prompting.
* **False** if the object should not be deleted.
* Anything else: Caller should take its default action (which might
include prompting the user to confirm deletion).
"""
def delete_child ( self, index ):
""" Deletes a child at a specified index from the object's children.
"""
def when_children_replaced ( self, listener, remove ):
""" Sets up or removes a listener for children being replaced on a
specified object.
"""
def when_children_changed ( self, listener, remove ):
""" Sets up or removes a listener for children being changed on a
specified object.
"""
def get_label ( self ):
""" Gets the label to display for a specified object.
"""
def set_label ( self, label ):
""" Sets the label for a specified object.
"""
def when_label_changed ( self, listener, remove ):
""" Sets up or removes a listener for the label being changed on a
specified object.
"""
def get_column_labels(self, object):
""" Get the labels for any columns that have been defined.
"""
def when_column_labels_change(self, object, listener, remove):
""" Sets up or removes a listener for the column labels being changed on
a specified object.
This will fire when either the list is reassigned or when it is
modified. I.e., it listens both to the trait change event and the
trait_items change event. Implement the listener appropriately to handle
either case.
"""
def get_tooltip ( self ):
""" Gets the tooltip to display for a specified object.
"""
def get_icon ( self, is_expanded ):
""" Returns the icon for a specified object.
"""
def get_icon_path ( self ):
""" Returns the path used to locate an object's icon.
"""
def get_name ( self ):
""" Returns the name to use when adding a new object instance
(displayed in the "New" submenu).
"""
def get_view ( self ):
""" Gets the view to use when editing an object.
"""
def get_menu ( self ):
""" Returns the right-click context menu for an object.
"""
def can_rename ( self ):
""" Returns whether the object's children can be renamed.
"""
def can_rename_me ( self ):
""" Returns whether the object can be renamed.
"""
def can_copy ( self ):
""" Returns whether the object's children can be copied.
"""
def can_delete ( self ):
""" Returns whether the object's children can be deleted.
"""
def can_delete_me ( self ):
""" Returns whether the object can be deleted.
"""
def can_insert ( self ):
""" Returns whether the object's children can be inserted (vs.
appended).
"""
def can_auto_open ( self ):
""" Returns whether the object's children should be automatically
opened.
"""
def can_auto_close ( self ):
""" Returns whether the object's children should be automatically
closed.
"""
def can_add ( self, add_object ):
""" Returns whether a given object is droppable on the node.
"""
def get_add ( self ):
""" Returns the list of classes that can be added to the object.
"""
def get_drag_object ( self ):
""" Returns a draggable version of a specified object.
"""
def drop_object ( self, dropped_object ):
""" Returns a droppable version of a specified object.
"""
def select ( self ):
""" Handles an object being selected.
"""
def click ( self ):
""" Handles an object being clicked.
"""
def dclick ( self ):
""" Handles an object being double-clicked.
"""
def activated ( self ):
""" Handles an object being activated.
"""
#-------------------------------------------------------------------------------
# 'ITreeNodeAdapter' class
#-------------------------------------------------------------------------------
class ITreeNodeAdapter ( Adapter ):
""" Abstract base class for an adapter that implements the ITreeNode
interface.
Usage:
1. Create a subclass of ITreeNodeAdapter.
2. Add an 'adapts( xxx_class, ITreeNode )' declaration (usually placed
right after the 'class' statement) to define what class (or classes)
this is an ITreeNode adapter for.
3. Override any of the following methods as necessary, using the
'self.adaptee' trait to access the adapted object if needed.
Note: This base class implements all of the ITreeNode interface methods,
but does not necessarily provide useful implementations for all of the
methods. It allows you to get a new adapter class up and running quickly,
but you should carefully review your final adapter implementation class
to make sure it behaves correctly in your application.
"""
def allows_children ( self ):
""" Returns whether this object can have children.
"""
return False
def has_children ( self ):
""" Returns whether the object has children.
"""
return False
def get_children ( self ):
""" Gets the object's children.
"""
return []
def get_children_id ( self ):
""" Gets the object's children identifier.
"""
return ''
def append_child ( self, child ):
""" Appends a child to the object's children.
"""
pass
def insert_child ( self, index, child ):
""" Inserts a child into the object's children.
"""
pass
def confirm_delete ( self ):
""" Checks whether a specified object can be deleted.
Returns
-------
* **True** if the object should be deleted with no further prompting.
* **False** if the object should not be deleted.
* Anything else: Caller should take its default action (which might
include prompting the user to confirm deletion).
"""
return False
def delete_child ( self, index ):
""" Deletes a child at a specified index from the object's children.
"""
pass
def when_children_replaced ( self, listener, remove ):
""" Sets up or removes a listener for children being replaced on a
specified object.
"""
pass
def when_children_changed ( self, listener, remove ):
""" Sets up or removes a listener for children being changed on a
specified object.
"""
pass
def get_label ( self ):
""" Gets the label to display for a specified object.
"""
return 'No label specified'
def set_label ( self, label ):
""" Sets the label for a specified object.
"""
pass
def when_label_changed ( self, listener, remove ):
""" Sets up or removes a listener for the label being changed on a
specified object.
"""
pass
def get_column_labels(self):
""" Get the labels for any columns that have been defined.
"""
return []
def when_column_labels_change(self, listener, remove):
""" Sets up or removes a listener for the column labels being changed on
a specified object.
This will fire when either the list is reassigned or when it is
modified. I.e., it listens both to the trait change event and the
trait_items change event. Implement the listener appropriately to handle
either case.
"""
pass
def get_tooltip ( self ):
""" Gets the tooltip to display for a specified object.
"""
return ''
def get_icon ( self, is_expanded ):
""" Returns the icon for a specified object.
"""
return '<item>'
def get_icon_path ( self ):
""" Returns the path used to locate an object's icon.
"""
return ''
def get_name ( self ):
""" Returns the name to use when adding a new object instance
(displayed in the "New" submenu).
"""
return ''
def get_view ( self ):
""" Gets the view to use when editing an object.
"""
return None
def get_menu ( self ):
""" Returns the right-click context menu for an object.
"""
return None
def get_background ( self ):
""" Returns the background for object
"""
return None
def get_foreground ( self ):
""" Returns the foreground for object
"""
return None
def can_rename ( self ):