1 from Ganga.GPIDev.Base.Objects import GangaObject
2 from Ganga.GPIDev.Base.Filters import allComponentFilters
3 from Ganga.GPIDev.Base.Proxy import addProxy,isType,getProxyAttr,stripProxy, TypeMismatchError
4 from Ganga.GPIDev.Base.VPrinter import full_print
5 from Ganga.GPIDev.Schema.Schema import ComponentItem,Schema,SimpleItem,Version
6 from Ganga.Utility.Plugin.GangaPlugin import allPlugins
7 from Ganga.Utility.util import containsGangaObjects,isNestedList
8 from Ganga.GPIDev.Base.Proxy import ReadOnlyObjectError
9 import copy,sys
10
37
44
46 """Faster version of makeGangaList. Does not make a copy of _list but use it by reference."""
47 result = GangaList()
48 result._list = _list
49 return result
50
52 return "[%d Entries of type '%s']" % (entries,typename)
53
55 """Simple wrapper around the listiterator"""
62
64
65 _category = 'internal'
66 _exportmethods = ['__add__', '__contains__', '__delitem__', '__delslice__', '__eq__', '__ge__',\
67 '__getitem__', '__getslice__', '__gt__', '__iadd__', '__imul__',\
68 '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__','__reversed__','__radd__','__rmul__',\
69 '__setitem__', '__setslice__', 'append', 'count', 'extend', 'index',\
70 'insert', 'pop', 'remove', 'reverse', 'sort','__hash__']
71 _hidden = 1
72 _enable_plugin = 1
73 _name = 'GangaList'
74 _schema = Schema(Version(1, 0), {
75 '_list' : SimpleItem(defvalue=[], doc='The raw list', hidden = 1),
76 })
77 _enable_config = 1
78
81
82
84 result = (obj != None) and (isType(obj, GangaList) or isinstance(obj,list))
85 return result
86
97
98 obj = stripProxy(obj)
99
100 if filter:
101 parent = self._getParent()
102 item = self.findSchemaParentSchemaEntry(parent)
103 if item and item.isA(ComponentItem):
104 category = item['category']
105 if isType(obj, GangaObject):
106 if obj._category != category:
107 obj = applyFilter(obj, item)
108 obj._setParent(parent)
109 else:
110 obj = applyFilter(obj, item)
111 return obj
112
113
122
124 """Returns a list of categories for the objects in the list. Returns [] for an empty list."""
125
126 result = []
127 for o in self._list:
128 category = o._category
129 if not category in result:
130 result.append(category)
131 return result
132
140
142 """The rule is that if there are nested lists then they
143 must not contain GangaObjects, as this corrupts the repository"""
144 if isNestedList(value) and containsGangaObjects(value):
145 raise TypeMismatchError('Assigning nested lists which contain Ganga GPI Objects is not supported.')
146
147
148
149
150
151
162
165
169
175
181
185
193
196
201
206
209
213
221
228
233
236
238 return len(self._list)
239
242
247
249 if obj_list is self:
250 return True
251 result = True
252 if self.is_list(obj_list):
253 result = self._list.__ne__(self.strip_proxy_list(obj_list))
254 return result
255
257 """Implements the __reversed__ list method introduced in 2.4"""
258
259 try:
260 return reversed(self._list)
261 except NameError:
262
263 class GangaReverseIter(object):
264 """Simple wrapper around the list"""
265 def __init__(self, data):
266 self.data = data
267 self.count = len(self.data) - 1
268 def next(self):
269 self.count -= 1
270 if self.count:
271 result = self.data[self.count + 1]
272 return result
273 else:
274 raise StopIteration()
275
276 def __iter__(self):
277 return self
278
279 return GangaReverseIter(self._list)
280
283
285 return obj + self._list
292
297
304
311
316
323
326
334
337
338 - def insert(self, index, obj):
344
345 - def pop(self, index = -1):
350
356
362
363 - def sort(self, cmpfunc = None):
369
370
372 """Finds the schema entry for this GangaList"""
373 result = None
374 if parent and parent._schema:
375 for k, v in parent._schema.allItems():
376 if getattr(parent,k) is self:
377 result = v
378 break
379 return result
380
381 - def printSummaryTree(self,level = 0, verbosity_level = 0, whitespace_marker = '', out = sys.stdout, selection = ''):
382 parent = self._getParent()
383 schema_entry = self.findSchemaParentSchemaEntry(parent)
384
385 if parent is None:
386 full_print(self,out)
387 return
388
389 if schema_entry:
390 self_len = len(self)
391 print_summary = schema_entry['summary_print']
392 maxLen = schema_entry['summary_sequence_maxlen']
393
394 if print_summary:
395 fp = getattr(parent,print_summary)
396 str_val = fp(self._list,verbosity_level)
397 print >>out, str_val,
398 return
399
400 if (maxLen != -1) and (self_len > maxLen):
401 print >>out, decorateListEntries(self_len, type(self[0]).__name__),
402 return
403 else:
404 full_print(self,out)
405 return
406
407 print >>out, str(self._list),
408 return
409
411 """Returns a simple str of the _list."""
412 return str(self._list)
413