My GUI currently has right-click options (Cut, Copy, Paste)
However, I realize when I right-click over my search bar (wx.SearchCtrl) to try and paste, focus is not set onto the search bar, therefore I cannot paste.
self.panel.Bind(wx.EVT_CONTEXT_MENU, self.OnShowPopup)
def OnShowPopup(self, event):
""" Obtain right-click selection """
pos = event.GetPosition()
pos = self.panel.ScreenToClient(pos)
self.panel.PopupMenu(self.rightClickMenu, pos)
def OnPopupItemSelected(self, event):
""" Display right-click menu """
item = self.rightClickMenu.FindItemById(event.GetId())
text = item.GetText()
elif text == "Paste":
self.OnPaste()
def OnPaste(self, event = None):
""" Paste content from clipboard """
text = self.FindFocus()
if text:
if isinstance(text, wx.TextCtrl):
text.Paste()
Here is my idea: Get the position of mouse when right-clicked. Then use that position to set focus on the Ctrl that holds that position.
Is this possible? Or is there a better solution?
Save the object of where right-clicked was performed, then setFocus after selecting Paste. The reason why event.GetEventObject().SetFocus() does not work is most likely because after selecting Paste from the PopupMenu, the TextCtrl loses focus. So text would not print there