[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8179 - in trunk/gnue-forms/src: input/displayHandlers uidrivers/
From: |
johannes |
Subject: |
[gnue] r8179 - in trunk/gnue-forms/src: input/displayHandlers uidrivers/wx26/widgets |
Date: |
Mon, 27 Feb 2006 08:55:00 -0600 (CST) |
Author: johannes
Date: 2006-02-27 08:54:59 -0600 (Mon, 27 Feb 2006)
New Revision: 8179
Modified:
trunk/gnue-forms/src/input/displayHandlers/Cursor.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
Log:
Fixed handling of <Enter> in multiline text fields, as well as
positioning for wx.MSW.
Modified: trunk/gnue-forms/src/input/displayHandlers/Cursor.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/Cursor.py 2006-02-24
17:46:55 UTC (rev 8178)
+++ trunk/gnue-forms/src/input/displayHandlers/Cursor.py 2006-02-27
14:54:59 UTC (rev 8179)
@@ -146,8 +146,7 @@
"""
assert gDebug (5, "generateRefreshEvent on %s '%s' %s" % \
(self, self.display, self.entry))
- # TODO: this should probably actually happen in UIwxpython!
-
+
if (self.handleCR and type(self.display)=='str'):
self.dispatchEvent(events.Event('updateEntryEditor',
object = self.field,
@@ -330,6 +329,7 @@
self._buildValue()
self.field.setValue(self.value)
+
def _insertTextAt(self, event):
"""
Insert text at specified position
@@ -363,18 +363,19 @@
self._cursor = event.position
self._delete (event)
- def __handleENTER(self, event):
+ def __handleENTER (self, event):
"""
Private function to handle enter key presses in an multiline entry.
@param event: The GFEvent making the request
"""
- if gConfigForms('EnterIsNewLine') and \
- hasattr(self.entry, 'Char__height') and \
- self.entry.Char__height > 1:
+ isNewLine = gConfigForms ('EnterIsNewLine')
+ lines = getattr (self.entry, 'Char__height', 1)
+
+ if isNewLine and lines > 1:
event.text = '\n'
- self._addText(event)
- event.drop()
+ self._addText (event)
+ event.drop ()
# ===========================================================================
# Cursor movement functions
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py 2006-02-24
17:46:55 UTC (rev 8178)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py 2006-02-27
14:54:59 UTC (rev 8179)
@@ -22,6 +22,7 @@
# $Id$
import wx
+import os
from gnue.forms.GFForm import *
from gnue.forms.uidrivers._base.widgets._base import UIWidget
@@ -218,7 +219,7 @@
widget.SetMark (position, position)
elif hasattr (widget, 'SetInsertionPoint'):
- widget.SetInsertionPoint (position)
+ widget.SetInsertionPoint (self._positionToWx (widget, position))
# --------------------------------------------------------------------------
@@ -243,6 +244,10 @@
widget.SetMark (selection1, selection2)
elif hasattr (widget, 'SetSelection'):
+ if isinstance (widget, wx.TextCtrl) and widget.IsMultiLine ():
+ selection1 = self._positionToWx (widget, selection1)
+ selection2 = self._positionToWx (widget, selection2)
+
widget.SetSelection (selection1, selection2)
@@ -266,3 +271,36 @@
finally:
widget.Thaw ()
+
+
+ # ---------------------------------------------------------------------------
+ # Convert a GF-position to a wx position within a multiline edit
+ # ---------------------------------------------------------------------------
+
+ def _positionToWx (self, widget, position):
+
+ if len (os.linesep) < 2 or not position:
+ return position
+
+ text = widget.GetValue () [:position]
+ num = text.count ('\n')
+ result = position + num
+
+ return result
+
+
+ # ---------------------------------------------------------------------------
+ # Convert a wx position to a GF position within a multiline edit
+ # ---------------------------------------------------------------------------
+
+ def _wxToPosition (self, widget, position):
+
+ if len (os.linesep) < 2 or not position:
+ return position
+
+ text = widget.GetValue ().replace ('\n', os.linesep) [:position]
+ num = text.count (os.linesep)
+ result = max (0, position - num)
+
+ return result
+
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py 2006-02-24
17:46:55 UTC (rev 8178)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py 2006-02-27
14:54:59 UTC (rev 8179)
@@ -230,6 +230,10 @@
if isinstance (widget, wx.TextCtrl):
(left, right) = widget.GetSelection ()
+ if widget.IsMultiLine ():
+ left = self._wxToPosition (widget, left)
+ right = self._wxToPosition (widget, right)
+
elif isinstance (widget, wx.ComboBox):
if 'wxMac' in wx.PlatformInfo:
(left, right) = widget._entry.GetSelection ()
@@ -240,8 +244,7 @@
self._request ('CURSORMOVE', position = left)
else:
- self._request ('SELECTWITHMOUSE', position1 = left, position2 = right,
- cursor = widget.GetInsertionPoint ())
+ self._request ('SELECTWITHMOUSE', position1 = left, position2 = right)
# ---------------------------------------------------------------------------
@@ -276,7 +279,8 @@
def __keypress (self, event):
- if 'wxMac' in wx.PlatformInfo or 'wxMSW' in wx.PlatformInfo:
+ if 'wxMac' in wx.PlatformInfo or \
+ ('wxMSW' in wx.PlatformInfo and self._gfObject.style == 'dropdown'):
self.__updateInsertionPoint (event.GetEventObject ())
keycode = event.GetKeyCode ()
@@ -294,7 +298,10 @@
command = None
if command:
- self._request (command, triggerName = args)
+ if command == 'NEWLINE':
+ self._request ('KEYPRESS', text = '\n')
+ else:
+ self._request (command, triggerName = args)
elif unikey == keycode or unikey > 127:
self._keypress (unichr (unikey))
@@ -302,7 +309,11 @@
else:
event.Skip ()
+ # If a keypress will be handled by the wx widget, make sure to keep in
+ # sync with the position and/or selection
+ wx.CallAfter (self.__updateInsertionPoint, event.GetEventObject ())
+
# ---------------------------------------------------------------------------
# Key-Down-Eventtrap for wx.MSW's ComboBox widgets
# ---------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8179 - in trunk/gnue-forms/src: input/displayHandlers uidrivers/wx26/widgets,
johannes <=