summaryrefslogtreecommitdiff
path: root/wizards/com/sun/star/wizards/common/Properties.py
blob: 4a906ed27d794368bc39557d1b2a0641a92a9aee (plain)
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
from com.sun.star.beans import PropertyValue

'''
Simplifies handling Arrays of PropertyValue.
To make a use of this class, instantiate it, and call
the put(propName,propValue) method.
caution: propName should always be a String.
When finished, call the getProperties() method to get an array of the set properties.
@author  rp
'''

class Properties(dict):

    @classmethod
    def getPropertyValue(self, props, propName):
        for i in props:
            if propName == i.Name:
                return i.Value

        raise AttributeError ("Property '" + propName + "' not found.")

    @classmethod
    def hasPropertyValue(self, props, propName):
        for i in props:
            if propName == i.Name:
                return True
        return False

    @classmethod
    def getProperties(self, _map):
        pv = []
        for k,v in _map.items():
            pv.append(self.createProperty(k, v))
        return pv

    @classmethod
    def createProperty(self, name, value, handle=None):
        pv = PropertyValue()
        pv.Name = name
        pv.Value = value
        if handle is not None:
            pv.Handle = handle
        return pv