Override context menu of combobox text-entry-field

Sommerforsker <[email protected]>
Newsgroups gmane.comp.python.wxpython
Message-ID <[email protected]>
Hi all,

In an application, I am trying to implement a context menu for various 
actions. 
Simply using "panel.Bind(wx.EVT_CONTEXT_MENU, self.onContext)" works for 
all widgets in my application except for editable ComboBoxes. The 
text-entry-field of the ComboBoxes produces the standard TextCtrl context 
menu when right-clicked, instead of my own. I suspect that the problem 
stems from the ComboBox being both a text-entry and item containing widget, 
as there is no problem overriding the menu of the TextCtrl widget.

Is it possible to override the default text-entry-field context menu?

Please find the attached example.

Best regards,

Sommerforsker

-- 
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/0afe0cb2-1020-45cc-82c4-7433e83a69fdn%40googlegroups.com.
temp2.py (text/plain, 1.9 KB)
import wx


# ----------------------------------------------------------------------
class Example(wx.Frame):
    # ----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, title="Popup Menu Tutorial")
        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(panel, -1, wx.EXPAND | wx.ALL)
        self.SetSizerAndFit(sizer)
        self.SetMinSize((400, 400))

        vBox = wx.BoxSizer(wx.VERTICAL)
        textCtrl = wx.TextCtrl(panel, -1)
        vBox.Add(textCtrl, 0, wx.EXPAND | wx.ALL, 10)
        comboBox = wx.ComboBox(panel, 0, choices=["1", "2"])
        vBox.Add(comboBox, 0, wx.EXPAND | wx.ALL, 10)
        comboBoxRO = wx.ComboBox(panel, 0, choices=["1", "2"], style=wx.CB_READONLY)
        vBox.Add(comboBoxRO, 0, wx.EXPAND | wx.ALL, 10)
        self.button = wx.Button(panel, -1, 'Push me!')
        vBox.Add(self.button, 0, wx.EXPAND | wx.ALL, 10)
        panel.SetSizerAndFit(vBox)

        panel.Bind(wx.EVT_CONTEXT_MENU, self.onContext)

    # ----------------------------------------------------------------------
    def onContext(self, event):
        # only do this part the first time so the events are only bound once
        if not hasattr(self, "popupID1"):
            self.popupID1 = wx.NewId()
            self.Bind(wx.EVT_MENU, self.onPopup, id=self.popupID1)

        # build the menu
        menu = wx.Menu()
        menu.Append(self.popupID1, "ItemOne")

        # show the popup menu
        self.PopupMenu(menu)
        menu.Destroy()

    # ----------------------------------------------------------------------
    def onPopup(self, e):
        print 'menu item clicked'


# ----------------------------------------------------------------------
if __name__ == "__main__":
    app = wx.App()
    frame = Example()
    frame.Show()
    app.MainLoop()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.