dabo Commit Revision 2773 Date: 2007-02-03 16:37:27 -0800 (Sat, 03 Feb 2007) Author: Paul
Changed: U trunk/dabo/ui/uiwx/dEditBox.py A trunk/dabo/ui/uiwx/test/test_dEditBox.py Log: Added the fixes for handling None values to dEditBox, and added a TestCase for dEditBox. Diff: Modified: trunk/dabo/ui/uiwx/dEditBox.py =================================================================== --- trunk/dabo/ui/uiwx/dEditBox.py 2007-02-03 23:39:28 UTC (rev 2772) +++ trunk/dabo/ui/uiwx/dEditBox.py 2007-02-04 00:37:27 UTC (rev 2773) @@ -194,7 +194,20 @@ def _getValue(self): - return super(dEditBox, self)._getValue() + try: + _value = self._value + except AttributeError: + _value = self._value = unicode("") + + # Get the string value as reported by wx, which is the up-to-date + # string value of the control: + strVal = self.GetValue() + + if _value is None: + if strVal == self.Application.NoneDisplay: + # Keep the value None + return None + return strVal def _setValue(self, val): if self._constructed(): @@ -204,9 +217,22 @@ self.SetValue(val) return else: - ret = super(dEditBox, self)._setValue(val) - self.__forceCase() - return ret + dabo.ui.callAfter(self.__forceCase) + + if val is None: + strVal = self.Application.NoneDisplay + else: + strVal = val + _oldVal = self._oldVal = self.Value + + # save the actual value for return by _getValue: + self._value = val + + # Update the display no matter what: + self.SetValue(strVal) + + if type(_oldVal) != type(val) or _oldVal != val: + self._afterValueChanged() else: self._properties["Value"] = val Added: trunk/dabo/ui/uiwx/test/test_dEditBox.py =================================================================== --- trunk/dabo/ui/uiwx/test/test_dEditBox.py 2007-02-03 23:39:28 UTC (rev 2772) +++ trunk/dabo/ui/uiwx/test/test_dEditBox.py 2007-02-04 00:37:27 UTC (rev 2773) @@ -0,0 +1,41 @@ +import datetime +import decimal +import unittest +import dabo +from dabo.lib import getRandomUUID + + +class Test_dEditBox(unittest.TestCase): + def setUp(self): + app = self.app = dabo.dApp(MainFormClass=None) + app.setup() + frm = dabo.ui.dForm(Caption="test_dEditBox") + self.edt = frm.addObject(dabo.ui.dEditBox) + + def tearDown(self): + self.edt = None + self.app = None + + def mockUserInput(self, str_val): + edt = self.edt + edt._gotFocus() + edt.SetValue(str_val) + edt._lostFocus() + + def testValue(self): + edt = self.edt + edt.Value = "This is a string" + self.assertTrue(isinstance(edt.Value, basestring)) + self.assertEqual(edt.Value, "This is a string") + self.mockUserInput("23") + self.assertTrue(isinstance(edt.Value, basestring)) + self.assertEqual(edt.Value, "23") + edt.Value = None + self.assertEqual(edt.Value, None) + self.mockUserInput("hi there") + self.assertEqual(edt.Value, "hi there") + + +if __name__ == "__main__": + suite = unittest.TestLoader().loadTestsFromTestCase(Test_dEditBox) + unittest.TextTestRunner(verbosity=2).run(suite) _______________________________________________ Post Messages to: Dabo-dev@leafe.com Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev