commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r8725 - trunk/gnue-forms/src/GFObjects


From: reinhard
Subject: [gnue] r8725 - trunk/gnue-forms/src/GFObjects
Date: Tue, 10 Oct 2006 10:50:12 -0500 (CDT)

Author: reinhard
Date: 2006-10-10 10:50:11 -0500 (Tue, 10 Oct 2006)
New Revision: 8725

Modified:
   trunk/gnue-forms/src/GFObjects/GFComponent.py
   trunk/gnue-forms/src/GFObjects/GFEntry.py
   trunk/gnue-forms/src/GFObjects/GFImage.py
   trunk/gnue-forms/src/GFObjects/GFObj.py
   trunk/gnue-forms/src/GFObjects/GFTabStop.py
Log:
New class GFFieldBound as a base class for GFEntry, GFImage, and GFComponent.
Implemented GFFieldBound.update_ui to update the user interface with the
current field value (will replace updateENTRY events).


Modified: trunk/gnue-forms/src/GFObjects/GFComponent.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFComponent.py       2006-10-10 14:39:49 UTC 
(rev 8724)
+++ trunk/gnue-forms/src/GFObjects/GFComponent.py       2006-10-10 15:50:11 UTC 
(rev 8725)
@@ -25,68 +25,33 @@
 """
 
 from gnue.common import events
-from gnue.forms.input import displayHandlers
-from gnue.forms.GFObjects.GFValue import GFValue
+from gnue.forms.GFObjects.GFTabStop import GFFieldBound
 
 
 # =============================================================================
 # A component wrapper class
 # =============================================================================
 
-class GFComponent(GFValue):
+class GFComponent(GFFieldBound):
 
     # -------------------------------------------------------------------------
     # Constructor
     # -------------------------------------------------------------------------
 
-    def __init__(self, parent=None, value=None):
+    def __init__(self, parent=None):
 
-        GFValue.__init__(self, parent, value, 'GFComponent')
-        self.subEventHandler = events.EventController()
+        GFFieldBound.__init__(self, parent, 'GFComponent')
 
         # Default attributes (these may be replaced by parser)
         self.type = "URL"
 
-
     # -------------------------------------------------------------------------
-    # Get the current value
-    # -------------------------------------------------------------------------
-
-    def getValue(self, *args, **parms):
-
-        return self._field.getValue(*args, **parms)
-
-
-    # -------------------------------------------------------------------------
-    # Set the object's value (by passing the new value to the bound field)
-    # -------------------------------------------------------------------------
-
-    def setValue(self, value):
-
-        self._field.setValue(value)
-        if not self._value:
-            GFValue.setValue(self, value)
-
-
-    # -------------------------------------------------------------------------
     # Implementation of virtual methods
     # -------------------------------------------------------------------------
 
     def _phase_1_init_(self):
     
-        GFValue._phase_1_init_(self)
+        GFFieldBound._phase_1_init_(self)
 
         if not hasattr(self, 'Char__height'):
             self.Char__height = int(gConfigForms('widgetHeight'))
-
-        self._block = self.get_block()
-        self._block._entryList.append(self)
-
-        self._field = self.get_field()
-        self._field._entryList.append(self)
-
-        self._page = self.findParentOfType('GFPage')
-        self._page._entryList.append(self)
-    
-        self._displayHandler = displayHandlers.Component (self,
-                self._form._instance.eventController, self.subEventHandler)

Modified: trunk/gnue-forms/src/GFObjects/GFEntry.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFEntry.py   2006-10-10 14:39:49 UTC (rev 
8724)
+++ trunk/gnue-forms/src/GFObjects/GFEntry.py   2006-10-10 15:50:11 UTC (rev 
8725)
@@ -25,22 +25,21 @@
 The primary data entry widget in forms
 """
 
-from gnue.forms.input import displayHandlers
-from gnue.forms.GFObjects.GFTabStop import GFTabStop
+from gnue.forms.GFObjects.GFTabStop import GFFieldBound
 
 # =============================================================================
 # Class for data entry widgets
 # =============================================================================
 
-class GFEntry(GFTabStop):
+class GFEntry(GFFieldBound):
 
     # -------------------------------------------------------------------------
     # Constructor
     # -------------------------------------------------------------------------
 
-    def __init__(self, parent=None, value=None):
+    def __init__(self, parent=None):
 
-        GFTabStop.__init__(self, parent, 'GFEntry')
+        GFFieldBound.__init__(self, parent, 'GFEntry')
 
         # Default attributes (these may be replaced by parser)
         self.style = "default"
@@ -81,19 +80,13 @@
         list as well as to the pages' field list.
         """
 
-        GFTabStop._phase_1_init_(self)
+        GFFieldBound._phase_1_init_(self)
 
         if not hasattr(self, 'Char__height'):
             self.Char__height = int(gConfigForms('widgetHeight'))
         if not hasattr(self, 'Char__width'):
             self.Char__width  = int(gConfigForms('widgetWidth'))
 
-        self._block = self.get_block()
-        self._block._entryList.append(self)
-
-        self._field = self.get_field()
-        self._field._entryList.append(self)
-
         # Have a look wether the entry will be navigable or not
         style = self.style.lower()
         if style == 'label':
@@ -103,26 +96,7 @@
             if style == 'default' and self.Char__height > 1:
                 self.style = 'multiline'
 
-        self._formatmask  = ""
-        self._inputmask   = getattr(self, 'inputmask', '')
-        self._displaymask = getattr(self, 'displaymask', '')
 
-        # Associate a display handler with this instance
-        self._displayHandler = displayHandlers.factory(self,
-                             self._form._instance.eventController,
-                             self.subEventHandler,
-                             self._displaymask,
-                             self._inputmask)
-
-        # Row settings
-        grid = self.findParentOfType('GFGrid')
-        if grid:
-            self._rows = int(getattr(grid, 'rows', 1))
-        else:
-            self._rows = getattr(self, 'rows', self._field._rows)
-            self._gap  = getattr(self, 'rowSpacer', self._field._gap)
-
-
     # -------------------------------------------------------------------------
     # Implementation of virtual methods
     # -------------------------------------------------------------------------

Modified: trunk/gnue-forms/src/GFObjects/GFImage.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFImage.py   2006-10-10 14:39:49 UTC (rev 
8724)
+++ trunk/gnue-forms/src/GFObjects/GFImage.py   2006-10-10 15:50:11 UTC (rev 
8725)
@@ -24,15 +24,14 @@
 Wrapper class for image objects
 """
 
-from gnue.forms.input import displayHandlers
-from gnue.forms.GFObjects.GFTabStop import GFTabStop
+from gnue.forms.GFObjects.GFTabStop import GFFieldBound
 
 
 # =============================================================================
 # Image objects
 # =============================================================================
 
-class GFImage(GFTabStop):
+class GFImage(GFFieldBound):
 
     # -------------------------------------------------------------------------
     # Constructor
@@ -40,7 +39,7 @@
 
     def __init__(self, parent=None, value=None):
 
-        GFTabStop.__init__(self, parent, 'GFImage')
+        GFFieldBound.__init__(self, parent, 'GFImage')
 
         # Default attributes (these may be replaced by parser)
         self.type = "URL"
@@ -61,21 +60,11 @@
 
     def _phase_1_init_(self):
 
-        GFTabStop._phase_1_init_(self)
+        GFFieldBound._phase_1_init_(self)
 
         if not hasattr(self, 'Char__height'):
             self.Char__height = int(gConfigForms('widgetHeight'))
 
-        self._block = self.get_block()
-        self._block._entryList.append(self)
-
-        self._field = self.get_field()
-        self._field._entryList.append(self)
-
-        self._displayHandler = displayHandlers.factory(self,
-                              self._form._instance.eventController,
-                              self.subEventHandler, None, None)
-
     # -------------------------------------------------------------------------
 
     def _is_navigable_(self, mode):

Modified: trunk/gnue-forms/src/GFObjects/GFObj.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFObj.py     2006-10-10 14:39:49 UTC (rev 
8724)
+++ trunk/gnue-forms/src/GFObjects/GFObj.py     2006-10-10 15:50:11 UTC (rev 
8725)
@@ -89,12 +89,7 @@
         # uidrivers._base.UIdriver._buildUI () function.
         self.uiWidget = None
 
-        # FIXME: does not make sense for all descendants, create a separate
-        # abstract base class?
-        self.__first_visible_record = 0
-        self.__last_enabled_row = 0
 
-
     # -------------------------------------------------------------------------
     # Check wether an object is navigable or not
     # -------------------------------------------------------------------------
@@ -147,64 +142,6 @@
         return option
 
 
-    # -------------------------------------------------------------------------
-    # Recalculate the visible index of an object
-    # -------------------------------------------------------------------------
-
-    def recalculate_visible(self, adjustment, cur_record, rec_count):
-        """
-        Recalculate the visible index of an object. This determines that real 
UI
-        widget of a 'row-based grid' which should be visible.
-
-        @param adjustment: value to change the visible index, e.g. 1 or -1
-        @param cur_record: the currently active record
-        @param rec_count: the number of records available at all
-
-        As a result of this recalculation the property self._visibleIndex will
-        be set to the new value.
-        """
-
-        if not self.hidden:
-            index = min(max(self._visibleIndex + adjustment, 0),
-                        int(self._rows)-1)
-
-            # Don't let the index pass the number of records
-            lowestVisible = max(cur_record - index, 0)
-            if lowestVisible + index > rec_count:
-                index = index -1
-
-            # If the current record has rolled around from the top to the
-            # bottom then reset the counter.
-            if cur_record == 0:
-                index = 0
-
-            self._visibleIndex = index
-
-            if self.uiWidget is not None:
-                last_enabled_row = self._visibleIndex + \
-                        (rec_count - cur_record) - 1
-                last_enabled_row = min(last_enabled_row, self._rows - 1)
-
-                # Disable rows if necessary
-                for i in range(last_enabled_row+1, self.__last_enabled_row+1):
-                    self.uiWidget._ui_disable_(i)
-
-                # Enable rows if necessary
-                for i in range(self.__last_enabled_row+1, last_enabled_row+1):
-                    self.uiWidget._ui_enable_(i)
-
-                self.__last_enabled_row = last_enabled_row
-
-                # If we have scrolled, redisplay all records
-                first_visible_record = cur_record - self._visibleIndex
-                # FIXME
-                # if first_visible_record != self.__first_visible_record:
-                if True:
-                    self._form.dispatchEvent('updateENTRY', self,
-                            _form=self._form)
-                    self.__first_visible_record = first_visible_record
-
-
     # 
--------------------------------------------------------------------------
     # Get a block from the block map
     # -------------------------------------------------------------------------

Modified: trunk/gnue-forms/src/GFObjects/GFTabStop.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFTabStop.py 2006-10-10 14:39:49 UTC (rev 
8724)
+++ trunk/gnue-forms/src/GFObjects/GFTabStop.py 2006-10-10 15:50:11 UTC (rev 
8725)
@@ -26,6 +26,7 @@
 """
 
 from gnue.common import events
+from gnue.forms.input import displayHandlers
 from gnue.forms.GFObjects.GFObj import GFObj
 
 __all__ = ['GFTabStop']
@@ -104,3 +105,135 @@
                 return self.navigable and self._navigableInQuery_
             else:
                 return self.navigable and (not self.readonly)
+
+
+# =============================================================================
+# Mixin class for all widgets bound to a field
+# =============================================================================
+
+class GFFieldBound(GFTabStop):
+
+    # -------------------------------------------------------------------------
+    # Constructor
+    # -------------------------------------------------------------------------
+
+    def __init__(self, parent, object_type):
+
+        GFTabStop.__init__(self, parent, object_type)
+
+        self._block = None
+        self._field = None
+
+        self._rows = 1
+        self._gap = 0
+
+        self.__first_visible_record = 0
+        self.__last_enabled_row = 0
+
+
+    # -------------------------------------------------------------------------
+    # Phase 1 init
+    # -------------------------------------------------------------------------
+
+    def _phase_1_init_(self):
+
+        GFTabStop._phase_1_init_(self)
+
+        self._block = self.get_block()
+        self._block._entryList.append(self)
+
+        self._field = self.get_field()
+        self._field._entryList.append(self)
+
+        self._formatmask  = ""
+        self._inputmask   = getattr(self, 'inputmask', '')
+        self._displaymask = getattr(self, 'displaymask', '')
+
+        # Associate a display handler with this instance
+        self._displayHandler = displayHandlers.factory(self,
+                             self._form._instance.eventController,
+                             self.subEventHandler,
+                             self._displaymask,
+                             self._inputmask)
+
+        # Row settings
+        grid = self.findParentOfType('GFGrid')
+        if grid:
+            self._rows = int(getattr(grid, 'rows', 1))
+        else:
+            self._rows = getattr(self, 'rows', self._field._rows)
+            self._gap  = getattr(self, 'rowSpacer', self._field._gap)
+
+
+    # -------------------------------------------------------------------------
+    # Recalculate the visible index of an object
+    # -------------------------------------------------------------------------
+
+    def recalculate_visible(self, adjustment, cur_record, rec_count):
+        """
+        Recalculate the visible index of an object. This determines that real 
UI
+        widget of a 'row-based grid' which should be visible.
+
+        @param adjustment: value to change the visible index, e.g. 1 or -1
+        @param cur_record: the currently active record
+        @param rec_count: the number of records available at all
+
+        As a result of this recalculation the property self._visibleIndex will
+        be set to the new value.
+        """
+
+        if not self.hidden:
+            index = min(max(self._visibleIndex + adjustment, 0),
+                        int(self._rows)-1)
+
+            # Don't let the index pass the number of records
+            lowestVisible = max(cur_record - index, 0)
+            if lowestVisible + index > rec_count:
+                index = index -1
+
+            # If the current record has rolled around from the top to the
+            # bottom then reset the counter.
+            if cur_record == 0:
+                index = 0
+
+            self._visibleIndex = index
+
+            if self.uiWidget is not None:
+                last_enabled_row = self._visibleIndex + \
+                        (rec_count - cur_record) - 1
+                last_enabled_row = min(last_enabled_row, self._rows - 1)
+
+                # Disable rows if necessary
+                for i in range(last_enabled_row+1, self.__last_enabled_row+1):
+                    self.uiWidget._ui_disable_(i)
+
+                # Enable rows if necessary
+                for i in range(self.__last_enabled_row+1, last_enabled_row+1):
+                    self.uiWidget._ui_enable_(i)
+
+                self.__last_enabled_row = last_enabled_row
+
+                # If we have scrolled, redisplay all records
+                first_visible_record = cur_record - self._visibleIndex
+                # FIXME
+                # if first_visible_record != self.__first_visible_record:
+                if True:
+                    self.refresh_ui(0, self._rows - 1)
+                    self.__first_visible_record = first_visible_record
+
+
+    # -------------------------------------------------------------------------
+    # Refresh the user interface with the current field data
+    # -------------------------------------------------------------------------
+
+    def refresh_ui(self, from_index, to_index):
+
+        if self.hidden:
+            return
+
+        for index in range (from_index, to_index + 1):
+            # Do not execute if we were editing - would overwrite unsaved 
change
+            if not self._displayHandler.editing:
+                value = self._field.getValue(index - self._visibleIndex)
+                display = self._displayHandler.getDisplayFiller(value)
+                self.uiWidget._ui_set_value_(index, value)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]