dabo Commit
Revision 3714
Date: 2007-11-17 09:13:48 -0800 (Sat, 17 Nov 2007)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/3714
Changed:
U trunk/dabo/ui/uiwx/dMaskedTextBox.py
Log:
Added the pre-defined format code to dMaskedTextBox. These provide an easy way
to create controls with common formats. Note: there are still issues with
integrating various data types and these masked controls. Example: assigning a
datetime value to a control that is formatted with one of the date formats will
usually generate an error, as it cannot "figure out" how to format the value
for the control. More work will be needed to integrate Value into this control.
Also, lots of the dPemMixin properties do not work correctly. Again, more work
is needed here.
Diff:
Modified: trunk/dabo/ui/uiwx/dMaskedTextBox.py
===================================================================
--- trunk/dabo/ui/uiwx/dMaskedTextBox.py 2007-11-16 23:52:01 UTC (rev
3713)
+++ trunk/dabo/ui/uiwx/dMaskedTextBox.py 2007-11-17 17:13:48 UTC (rev
3714)
@@ -17,31 +17,103 @@
mask determines what characters are allowed in the textbox, and can also
include formatting characters that are not part of the control's Value.
"""
+ _formatMap = {"phone-us": "USPHONEFULL",
+ "phone-us-ext": "USPHONEFULLEXT",
+ "ssn-us": "USSOCIALSEC",
+ "zip-us": "USZIP",
+ "zipplus4-us": "USZIPPLUS4",
+ "date-us": "USDATEMMDDYYYY/",
+ "date-us-slash": "USDATEMMDDYYYY/",
+ "date-us-dash": "USDATEMMDDYYYY-",
+ "date-us-yy": "USDATEMMDDYY/",
+ "date-eu": "EUDATEDDMMYYYY.",
+ "date-eu-slash": "EUDATEDDMMYYYY/",
+ "date-eu-month": "EUDATEDDMMMYYYY.",
+ "date-eu-month-slash": "EUDATEDDMMMYYYY/",
+ "datetime-us": "USDATETIMEMMDDYYYY/HHMMSS",
+ "datetime-us-dash": "USDATETIMEMMDDYYYY-HHMMSS",
+ "datetime-us-24": "USDATE24HRTIMEMMDDYYYY/HHMMSS",
+ "datetime-us-24-dash": "USDATE24HRTIMEMMDDYYYY-HHMMSS",
+ "datetime-us-nosec": "USDATETIMEMMDDYYYY/HHMM",
+ "datetime-us-dash-nosec": "USDATETIMEMMDDYYYY-HHMM",
+ "datetime-us-24-nosec": "USDATE24HRTIMEMMDDYYYY/HHMM",
+ "datetime-us-24-dash-nosec":
"USDATE24HRTIMEMMDDYYYY-HHMM",
+ "datetime-eu": "EUDATETIMEYYYYMMDD.HHMMSS",
+ "datetime-eu-slash": "EUDATETIMEYYYYMMDD/HHMMSS",
+ "datetime-eu-nosec": "EUDATETIMEYYYYMMDD.HHMM",
+ "datetime-eu-slash-nosec": "EUDATETIMEYYYYMMDD/HHMM",
+ "datetime-eu-24": "EUDATE24HRTIMEYYYYMMDD.HHMMSS",
+ "datetime-eu-24-slash": "EUDATE24HRTIMEYYYYMMDD/HHMMSS",
+ "datetime-eu-24-nosec": "EUDATE24HRTIMEYYYYMMDD.HHMM",
+ "datetime-eu-24-slash-nosec":
"EUDATE24HRTIMEYYYYMMDD/HHMM",
+ "datetime-eu-dmy": "EUDATETIMEDDMMYYYY.HHMMSS",
+ "datetime-eu-dmy-slash": "EUDATETIMEDDMMYYYY/HHMMSS",
+ "datetime-eu-dmy-nosec": "EUDATETIMEDDMMYYYY.HHMM",
+ "datetime-eu-dmy-slash-nosec":
"EUDATETIMEDDMMYYYY/HHMM",
+ "datetime-eu-dmy-24": "EUDATE24HRTIMEDDMMYYYY.HHMMSS",
+ "datetime-eu-dmy-24-slash":
"EUDATE24HRTIMEDDMMYYYY/HHMMSS",
+ "datetime-eu-dmy-24-nosec":
"EUDATE24HRTIMEDDMMYYYY.HHMM",
+ "datetime-eu-dmy-24-slash-nosec":
"EUDATE24HRTIMEDDMMYYYY/HHMM",
+ "time": "TIMEHHMMSS",
+ "time-nosec": "TIMEHHMM",
+ "time-24": "24HRTIMEHHMMSS",
+ "time-24-nosec": "24HRTIMEHHMM",
+ "date-expiration": "EXPDATEMMYY",
+ "email": "EMAIL",
+ "ip": "IPADDR"}
+
def __init__(self, parent, properties=None, attProperties=None, *args,
**kwargs):
self._baseClass = dMaskedTextBox
self._mask = self._extractKey((properties, attProperties,
kwargs), "Mask", "")
+ self._format = self._extractKey((properties, attProperties,
kwargs), "Format", "")
kwargs["mask"] = self._mask
kwargs["formatcodes"] = "_"
+ if self._format:
+ code = self._formatMap.get(self._format.lower(), "")
+ if code:
+ kwargs["autoformat"] = code
+ kwargs["mask"] = ""
#kwargs["useFixedWidthFont"] = bool(self._mask)
- kwargs["useFixedWidthFont"] = True
+ kwargs["useFixedWidthFont"] = False
preClass = wx.lib.masked.TextCtrl
tbm.dTextBoxMixin.__init__(self, preClass, parent, properties,
attProperties,
*args, **kwargs)
+ def getFormats(cls):
+ """Return a list of available format codes."""
+ return cls._formatMap.keys()
+ getFormats = classmethod(getFormats)
+
+
# property get/set functions
+ def _getFormat(self):
+ return self._format
+
+ def _setFormat(self, val):
+ if self._constructed():
+ try:
+ self.SetAutoformat(self._formatMap.get(val))
+ self._format = val
+ except AttributeError:
+ dabo.errorLog.write(_("Invalid Format value:
%s") % val)
+ else:
+ self._properties["Format"] = val
+
+
def _getMask(self):
- return self._mask
+ return self.GetMask()
def _setMask(self, val):
if self._constructed():
- self._mask = val
- try:
+ if self.GetAutoformat() and val:
+ # Cannot have both a mask and a format
+ dabo.errorLog.write(_("Cannot set a Mask when a
Format has been set"))
+ else:
+ self._mask = val
self.SetMask(val)
- except AttributeError:
- raise TypeError, _("You must initialize the
Mask property when the control is constructed.")
else:
self._properties["Mask"] = val
@@ -51,6 +123,22 @@
# Property definitions:
+ Format = property(_getFormat, _setFormat, None,
+ _("""Several pre-defined formats are available. When
you set the Format
+ property, any Mask setting is ignored, and the
specified Format is
+ used instead. The format codes are NOT case-sensitive.
(str)
+
+ Formats are available in several categories:
+ Date (US and European)
+ DateTime (US and European)
+ Time
+ Email
+ IP Address
+ SSN (US)
+ Zip Code (US)
+ Phone (US)
+ """))
+
Mask = property(_getMask, _setMask, None,
_("""Display Mask for the control. (str)
@@ -71,7 +159,9 @@
eg: '&|###' means "field 0 =
'&', field 1 = '###'", but there's
no fixed characters in between.
===============================================
- """))
+
+ Repetitions of the same mask code can be represented by
placing the number
+ of repetitions in curly braces after the code. E.g.:
CCCCCCCC = C{6} """))
MaskedValue = property(_getMaskedValue, None, None,
_("Value of the control, including mask characters, if
any. (read-only) (str)"))
@@ -82,66 +172,56 @@
if __name__ == "__main__":
import test
- class TestBase(dMaskedTextBox):
- def initProperties(self):
- self.SelectOnEntry = True
- super(TestBase, self).initProperties()
- self.LogEvents = ["ValueChanged",]
-
- def onValueChanged(self, evt):
- print "%s.onValueChanged:" % self.Name, self.Value,
type(self.Value),
- print "Masked Value:", self.MaskedValue
-
- class UsPhoneText(TestBase):
- def __init__(self, *args, **kwargs):
- kwargs["Mask"] = "(###) ###-####"
- super(UsPhoneText, self).__init__(*args, **kwargs)
-
- class UsSSNText(TestBase):
- def __init__(self, *args, **kwargs):
- kwargs["Mask"] = "###-##-####"
- super(UsSSNText, self).__init__(*args, **kwargs)
-
- class NoMaskText(TestBase):
- def __init__(self, *args, **kwargs):
- kwargs["Mask"] = ""
- super(NoMaskText, self).__init__(*args, **kwargs)
-
-
class MaskedForm(dabo.ui.dForm):
def afterInit(self):
self.Caption = "dMaskedTextBox"
- pnl = dabo.ui.dPanel(self)
- self.Sizer.append1x(pnl)
- sz = pnl.Sizer = dabo.ui.dGridSizer(MaxCols=2, HGap=3,
VGap=5)
- sz.append(dabo.ui.dLabel(pnl, Caption="US Phone
Format:"), halign="right")
- sz.append(dMaskedTextBox(pnl, Mask="(###) ###-####"),
"x")
+ pnl = dabo.ui.dScrollPanel(self)
+ self.Sizer.append1x(pnl, border=20)
+ sz = pnl.Sizer = dabo.ui.dGridSizer(MaxCols=2, HGap=5,
VGap=5)
- sz.append(dabo.ui.dLabel(pnl, Caption="US SSN
Format:"), halign="right")
- sz.append(dMaskedTextBox(pnl, Mask="###-##-####"), "x")
-
+ lbl = dabo.ui.dLabel(pnl, Caption="Basic Masks")
+ lbl.FontSize += 2
+ sz.append(lbl, colSpan=2, halign="center")
+
sz.append(dabo.ui.dLabel(pnl, Caption="Uppercase
Letters Only:"), halign="right")
- sz.append(dMaskedTextBox(pnl, Mask="A"*20), "x")
+ sz.append(dMaskedTextBox(pnl, Width=240, Mask="A{20}"))
sz.append(dabo.ui.dLabel(pnl, Caption="Lowercase
Letters Only:"), halign="right")
- sz.append(dMaskedTextBox(pnl, Mask="a"*20), "x")
+ sz.append(dMaskedTextBox(pnl, Width=240, Mask="a{20}"))
sz.append(dabo.ui.dLabel(pnl, Caption="Letters (any
case) Only:"), halign="right")
- sz.append(dMaskedTextBox(pnl, Mask="C"*20), "x")
+ sz.append(dMaskedTextBox(pnl, Width=240, Mask="C{20}"))
sz.append(dabo.ui.dLabel(pnl, Caption="Punctuation
Only:"), halign="right")
- sz.append(dMaskedTextBox(pnl, Mask="&"*20), "x")
+ sz.append(dMaskedTextBox(pnl, Width=240, Mask="&{20}"))
sz.append(dabo.ui.dLabel(pnl, Caption="Letter left;
Numbers right:"), halign="right")
- sz.append(dMaskedTextBox(pnl, Mask="CCCCCC - ######"),
"x")
+ sz.append(dMaskedTextBox(pnl, Width=240, Mask="C{6} -
#{6}"))
sz.append(dabo.ui.dLabel(pnl, Caption="No Mask:"),
halign="right")
- sz.append(dMaskedTextBox(pnl, Mask=""), "x")
+ sz.append(dMaskedTextBox(pnl, Width=240, Mask=""))
lbl = dabo.ui.dLabel(pnl, FontItalic=True,
Caption="The 'No Mask' value can never
be valid,\nand will be cleared when the control loses focus.")
lbl.FontSize -= 2
sz.append(lbl, colSpan=2, halign="center")
+ sz.appendSpacer(10, colSpan=2)
+
+ lbl = dabo.ui.dLabel(pnl, Caption="Pre-defined Formats")
+ lbl.FontSize += 2
+ sz.append(lbl, colSpan=2, halign="center")
+
+ fmts = dMaskedTextBox.getFormats()
+ fmts.sort()
+ for fmt in fmts:
+ self.addRow(fmt, pnl)
+
sz.setColExpand(1, True)
+
+
+ def addRow(self, fmt, parent):
+ sz = parent.Sizer
+ sz.append(dabo.ui.dLabel(parent, Caption="%s:" % fmt),
halign="right")
+ sz.append(dMaskedTextBox(parent, Width=240, Format=fmt))
test.Test().runTest(MaskedForm)
_______________________________________________
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/dabo-dev/[EMAIL PROTECTED]