How to use PreMaskedTextCtrl

Hi All,

Is there an example on how to use MaskedTextCtrl as a subclass in XRC ?

I am trying to create an EmailField class.
I tried wx.PreTextCtrl and wx.lib.masked.PreMaskedTextCtrl but they all failed when I SetValue() to it.

Attached is the wx.PreTextCtrl sample that gives me a list index out of range error.

Thanks in advance
George

TestDialog.xrc (1.87 KB)

TestMask.py (2.8 KB)

George Verdad wrote:

Hi All,

Is there an example on how to use MaskedTextCtrl as a subclass in XRC ?

I am trying to create an EmailField class.
I tried wx.PreTextCtrl and wx.lib.masked.PreMaskedTextCtrl but they all failed when I SetValue() to it.

Attached is the wx.PreTextCtrl sample that gives me a list index out of range error.

PreMaskedTextCtrl already has the code needed to integrate with XRC as a subclass, so just derive your class from that one and let it use the default __init__. If you want to set some properties or whatever when it is initialized then you can override the OnCreate method, just be sure to call the base class version from yours.

class EmailField(masked.PreMaskedTextCtrl):
     def SetValue(self, value):
         print value
         if value is None:
             value = ""
         masked.BaseMaskedTextCtrl.SetValue(self, value)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi Robin,

That did the trick.

For those interested here is the code:

class EmailField(PreMaskedTextCtrl):
def OnCreate(self, event):
if self is event.GetEventObject():
PreMaskedTextCtrl.OnCreate(self, event)
self.SetCtrlParameters(autoformat=“EMAIL”)

def SetValue(self, value):
    if value is None:
        value = ""
    PreMaskedTextCtrl.SetValue(self, value)

Thanks,
George

···

On Sat, Feb 7, 2009 at 12:22 PM, Robin Dunn robin@alldunn.com wrote:

George Verdad wrote:

Hi All,

Is there an example on how to use MaskedTextCtrl as a subclass in XRC ?

I am trying to create an EmailField class.

I tried wx.PreTextCtrl and wx.lib.masked.PreMaskedTextCtrl but they all failed when I SetValue() to it.

Attached is the wx.PreTextCtrl sample that gives me a list index out of range error.

PreMaskedTextCtrl already has the code needed to integrate with XRC as a subclass, so just derive your class from that one and let it use the default init. If you want to set some properties or whatever when it is initialized then you can override the OnCreate method, just be sure to call the base class version from yours.

class EmailField(masked.PreMaskedTextCtrl):

def SetValue(self, value):

    print value

    if value is None:

        value = ""

    masked.BaseMaskedTextCtrl.SetValue(self, value)

Robin Dunn

Software Craftsman

http://wxPython.org Java give you jitters? Relax with wxPython!


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users