masked control, bug!

Hi friends!

I descover some strange bug, that sometime appear sometime not :frowning:
Here a traceback:

Traceback (most recent call last):
聽聽聽File "/home/bashu/work/devel/wxExpress/gui/localdeliverydlg.py", line 405, in OnCreate
聽聽聽聽聽self.maskedCtrl.SetValue(self._deferredValue)
聽聽聽File "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/lib/masked/textctrl.py", line 200, in SetValue
聽聽聽聽聽value, replace_to = self._Paste(value, raise_on_invalid=True, just_return_value=True)
聽聽聽File "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/lib/masked/maskededit.py", line 5712, in _Paste
聽聽聽聽聽valid_paste, replacement_text, replace_to = self._validatePaste(paste_text, sel_start, sel_to, raise_on_invalid)
聽聽聽File "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/lib/masked/maskededit.py", line 5534, in _validatePaste
聽聽聽聽聽raise ValueError('"%s" will not fit into the control "%s"' % (paste_text, self.name))
ValueError: "00:00" will not fit into the control "maskedTextCtrl"

This bug appear for following code:

class LocalDeliveryDialog:

聽聽聽聽聽def __init__(self, parent):
聽聽聽聽聽聽聽聽聽self.resource = xrc.XmlResource('xrc/localdeliverydlg.xrc')

聽聽聽聽聽聽聽聽聽self.dlg = self.resource.LoadDialog(parent, 'LocalDeliveryDlg')

聽聽聽聽聽聽聽聽聽self.dlg.FindWindowByName('wxID_OK').SetId(wx.ID_OK)
聽聽聽聽聽聽聽聽聽self.dlg.FindWindowByName('wxID_CANCEL').SetId(wx.ID_CANCEL)

聽聽聽聽聽聽聽聽聽self.maskedTime = xrc.XRCCTRL(self.dlg, 'maskedTime')

聽聽聽聽聽def GetTime(self):
聽聽聽聽聽聽聽聽聽return self.maskedTime.maskedCtrl.GetValue()

聽聽聽聽聽def SetTime(self, value):
聽聽聽聽聽聽聽聽聽self.maskedTime.SetValue(value)

class MaskedTime(wx.Panel):

聽聽聽聽聽def __init__(self):
聽聽聽聽聽聽聽聽聽p = wx.PrePanel()
聽聽聽聽聽聽聽聽聽# the Create step is done by XRC.
聽聽聽聽聽聽聽聽聽self.PostCreate(p)
聽聽聽聽聽聽聽聽聽self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)

聽聽聽聽聽def SetValue(self, value):
聽聽聽聽聽聽聽聽聽if hasattr(self, 'maskedCtrl'):
聽聽聽聽聽聽聽聽聽聽聽聽聽self.maskedCtrl.SetValue(value)
聽聽聽聽聽聽聽聽聽else:
聽聽聽聽聽聽聽聽聽聽聽聽聽self._deferredValue = value

聽聽聽聽聽def OnCreate(self, event):
聽聽聽聽聽聽聽聽聽self.maskedCtrl = masked.Ctrl(self, wx.ID_ANY,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽autoformat="24HRTIMEHHMM",
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽defaultValue='00:00')
聽聽聽聽聽聽聽聽聽if hasattr(self, '_deferredValue'):
聽聽聽聽聽聽聽聽聽聽聽聽聽self.maskedCtrl.SetValue(self._deferredValue)
聽聽聽聽聽聽聽聽聽聽聽聽聽del self._deferredValue
聽聽聽聽聽聽聽聽聽sizer = wx.BoxSizer(wx.VERTICAL)
聽聽聽聽聽聽聽聽聽sizer.Add(self.maskedCtrl, 0, wx.EXPAND)
聽聽聽聽聽聽聽聽聽self.SetSizerAndFit(sizer)
聽聽聽聽聽聽聽聽聽self.GetParent().Layout()
聽聽聽聽聽聽聽聽聽self.GetParent().Fit()

Looks like GetTime return '00:00' if do not input nothing. I store it in some variable, then try out SetTime(value) (of course after creating dialog subclass) and than above bug may appera or may not :frowning: strange I dont know what to to next? Is this a 'real' bug or I misunderstood something? How I can fix it?

Thanks!

路路路

--
Basil Shubin
Freelance Software Developer

Basil Shubin wrote:

Hi friends!

Looks like GetTime return '00:00' if do not input nothing. I store it in some variable, then try out SetTime(value) (of course after creating dialog subclass) and than above bug may appera or may not :frowning: strange I dont know what to to next? Is this a 'real' bug or I misunderstood something? How I can fix it?

We first need to better understand the problem. Please try to reproduce it in a small runnable application that is as simple as possible, (preferably without XRC just to eliminate the potential complication that it adds to the situation.)

路路路

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