MaskedEdit patch from Will Sadkin:
- Added handling for WXK_DELETE and WXK_INSERT, such that shift-delete cuts, shift-insert pastes, and ctrl-insert copies. - Fixed masked.numctrl to allow space for a group char, as this format is apparently used in several world locales. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39665 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -33,8 +33,8 @@ The controls at the top reconfigure the resulting control at the bottom.
|
||||
|
||||
groupcharlabel = wx.StaticText( panel,-1, "Grouping char:" )
|
||||
self.groupchar = masked.TextCtrl(
|
||||
panel, -1, value=',', mask='&', excludeChars = '-()',
|
||||
formatcodes='F', emptyInvalid=True, validRequired=True
|
||||
panel, -1, value=',', mask='*', includeChars = ' ', excludeChars = '-()0123456789',
|
||||
formatcodes='F', emptyInvalid=False, validRequired=True
|
||||
)
|
||||
|
||||
decimalcharlabel = wx.StaticText( panel,-1, "Decimal char:" )
|
||||
|
@@ -831,7 +831,7 @@ nav = (
|
||||
)
|
||||
|
||||
control = (
|
||||
wx.WXK_BACK, wx.WXK_DELETE, WXK_CTRL_A, WXK_CTRL_C, WXK_CTRL_S, WXK_CTRL_V,
|
||||
wx.WXK_BACK, wx.WXK_DELETE, wx.WXK_INSERT, WXK_CTRL_A, WXK_CTRL_C, WXK_CTRL_S, WXK_CTRL_V,
|
||||
WXK_CTRL_X, WXK_CTRL_Z
|
||||
)
|
||||
|
||||
@@ -1715,7 +1715,8 @@ class MaskedEditMixin:
|
||||
wx.WXK_NEXT: self._OnAutoCompleteField,
|
||||
|
||||
# default function control keys and handlers:
|
||||
wx.WXK_DELETE: self._OnErase,
|
||||
wx.WXK_DELETE: self._OnDelete,
|
||||
wx.WXK_INSERT: self._OnInsert,
|
||||
WXK_CTRL_A: self._OnCtrl_A,
|
||||
WXK_CTRL_C: self._OnCtrl_C,
|
||||
WXK_CTRL_S: self._OnCtrl_S,
|
||||
@@ -3199,6 +3200,32 @@ class MaskedEditMixin:
|
||||
Should return False to skip other processing. """
|
||||
## dbg("MaskedEditMixin::_OnCtrl_V", indent=1)
|
||||
self.Paste()
|
||||
dbg(indent=0)
|
||||
return False
|
||||
|
||||
def _OnInsert(self, event=None):
|
||||
""" Handles shift-insert and control-insert operations (paste and copy, respectively)"""
|
||||
## dbg("MaskedEditMixin::_OnInsert", indent=1)
|
||||
if event and isinstance(event, wx.KeyEvent):
|
||||
if event.ShiftDown():
|
||||
self.Paste()
|
||||
elif event.ControlDown():
|
||||
self.Copy()
|
||||
# (else do nothing)
|
||||
# (else do nothing)
|
||||
## dbg(indent=0)
|
||||
return False
|
||||
|
||||
def _OnDelete(self, event=None):
|
||||
""" Handles shift-delete and delete operations (cut and erase, respectively)"""
|
||||
## dbg("MaskedEditMixin::_OnDelete", indent=1)
|
||||
if event and isinstance(event, wx.KeyEvent):
|
||||
if event.ShiftDown():
|
||||
self.Cut()
|
||||
else:
|
||||
self._OnErase(event)
|
||||
else:
|
||||
self._OnErase(event)
|
||||
## dbg(indent=0)
|
||||
return False
|
||||
|
||||
@@ -6572,6 +6599,10 @@ __i=0
|
||||
|
||||
## CHANGELOG:
|
||||
## ====================
|
||||
## Version 1.10
|
||||
## 1. Added handling for WXK_DELETE and WXK_INSERT, such that shift-delete
|
||||
## cuts, shift-insert pastes, and ctrl-insert copies.
|
||||
##
|
||||
## Version 1.9
|
||||
## 1. Now ignores kill focus events when being destroyed.
|
||||
## 2. Added missing call to set insertion point on changing fields.
|
||||
|
@@ -678,6 +678,7 @@ class NumCtrl(BaseMaskedTextCtrl, NumCtrlAccessorsMixin):
|
||||
## dbg("old_decimalchar: '%s'" % old_decimalchar)
|
||||
groupchar = old_groupchar
|
||||
decimalchar = old_decimalchar
|
||||
old_numvalue = self._GetNumValue(self._GetValue())
|
||||
|
||||
if kwargs.has_key('groupChar'):
|
||||
maskededit_kwargs['groupChar'] = kwargs['groupChar']
|
||||
@@ -829,12 +830,20 @@ class NumCtrl(BaseMaskedTextCtrl, NumCtrlAccessorsMixin):
|
||||
# Ensure current value of control obeys any new restrictions imposed:
|
||||
text = self._GetValue()
|
||||
## dbg('text value: "%s"' % text)
|
||||
if kwargs.has_key('groupChar') and text.find(old_groupchar) != -1:
|
||||
text = text.replace(old_groupchar, self._groupChar)
|
||||
if kwargs.has_key('decimalChar') and text.find(old_decimalchar) != -1:
|
||||
text = text.replace(old_decimalchar, self._decimalChar)
|
||||
if kwargs.has_key('groupChar') and self._groupChar != old_groupchar and text.find(old_groupchar) != -1:
|
||||
text = old_numvalue
|
||||
## dbg('old_groupchar: "%s" newgroupchar: "%s"' % (old_groupchar, self._groupChar))
|
||||
if kwargs.has_key('decimalChar') and self._decimalChar != old_decimalchar and text.find(old_decimalchar) != -1:
|
||||
text = old_numvalue
|
||||
|
||||
if text != self._GetValue():
|
||||
wx.TextCtrl.SetValue(self, text)
|
||||
if self._decimalChar != '.':
|
||||
# ensure latest decimal char is in "numeric value" so it won't be removed
|
||||
# when going to the GUI:
|
||||
text = text.replace('.', self._decimalChar)
|
||||
newtext = self._toGUI(text)
|
||||
## dbg('calling wx.TextCtrl.SetValue(self, %s)' % newtext)
|
||||
wx.TextCtrl.SetValue(self, newtext)
|
||||
|
||||
value = self.GetValue()
|
||||
|
||||
@@ -1568,7 +1577,12 @@ class NumCtrl(BaseMaskedTextCtrl, NumCtrlAccessorsMixin):
|
||||
#
|
||||
field = self._FindField(sel_start)
|
||||
edit_start, edit_end = field._extent
|
||||
paste_text = paste_text.replace(self._groupChar, '').replace('(', '-').replace(')','')
|
||||
|
||||
# handle possibility of groupChar being a space:
|
||||
newtext = paste_text.lstrip()
|
||||
lspace_count = len(paste_text) - len(newtext)
|
||||
paste_text = ' ' * lspace_count + newtext.replace(self._groupChar, '').replace('(', '-').replace(')','')
|
||||
|
||||
if field._insertRight and self._groupDigits:
|
||||
# want to paste to the left; see if it will fit:
|
||||
left_text = old_value[edit_start:sel_start].lstrip()
|
||||
@@ -1759,6 +1773,9 @@ __i=0
|
||||
## 1. Add support for printf-style format specification.
|
||||
## 2. Add option for repositioning on 'illegal' insertion point.
|
||||
##
|
||||
## Version 1.3
|
||||
## 1. fixed to allow space for a group char.
|
||||
##
|
||||
## Version 1.2
|
||||
## 1. Allowed select/replace digits.
|
||||
## 2. Fixed undo to ignore grouping chars.
|
||||
|
Reference in New Issue
Block a user