[Libreoffice-commits] .: Branch 'feature/gsoc2011_wizards' - wizards/com

Xisco Fauli xfauli at kemper.freedesktop.org
Wed Jun 29 16:57:30 PDT 2011


 wizards/com/sun/star/wizards/ui/event/DataAware.py      |   39 +------
 wizards/com/sun/star/wizards/ui/event/DataAwareField.py |   35 ------
 wizards/com/sun/star/wizards/ui/event/RadioDataAware.py |   10 -
 wizards/com/sun/star/wizards/ui/event/UnoDataAware.py   |   89 +---------------
 4 files changed, 20 insertions(+), 153 deletions(-)

New commits:
commit ce0ce6023647e12085445a87b086d3254178401b
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Thu Jun 30 01:56:32 2011 +0200

    Remember last template and clean ui/event/

diff --git a/wizards/com/sun/star/wizards/ui/event/DataAware.py b/wizards/com/sun/star/wizards/ui/event/DataAware.py
index b0360eb..c2771d5 100644
--- a/wizards/com/sun/star/wizards/ui/event/DataAware.py
+++ b/wizards/com/sun/star/wizards/ui/event/DataAware.py
@@ -28,9 +28,9 @@ class DataAware(object):
     @param value_
     '''
 
-    def __init__(self, dataObject_, value_):
+    def __init__(self, dataObject_, field_):
         self._dataObject = dataObject_
-        self._value = value_
+        self._field = field_
 
     '''
     sets the given value to the UI control
@@ -55,7 +55,7 @@ class DataAware(object):
     '''
 
     def updateUI(self):
-        data = self._value.get(self._dataObject)
+        data = getattr(self._dataObject, self._field)
         ui = self.getFromUI()
         if data is not ui:
             try:
@@ -71,38 +71,17 @@ class DataAware(object):
 
     def updateData(self):
         try:
-            data = self._value.get(self._dataObject)
+            data = getattr(self._dataObject, self._field)
             ui = self.getFromUI()
             if data is not ui:
-                self._value.Set(ui, self._dataObject)
+                if isinstance(ui,tuple):
+                    #Selected Element listbox
+                    ui = ui[0]
+                setattr(self._dataObject, self._field, ui)
         except Exception:
             traceback.print_exc()
 
     '''
-    compares the two given objects.
-    This method is null safe and returns true also if both are null...
-    If both are arrays, treats them as array of short and compares them.
-    @param a first object to compare
-    @param b second object to compare.
-    @return true if both are null or both are equal.
-    '''
-
-    def equals(self, a, b):
-        if not a and not b :
-            return True
-
-        if not a or not b:
-            return False
-
-        if a.getClass().isArray():
-            if b.getClass().isArray():
-                return Arrays.equals(a, b)
-            else:
-                return False
-
-        return a.equals(b)
-
-    '''
     given a collection containing DataAware objects,
     calls updateUI() on each memebr of the collection.
     @param dataAwares a collection containing DataAware objects.
@@ -124,7 +103,7 @@ class DataAware(object):
 
     def setDataObject(self, dataObject, updateUI):
         if dataObject is not None:
-            if not (type(self._value) is not
+            if not (type(self._field) is not
                 type(dataObject)):
                 raise ClassCastException (
                     "can not cast new DataObject to original Class")
diff --git a/wizards/com/sun/star/wizards/ui/event/DataAwareField.py b/wizards/com/sun/star/wizards/ui/event/DataAwareField.py
deleted file mode 100644
index 8f8b64f..0000000
--- a/wizards/com/sun/star/wizards/ui/event/DataAwareField.py
+++ /dev/null
@@ -1,35 +0,0 @@
-import traceback
-from DataAware import *
-import uno
-
-class DataAwareField(object):
-
-    def __init__(self, field, convertTo):
-        self.convertTo = convertTo
-        self.field = field
-
-    def get(self, target):
-        try:
-            i = getattr(target, self.field)
-            if isinstance(self.convertTo, bool):
-                if i:
-                    return True
-                else:
-                    return False
-            elif isinstance(self.convertTo,int):
-                return int(i)
-            elif isinstance(self.convertTo,str):
-                return str(i)
-            elif self.convertTo.type == uno.Any("short",0).type:
-                return uno.Any("[]short",(i,))
-            else:
-                raise AttributeError(
-                    "Cannot convert int value to given type (" + \
-                    str(type(self.convertTo)) + ").")
-
-        except AttributeError, ex:
-            traceback.print_exc()
-            return None
-
-    def Set(self, value, target):
-            setattr(target, self.field, value)
diff --git a/wizards/com/sun/star/wizards/ui/event/RadioDataAware.py b/wizards/com/sun/star/wizards/ui/event/RadioDataAware.py
index 12f6e94..457f758 100644
--- a/wizards/com/sun/star/wizards/ui/event/RadioDataAware.py
+++ b/wizards/com/sun/star/wizards/ui/event/RadioDataAware.py
@@ -1,5 +1,4 @@
 from DataAware import *
-from DataAwareField import DataAwareField
 from UnoDataAware import *
 import time
 '''
@@ -32,13 +31,8 @@ class RadioDataAware(DataAware):
         return -1
 
     @classmethod
-    def attachRadioButtons(self, data, dataProp, buttons, field):
-        if field:
-            aux = DataAwareField(dataProp, 0)
-        else:
-            aux = DataAware.PropertyValue(dataProp, data)
-
-        da = RadioDataAware(data, aux , buttons)
+    def attachRadioButtons(self, data, prop, buttons, field):
+        da = RadioDataAware(data, prop, buttons)
         method = getattr(da,"updateData")
         for i in da.radioButtons:
             i.addItemListener(ItemListenerProcAdapter(method))
diff --git a/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py b/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py
index c12a81c..7c3436c 100644
--- a/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py
+++ b/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py
@@ -1,5 +1,4 @@
 from DataAware import *
-from DataAwareField import DataAwareField
 from common.Helper import *
 
 '''
@@ -15,79 +14,25 @@ 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)
+    def __init__(self, dataObject, field, unoObject_, unoPropName_, isShort=False):
+        super(UnoDataAware,self).__init__(dataObject, field)
         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
+        self.isShort = isShort
 
     def setToUI(self, value):
+        if self.isShort:
+            value = uno.Any("[]short", (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)
+        uda = UnoDataAware(data, prop, unoText, unoProperty)
         method = getattr(uda,"updateData")
         unoText.addTextListener(TextListenerProcAdapter(method))
         return uda
@@ -113,33 +58,17 @@ class UnoDataAware(DataAware):
 
     @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)
+        uda = UnoDataAware(data, prop, 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)
+        return UnoDataAware(data, prop, 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")
+        uda = UnoDataAware(data, prop, listBox, "SelectedItems", True)
         method = getattr(uda,"updateData")
         listBox.addItemListener(ItemListenerProcAdapter(method))
         return uda
-
-    def setEnabled(self, control, enabled):
-        Helper.setUnoPropertyValue(
-            getModel(control), PropertyNames.PROPERTY_ENABLED, enabled)


More information about the Libreoffice-commits mailing list