[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r9178 - trunk/gnue-forms/src/input/displayHandlers
From: |
johannes |
Subject: |
[gnue] r9178 - trunk/gnue-forms/src/input/displayHandlers |
Date: |
Tue, 19 Dec 2006 09:35:44 -0600 (CST) |
Author: johannes
Date: 2006-12-19 09:35:43 -0600 (Tue, 19 Dec 2006)
New Revision: 9178
Modified:
trunk/gnue-forms/src/input/displayHandlers/Cursor.py
Log:
Proper handling of cursor-movement and selecting
Modified: trunk/gnue-forms/src/input/displayHandlers/Cursor.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/Cursor.py 2006-12-19
14:51:26 UTC (rev 9177)
+++ trunk/gnue-forms/src/input/displayHandlers/Cursor.py 2006-12-19
15:35:43 UTC (rev 9178)
@@ -28,7 +28,7 @@
The base display handler for entries that deal with cursor based
input (aka text).
-This class should not be used directly. Other handlers should
+This class should not be used directly. Other handlers should
inherit from this one.
"""
@@ -39,156 +39,158 @@
class BaseCursor(events.EventAware):
- """
- The base display handler for entries that deal with cursor based
- input (aka text).
-
- This class should not be used directly. Other handlers should
- inherit from this one.
- """
-
- def __init__(self, entry, eventHandler, subEventHandler, displayMask,
- inputMask):
"""
- Constructor
+ The base display handler for entries that deal with cursor based
+ input (aka text).
- @param entry: The GFEntry instance associated with this handler
- @param eventHandler: The
- @param subEventHandler: The event handler this display helper will
- user to register it's listeners.
+ This class should not be used directly. Other handlers should
+ inherit from this one.
"""
- events.EventAware.__init__(self, eventHandler)
-
- self.entry = entry # The GFEntry that this instance will support
- 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.display = u"" # The current display-formatted value
- self.subEventHandler = subEventHandler
- # Cursor based vars
- self._selection1 = None # Start of highlight
- self._selection2 = None # End of highlight
- self._cursor = 0 # Cursor position
+ def __init__(self, entry, eventHandler, subEventHandler, displayMask,
+ inputMask):
+ """
+ Constructor
- # TODO: replace w/an event that asks the
- # TODO: UIdriver if this should happen!
- self.handleCR = sys.platform == "win32"
+ @param entry: The GFEntry instance associated with this handler
+ @param eventHandler: The
+ @param subEventHandler: The event handler this display helper will
+ user to register it's listeners.
+ """
+ events.EventAware.__init__(self, eventHandler)
- self.subEventHandler.registerEventListeners( {
-
- # "Entry" events
- 'requestKEYPRESS' : self._addText,
- 'requestCURSORLEFT' : self._moveCursorLeft,
- 'requestCURSORRIGHT' : self._moveCursorRight,
- 'requestCURSOREND' : self._moveCursorToEnd,
- 'requestCURSORHOME' : self._moveCursorToBegin,
- 'requestCURSORMOVE' : self._moveCursor,
- 'requestBACKSPACE' : self._backspace,
- 'requestDELETE' : self._delete,
- 'requestENTER' : self.__handleENTER,
- 'requestREPLACEVALUE' : self._replace_text,
+ self.entry = entry # The GFEntry that this instance will
+ # support
+ 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.display = u"" # The current display-formatted value
+ self.subEventHandler = subEventHandler
- # Selection
- 'requestSELECTWITHMOUSE' : self._selectWithMouse,
- 'requestSELECTTOHOME' : self._selectToBegin,
- 'requestSELECTTOEND' : self._selectToEnd,
- 'requestSELECTLEFT' : self._selectLeft,
- 'requestSELECTRIGHT' : self._selectRight,
+ # Cursor based vars
+ self._selection1 = None # Start of highlight
+ self._selection2 = None # End of highlight
+ self._cursor = 0 # Cursor position
- # Request for direct buffer manipulation
- 'requestINSERTAT' : self._insertTextAt,
- 'requestDELETERANGE' : self._deleteRange,
- })
-
- #####################
- #
- # General methods
- #
+ # TODO: replace w/an event that asks the
+ # TODO: UIdriver if this should happen!
+ self.handleCR = sys.platform == "win32"
- def generateRefreshEvent(self):
- """
- Function to emit an event that will cause forms
- to update the UI.
- """
- assert gDebug (5, "generateRefreshEvent on %s '%s' %s" % \
- (self, self.display, self.entry))
+ self.subEventHandler.registerEventListeners( {
- if (self.handleCR and type(self.display)=='str'):
- cursor=self._cursor + len(self.display[:self._cursor+1].split('\n'))-1
- else:
- cursor=self._cursor
+ # "Entry" events
+ 'requestKEYPRESS' : self._addText,
+ 'requestCURSORLEFT' : self._moveCursorLeft,
+ 'requestCURSORRIGHT' : self._moveCursorRight,
+ 'requestCURSOREND' : self._moveCursorToEnd,
+ 'requestCURSORHOME' : self._moveCursorToBegin,
+ 'requestCURSORMOVE' : self._moveCursor,
+ 'requestBACKSPACE' : self._backspace,
+ 'requestDELETE' : self._delete,
+ 'requestENTER' : self.__handleENTER,
+ 'requestREPLACEVALUE' : self._replace_text,
- index = self.entry._visibleIndex
+ # Selection
+ 'requestSELECTWITHMOUSE' : self._selectWithMouse,
+ 'requestSELECTTOHOME' : self._selectToBegin,
+ 'requestSELECTTOEND' : self._selectToEnd,
+ 'requestSELECTLEFT' : self._selectLeft,
+ 'requestSELECTRIGHT' : self._selectRight,
- self.entry.uiWidget._ui_set_value_(index, self.display)
- self.entry.uiWidget._ui_set_cursor_position_(index, cursor)
+ # Request for direct buffer manipulation
+ 'requestINSERTAT' : self._insertTextAt,
+ 'requestDELETERANGE' : self._deleteRange,
+ })
- selection = self.getSelectionArea()
- if selection is not None:
- selection1, selection2 = selection
- self.entry.uiWidget._ui_set_selected_area_(index, selection1, selection2)
+ #####################
+ #
+ # General methods
+ #
- def __beep(self):
- """
- Generates an event requesting that the UI beep.
- """
- self.entry._form.beep()
+ def generateRefreshEvent(self):
+ """
+ Function to emit an event that will cause forms
+ to update the UI.
+ """
+ assert gDebug (5, "generateRefreshEvent on %s '%s' %s" % \
+ (self, self.display, self.entry))
- def isPending(self):
- """
- Return True if the display handler is in edit mode and has modified text
- """
- return self.editing and self.modified
+ if (self.handleCR and type(self.display)=='str'):
+ cursor=self._cursor +
len(self.display[:self._cursor+1].split('\n'))-1
+ else:
+ cursor=self._cursor
- #####################
- #
- # Editing methods
- #
+ index = self.entry._visibleIndex
- def beginEdit(self):
- """
- Notifies the handler that it will be doing edits.
-
- Called when a widget first gets focus. It places the display handler into
- edit mode, syncs the current value with the GFField associated with this
- display handler, and creates the string to display in the form.
- """
- self.editing = self.field.isEditable()
- self.modified = False
- self.display = self.build_display(self.field.get_value(), True)
- self._cursor = len(self.display)
- self.setSelectionArea(0, self._cursor)
- self.generateRefreshEvent()
+ self.entry.uiWidget._ui_set_value_(index, self.display)
+ self.entry.uiWidget._ui_set_cursor_position_(index, cursor)
- def endEdit(self):
- """
- Called when a widget loses focus or when ENTER is hit.
- """
- if not self.editing:
- return
+ selection = self.getSelectionArea()
+ if selection is not None:
+ selection1, selection2 = selection
+ self.entry.uiWidget._ui_set_selected_area_(index, selection1,
selection2)
- # Set editing to False early. The later call to __updateFieldValue() can,
- # if it is an autoquery field, cause a query to run, in which case editing
- # should not be True at that moment.
- self.editing = False
+ def __beep(self):
+ """
+ Generates an event requesting that the UI beep.
+ """
+ self.entry._form.beep()
- self._selection1 = None
+ def isPending(self):
+ """
+ Return True if the display handler is in edit mode and has modified
text
+ """
+ return self.editing and self.modified
- if self.modified:
- try:
- self.__updateFieldValue()
- except:
- self.editing = True
- raise
+ #####################
+ #
+ # Editing methods
+ #
+ def beginEdit(self):
+ """
+ Notifies the handler that it will be doing edits.
- # ---------------------------------------------------------------------------
- # Text manipulation
- # ---------------------------------------------------------------------------
+ Called when a widget first gets focus. It places the display handler
+ into edit mode, syncs the current value with the GFField associated
+ with this display handler, and creates the string to display in the
+ form.
+ """
+ self.editing = self.field.isEditable()
+ self.modified = False
+ self.display = self.build_display(self.field.get_value(), True)
+ self._cursor = len(self.display)
+ self.setSelectionArea(0, self._cursor)
+ self.generateRefreshEvent()
- def _addText(self, event):
+ def endEdit(self):
+ """
+ Called when a widget loses focus or when ENTER is hit.
+ """
+ if not self.editing:
+ return
+ # Set editing to False early. The later call to __updateFieldValue()
+ # can, if it is an autoquery field, cause a query to run, in which case
+ # editing should not be True at that moment.
+ self.editing = False
+
+ self._selection1 = None
+
+ if self.modified:
+ try:
+ self.__updateFieldValue()
+ except:
+ self.editing = True
+ raise
+
+
+ # -------------------------------------------------------------------------
+ # Text manipulation
+ # -------------------------------------------------------------------------
+
+ def _addText(self, event):
+
if not self.editing:
return
@@ -201,9 +203,9 @@
self.__change_text(start, end, event.text, start + len(event.text))
- # -------------------------------------------------------------------------
+ # -------------------------------------------------------------------------
- def _replace_text(self, event):
+ def _replace_text(self, event):
if not self.editing:
return
@@ -215,9 +217,9 @@
self.__change_text(0, len(self.display), event.text, new_cursor)
- # -------------------------------------------------------------------------
+ # -------------------------------------------------------------------------
- def _insertTextAt(self, event):
+ def _insertTextAt(self, event):
if not self.editing:
return
@@ -225,9 +227,9 @@
self.__change_text(event.position, event.position, event.text,
event.position)
- # -------------------------------------------------------------------------
+ # -------------------------------------------------------------------------
- def _deleteRange(self, event):
+ def _deleteRange(self, event):
if not self.editing:
return
@@ -235,9 +237,9 @@
self.__change_text(event.start_pos, event.end_pos, u"",
event.start_pos)
- # -------------------------------------------------------------------------
+ # -------------------------------------------------------------------------
- def __handleENTER(self, event):
+ def __handleENTER(self, event):
isNewLine = gConfigForms ('EnterIsNewLine')
@@ -246,9 +248,9 @@
self._addText(event)
event.drop()
- # -------------------------------------------------------------------------
+ # -------------------------------------------------------------------------
- def _backspace(self, event):
+ def _backspace(self, event):
if not self.editing:
return
@@ -273,9 +275,9 @@
self.__change_text(self._cursor - 1, self._cursor, u"",
self._cursor - 1)
- # -------------------------------------------------------------------------
+ # -------------------------------------------------------------------------
- def _delete(self, event):
+ def _delete(self, event):
if not self.editing:
return
@@ -299,9 +301,9 @@
self.__change_text(self._cursor, self._cursor + 1, u"",
self._cursor)
- # -------------------------------------------------------------------------
+ # -------------------------------------------------------------------------
- def __change_text(self, start, end, text, new_cursor):
+ 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:
@@ -353,234 +355,241 @@
pass
- # ===========================================================================
- # Cursor movement functions
- # ===========================================================================
+ # =========================================================================
+ # Cursor movement functions
+ # =========================================================================
- def _moveCursor(self, event, selecting=False):
- """
- Moves the cursor to the specified position optionally selecting the text.
-
- @param event: The GFEvent making the request
- @param selecting: Boolean indicating if text should be selected
- as part of the cursor move
- """
- if not selecting:
- self._selection1 = None
+ def __move_cursor(self, position, selecting=False):
+ """
+ Move the cursor to the specified position optionally selecting the
+ text. After moving the cursor a refresh event will be generated.
- self._cursor = min(event.position, len(self.display))
- self.generateRefreshEvent()
+ @param position: the position to set the cursor to
+ @param selecting: boolean indicating if the text should be selected.
+ """
+ if selecting:
+ if self._selection1 is None:
+ self._selection1 = self._cursor
+ else:
+ self._selection1 = None
- def _moveCursorLeft(self, event, selecting=False):
- """
- Moves the cursor to the left optionally selecting the text.
-
- @param event: The GFEvent making the request
- @param selecting: Boolean indicating if text should be selected
- as part of the cursor move
- """
- if not selecting:
- self._selection1 = None
+ self._cursor = min(position, len(self.display))
- if self._cursor > 0:
- self._cursor -= 1
- self.generateRefreshEvent()
+ if selecting:
+ self._selection2 = self._cursor
- def _moveCursorRight(self, event, selecting=False):
- """
- Moves the cursor to the right optionally selecting the text.
-
- @param event: The GFEvent making the request
- @param selecting: Boolean indicating if text should be selected
- as part of the cursor move
- """
- if not selecting:
- self._selection1 = None
+ self.generateRefreshEvent()
- if self._cursor < len(self.display):
- self._cursor += 1
- self.generateRefreshEvent()
+ # -------------------------------------------------------------------------
- def _moveCursorToEnd(self, event, selecting=False):
- """
- Moves the cursor to the end optionally selecting the text.
-
- @param event: The GFEvent making the request
- @param selecting: Boolean indicating if text should be selected
- as part of the cursor move
- """
- if not selecting:
- self._selection1 = None
+ def _moveCursor(self, event, selecting=False):
+ """
+ Moves the cursor to the specified position optionally selecting the
+ text.
- self._cursor = len(self.display)
- self.generateRefreshEvent()
+ @param event: The GFEvent making the request
+ @param selecting: Boolean indicating if text should be selected
+ as part of the cursor move
+ """
+ self.__move_cursor(event.position, selecting)
+ # -------------------------------------------------------------------------
- def _moveCursorToBegin(self, event, selecting=False):
- """
- Moves the cursor to the beginning optionally selecting the text.
-
- @param event: The GFEvent making the request
- @param selecting: Boolean indicating if text should be selected
- as part of the cursor move
- """
- if not selecting:
- self._selection1 = None
+ def _moveCursorLeft(self, event, selecting=False):
+ """
+ Moves the cursor to the left optionally selecting the text.
- self._cursor = 0
- self.generateRefreshEvent()
+ @param event: The GFEvent making the request
+ @param selecting: Boolean indicating if text should be selected
+ as part of the cursor move
+ """
+ if self._cursor > 0:
+ self.__move_cursor(self._cursor - 1, selecting)
- # ---------------------------------------------------------------------------
- # Selection Support
- # ---------------------------------------------------------------------------
+ # -------------------------------------------------------------------------
- def setSelectionArea(self, cursor1, cursor2):
- """
- Set the selection area
-
- Starting and ending position can be passed in an any order.
-
- @param cursor1: A starting or ending position for the selection
- @param cursor2: A starting or ending position for the selection
- """
- self._selection1 = min(cursor1, cursor2)
- self._selection2 = max(cursor1, cursor2)
+ def _moveCursorRight(self, event, selecting=False):
+ """
+ Moves the cursor to the right optionally selecting the text.
- def getSelectionArea(self):
- """
- Return the selected area
-
- @return: The selected area as a tuple or None if no selection
- """
- if self._selection1 is None:
- return None
- else:
- return ( min(self._selection1, self._selection2),
- max(self._selection1, self._selection2) )
+ @param event: The GFEvent making the request
+ @param selecting: Boolean indicating if text should be selected
+ as part of the cursor move
+ """
+ if self._cursor < len(self.display):
+ self.__move_cursor(self._cursor + 1, selecting)
+ # -------------------------------------------------------------------------
- def _selectWithMouse(self, event):
- """
- Select an area of text based upon the mouse
-
- @param event: The GFEvent making the request
- """
- self._selection1 = event.position1
- self._selection2 = event.position2
- if self._cursor == self._selection2:
- event.position = self._selection1
- else:
- event.position = self._selection2
- self._moveCursor(event, True)
+ def _moveCursorToEnd(self, event, selecting=False):
+ """
+ Moves the cursor to the end optionally selecting the text.
+ @param event: The GFEvent making the request
+ @param selecting: Boolean indicating if text should be selected
+ as part of the cursor move
+ """
- def _selectAll (self, event):
- """
- Select the entire text of the entry and move the cursor to the end
-
- @param event: The GFEvent making the request
- """
- self._selection1 = 0
- self._moveCursorToEnd (event, True)
- self._selection2 = self._cursor
+ self.__move_cursor(len(self.display), selecting)
+ # -------------------------------------------------------------------------
- def _selectLeft(self, event):
- """
- Move the selection cursor to the left one unit
-
- @param event: The GFEvent making the request
- """
- if self._selection1 == None:
- self._selection1 = self._cursor
+ def _moveCursorToBegin(self, event, selecting=False):
+ """
+ Moves the cursor to the beginning optionally selecting the text.
- self._moveCursorLeft(event, True)
- self._selection2 = self._cursor
+ @param event: The GFEvent making the request
+ @param selecting: Boolean indicating if text should be selected
+ as part of the cursor move
+ """
+ self.__move_cursor(0, selecting)
- def _selectRight(self, event):
- """
- Move the selection cursor to the right one unit
-
- @param event: The GFEvent making the request
- """
- if self._selection1 == None:
- self._selection1 = self._cursor
+ # -------------------------------------------------------------------------
+ # Selection Support
+ # -------------------------------------------------------------------------
- self._moveCursorRight(event, True)
- self._selection2 = self._cursor
+ def setSelectionArea(self, cursor1, cursor2):
+ """
+ Set the selection area
+ Starting and ending position can be passed in an any order.
-
- def _selectToBegin(self, event):
- """
- Select from the current curson position to the beginning of the entry
-
- @param event: The GFEvent making the request
- """
- if self._selection1 == None:
- self._selection1 = self._cursor
+ @param cursor1: A starting or ending position for the selection
+ @param cursor2: A starting or ending position for the selection
+ """
+ self._selection1 = min(cursor1, cursor2)
+ self._selection2 = max(cursor1, cursor2)
- self._moveCursorToBegin(event, True)
- self._selection2 = self._cursor
+ # -------------------------------------------------------------------------
+ # Get the currently selected area
+ # -------------------------------------------------------------------------
-
- def _selectToEnd(self, event):
- """
- Select from the current curson position to the end of the entry
-
- @param event: The GFEvent making the request
- """
+ def getSelectionArea(self):
+ """
+ Return the selected area
- if self._selection1 == None:
- self._selection1 = self._cursor
+ @return: The selected area as a tuple or None if no selection
+ """
+ if self._selection1 is None:
+ return None
+ else:
+ return ( min(self._selection1, self._selection2),
+ max(self._selection1, self._selection2) )
- self._moveCursorToEnd(event, True)
- self._selection2 = self._cursor
- # -------------------------------------------------------------------------
- # Parse the display string
- # -------------------------------------------------------------------------
+ # -------------------------------------------------------------------------
- def parse_display(self, display):
+ def _selectWithMouse(self, event):
+ """
+ Select an area of text based upon the mouse
- if display == u"":
- return None
- else:
- return display
+ @param event: The GFEvent making the request
+ """
+ self._selection1 = event.position1
+ self._selection2 = event.position2
+ if self._cursor == self._selection2:
+ event.position = self._selection1
+ else:
+ event.position = self._selection2
+ self._moveCursor(event, True)
+ # -------------------------------------------------------------------------
- # -------------------------------------------------------------------------
- # Build the display string
- # -------------------------------------------------------------------------
+ def _selectAll (self, event):
+ """
+ Select the entire text of the entry and move the cursor to the end
- def build_display(self, value, editing):
+ @param event: The GFEvent making the request
"""
+ self._selection1 = 0
+ self._moveCursorToEnd(event, True)
+
+ # -------------------------------------------------------------------------
+
+ def _selectLeft(self, event):
+ """
+ Move the selection cursor to the left one unit
+
+ @param event: The GFEvent making the request
+ """
+ self._moveCursorLeft(event, True)
+
+ # -------------------------------------------------------------------------
+
+ def _selectRight(self, event):
+ """
+ Move the selection cursor to the right one unit
+
+ @param event: The GFEvent making the request
+ """
+ self._moveCursorRight(event, True)
+
+ # -------------------------------------------------------------------------
+
+ def _selectToBegin(self, event):
+ """
+ Select from the current curson position to the beginning of the entry
+
+ @param event: The GFEvent making the request
+ """
+ self._moveCursorToBegin(event, True)
+
+ # -------------------------------------------------------------------------
+
+ def _selectToEnd(self, event):
+ """
+ Select from the current curson position to the end of the entry
+
+ @param event: The GFEvent making the request
+ """
+ self._moveCursorToEnd(event, True)
+
+
+ # -------------------------------------------------------------------------
+ # Parse the display string
+ # -------------------------------------------------------------------------
+
+ def parse_display(self, display):
+
+ if display == u"":
+ return None
+ else:
+ return display
+
+
+ # -------------------------------------------------------------------------
+ # Build the display string
+ # -------------------------------------------------------------------------
+
+ def build_display(self, value, editing):
+ """
Build the display string from the user value.
"""
-
+
if value is None:
return u""
else:
return unicode(value)
- def updateFieldValue (self):
- """
- Update the associated field with the current value of the display handler
- """
+ def updateFieldValue (self):
+ """
+ Update the associated field with the current value of the display
+ handler.
+ """
- if self.isPending ():
- try:
- self.__updateFieldValue()
- except:
- pass
+ if self.isPending ():
+ try:
+ self.__updateFieldValue()
+ except:
+ pass
- def __updateFieldValue(self):
+ def __updateFieldValue(self):
- value = self.parse_display(self.display)
- self.field.set_value(value)
+ value = self.parse_display(self.display)
+ self.field.set_value(value)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r9178 - trunk/gnue-forms/src/input/displayHandlers,
johannes <=