[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r9153 - in trunk/gnue-forms/src: . input/displayHandlers
From: |
reinhard |
Subject: |
[gnue] r9153 - in trunk/gnue-forms/src: . input/displayHandlers |
Date: |
Tue, 12 Dec 2006 13:50:38 -0600 (CST) |
Author: reinhard
Date: 2006-12-12 13:50:37 -0600 (Tue, 12 Dec 2006)
New Revision: 9153
Modified:
trunk/gnue-forms/src/GFInstance.py
trunk/gnue-forms/src/input/displayHandlers/Cursor.py
Log:
Restructured text editing routines.
Modified: trunk/gnue-forms/src/GFInstance.py
===================================================================
--- trunk/gnue-forms/src/GFInstance.py 2006-12-12 19:08:16 UTC (rev 9152)
+++ trunk/gnue-forms/src/GFInstance.py 2006-12-12 19:50:37 UTC (rev 9153)
@@ -390,15 +390,6 @@
# Pass off the event to the current entry's event handler
entry.subEventHandler.dispatchEvent(event)
- # Refresh entry display if appropriate
- if event.refreshDisplay:
- # FIXME: This is not clean. Maybe the event should set
- # event.__after__?
- if hasattr (entry, '_displayHandler'):
- entry._displayHandler.generateRefreshEvent()
-
- event._form.refreshUIEvents()
-
# If the entry needs an error message displayed, then the proxied event
# should set this to the message text
if event.__errortext__:
Modified: trunk/gnue-forms/src/input/displayHandlers/Cursor.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/Cursor.py 2006-12-12
19:08:16 UTC (rev 9152)
+++ trunk/gnue-forms/src/input/displayHandlers/Cursor.py 2006-12-12
19:50:37 UTC (rev 9153)
@@ -183,168 +183,126 @@
raise
+ # ---------------------------------------------------------------------------
+ # Text manipulation
+ # ---------------------------------------------------------------------------
+
def _addText(self, event):
- """
- Handles the adding of new text
- """
- # Skip if this display handler isn't the one currently being edited
- if not self.editing:
- assert gDebug(5,
- "Entry %s: Received request to add text but isn't in edit mode" %
- self.entry.name )
- return
- # -------------------------------------------------------------------------
- # Insert the text
- # -------------------------------------------------------------------------
- # To do overstrike, we'll fudge by first "highlighting"
- # the character to replace, then use the selection logic.
+ if not self.editing:
+ return
- if getattr(event, 'overstrike', False) and self._selection1 is None:
- self._selection1 = self._cursor
- self._selection2 = self._selection1 + 1
-
- 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)
- 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)
+ if self._selection1 is not None:
+ # If text is selected, then we will replace
+ (start, end) = getSelectionArea()
+ else:
+ # Otherwise just graft the new text in place
+ (start, end) = (self._cursor, self._cursor)
- event.refreshDisplay = True
- event.__dropped__ = True
+ self.__change_text(start, end, event.text, start + len(event.text))
- # Update the field. This means PRE-CHANGE and POST-CHANGE will get fired
- # now. For now, only do this here if we are a lookup.
- if hasattr(self.field, 'fk_source'):
- try:
- self.__updateFieldValue()
- self.modified = False
- except Exception:
- # We don't care about exceptions now, the user can still correct
- pass
-
# -------------------------------------------------------------------------
- # Replac the current contents
- # -------------------------------------------------------------------------
def _replace_text(self, event):
- self._selection1 = 0
- self._selection2 = len(self.display)
- self._addText(event)
- if hasattr(event, 'position'):
- self._cursor = event.position
+ if not self.editing:
+ return
+ if hasattr(event, 'position'):
+ new_cursor = event.position
+ else:
+ new_cursor= self._cursor
+ self.__change_text(0, len(self.display), event.text, event.position)
+
+ # -------------------------------------------------------------------------
+
def _insertTextAt(self, event):
- """
- Insert text at specified position
- """
- if not self.editing:
- assert gDebug(5,
- "Entry %s: Received request to insert text but not in edit mode" %
- self.entry.name )
- return
- # set cursor position
- self._cursor = event.position
+ if not self.editing:
+ return
- # add the event text
- self._addText(event)
+ self.__change_text(event.position, event.position, event.text,
+ event.position)
+ # -------------------------------------------------------------------------
+
def _deleteRange(self, event):
- """
- Deletes the requested range of test from the entry
-
- @param event: The GFEvent making the request
- """
- if not self.editing:
- assert gDebug(5,
- "Entry %s: Received request to delete text but not in edit mode" %
- self.entry.name )
- return
- self._selection1 = event.start_pos
- self._selection2 = event.end_pos
- self._cursor = event.position
- self._delete (event)
+ if not self.editing:
+ return
- def __handleENTER (self, event):
- """
- Private function to handle enter key presses in an multiline entry.
-
- @param event: The GFEvent making the request
- """
- isNewLine = gConfigForms ('EnterIsNewLine')
- lines = getattr (self.entry, 'Char__height', 1)
+ self.__change_text(event.start_pos, event.end_pos, u"",
+ event.start_pos)
- if isNewLine and lines > 1:
- event.text = '\n'
- self._addText (event)
- event.drop ()
+ # -------------------------------------------------------------------------
+ def __handleENTER(self, event):
+ isNewLine = gConfigForms ('EnterIsNewLine')
+ lines = getattr(self.entry, 'Char__height', 1)
+
+ if isNewLine and lines > 1:
+ event.text = '\n'
+ self._addText(event)
+ event.drop()
+
+ # -------------------------------------------------------------------------
+
def _backspace(self, event):
- """
- Delete backwards one character
-
- @param event: The GFEvent making the request
- """
- if not self.editing:
- assert gDebug(5,
- "Entry %s: Received request to backspace but not in edit mode" %
- self.entry.name )
- return
+ if not self.editing:
+ return
- # If we have a "selection", then act like a "delete"
- if self._selection1 != None:
- self._delete(event)
- return
+ # If there is a selection, delete the selected portion.
+ if self._selection1 is not None:
+ (start, end) = self.getSelectionArea()
+ self.__change_text(start, end, u"", start)
+ return
- precurs = self._cursor
- self._moveCursorLeft(event)
+ # Can't backspace if at the beginning.
+ if self._cursor == 0:
+ return
- if self._cursor != precurs:
- event.overstrike = True
- event.text = ""
+ # Delete character left to the cursor.
+ self.__change_text(self._cursor - 1, self._cursor, u"",
+ self._cursor - 1)
- self._addText(event)
+ # On win32, also delete the \r along with the \n.
+ if sys.platform == "win32":
+ if self._cursor > 0 and self.display[self._cursor-1] == "\r":
+ self.__change_text(self._cursor - 1, self._cursor, u"",
+ self._cursor - 1)
- if sys.platform == "win32":
- if self._cursor > 0 and self.display[self._cursor-1] == "\r":
- self._moveCursorLeft(event)
-
- event.overstrike = True
- event.text = ""
- self._addText(event)
+ # -------------------------------------------------------------------------
def _delete(self, event):
- """
- Delete forward one character
-
- @param event: The GFEvent making the request
- """
- if not self.editing:
- assert gDebug(5,
- "Entry %s: Received request to delete text but not in edit mode" %
- self.entry.name )
- return
- event.overstrike = True
- event.text = ""
+ if not self.editing:
+ return
- self._addText(event)
+ # If there is a selection, delete the selected portion.
+ if self._selection1 is not None:
+ (start, end) = self.getSelectionArea()
+ self.__change_text(start, end, u"", start)
+ return
+ if self._cursor == len(self.display):
+ return
+ # Delete character right to the cursor.
+ self.__change_text(self._cursor, self._cursor + 1, u"", self._cursor)
+
+ # On win32, also delete the \n along with the \r.
+ if sys.platform == "win32":
+ if self._cursor < len(self.display) \
+ and self.display[self._cursor] == "\n":
+ self.__change_text(self._cursor, self._cursor + 1, u"",
+ self._cursor)
+
# -------------------------------------------------------------------------
- # General helper function for text changes by the user
- # -------------------------------------------------------------------------
- def __change_text(self, start, end, text):
+ def __change_text(self, start, end, text, new_cursor):
# Get the text to be added forcing to specific case if necessary.
if self.field._lowercase:
@@ -367,9 +325,6 @@
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)
@@ -384,8 +339,21 @@
self._cursor = new_cursor
self._selection1, self._selection2 = new_selection
self.modified = True
+ self.generateRefreshEvent()
+ self.entry._form.refreshUIEvents()
+ # Update the field. This means PRE-CHANGE and POST-CHANGE will get
+ # fired now. For now, only do this here if we are a lookup.
+ if hasattr(self.field, 'fk_source'):
+ try:
+ self.__updateFieldValue()
+ self.modified = False
+ except Exception:
+ # We don't care about exceptions now, the user can still
+ # correct the mistake
+ pass
+
# ===========================================================================
# Cursor movement functions
# ===========================================================================
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r9153 - in trunk/gnue-forms/src: . input/displayHandlers,
reinhard <=