]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wx/lib/masked/numctrl.py
fix label
[wxWidgets.git] / wxPython / wx / lib / masked / numctrl.py
index e48eacd7b7a5b07984fbe9103edd215e7750ec63..3104724c7ac02284f878945a5953ac90bd66eba9 100644 (file)
@@ -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']
@@ -762,12 +763,6 @@ class NumCtrl(BaseMaskedTextCtrl, NumCtrlAccessorsMixin):
         if maskededit_kwargs.keys():
             self.SetCtrlParameters(**maskededit_kwargs)
 
-        # Record end of integer and place cursor there:
-        integerEnd = self._fields[0]._extent[1]
-        self.SetInsertionPoint(0)
-        self.SetInsertionPoint(integerEnd)
-        self.SetSelection(integerEnd, integerEnd)
-
         # Go ensure all the format codes necessary are present:
         orig_intformat = intformat = self.GetFieldParameter(0, 'formatcodes')
         if 'r' not in intformat:
@@ -780,6 +775,17 @@ class NumCtrl(BaseMaskedTextCtrl, NumCtrlAccessorsMixin):
             else:
                 self.SetCtrlParameters(formatcodes=intformat)
 
+        # Record end of integer and place cursor there unless selecting, or select entire field:
+        integerStart, integerEnd = self._fields[0]._extent
+        if not self._fields[0]._selectOnFieldEntry:
+            self.SetInsertionPoint(0)
+            self.SetInsertionPoint(integerEnd)
+            self.SetSelection(integerEnd, integerEnd)
+        else:
+            self.SetInsertionPoint(0)   # include any sign
+            self.SetSelection(0, integerEnd)
+
+
         # Set min and max as appropriate:
         if kwargs.has_key('min'):
             min = kwargs['min']
@@ -824,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()
 
@@ -1563,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()
@@ -1754,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.