Changeset 3257

Show
Ignore:
Timestamp:
07/17/07 11:39:36 (1 year ago)
Author:
ed
Message:

Added the properties 'Mask' and 'MaskedValue?' to the textbox controls. 'Mask' needs to be set as part of the constructor; if it is, then a MaskedText? control is created, and the mask is used to control the display.

When a masked control is used, Value will return the content of the control without the mask, and MaskedValue? will return the displayed contents (i.e., with the mask).

Changed the internal getter/setter for dPemMixin.Font, as the names conflicted with methods in the masked text control.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/ui/uiwx/dPemMixin.py

    r3248 r3257  
    18351835 
    18361836 
    1837     def _getFont(self): 
     1837    def _getDaboFont(self): 
    18381838        if hasattr(self, "_font"): 
    18391839            v = self._font 
     
    18421842        return v 
    18431843     
    1844     def _setFont(self, val): 
     1844    def _setDaboFont(self, val): 
    18451845        assert isinstance(val, dabo.ui.dFont) 
    18461846        if self._constructed(): 
     
    24662466            _("""Specifies whether the object and children can get user input. (bool)""") ) 
    24672467 
    2468     Font = property(_getFont, _setFont, None, 
     2468    Font = property(_getDaboFont, _setDaboFont, None, 
    24692469            _("Specifies font object for this control. (dFont)") ) 
    24702470     
  • trunk/dabo/ui/uiwx/dTextBox.py

    r3120 r3257  
    33import datetime 
    44import wx 
    5  
    6 import dabo, dabo.ui 
     5import wx.lib.masked as masked 
     6import dabo 
    77if __name__ == "__main__": 
    88    dabo.ui.loadUI("wx") 
     
    1515        self._baseClass = dTextBox 
    1616         
    17         preClass = wx.PreTextCtrl 
     17        msk = self._extractKey((properties, attProperties, kwargs), "Mask") 
     18        if msk is not None: 
     19            kwargs["mask"] = msk 
     20            kwargs["formatcodes"] = "_" 
     21            def _preMask(): 
     22                return wx.lib.masked.TextCtrl 
     23            preClass = wx.lib.masked.TextCtrl 
     24             
     25            dTextBox.__bases__ = (tbm.dTextBoxMixin, masked.TextCtrl) 
     26        else: 
     27            preClass = wx.PreTextCtrl 
     28         
    1829        tbm.dTextBoxMixin.__init__(self, preClass, parent, properties, attProperties,  
    1930                *args, **kwargs) 
     
    3344    class TestBase(dTextBox): 
    3445        def initProperties(self): 
     46            self.SelectOnEntry = True 
    3547            self.super() 
    3648            self.LogEvents = ["ValueChanged",] 
     
    3850        def onValueChanged(self, evt): 
    3951            if self.IsSecret: 
    40                 print "%s changed, but the new value is a secret!" % self.Name 
     52                print "%s changed, but the new value is a secret! " % self.Name, 
    4153            else: 
    42                 print "%s.onValueChanged:" % self.Name, self.Value, type(self.Value) 
    43          
     54                print "%s.onValueChanged:" % self.Name, self.Value, type(self.Value), 
     55            if self.Mask: 
     56                print "Masked Value:", self.MaskedValue 
     57            else: 
     58                print 
    4459 
    4560    class IntText(TestBase): 
     
    7489            self.Value = datetime.datetime.now() 
    7590     
    76     testParms = [IntText, FloatText, StrText, PWText, BoolText, DateText, DateTimeText]          
     91    class MaskedText(TestBase): 
     92        def __init__(self, *args, **kwargs): 
     93            kwargs["Mask"] = "(###) ###-####" 
     94            super(MaskedText, self).__init__(*args, **kwargs) 
     95     
     96    testParms = [IntText, FloatText, StrText, PWText, BoolText, DateText, DateTimeText, MaskedText] 
    7797     
    7898    try: 
  • trunk/dabo/ui/uiwx/dTextBoxMixin.py

    r3235 r3257  
    33import datetime 
    44import wx 
     5import wx.lib.masked as masked 
    56import dabo.lib.dates 
    67 
     
    381382    def __init__(self, preClass, parent, properties=None, attProperties=None, *args, **kwargs): 
    382383        self._dregex = {} 
     384        self._mask = None 
    383385        self._lastDataType = unicode 
    384386         
     
    525527     
    526528    # property get/set functions 
     529    def _getMask(self): 
     530        return self._mask 
     531 
     532    def _setMask(self, val): 
     533        if self._constructed(): 
     534            self._mask = val 
     535            try: 
     536                self.SetMask(val) 
     537            except AttributeError: 
     538                raise TypeError, _("You must initialize the Mask property when the control is constructed.") 
     539        else: 
     540            self._properties["Mask"] = val 
     541 
     542 
     543    def _getMaskedValue(self): 
     544        return self.GetValue() 
     545 
     546 
    527547    def _getPasswordEntry(self): 
    528548        return self._hasWindowStyleFlag(wx.TE_PASSWORD) 
     
    559579        # Get the string value as reported by wx, which is the up-to-date  
    560580        # string value of the control: 
    561         strVal = self.GetValue() 
     581        if isinstance(self, masked.TextCtrl) and hasattr(self, "_template"): 
     582            strVal = self.GetPlainValue() 
     583        else: 
     584            strVal = self.GetValue() 
    562585         
    563586        # Convert the current string value of the control, as entered by the  
     
    637660     
    638661    # Property definitions: 
     662    Mask = property(_getMask, _setMask, None, 
     663            _("Display Mask for the control  (str)")) 
     664     
     665    MaskedValue = property(_getMaskedValue, None, None, 
     666            _("Value of the control, including mask characters, if any. (read-only) (str)")) 
     667     
    639668    PasswordEntry = property(_getPasswordEntry, _setPasswordEntry, None, 
    640669            _("Specifies whether plain-text or asterisks are echoed. (bool)"))