Hello,
I can’t find what event to catch when the user type CTRL+C, ie. copy the selected text into the clipboard, in addition to catching the Esc key to close the application.
class MyPanel(wx.Panel):
def __init__(self, parent):
super().__init__(parent)
#catch Esc key to close app
self.Bind(wx.EVT_CHAR_HOOK, self.OnKeyUP)
self.text = wx.TextCtrl ( self, value = "blah\r\nblah", style = wx.TE_READONLY | wx.TE_MULTILINE)
#How to get clipboard contents?
#NOTHING self.text.Bind(wx.EVT_TEXT_COPY, self.onCopy)
#NOTHING self.Bind(wx.EVT_TEXT_COPY, self.onCopy)
#BAD text.Bind(wx.EVT_TEXT_COPY, self.onCopy)
main_sizer = wx.BoxSizer(wx.HORIZONTAL)
main_sizer.Add(self.text, proportion=1, flag=wx.ALL | wx.CENTER | wx.EXPAND, border=5)
self.SetSizer(main_sizer)
def onCopy(self, evt):
print("COPY")
# Read some text
text_data = wx.TextDataObject()
if wx.TheClipboard.Open():
success = wx.TheClipboard.GetData(text_data)
wx.TheClipboard.Close()
if success:
print(text_data.GetText())
#What about using a single function to catch CTRL+C and ESc?
def OnKeyUP(self, event):
keyCode = event.GetKeyCode()
if keyCode == wx.WXK_ESCAPE:
#NOTHING self.Close()
#NOT RECOMMENDED sys.exit(0)
self.GetParent().Destroy()
#event.Skip()
Thank you.