Patch from Will Sadkin:

Enclosed are two patches, one for timectrl, re: exceptions (now?)
    thrown on wxDateTime.strftime(%p) in a non-am/pm locale, and one
    for a problem that prevented input into the integer digit of a
    integerwidth=1 numctrl, if the current value was 0.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32483 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2005-02-28 18:45:13 +00:00
parent 7e8f0df953
commit 766abb5bc9
2 changed files with 39 additions and 19 deletions

View File

@@ -50,7 +50,7 @@
# o wxTimeCtrl -> TimeCtrl # o wxTimeCtrl -> TimeCtrl
# #
'''\ """\
==================== ====================
Masked Edit Overview Masked Edit Overview
==================== ====================
@@ -249,7 +249,7 @@ decimalChar
Eg:: Eg::
formatcodes = ',', groupChar="'" allows 12'345.34 formatcodes = ',', groupChar='\'' allows 12'345.34
formatcodes = ',', groupChar='.', decimalChar=',' allows 12.345,34 formatcodes = ',', groupChar='.', decimalChar=',' allows 12.345,34
(These are control-level parameters.) (These are control-level parameters.)
@@ -546,7 +546,7 @@ use either of the following::
If not specified as a keyword argument, the default controlType is If not specified as a keyword argument, the default controlType is
controlTypes.TEXT. controlTypes.TEXT.
''' """
""" """
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -2892,9 +2892,9 @@ class MaskedEditMixin:
field = self._FindField(pos) field = self._FindField(pos)
## dbg("key ='%s'" % chr(key)) ## dbg("key ='%s'" % chr(key))
## if chr(key) == ' ': if chr(key) == ' ':
## dbg('okSpaces?', field._okSpaces) ## dbg('okSpaces?', field._okSpaces)
## pass pass
char = chr(key) # (must work if we got this far) char = chr(key) # (must work if we got this far)
@@ -4434,9 +4434,16 @@ class MaskedEditMixin:
# if entire field is selected or position is at end and field is not full, # if entire field is selected or position is at end and field is not full,
# or if allowed to right-insert at any point in field and field is not full and cursor is not at a fillChar: # or if allowed to right-insert at any point in field and field is not full and cursor is not at a fillChar
# or the field is a singleton integer field and is currently 0 and we're at the end:
if( (sel_start, sel_to) == field._extent if( (sel_start, sel_to) == field._extent
or (pos == end and input_len < field_len)): or (pos == end and ((input_len < field_len)
or (field_len == 1
and input_len == field_len
and field._isInt
and value[end-1] == '0'
)
) ) ):
pos = end - 1 pos = end - 1
## dbg('pos = end - 1 = ', pos, 'right_insert? 1') ## dbg('pos = end - 1 = ', pos, 'right_insert? 1')
right_insert = True right_insert = True
@@ -4476,6 +4483,7 @@ class MaskedEditMixin:
## dbg("checking appropriate regex's") ## dbg("checking appropriate regex's")
value = self._eraseSelection(self._GetValue()) value = self._eraseSelection(self._GetValue())
if right_insert: if right_insert:
# move the position to the right side of the insertion:
at = pos+1 at = pos+1
else: else:
at = pos at = pos
@@ -4873,15 +4881,15 @@ class MaskedEditMixin:
fstr = text[start:end] fstr = text[start:end]
erasable_chars = [field._fillChar, ' '] erasable_chars = [field._fillChar, ' ']
if field._padZero: # if zero padding field, or a single digit, and currently a value of 0, allow erasure of 0:
if field._padZero or (field._isInt and (end - start == 1) and fstr[0] == '0'):
erasable_chars.append('0') erasable_chars.append('0')
erased = '' erased = ''
#### dbg("fstr[0]:'%s'" % fstr[0]) #### dbg("fstr[0]:'%s'" % fstr[0])
#### dbg('field_index:', field._index) #### dbg('field_index:', field._index)
#### dbg("fstr[0] in erasable_chars?", fstr[0] in erasable_chars) #### dbg("fstr[0] in erasable_chars?", fstr[0] in erasable_chars)
#### dbg("self._signOk and field._index == 0 and fstr[0] in ('-','(')?", #### dbg("self._signOk and field._index == 0 and fstr[0] in ('-','(')?", self._signOk and field._index == 0 and fstr[0] in ('-','('))
## self._signOk and field._index == 0 and fstr[0] in ('-','('))
if fstr[0] in erasable_chars or (self._signOk and field._index == 0 and fstr[0] in ('-','(')): if fstr[0] in erasable_chars or (self._signOk and field._index == 0 and fstr[0] in ('-','(')):
erased = fstr[0] erased = fstr[0]
#### dbg('value: "%s"' % text) #### dbg('value: "%s"' % text)

View File

@@ -365,11 +365,17 @@ class TimeCtrl(BaseMaskedTextCtrl):
self.__fmt24hr = False self.__fmt24hr = False
wxdt = wx.DateTimeFromDMY(1, 0, 1970) wxdt = wx.DateTimeFromDMY(1, 0, 1970)
try:
if wxdt.Format('%p') != 'AM': if wxdt.Format('%p') != 'AM':
TimeCtrl.valid_ctrl_params['format'] = '24HHMMSS' TimeCtrl.valid_ctrl_params['format'] = '24HHMMSS'
self.__fmt24hr = True self.__fmt24hr = True
fmt24hr = True # force/change default positional argument fmt24hr = True # force/change default positional argument
# (will countermand explicit set to False too.) # (will countermand explicit set to False too.)
except:
TimeCtrl.valid_ctrl_params['format'] = '24HHMMSS'
self.__fmt24hr = True
fmt24hr = True # force/change default positional argument
# (will countermand explicit set to False too.)
for key, param_value in TimeCtrl.valid_ctrl_params.items(): for key, param_value in TimeCtrl.valid_ctrl_params.items():
# This is done this way to make setattr behave consistently with # This is done this way to make setattr behave consistently with
@@ -498,10 +504,13 @@ class TimeCtrl(BaseMaskedTextCtrl):
if key == 'format': if key == 'format':
wxdt = wx.DateTimeFromDMY(1, 0, 1970) wxdt = wx.DateTimeFromDMY(1, 0, 1970)
try:
if wxdt.Format('%p') != 'AM': if wxdt.Format('%p') != 'AM':
require24hr = True require24hr = True
else: else:
require24hr = False require24hr = False
except:
require24hr = True
# handle both local or generic 'maskededit' autoformat codes: # handle both local or generic 'maskededit' autoformat codes:
if param_value == 'HHMMSS' or param_value == 'TIMEHHMMSS': if param_value == 'HHMMSS' or param_value == 'TIMEHHMMSS':
@@ -704,12 +713,15 @@ class TimeCtrl(BaseMaskedTextCtrl):
if not valid: if not valid:
# deal with bug/deficiency in wx.DateTime: # deal with bug/deficiency in wx.DateTime:
try:
if wxdt.Format('%p') not in ('AM', 'PM') and checkTime in (5,8): if wxdt.Format('%p') not in ('AM', 'PM') and checkTime in (5,8):
# couldn't parse the AM/PM field # couldn't parse the AM/PM field
raise ValueError('cannot convert string "%s" to valid time for the current locale; please use 24hr time instead' % value) raise ValueError('cannot convert string "%s" to valid time for the current locale; please use 24hr time instead' % value)
else: else:
## dbg(indent=0, suspend=0) ## dbg(indent=0, suspend=0)
raise ValueError('cannot convert string "%s" to valid time' % value) raise ValueError('cannot convert string "%s" to valid time' % value)
except:
raise ValueError('cannot convert string "%s" to valid time for the current locale; please use 24hr time instead' % value)
else: else:
if isinstance(value, wx.DateTime): if isinstance(value, wx.DateTime):