commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r9152 - trunk/gnue-forms/src/input/displayHandlers


From: reinhard
Subject: [gnue] r9152 - trunk/gnue-forms/src/input/displayHandlers
Date: Tue, 12 Dec 2006 13:08:17 -0600 (CST)

Author: reinhard
Date: 2006-12-12 13:08:16 -0600 (Tue, 12 Dec 2006)
New Revision: 9152

Modified:
   trunk/gnue-forms/src/input/displayHandlers/Checkbox.py
   trunk/gnue-forms/src/input/displayHandlers/Cursor.py
Log:
Get rid of displayHandler.work, only displayHandler.display is used now. Start
of restructuring of user text change handling.


Modified: trunk/gnue-forms/src/input/displayHandlers/Checkbox.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/Checkbox.py      2006-12-12 
18:05:33 UTC (rev 9151)
+++ trunk/gnue-forms/src/input/displayHandlers/Checkbox.py      2006-12-12 
19:08:16 UTC (rev 9152)
@@ -85,9 +85,8 @@
 
   # Set checkbox to boolean value
   def __set (self, value):
-    if value != self.work:
-      self.work = value
-      self.display = self.work
+    if value != self.display:
+      self.display = value
       self.modified = True
       self.updateFieldValue()
 
@@ -96,12 +95,11 @@
     allowed = [True, False]
     if self.field._block.mode == 'query':
         allowed.append(None)
-    next = allowed.index(self.work) + 1
+    next = allowed.index(self.display) + 1
     if next == len(allowed):
         next = 0
 
-    self.work = allowed[next]
-    self.display = self.work
+    self.display = allowed[next]
     self.modified = True
     self.updateFieldValue()
 
@@ -120,8 +118,7 @@
   def beginEdit(self):
 
     self.editing = self.field.isEditable()
-    self.work = self.__sanitize_value(self.field.get_value())
-    self.display = self.work
+    self.display = self.build_display(self.field.get_value(), self.editing)
     self.modified = False
     self._cursor = 0
 

Modified: trunk/gnue-forms/src/input/displayHandlers/Cursor.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/Cursor.py        2006-12-12 
18:05:33 UTC (rev 9151)
+++ trunk/gnue-forms/src/input/displayHandlers/Cursor.py        2006-12-12 
19:08:16 UTC (rev 9152)
@@ -63,8 +63,7 @@
     self.field = entry._field     # The GFField associated with that GFEntry
     self.editing = False          # Is handler in edit mode
     self.modified = False         # Have we been modified??
-    self.work = ""                # Our working value
-    self.display = ""             # The latest display-formatted value
+    self.display = u""            # The current display-formatted value
     self.subEventHandler = subEventHandler
 
     # Cursor based vars
@@ -157,8 +156,7 @@
     """
     self.editing = self.field.isEditable()
     self.modified = False
-    self.work = self.field.get_value() or u""
-    self.display = self.build_display(self.work, True)
+    self.display = self.build_display(self.field.get_value(), True)
     self._cursor = len(self.display)
     self.setSelectionArea(0, self._cursor)
     self.generateRefreshEvent()
@@ -196,26 +194,7 @@
         self.entry.name )
       return
 
-    # Get the text to be added forcing to specific case if necessary
-    if self.field._lowercase:
-      value = event.text.lower()
-    elif self.field._uppercase:
-      value = event.text.upper()
-    else:
-      value = event.text
-    
     # -------------------------------------------------------------------------
-    # Validate the input
-    # -------------------------------------------------------------------------
-    if ( self.field._numeric and \
-         self.field._block.mode == 'normal' ):
-      for char in value:
-        if not (char.isdigit() or char in '.-') :
-          # TODO: Should we beep?
-          assert gDebug (6, "Entry %s: Invalid numeric input" % 
self.entry.name)
-          return
-
-    # -------------------------------------------------------------------------
     # Insert the text
     # -------------------------------------------------------------------------
     # To do overstrike, we'll fudge by first "highlighting"
@@ -227,46 +206,13 @@
         
     if self._selection1 is not None:
       # If text is selected, then we will replace
-
       minSelectionPos = min(self._selection1, self._selection2)
       maxSelectionPos = max(self._selection1, self._selection2)
-
-      new_value = self.work[:minSelectionPos]  \
-                   + value        \
-                   + self.work[maxSelectionPos:]
-
-      new_cursor = minSelectionPos + len(value)
-
+      self.__change_text(minSelectionPos, maxSelectionPos, event.text)
     else:
       # Otherwise just graft the new text in place
+      self.__change_text(self._cursor, self._cursor, event.text)
 
-      new_value = self.work[:self._cursor] \
-                   + value                \
-                   + self.work[self._cursor:]
-
-      new_cursor = self._cursor + len(value)
-
-    # Check if max length isn't exceeded.
-    if self.field.length is not None and len(new_value) > self.field.length:
-        self.__beep()
-        event.refreshDisplay = True
-        return
-
-    # If text was added at the end, do autocompletion.
-    if new_cursor == len(new_value) and len(new_value) > len(self.work):
-        new_value = self.field.autocomplete(new_value)
-        if len(new_value) > new_cursor:
-            new_selection = (new_cursor, len(new_value))
-        else:
-            new_selection = (None, None)
-    else:
-        new_selection = (None, None)
-
-    self.work = new_value
-    self._cursor = new_cursor
-    self._selection1, self._selection2 = new_selection
-    self.modified = True
-    self.display = self.build_display(self.work, True)
     event.refreshDisplay = True
     event.__dropped__ = True
 
@@ -340,9 +286,6 @@
       self._addText (event)
       event.drop ()
 
-  # ===========================================================================
-  # Cursor movement functions
-  # ===========================================================================
 
   def _backspace(self, event):
     """
@@ -396,6 +339,57 @@
 
     self._addText(event)
 
+
+  # -------------------------------------------------------------------------
+  # General helper function for text changes by the user
+  # -------------------------------------------------------------------------
+
+  def __change_text(self, start, end, text):
+
+        # Get the text to be added forcing to specific case if necessary.
+        if self.field._lowercase:
+            text = text.lower()
+        elif self.field._uppercase:
+            text = text.upper()
+
+        # Check if the text is numeric if need to.
+        if (self.field._numeric and self.field._block.mode == 'normal'):
+            for char in text:
+                if not (char.isdigit() or char in '.-'):
+                    self.__beep()
+                    return
+
+        # Now, assemble the new text.
+        new_text = self.display[:start] + text + self.display[end:]
+
+        # Check if max length isn't exceeded.
+        if self.field.length is not None and len(new_text) > self.field.length:
+            self.__beep()
+            return
+
+        # Place the cursor at the end of the inserted text.
+        new_cursor = start + len(text)
+
+        # If text was added at the end, do autocompletion.
+        if new_cursor == len(new_text) and len(new_text) > len(self.display):
+            new_text = self.field.autocomplete(new_text)
+            if len(new_text) > new_cursor:
+                new_selection = (new_cursor, len(new_text))
+            else:
+                new_selection = (None, None)
+        else:
+            new_selection = (None, None)
+
+        self.display = new_text
+        self._cursor = new_cursor
+        self._selection1, self._selection2 = new_selection
+        self.modified = True
+
+
+  # ===========================================================================
+  # Cursor movement functions
+  # ===========================================================================
+
   def _moveCursor(self, event, selecting=False):
     """
     Moves the cursor to the specified position optionally selecting the text.





reply via email to

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