dabo Commit
Revision 3712
Date: 2007-11-16 15:51:08 -0800 (Fri, 16 Nov 2007)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/3712
Changed:
U trunk/dabo/ui/uiwx/__init__.py
A trunk/dabo/ui/uiwx/dMaskedTextBox.py
U trunk/dabo/ui/uiwx/dTextBox.py
U trunk/dabo/ui/uiwx/dTextBoxMixin.py
Log:
Refactored out the Masked stuff into a separate subclass of dTextBox.
Diff:
Modified: trunk/dabo/ui/uiwx/__init__.py
===================================================================
--- trunk/dabo/ui/uiwx/__init__.py 2007-11-16 19:15:01 UTC (rev 3711)
+++ trunk/dabo/ui/uiwx/__init__.py 2007-11-16 23:51:08 UTC (rev 3712)
@@ -109,6 +109,7 @@
from dListBox import dListBox
from dListControl import dListControl
from dBaseMenuBar import dBaseMenuBar
+from dMaskedTextBox import dMaskedTextBox
from dMenuBar import dMenuBar
from dMenu import dMenu
from dMenuItem import dMenuItem
Added: trunk/dabo/ui/uiwx/dMaskedTextBox.py
===================================================================
--- trunk/dabo/ui/uiwx/dMaskedTextBox.py (rev 0)
+++ trunk/dabo/ui/uiwx/dMaskedTextBox.py 2007-11-16 23:51:08 UTC (rev
3712)
@@ -0,0 +1,147 @@
+# -*- coding: utf-8 -*-
+import wx
+import wx.lib.masked as masked
+import dabo
+if __name__ == "__main__":
+ dabo.ui.loadUI("wx")
+import dabo.dEvents as dEvents
+from dabo.dLocalize import _
+from dTextBox import dTextBox
+from dabo.ui import makeDynamicProperty
+import dTextBoxMixin as tbm
+
+
+
+class dMaskedTextBox(tbm.dTextBoxMixin, masked.TextCtrl):
+ """ This is a specialized textbox class that supports a Mask property.
The
+ mask determines what characters are allowed in the textbox, and can also
+ include formatting characters that are not part of the control's Value.
+ """
+
+ def __init__(self, parent, properties=None, attProperties=None, *args,
**kwargs):
+ self._baseClass = dMaskedTextBox
+ self._mask = self._extractKey((properties, attProperties,
kwargs), "Mask", "")
+ kwargs["mask"] = self._mask
+ kwargs["formatcodes"] = "_"
+ #kwargs["useFixedWidthFont"] = bool(self._mask)
+ kwargs["useFixedWidthFont"] = True
+
+ preClass = wx.lib.masked.TextCtrl
+ tbm.dTextBoxMixin.__init__(self, preClass, parent, properties,
attProperties,
+ *args, **kwargs)
+
+
+ # property get/set functions
+ def _getMask(self):
+ return self._mask
+
+ def _setMask(self, val):
+ if self._constructed():
+ self._mask = val
+ try:
+ self.SetMask(val)
+ except AttributeError:
+ raise TypeError, _("You must initialize the
Mask property when the control is constructed.")
+ else:
+ self._properties["Mask"] = val
+
+
+ def _getMaskedValue(self):
+ return self.GetValue()
+
+
+ # Property definitions:
+ Mask = property(_getMask, _setMask, None,
+ _("""Display Mask for the control. (str)
+
+ These are the allowed mask characters and their
function:
+ ===============================================
+ Character Function
+ ===============================================
+ # Allow numeric only (0-9)
+ N Allow letters and numbers (0-9)
+ A Allow uppercase letters only
+ a Allow lowercase letters only
+ C Allow any letter, upper or lower
+ X Allow string.letters,
string.punctuation, string.digits
+ & Allow string.punctuation only (doesn't
include all unicode symbols)
+ * Allow any visible character
+ | explicit field boundary (takes no space
in the control; allows mix
+ of adjacent mask characters to
be treated as separate fields,
+ eg: '&|###' means "field 0 =
'&', field 1 = '###'", but there's
+ no fixed characters in between.
+ ===============================================
+ """))
+
+ MaskedValue = property(_getMaskedValue, None, None,
+ _("Value of the control, including mask characters, if
any. (read-only) (str)"))
+
+
+
+
+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")
+
+ sz.append(dabo.ui.dLabel(pnl, Caption="US SSN
Format:"), halign="right")
+ sz.append(dMaskedTextBox(pnl, Mask="###-##-####"), "x")
+
+ sz.append(dabo.ui.dLabel(pnl, Caption="Uppercase
Letters Only:"), halign="right")
+ sz.append(dMaskedTextBox(pnl, Mask="A"*20), "x")
+
+ sz.append(dabo.ui.dLabel(pnl, Caption="Lowercase
Letters Only:"), halign="right")
+ sz.append(dMaskedTextBox(pnl, Mask="a"*20), "x")
+
+ sz.append(dabo.ui.dLabel(pnl, Caption="Letters (any
case) Only:"), halign="right")
+ sz.append(dMaskedTextBox(pnl, Mask="C"*20), "x")
+
+ sz.append(dabo.ui.dLabel(pnl, Caption="Punctuation
Only:"), halign="right")
+ sz.append(dMaskedTextBox(pnl, Mask="&"*20), "x")
+
+ sz.append(dabo.ui.dLabel(pnl, Caption="Letter left;
Numbers right:"), halign="right")
+ sz.append(dMaskedTextBox(pnl, Mask="CCCCCC - ######"),
"x")
+
+ sz.append(dabo.ui.dLabel(pnl, Caption="No Mask:"),
halign="right")
+ sz.append(dMaskedTextBox(pnl, Mask=""), "x")
+ 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.setColExpand(1, True)
+
+ test.Test().runTest(MaskedForm)
Property changes on: trunk/dabo/ui/uiwx/dMaskedTextBox.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/dabo/ui/uiwx/dTextBox.py
===================================================================
--- trunk/dabo/ui/uiwx/dTextBox.py 2007-11-16 19:15:01 UTC (rev 3711)
+++ trunk/dabo/ui/uiwx/dTextBox.py 2007-11-16 23:51:08 UTC (rev 3712)
@@ -2,40 +2,24 @@
import re
import datetime
import wx
-import wx.lib.masked as masked
import dabo
if __name__ == "__main__":
dabo.ui.loadUI("wx")
-
import dTextBoxMixin as tbm
+
+
class dTextBox(tbm.dTextBoxMixin, wx.TextCtrl):
"""Creates a text box for editing one line of string data."""
def __init__(self, parent, properties=None, attProperties=None, *args,
**kwargs):
self._baseClass = dTextBox
+ preClass = wx.PreTextCtrl
- msk = self._extractKey((properties, attProperties, kwargs),
"Mask")
- if msk is not None:
- kwargs["mask"] = msk
- kwargs["formatcodes"] = "_"
- def _preMask():
- return wx.lib.masked.TextCtrl
- preClass = wx.lib.masked.TextCtrl
-
- dTextBox.__bases__ = (tbm.dTextBoxMixin,
masked.TextCtrl)
- else:
- preClass = wx.PreTextCtrl
-
tbm.dTextBoxMixin.__init__(self, preClass, parent, properties,
attProperties,
*args, **kwargs)
-class _dTextBox_test(dTextBox):
- def afterInit(self):
- self.Value = "Dabo rules!"
- self.Size = (200, 20)
-
if __name__ == "__main__":
import test
import datetime
@@ -49,13 +33,9 @@
def onValueChanged(self, evt):
if self.IsSecret:
- print "%s changed, but the new value is a
secret! " % self.Name,
+ print "%s changed, but the new value is a
secret! " % self.Name
else:
- print "%s.onValueChanged:" % self.Name,
self.Value, type(self.Value),
- if self.Mask:
- print "Masked Value:", self.MaskedValue
- else:
- print
+ print "%s.onValueChanged:" % self.Name,
self.Value, type(self.Value)
class IntText(TestBase):
def afterInit(self):
@@ -88,13 +68,8 @@
def afterInit(self):
self.Value = datetime.datetime.now()
- class MaskedText(TestBase):
- def __init__(self, *args, **kwargs):
- kwargs["Mask"] = "(###) ###-####"
- super(MaskedText, self).__init__(*args, **kwargs)
+ testParms = [IntText, FloatText, StrText, PWText, BoolText, DateText,
DateTimeText]
- testParms = [IntText, FloatText, StrText, PWText, BoolText, DateText,
DateTimeText, MaskedText]
-
try:
import mx.DateTime
class MxDateTimeText(TestBase):
Modified: trunk/dabo/ui/uiwx/dTextBoxMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dTextBoxMixin.py 2007-11-16 19:15:01 UTC (rev 3711)
+++ trunk/dabo/ui/uiwx/dTextBoxMixin.py 2007-11-16 23:51:08 UTC (rev 3712)
@@ -389,7 +389,6 @@
class dTextBoxMixin(dTextBoxMixinBase):
def __init__(self, preClass, parent, properties=None,
attProperties=None, *args, **kwargs):
self._dregex = {}
- self._mask = None
self._lastDataType = unicode
dTextBoxMixinBase.__init__(self, preClass, parent, properties,
attProperties, *args, **kwargs)
@@ -535,25 +534,6 @@
return dabo.lib.dates.getTimeFromString(strVal, formats)
- # property get/set functions
- def _getMask(self):
- return self._mask
-
- def _setMask(self, val):
- if self._constructed():
- self._mask = val
- try:
- self.SetMask(val)
- except AttributeError:
- raise TypeError, _("You must initialize the
Mask property when the control is constructed.")
- else:
- self._properties["Mask"] = val
-
-
- def _getMaskedValue(self):
- return self.GetValue()
-
-
def _getPasswordEntry(self):
return self._hasWindowStyleFlag(wx.TE_PASSWORD)
@@ -673,32 +653,6 @@
# Property definitions:
- Mask = property(_getMask, _setMask, None,
- _("""Display Mask for the control. Must be set when the
control is constructed, but may be
- changed afterwards. (str)
-
- These are the allowed mask characters and their
function:
- ===============================================
- Character Function
- ===============================================
- # Allow numeric only (0-9)
- N Allow letters and numbers (0-9)
- A Allow uppercase letters only
- a Allow lowercase letters only
- C Allow any letter, upper or lower
- X Allow string.letters,
string.punctuation, string.digits
- & Allow string.punctuation only (doesn't
include all unicode symbols)
- * Allow any visible character
- | explicit field boundary (takes no space
in the control; allows mix
- of adjacent mask characters to
be treated as separate fields,
- eg: '&|###' means "field 0 =
'&', field 1 = '###'", but there's
- no fixed characters in between.
- ===============================================
- """))
-
- MaskedValue = property(_getMaskedValue, None, None,
- _("Value of the control, including mask characters, if
any. (read-only) (str)"))
-
PasswordEntry = property(_getPasswordEntry, _setPasswordEntry, None,
_("Specifies whether plain-text or asterisks are
echoed. (bool)"))
_______________________________________________
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]