【问题标题】:wxPython ListBox event not firingwxPython ListBox 事件未触发
【发布时间】:2017-06-09 11:56:33
【问题描述】:

我有一个包含一个按钮和 2 个列表框的 wx.Dialog,按钮 findAppBtn 搜索目录列表,然后在 actListBox 中显示结果。从actListBox 中选择您选择的目录应该会触发事件EVT_LISTBOX,它调用actListBoxList。此函数在目录上执行ls,并应使用附加列出它在下部列表框binListBox 中找到的文件。从下方的 ListBox 中选择一个项目后,窗口将关闭。

问题是self.Bind(EVT_LISTBOX, self.actListBoxList) 在选择项目时似乎没有触发。

(也请原谅糟糕的编码,我正在尝试在缩小之前让它工作)

    self.findAppBtn = wx.Button(panel, -1, "Find app")
    self.findAppBtn.SetDefault()
    self.Bind(wx.EVT_BUTTON, self.startConf, self.findAppBtn)
    hBox2.Add(self.findAppBtn, 0, flag=wx.LEFT, border=5)
    vBox.Add(hBox2, flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, border=3)

    self.actListBox = wx.ListBox(panel, choices=[])
    self.Bind(wx.EVT_LISTBOX, self.actListBoxList)
    vBox.Add(self.actListBox, 2, flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, border=3)

    self.binListBox = wx.ListBox(panel, choices=[])
    self.Bind(wx.EVT_LISTBOX, self.binListBoxList)
    vBox.Add(self.binListBox, 2, flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, border=3)

    self.closeBtn = wx.Button(panel, wx.ID_OK)
    hBox4.Add(self.closeBtn, 0, flag=wx.LEFT, border=5)

    vBox.Add(hBox4, 0, flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.BOTTOM, border=5)

    panel.SetSizer(vBox)


def startConf(self,e):
    val = self.cmdTxt.GetValue().replace(" ","\ ")
    path = "/private/"
    aCmd = "find " + path + " -iname '*"+val+"*.app'"
    try:
        s = pxssh.pxssh()
        s.login(sshIP, "root", sshPort, sshPass)
        s.sendline(aCmd)
        s.prompt()
        AP = s.before
        for m in AP.split('\n'):
            if path in m:
                self.actListBox.Append(m.replace(path,"").strip())
        s.logout()
        return path
    except pxssh.ExceptionPxssh as e:
        self.parent.progressBox.AppendText(str(e))


def actListBoxList(self,e):
    #get string from top box selection e.g xxxx-xxxx-xxxx-/myapp.app
    selName = self.actListBox.GetStringSelection() 
    path = "/private/"
    #list all the files in the dir from top box selection
    aCmd = "ls " + path + selName
    try:
        s = pxssh.pxssh()
        s.login(sshIP, "root", sshPort, sshPass)
        s.sendline(aCmd)
        s.prompt()
        ls = s.before
        for file in ls.split('\n'):
            if not file.endswith("/"):
                reg = r"\..*"
                matchObj = re.search(reg, file)
                if not matchObj:
                    self.binListBox.Append(file)
        s.logout()
    except pxssh.ExceptionPxssh as e:
        self.parent.progressBox.AppendText(str(e))

def binListBoxList(self,e):
    binaryName = self.binListBox.GetStringSelection()
    self.Close()

编辑:self.actListBox.Bind(wx.EVT_LISTBOX, self.actListBoxList) 解决了这个问题。

【问题讨论】:

    标签: events listbox wxpython


    【解决方案1】:

    调用 self.Bind(... 将事件绑定到父窗口,这就是为什么您没有看到正在调用的事件。改为绑定到列表框:

    self.actListBox.Bind(wx.EVT_LISTBOX, self.actListBoxList)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 2014-05-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多