]> git.saurik.com Git - wxWidgets.git/commitdiff
Patch from Will Sadkin:
authorRobin Dunn <robin@alldunn.com>
Mon, 28 Feb 2005 18:45:13 +0000 (18:45 +0000)
committerRobin Dunn <robin@alldunn.com>
Mon, 28 Feb 2005 18:45:13 +0000 (18:45 +0000)
    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

wxPython/wx/lib/masked/maskededit.py
wxPython/wx/lib/masked/timectrl.py

index 0bd99c567f68332e10771aefe6c365450097778f..5a99f9ec43aa9157fd3172e3f132f8fbdce22331 100644 (file)
@@ -50,7 +50,7 @@
 # o wxTimeCtrl -> TimeCtrl
 #
 
-'''\
+"""\
 ====================
 Masked Edit Overview
 ====================
@@ -249,7 +249,7 @@ decimalChar
 
   Eg::
 
-        formatcodes = ',', groupChar="'"                   allows  12'345.34
+        formatcodes = ',', groupChar='\''                  allows  12'345.34
         formatcodes = ',', groupChar='.', decimalChar=','  allows  12.345,34
 
   (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
 controlTypes.TEXT.
 
-'''
+"""
 
 """
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -2892,9 +2892,9 @@ class MaskedEditMixin:
             field = self._FindField(pos)
 
 ##            dbg("key ='%s'" % chr(key))
-##            if chr(key) == ' ':
+            if chr(key) == ' ':
 ##                dbg('okSpaces?', field._okSpaces)
-##                pass
+                pass
 
             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,
-            # 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
-                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
 ##                dbg('pos = end - 1 = ', pos, 'right_insert? 1')
                 right_insert = True
@@ -4476,6 +4483,7 @@ class MaskedEditMixin:
 ##                dbg("checking appropriate regex's")
                 value = self._eraseSelection(self._GetValue())
                 if right_insert:
+                    # move the position to the right side of the insertion:
                     at = pos+1
                 else:
                     at = pos
@@ -4873,15 +4881,15 @@ class MaskedEditMixin:
             fstr = text[start:end]
             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')
 
             erased = ''
 ####            dbg("fstr[0]:'%s'" % fstr[0])
 ####            dbg('field_index:', field._index)
 ####            dbg("fstr[0] in erasable_chars?", fstr[0] in erasable_chars)
-####            dbg("self._signOk and field._index == 0 and fstr[0] in ('-','(')?",
-##                 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 ('-','('))
             if fstr[0] in erasable_chars or (self._signOk and field._index == 0 and fstr[0] in ('-','(')):
                 erased = fstr[0]
 ####                dbg('value:      "%s"' % text)
index fe85da450caff2eb9b3d263810cb2825993b0d4f..06e36e2d80d315d3d1e2b728862d09c79a81a549 100644 (file)
@@ -365,7 +365,13 @@ class TimeCtrl(BaseMaskedTextCtrl):
 
         self.__fmt24hr = False
         wxdt = wx.DateTimeFromDMY(1, 0, 1970)
-        if wxdt.Format('%p') != 'AM':
+        try:
+            if wxdt.Format('%p') != 'AM':
+                TimeCtrl.valid_ctrl_params['format'] = '24HHMMSS'
+                self.__fmt24hr = True
+                fmt24hr = True  # force/change default positional argument
+                                # (will countermand explicit set to False too.)
+        except:
             TimeCtrl.valid_ctrl_params['format'] = '24HHMMSS'
             self.__fmt24hr = True
             fmt24hr = True  # force/change default positional argument
@@ -498,10 +504,13 @@ class TimeCtrl(BaseMaskedTextCtrl):
 
             if key == 'format':
                 wxdt = wx.DateTimeFromDMY(1, 0, 1970)
-                if wxdt.Format('%p') != 'AM':
+                try:
+                    if wxdt.Format('%p') != 'AM':
+                        require24hr = True
+                    else:
+                        require24hr = False
+                except:
                     require24hr = True
-                else:
-                    require24hr = False
 
                 # handle both local or generic 'maskededit' autoformat codes:
                 if param_value == 'HHMMSS' or param_value == 'TIMEHHMMSS':
@@ -704,12 +713,15 @@ class TimeCtrl(BaseMaskedTextCtrl):
 
             if not valid:
                 # deal with bug/deficiency in wx.DateTime:
-                if wxdt.Format('%p') not in ('AM', 'PM') and checkTime in (5,8):
-                    # couldn't parse the AM/PM field
+                try:
+                    if wxdt.Format('%p') not in ('AM', 'PM') and checkTime in (5,8):
+                        # 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)
+                    else:
+    ##                dbg(indent=0, suspend=0)
+                        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:
-##                dbg(indent=0, suspend=0)
-                    raise ValueError('cannot convert string "%s" to valid time' % value)
 
         else:
             if isinstance(value, wx.DateTime):