@@ -20,6 +20,7 @@ def __init__(
2020 self .parentItem = parent
2121 self .path = path
2222 self .itemData = [name , modified ]
23+ self .contained_size = 0
2324 self .childItems = []
2425 self .checkedState = False
2526 self .files_with_attributes = files_with_attributes
@@ -30,9 +31,18 @@ def __init__(
3031 self ._filtered_children = []
3132 search_path = os .path .join (self .path , name )
3233 if parent is None : # Find path for root folder
34+ self .contained_size = sum (f [0 ] for f in self .files_with_attributes )
3335 for root_folder in nested_file_list .keys ():
3436 self ._filtered_children .append ((0 , "" , root_folder , "" , 'd' ,))
3537 else :
38+ # Each folder contains the size of all children.
39+ # Note that string compare is used here for performance.
40+ self .contained_size = 0
41+ search_path_with_trailing_sep = os .path .join (search_path , '' )
42+ for f in self .files_with_attributes :
43+ if f [3 ] == search_path or f [3 ].startswith (search_path_with_trailing_sep ):
44+ self .contained_size += f [0 ]
45+
3646 self .checkedState = (
3747 parent .checkedState
3848 ) # If there is a parent, use its checked-status.
@@ -127,8 +137,8 @@ def columnCount(self):
127137 def data (self , column ):
128138 if column <= 1 :
129139 return self .itemData [column ]
130- else :
131- return None
140+ elif column == 2 :
141+ return pretty_bytes ( self . contained_size )
132142
133143 def parent (self ):
134144 return self .parentItem
0 commit comments