I have an IpAddrCtrl
element from wx.lib.masked
in my simple test:
import wx
import wx.lib.masked as masked
class MainWindow(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(500,500))
self.ipaddr1 = masked.IpAddrCtrl(self, -1, style=wx.TE_PROCESS_TAB)
self.grid_ip = wx.FlexGridSizer(cols=2, vgap=10, hgap=10)
self.grid_ip.Add(self.ipaddr1, 0, wx.ALIGN_LEFT)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.grid_ip, 0, wx.ALIGN_LEFT | wx.ALL, border=5)
self.SetSizer(self.sizer)
self.Bind(wx.EVT_TEXT, self.OnIpAddrChange, id=self.ipaddr1.GetId())
self.Show(True)
def OnIpAddrChange(self, event):
print(self.ipaddr1.GetAddress())
print(self.ipaddr1.IsValid())
if __name__ == '__main__':
app = wx.App(False)
frame = MainWindow(None, "IpAddrCtrl sample")
app.MainLoop()
After application starts, I try to insert correct numeric values in my IpAddrCtrl
element, but it falls with following log:
<BaseMaskedTextCtrl: . . . >
False
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/lib/masked/maskededit.py", line 3016, in _OnChar
keep_processing = self._keyhandlers[key](event)
File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/lib/masked/maskededit.py", line 3937, in _OnChangeField
self._AdjustField( pos )
File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/lib/masked/maskededit.py", line 4291, in _AdjustField
newfield = field._AdjustField(slice)
File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/lib/masked/maskededit.py", line 1649, in _AdjustField
intStr = str(long(intStr))
ValueError: invalid literal for long() with base 10: '.'
Here a screencast how does it actually works.
Similar demo from wxPython project causes same problems for me.
My environment: Debian Stretch with Python 2.7.13
, wxPython 3.0.2
and GTK2 2.24.31-2
from official stable repositories.
Any advices? Thanks for the help!
Update:
I try to use same sample on Win32 platform and there are no any problems with IpAddrCtrl
. After some debugging I found out that the difference in GTK/Win versions in additional EVT_TEXT
event call that occurs in IpAddrCtrl
when I try to edit selected text region. That causes unnecessary _OnTextChange
event handler call, that brokes input.
That strange behavior described on wxPython wiki and commented in a sources of base class for IpAddrCtrl
, but currently a have no idea how to fix it.
It's a horrible control, which as far as I can tell, simply doesn't function intuitively at all.
You have to press
back space
,to clear the field, as you enter each segment of the ip address or it gets itself in a complete tizzy.Replace your lines
with
Clearly, it's a function that needs work, as it is
broken
in wxpython 4 as well.