Python wx.ListCtrl:如何在EVT\u右下角选择一行?

Python wx.ListCtrl:如何在EVT\u右下角选择一行?,python,wxpython,wxwidgets,Python,Wxpython,Wxwidgets,我正在用wxpython编写一个简单的数据库GUI 为了显示我的数据库条目,我使用了。让我们考虑下面的代码片段: class BookList(wx.ListCtrl): def __init__(self, parent, ID=wx.ID_ANY): wx.ListCtrl.__init__(self, parent, ID) self.InsertColumn(0, 'Title') self.InsertColumn(1, 'Author') #

我正在用wxpython编写一个简单的数据库GUI

为了显示我的数据库条目,我使用了。让我们考虑下面的代码片段:

class BookList(wx.ListCtrl):
  def __init__(self, parent, ID=wx.ID_ANY):
    wx.ListCtrl.__init__(self, parent, ID)

    self.InsertColumn(0, 'Title')
    self.InsertColumn(1, 'Author')

    # set column width ...

    self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)


  def OnRightDown(self, event):
    menu = wx.Menu()
    delete = menu.Append(wx.ID_ANY, 'Delete Item')

    self.Bind(wx.EVT_MENU, self.OnDelete, delete)

    # select row

    self.PopupMenu(menu, event.GetPosition())
在生成菜单之前,我不知道如何选择行

我考虑了两种可能的解决方案:

  • 使用,但我不知道如何获取与我要选择的行对应的
    idx
    参数
  • Trigger
    wx.EVT\u左下
    ,但我不知道如何(甚至是否)实现
  • 我走对了吗?有没有更好的解决办法


    提前感谢。

    我找到了一个解决方案,其中包括我猜到的两种可能的解决方案

    我已跟踪当前选定的行。片段本身就说明了这一点:

    class BookList(wx.ListCtrl):
      def __init__(self, parent, ID=wx.ID_ANY):
        wx.ListCtrl.__init__(self, parent, ID)
    
        self.InsertColumn(0, 'Title')
        self.InsertColumn(1, 'Author')
    
        # set column width ...
    
        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
        self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
    
        # currently selected row
        self.cur = None
    
    
      def OnLeftDown(self, event):
        if self.cur != None:
          self.Select( self.cur, 0) # deselect currently selected item
    
        x,y = event.GetPosition()
        row,flags = self.HitTest( (x,y) )
    
        self.Select(row)
        self.cur = row
    
    
      def OnRightDown(self, event):
        menu = wx.Menu()
        delete = menu.Append(wx.ID_ANY, 'Delete Item')
    
        self.Bind(wx.EVT_MENU, self.OnDelete, delete)
    
        # select row
        self.OnLeftDown(event)
    
        self.PopupMenu(menu, event.GetPosition())