masked.ctrl (error in Windows)

Marcio Moreira wrote:

Dear Friends,

I'm trying the masked text control to deal with dates
in the DD/MM/YYYY format.

The code below works fine in Mac OS X but fails on
Windows 98. The error message says:

NameError: global name 'dbg' is not defined

Windows is running on the most recent version of
wxPython-ansi for Python 2.3.

Any suggestion?
Thanks in advance,
Marcio Moreira

# - - - - - - - - - - - - - - - -
import wx
import wx.lib.masked as masked
import time

class MolduraPrincipal(wx.Frame):
  def __init__(self, *args, **kwds):
    # begin wxGlade: MolduraPrincipal.__init__
    kwds["style"] = wx.DEFAULT_FRAME_STYLE
    wx.Frame.__init__(self, *args, **kwds)
    #
    tempo = time.localtime()
    data_fmt = time.strftime("%d/%m/%Y", tempo)
    ctrl_data = masked.Ctrl(self, -1, data_fmt,
      autoformat="EUDATEDDMMYYYY/")
    #,
    # demo=True, name=autoformat)
    #
    sz = wx.BoxSizer(wx.VERTICAL)
    sz.Add(ctrl_data, 0, 0, 0)
    #
    self.SetSizer(sz)
    self.Layout()

if __name__ == "__main__":
  app = wx.PySimpleApp(0)
  wx.InitAllImageHandlers()
  Moldura = MolduraPrincipal(None, -1, "")
  app.SetTopWindow(Moldura)
  Moldura.Show()
  app.MainLoop()

# - - - - - - - - - - - - - - - - - - -

C:\Faber>python masked-1.pyw
Traceback (most recent call last):
  File "masked-1.pyw", line 28, in ?
    Moldura = MolduraPrincipal(None, -1, "")
  File "masked-1.pyw", line 14, in __init__
    autoformat="EUDATEDDMMYYYY/")
  File
"C:\PYTHON23\Lib\site-packages\wx-2.5.3-msw-ansi\wx\lib\masked\ctrl.py",
line 90, in Ctrl
    return TextCtrl(*args, **kwargs)
  File
"C:\PYTHON23\Lib\site-packages\wx-2.5.3-msw-ansi\wx\lib\masked\textctrl.p
y", line 79, in __init__
    name=name, value=value,**kwargs )
  File
"C:\PYTHON23\Lib\site-packages\wx-2.5.3-msw-ansi\wx\lib\masked\textctrl.p
y", line 88, in _PostInit
    self._SetInitialValue(value)
  File
"C:\PYTHON23\Lib\site-packages\wx-2.5.3-msw-ansi\wx\lib\masked\maskededit
.py", line 2711, in _SetInitialValue
    self.SetValue(value) # use public
(validating) .SetValue()
  File
"C:\PYTHON23\Lib\site-packages\wx-2.5.3-msw-ansi\wx\lib\masked\textctrl.p
y", line 207, in SetValue
    elif self._isDate and not self.IsValid(value) and
self._4digityear:
  File
"C:\PYTHON23\Lib\site-packages\wx-2.5.3-msw-ansi\wx\lib\masked\maskededit
.py", line 4788, in IsValid
    ret = self._CheckValid(value)
  File
"C:\PYTHON23\Lib\site-packages\wx-2.5.3-msw-ansi\wx\lib\masked\maskededit
.py", line 5075, in _CheckValid
    valid = self._validateDate(value)
  File
"C:\PYTHON23\Lib\site-packages\wx-2.5.3-msw-ansi\wx\lib\masked\maskededit
.py", line 5256, in _validateDate
    if valid: dbg('valid date')
NameError: global name 'dbg' is not defined

This is a bug in the version of wx.lib.masked that you are using; there
was a line that was supposed to be commented out, but wasn't. It was
reported earlier, and I have since checked in a fix for this, but it
there hasn't been an official release since.

So, all you have to do until the next official release comes out
is to comment out the offending line in the code, ie.

wx\lib\masked\maskededit.py", line 5256, in _validateDate
< if valid: dbg('valid date')

···

-

## if valid: dbg('valid date')

It's only a debugging statement, and so will not hurt anything.

Regards,
/Will Sadkin
author, lib.masked