Changeset 3828
- Timestamp:
- 12/21/07 05:56:07 (1 year ago)
- Files:
-
- trunk/dabo/ui/uiwx/dSpinnerX.py (modified) (3 diffs)
- trunk/dabo/ui/uiwx/dTextBoxMixin.py (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/ui/uiwx/dSpinnerX.py
r3738 r3828 40 40 self._baseClass = dSpinnerX 41 41 # Create the child controls 42 self._proxy_textbox = dabo.ui.dTextBox(self, Value=val, Width=32) 42 self._proxy_textbox = dabo.ui.dTextBox(self, Value=val, Width=32, 43 StrictNumericEntry=False) 43 44 self._proxy_spinner = dSpinButton(parent=self) 44 45 self.__constructed = True … … 286 287 self.Max = 10 287 288 self.Min = 0 288 self.Value = 0 .0289 self.Increment = 1 .0289 self.Value = 0 290 self.Increment = 1 290 291 self.SpinnerWrap = True 291 292 self.FontSize = 10 … … 323 324 gsz = dabo.ui.dGridSizer(MaxCols=2, HGap=4, VGap=6) 324 325 lbl = dabo.ui.dLabel(pnl, Caption="Min") 325 txt = dabo.ui.dTextBox(pnl, DataSource=spn, DataField="Min" )326 txt = dabo.ui.dTextBox(pnl, DataSource=spn, DataField="Min", StrictNumericEntry=False) 326 327 gsz.append(lbl, halign="right") 327 328 gsz.append(txt) 328 329 lbl = dabo.ui.dLabel(pnl, Caption="Max") 329 txt = dabo.ui.dTextBox(pnl, DataSource=spn, DataField="Max" )330 txt = dabo.ui.dTextBox(pnl, DataSource=spn, DataField="Max", StrictNumericEntry=False) 330 331 gsz.append(lbl, halign="right") 331 332 gsz.append(txt) 332 333 lbl = dabo.ui.dLabel(pnl, Caption="Increment") 333 txt = dabo.ui.dTextBox(pnl, DataSource=spn, DataField="Increment" )334 txt = dabo.ui.dTextBox(pnl, DataSource=spn, DataField="Increment", StrictNumericEntry=False) 334 335 gsz.append(lbl, halign="right") 335 336 gsz.append(txt) trunk/dabo/ui/uiwx/dTextBoxMixin.py
r3824 r3828 2 2 import re 3 3 import datetime 4 import locale 4 5 import wx 5 6 import wx.lib.masked as masked … … 8 9 try: 9 10 import decimal 11 numericTypes = (int, long, decimal.Decimal, float) 12 valueErrors = (ValueError, decimal.InvalidOperation) 10 13 except ImportError: 11 14 # decimal is only in Python 2.4 or greater 12 15 decimal = None 13 14 import dabo, dabo.ui 16 numericTypes = (int, long, float) 17 valueErrors = (ValueError, ) 18 # Make this locale-independent 19 decimalPoint = locale.localeconv()["decimal_point"] 20 21 import dabo 15 22 if __name__ == "__main__": 16 23 dabo.ui.loadUI("wx") … … 177 184 self._addWindowStyleFlag(wx.TE_RIGHT) 178 185 else: 179 raise ValueError, "The only possible values are 'Left', 'Center', and 'Right'"186 raise ValueError, _("The only possible values are 'Left', 'Center', and 'Right'") 180 187 self.SetEditable(rw) 181 188 else: … … 409 416 def convertStringValueToDataType(self, strVal, dataType): 410 417 """Given a string value and a type, return an appropriate value of that type. 411 412 418 If the value can't be converted, a ValueError will be raised. 413 """ 419 """ 414 420 if dataType == bool: 415 421 # Bools can't convert from string representations, because a zero- … … 429 435 430 436 if retVal is None: 431 raise ValueError, "String not in ISO 8601 format."437 raise ValueError, _("String not in ISO 8601 format.") 432 438 elif str(dataType) == "<type 'DateTime'>": 433 439 # mx DateTime type. MySQLdb will use this if mx is installed. … … 436 442 retVal = mx.DateTime.DateTimeFrom(str(strVal)) 437 443 except ImportError: 438 raise ValueError, "Can't import mx.DateTime"444 raise ValueError, _("Can't import mx.DateTime") 439 445 elif str(dataType) == "<type 'DateTimeDelta'>": 440 446 # mx TimeDelta type. MySQLdb will use this for Time columns if mx is installed. … … 443 449 retVal = mx.DateTime.TimeFrom(str(strVal)) 444 450 except ImportError: 445 raise ValueError, "Can't import mx.DateTime"446 elif (decimal is not None and dataType == decimal.Decimal):451 raise ValueError, _("Can't import mx.DateTime") 452 elif decimal is not None and (dataType == decimal.Decimal) and self.StrictNumericEntry: 447 453 try: 448 454 _oldVal = self._oldVal … … 457 463 retVal = decimal.Decimal(strVal) 458 464 except: 459 raise ValueError, "Can't convert to decimal."465 raise ValueError, _("Can't convert to decimal.") 460 466 elif dataType in (tuple, list): 461 467 retVal = eval(strVal) 468 elif not self.StrictNumericEntry and (dataType in numericTypes): 469 isint = (strVal.count(decimalPoint) == 0) and (strVal.lower().count("e") == 0) 470 try: 471 if isint: 472 if strVal.strip().endswith("L"): 473 retVal = long(strVal) 474 else: 475 retVal = int(strVal) 476 else: 477 if decimal.Decimal in numericTypes: 478 retVal = decimal.Decimal(strVal) 479 else: 480 retVal = float(strVal) 481 except valueErrors: 482 raise ValueError, _("Invalid Numeric Value: %s") % strVal 462 483 else: 463 484 # Other types can convert directly. … … 470 491 # implemented, won't let the user get this far. Just keep the 471 492 # old value. 472 raise ValueError, "Can't convert."493 raise ValueError, _("Can't convert.") 473 494 return retVal 474 495 … … 497 518 elif value is None: 498 519 strVal = self.Application.NoneDisplay 520 elif isinstance(value, long): 521 strVal = value.__repr__() 499 522 else: 500 523 # convert all other data types to string: … … 555 578 def _getStrictDateEntry(self): 556 579 try: 557 v= self._strictDateEntry580 ret = self._strictDateEntry 558 581 except AttributeError: 559 v= self._strictDateEntry = False560 return v582 ret = self._strictDateEntry = False 583 return ret 561 584 562 585 def _setStrictDateEntry(self, val): … … 564 587 565 588 589 def _getStrictNumericEntry(self): 590 try: 591 ret = self._strictNumericEntry 592 except AttributeError: 593 ret = self._strictNumericEntry = True 594 return ret 595 596 def _setStrictNumericEntry(self, val): 597 if self._constructed(): 598 self._strictNumericEntry = val 599 else: 600 self._properties["StrictNumericEntry"] = val 601 602 566 603 #Overrides the dTextBoxMixinBase getter and setters because of the data conversion 567 604 #introduced in this class … … 672 709 which will be coerced into sensible date values automatically.""")) 673 710 711 StrictNumericEntry = property(_getStrictNumericEntry, _setStrictNumericEntry, None, 712 _("""When True, the DataType will be preserved across numeric types. When False, the 713 DataType will respond to user input to convert to the 'obvious' numeric type. 714 Default=True. (bool)""")) 715 674 716 Value = property(_getValue, _setValue, None, 675 717 _("Specifies the current state of the control (the value of the field). (varies)"))
