chiark / gitweb /
Add uppercase STL and HEX to file dialog filters for linux/MacOS
[cura.git] / Cura / cura_sf / fabmetheus_utilities / geometry / geometry_utilities / evaluate_enumerables / list_attribute.py
1 """
2 List object attributes.
3
4 """
5
6 from __future__ import absolute_import
7 #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
8 import __init__
9
10 from fabmetheus_utilities import euclidean
11
12
13 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
14 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
15 __date__ = '$Date: 2008/02/05 $'
16 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
17
18
19 def _getAccessibleAttribute(attributeName, listObject):
20         'Get the accessible attribute.'
21         if attributeName in globalNativeFunctionSet:
22                 return getattr(listObject, attributeName, None)
23         if attributeName in globalGetAccessibleAttributeSet:
24                 stringAttribute = ListAttribute(listObject)
25                 return getattr(stringAttribute, attributeName, None)
26         return None
27
28
29 class ListAttribute:
30         'Class to handle a list.'
31         def __init__(self, listObject):
32                 'Initialize.'
33                 self.listObject = listObject
34
35         def __repr__(self):
36                 "Get the list representation of this ListAttribute."
37                 return str(self.listObject)
38
39         def add(self, value):
40                 'Get the concatenation, same as append.'
41                 return self.listObject + [value]
42
43         def copy(self):
44                 'Get the copy.'
45                 return self.listObject[:]
46
47         def delete(self, arguments):
48                 'Get the delete list.'
49                 deleteList = []
50                 enumeratorSet = set(euclidean.getEnumeratorKeysAlwaysList(self.listObject, arguments))
51                 for elementIndex, element in enumerate(self.listObject):
52                         if elementIndex not in enumeratorSet:
53                                 deleteList.append(element)
54                 return deleteList
55
56         def get(self, itemIndex):
57                 'Get value by index'
58                 return self.listObject[itemIndex]
59
60         def getExpansion(self, items):
61                 'Get the concatenated copies.'
62                 expansion = []
63                 for itemIndex in xrange(items):
64                         expansion += self.listObject[:]
65                 return expansion
66
67         def getIsIn(self, value):
68                 'Determine if the value is in.'
69                 return value in self.listObject
70
71         def getIsNotIn(self, value):
72                 'Determine if the value is in.'
73                 return not(value in self.listObject)
74
75         def getLength(self):
76                 'Get the length.'
77                 return len(self.listObject)
78
79         def getMax(self):
80                 'Get the max.'
81                 return max(self.listObject)
82
83         def getMin(self):
84                 'Get the min.'
85                 return min(self.listObject)
86
87         def insert(self, insertIndex, value):
88                 'Get the insert list.'
89                 if insertIndex < 0:
90                         insertIndex += len(self.listObject)
91                 insertIndex = max(0, insertIndex)
92                 return self.listObject[: insertIndex] + [value] + self.listObject[insertIndex :]
93
94         def keys(self):
95                 'Get the keys.'
96                 return range(len(self.listObject))
97
98         def length(self):
99                 'Get the length.'
100                 return len(self.listObject)
101
102         def rindex(self, value):
103                 'Get the rindex element.'
104                 for elementIndex, element in enumerate(self.listObject):
105                         if element == value:
106                                 return elementIndex
107                 raise ValueError('Value (%s) not found in rindex in ListAttribute for (%s).' % (value, self.listObject))
108
109         def set(self, itemIndex, value):
110                 'Set value.'
111                 self.listObject[itemIndex] = value
112                 return self.listObject
113
114         def values(self, arguments=None):
115                 'Get the values.'
116                 return self.listObject
117
118
119 globalAccessibleAttributeDictionary = 'add copy count delete get getExpansion getIsIn getIsNotIn getLength getMax getMin'.split()
120 globalAccessibleAttributeDictionary += 'insert keys length rindex set values'.split()
121 globalGetAccessibleAttributeSet = set(globalAccessibleAttributeDictionary)
122 globalNativeFunctions = 'append extend index pop remove reverse sort'.split()
123 globalNativeFunctionSet = set(globalNativeFunctions)