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
|
from DataAware import *
from DataAwareField import DataAwareField
from common.Helper import *
'''
@author rpiterman
This class suppoprts imple cases where a UI control can
be directly synchronized with a data property.
Such controls are: the different text controls
(synchronizing the "Text" , "Value", "Date", "Time" property),
Checkbox controls, Dropdown listbox controls (synchronizing the
SelectedItems[] property.
For those controls, static convenience methods are offered, to simplify use.
'''
class UnoDataAware(DataAware):
def __init__(self, dataObject, value, unoObject_, unoPropName_):
super(UnoDataAware,self).__init__(dataObject, value)
self.unoControl = unoObject_
self.unoModel = self.unoControl.Model
self.unoPropName = unoPropName_
self.disableObjects = range(0)
self.inverse = False
def setInverse(self, i):
self.inverse = i
def enableControls(self, value):
b = getBoolean(value)
if self.inverse:
if b.booleanValue():
b = False
else:
b = True
i = 0
while i < self.disableObjects.length:
setEnabled(self.disableObjects[i], b)
i += 1
def setToUI(self, value):
Helper.setUnoPropertyValue(self.unoModel, self.unoPropName, value)
'''
Try to get from an arbitrary object a boolean value.
Null returns False;
A Boolean object returns itself.
An Array returns true if it not empty.
An Empty String returns False.
everything else returns a True.
@param value
@return
'''
def getBoolean(self, value):
if value == None:
return False
if isinstance(value, bool):
return value
elif value.getClass().isArray():
if value.length != 0:
return True
else:
return False
elif value.equals(""):
return False
elif isinstance(value, int):
if value == 0:
return True
else:
return False
else:
return True
def disableControls(self, controls):
self.disableObjects = controls
def getFromUI(self):
return Helper.getUnoPropertyValue(self.unoModel, self.unoPropName)
@classmethod
def __attachTextControl(
self, data, prop, unoText, unoProperty, field, value):
if field:
aux = DataAwareField(prop, value)
else:
aux = DataAware.PropertyValue (prop, data)
uda = UnoDataAware(data, aux, unoText, unoProperty)
method = getattr(uda,"updateData")
unoText.addTextListener(TextListenerProcAdapter(method))
return uda
@classmethod
def attachEditControl(self, data, prop, unoControl, field):
return self.__attachTextControl(
data, prop, unoControl, "Text", field, "")
@classmethod
def attachDateControl(self, data, prop, unoControl, field):
return self.__attachTextControl(
data, prop, unoControl, "Date", field, 0)
def attachTimeControl(self, data, prop, unoControl, field):
return self.__attachTextControl(
data, prop, unoControl, "Time", field, 0)
@classmethod
def attachNumericControl(self, data, prop, unoControl, field):
return self.__attachTextControl(
data, prop, unoControl, "Value", field, float(0))
@classmethod
def attachCheckBox(self, data, prop, checkBox, field):
if field:
aux = DataAwareField(prop, 0)
else:
aux = DataAware.PropertyValue (prop, data)
uda = UnoDataAware(data, aux , checkBox, PropertyNames.PROPERTY_STATE)
method = getattr(uda,"updateData")
checkBox.addItemListener(ItemListenerProcAdapter(method))
return uda
def attachLabel(self, data, prop, label, field):
if field:
aux = DataAwareField(prop, "")
else:
aux = DataAware.PropertyValue (prop, data)
return UnoDataAware(data, aux, label, PropertyNames.PROPERTY_LABEL)
@classmethod
def attachListBox(self, data, prop, listBox, field):
if field:
aux = DataAwareField(prop, uno.Any("short",0))
else:
aux = DataAware.PropertyValue (prop, data)
uda = UnoDataAware(data, aux, listBox, "SelectedItems")
method = getattr(uda,"updateData")
listBox.addItemListener(ItemListenerProcAdapter(method))
return uda
def setEnabled(self, control, enabled):
Helper.setUnoPropertyValue(
getModel(control), PropertyNames.PROPERTY_ENABLED, enabled)
|