Paste and delete bug in wx.lib.intctrl.IntCtrl?

Two issues:

  1. If I paste non-numeric text, such as “max” using the context menu Paste, the non-numeric text is inserted. I think this is incorrect behavior, but worse an exception is raised, as follows:

    Traceback (most recent call last):
    File “C:\Programs\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\intctrl.py”, line 474, in OnText
    value = self.GetValue()
    File “C:\Programs\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\intctrl.py”, line 490, in GetValue
    return self._fromGUI( wx.TextCtrl.GetValue(self) )
    File “C:\Programs\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\intctrl.py”, line 782, in _fromGUI
    return long( value )
    ValueError: invalid literal for long() with base 10: ‘0max’

  2. If I cut or delete the control’s value using the context menu Cut or Delete, an empty string value is left in the control. This is an error because the IntCtrl option allow_none is False.

To reproduce, run the wxPython Demo from the command line and launch the IntCtrl demo. Now perform the operations enumerated above.

Some quick debugging shows that the “overridden” methods Cut() and Paste() are not called, but I’m thinking the original author expected them to be.

This seems like an issue to me. Anyone care to confirm if this is bug? Any suggestions for a work around?

Environment:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Windows XP
wxPython 2.8.12.1

I worked around the issue by disabling the default context menu of the base class, wx.TextCtrl. This reduces functionality somewhat, but at least the illegal behavior has been eliminated. Perhaps there is a better solution. Keystroke commands, such as Ctrl-v, still works.

I still suspect the root problem is that IntCtrl.Cut() and IntCtrl.Paste(), overrides of wx.TextCtrl.Cut() and wx.TextCtrl.Paste(), are supposed to be called to handle events but aren’t. Perhaps because “with wxPython, if a C++ method is called from C++, and it’s been overridden in Python then only the C++ method is called” [OverridingMethods - wxPyWiki].

Following is example of the workaround:

import wx
from wx.lib.intctrl import IntCtrl

class IntCtrlEx(IntCtrl):
def init(self, *args, **kwargs):
IntCtrl.init(self, *args, **kwargs)
self.Bind(wx.EVT_RIGHT_DOWN, self.onRightClick)

def onRightClick(self, event):
    # Gobble event to disable wx.TextCtrl's default context menu, as some
    # menu items (e.g. Paste) can raise unhandled exceptions due to a bug
    # in IntCtrl. Ctrl-V for paste works fine.
    self.SetFocus()

class MyFrame(wx.Frame):
def init(self):
wx.Frame.init(self, None, -1, “Int Ctrl Paste Work Around”)
panel = wx.Panel(self)
self._intctrl = IntCtrlEx(panel)

if name == ‘main’:
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()

···

On Wednesday, May 23, 2012 6:47:36 PM UTC-2:30, Jay wrote:

Two issues:

  1. If I paste non-numeric text, such as “max” using the context menu Paste, the non-numeric text is inserted. I think this is incorrect behavior, but worse an exception is raised, as follows:

    Traceback (most recent call last):
    File “C:\Programs\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\intctrl.py”, line 474, in OnText
    value = self.GetValue()
    File “C:\Programs\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\intctrl.py”, line 490, in GetValue
    return self._fromGUI( wx.TextCtrl.GetValue(self) )
    File “C:\Programs\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\intctrl.py”, line 782, in _fromGUI
    return long( value )
    ValueError: invalid literal for long() with base 10: ‘0max’

  1. If I cut or delete the control’s value using the context menu Cut or Delete, an empty string value is left in the control. This is an error because the IntCtrl option allow_none is False.

To reproduce, run the wxPython Demo from the command line and launch the IntCtrl demo. Now perform the operations enumerated above.

Some quick debugging shows that the “overridden” methods Cut() and Paste() are not called, but I’m thinking the original author expected them to be.

This seems like an issue to me. Anyone care to confirm if this is bug? Any suggestions for a work around?

Environment:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Windows XP
wxPython 2.8.12.1

I think this is a bug. Since no one has disagreed with that conclusion, I will submit a ticket.

···

On Wednesday, May 23, 2012 6:47:36 PM UTC-2:30, Jay wrote:

Two issues:

  1. If I paste non-numeric text, such as “max” using the context menu Paste, the non-numeric text is inserted. I think this is incorrect behavior, but worse an exception is raised, as follows:

    Traceback (most recent call last):
    File “C:\Programs\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\intctrl.py”, line 474, in OnText
    value = self.GetValue()
    File “C:\Programs\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\intctrl.py”, line 490, in GetValue
    return self._fromGUI( wx.TextCtrl.GetValue(self) )
    File “C:\Programs\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\intctrl.py”, line 782, in _fromGUI
    return long( value )
    ValueError: invalid literal for long() with base 10: ‘0max’

  1. If I cut or delete the control’s value using the context menu Cut or Delete, an empty string value is left in the control. This is an error because the IntCtrl option allow_none is False.

To reproduce, run the wxPython Demo from the command line and launch the IntCtrl demo. Now perform the operations enumerated above.

Some quick debugging shows that the “overridden” methods Cut() and Paste() are not called, but I’m thinking the original author expected them to be.

This seems like an issue to me. Anyone care to confirm if this is bug? Any suggestions for a work around?

Environment:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Windows XP
wxPython 2.8.12.1