I have made several changes to the dMaskTextBox (with the help of others).
These changes fixed a bug where the “validRegex” was not being passed to the
parent class. And I think an enhancement.
Coming from the VFP (Visual FoxPro) world I wanted something similar to the
VFP text control. Where I could setup special masks and format codes. While
updating my wxPython (it was long over due) I reviewed the new wxPython demo.
Where I noticed a maskedit control. Anyway, Ed had added it to the Dabo
framework some time ago. When I started working with it I noticed it was not
working with my database as I would have expected. I was getting errors
from the use of decimals. Most of the errors were when I retrieved data from
the database that had just been saved. I saw trouble with each data type
including (decimals, dates, and plain text). I have made changes
to “dTextBoxMixin”, added an attribute, and fixed a bug to get it to work
with databases.
The primary issue with retrieving data had to due with
using “self.UseGetPlain” in dTextBoxMixin. “UseGetPlain” is a method of the
parent (maskededit.py) which is suppose to always return the data in the
masked format and then validates against validRegex if present. However, it
did not always work (I never determine the root cause). Sometimes I would
get “u' 5000'” instead of “u'500.00'” with a masks of “#######.##”. Of
course this failed on the setting of the control “.Value” because of
validRegex fires to validate the paste. I noticed this on decimals data
types often. With char data types I had a few errors (may have been my code)
but decided not check them out because I was able to avoid all the issues
making one small change in dTextBoxMixin. By using the dabo
standard “self.GetValue()” all worked as expected. However, this means I was
saving the data in the masked format. “500.00” was saved as “500.00” and
required a decimal data type field. And this also meant I had to match the
control mask to match the database data type. Normally, all that would be
required was a char varying data type (as the control was designed to use).
But like I said I discovered issues.
But in the end this was a benefit because now I could use a plain or a
decorated (formatted) data storage. This also followed the VFP “Format='R'
property where the data was stored with formating or plain in the table. And
in following the VFP thinking I have added an attribute to allow a choice of
plain or formatted storage = “UseGetPlain”.
Testing has revealed that the control demands careful attention to all the
parameters passed. And it is very dependent on your platform settings. This
is especially true with dates. But I have also found that the date errors I
have run across can be solved using some form of “dabo.settings.dateFormat”
such as "%m/%d/%y".
The control also requires that the developer pay very close attention to how
the Mask and ValidRegex work with each other. As it is very possible to
setup conditions that are legal but make no sense.
In dTextBoxMixin I changed the following:
if isinstance(self, masked.TextCtrl) and hasattr(self, "_template"):
if self.UseGetPlain:
strVal = self.GetPlainValue()
else:
strVal = self.GetValue()
In dMaskedTextBox I set UseGetPlain = False.
############
In dMaskTextBox I changed:
def __init__(self, parent, properties=None, attProperties=None, *args,
**kwargs):
self._baseClass = dMaskedTextBox
self.UseGetPlain = False
self._useGetPlain = self._extractKey((properties,
attProperties,
kwargs), "UseGetPlain", "")
if self._useGetPlain:
self.UseGetPlain = self._useGetPlain
self._mask = self._extractKey((properties, attProperties,
kwargs), "Mask", "")
self._format = self._extractKey((properties, attProperties,
kwargs), "Format", "")
self._validregex = self._extractKey((properties, attProperties,
kwargs), "ValidRegex", "")
self._inputCodes =
self._uniqueCodes(self._extractKey((properties,
attProperties, kwargs),
"InputCodes", "_>"))
kwargs["mask"] = self._mask
kwargs["formatcodes"] = self._inputCodes
kwargs["validRegex"] = self._validregex
if self._format:
code = self._formatMap.get(self._format.lower(), "")
if code:
kwargs["autoformat"] = code
kwargs.pop("mask")
kwargs.pop("formatcodes")
kwargs.pop("validRegex")
kwargs["useFixedWidthFont"] = False
So I'm requesting to make the changes. Ed as suggested not many (if anyone
else is using the control) so I see the changes as minor and unlikely to
effect others.
--
John Fabiani
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]