RichTextCtrl -- Catching copy, cut, paste accelerators for use in overridden methods

41 views
Skip to first unread message

Todd L

unread,
Aug 7, 2018, 12:22:39 AM8/7/18
to wxPython-users
Hi all,

I'm having an issue with RichTextCtrl (RTC) and the Ctrl+C, Ctrl+V, and Ctrl+X accelerators.  Part of the program needs to know when the user copies, pastes, and cuts into the RTC.  The user can do this from a menu, or with the keyboard accelerators.  The most straightforward solution to do this is to override the RTC's functions, within which we do all the custom stuff first, then call e.g. super().Cut().  This works fine when calling from a menu, but the accelerators bypass the override functions for some reason, which leads me to wonder if the RTC's Copy(), Paste(), and Cut() methods are even called when the accelerators are used.  Any ideas on how to catch these accelerators?  I believe this was explored a bit in another post (link below) but never fully resolved.


Sample code provided to demonstrate the issue, try copy/cut/paste from the menu then with accelerators.  Thanks!

sample.py

Robin Dunn

unread,
Aug 7, 2018, 2:55:46 PM8/7/18
to wxPython-users
Those methods are not wrapped with the virtual flag, which means that calls to them from internal C++ code will not be routed through Python overrides. Virtualness is turned off in most cases because it saves a bunch overhead in the wrappers and most of the time it is not needed from Python, but I agree that in this case it makes sense to allow the clipboard-related methods to be overridden. I've added an issue for it.


--
Robin

Todd L

unread,
Aug 7, 2018, 9:08:31 PM8/7/18
to wxPython-users
Great, thanks much!
Reply all
Reply to author
Forward
0 new messages