2

So I'm learning wxPython and to do so I'm working on a text editor. I know that I can intercept a CUT / COPY / PASTE signal generated from a control, such as wx.TextCtrl by binding the equivalent wx.EVT_TEXT_COPY / wx.EVT_TEXT_PASTE / wx.EVT_TEXT_CUT. What I'm having trouble figuring out is how to override say a paste to the clipboard with other text.

For instance I have a wx.ListBox where a user can store clips of text and then select them latter to paste onto the wx.TextCtrl instead of whatever text is on the system clipboard. So basically I'm trying to intercept the paste signal and in lieu of pasting the system clipboard text have it paste the selected line from the wx.ListBox. Is this possible? If so, how would I go about doing this?

4

1 回答 1

2

一个简单的解决方案是不要Skip()在您的wx.EVT_TEXT_PASTE处理程序中使用并手动更新控件,例如:

    textCtrl.Bind(wx.EVT_TEXT_PASTE, self.onPaste)

def onPaste(self, evt):
    #do not use evt.Skip()
    print "PASTE but nothing happens"
    #do some manual update of the control

evt.Skip()将导致传播事件并执行粘贴内容的默认行为。如果没有调用,您会阻止传播,并且您可以替换默认行为。

于 2012-05-10T20:44:28.600 回答