Hello,

how i can creat menu in wx.ListCtrl(), for example when i double click in item list, i return menu like for wx.Menu().

Thanks for reply!

So, look in this link: http://www.bankfotek.pl/image/913024.jpeg

I use wx.ListCtrl() and if you double click left ( mouse ) in my list, open new dialog, and if you one click right ( mouse ), i want creat menu like for wx.Menu().

Sorry, my EN is ... ;]

#!/usr/bin/python

# mytaskbaricon.py

import wx

class MyTaskBarIcon(wx.TaskBarIcon):
    def __init__(self, frame):
        wx.TaskBarIcon.__init__(self)

        self.frame = frame
        self.SetIcon(wx.Icon('web.png', wx.BITMAP_TYPE_PNG), 'mytaskbaricon.py')
        self.Bind(wx.EVT_MENU, self.OnTaskBarActivate, id=1)
        self.Bind(wx.EVT_MENU, self.OnTaskBarDeactivate, id=2)
        self.Bind(wx.EVT_MENU, self.OnTaskBarClose, id=3)

    def CreatePopupMenu(self):
        menu = wx.Menu()
        menu.Append(1, 'Show')
        menu.Append(2, 'Hide')
        menu.Append(3, 'Close')
        return menu

    def OnTaskBarClose(self, event):
        self.frame.Close()

    def OnTaskBarActivate(self, event):
        if not self.frame.IsShown():
            self.frame.Show()

    def OnTaskBarDeactivate(self, event):
        if self.frame.IsShown():
            self.frame.Hide()

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, (-1, -1), (290, 280))

        self.tskic = MyTaskBarIcon(self)
        self.Centre()
        self.Bind(wx.EVT_CLOSE, self.OnClose)

    def OnClose(self, event):
        self.tskic.Destroy()
        self.Destroy()

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, 'mytaskbaricon.py')
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

app = MyApp(0)
app.MainLoop()

check, i want creat menu in wx.ListCtrl()

Okey, look - http://www.bankfotek.pl/image/913049.jpeg

my code, fisrt you must bind

self.listctrl.Bind(wx.EVT_RIGHT_DCLICK, self.right_dclick)

def right_dclick(self, event):
          menu = wx.Menu()
 
          menu.Append(-1, 'test')
          menu.Append(-1, 'test')
          menu.Append(-1, 'test')
          menu.Append(-1, 'test')
          menu.Append(-1, 'test')
          menu.Append(-1, 'test')
 
          self.PopupMenu(menu)
 
          menu.Destroy()

when you double click a listctrl the nearest logic menu should be popup menu. Is that what you want?

or you want to build a dynamic propagated menu based on user clicks????

when you double click a listctrl the nearest logic menu should be popup menu. Is that what you want?

yes

but you code does not have any ref. to wxlistctrl????
You must create a listctrl and bind that to your popup menu method. Very simple ;-)

This article has been dead for over six months. Start a new discussion instead.