2017-01-24 2 views
1

У меня есть wx.Dialog, который содержит кнопку и 2 ListBoxes, кнопка findAppBtn выполняет поиск по списку каталогов, а затем отображает результат в actListBox. После выбора каталога по вашему выбору от actListBox следует запустить событие EVT_LISTBOX, которое вызывает actListBoxList. Эта функция делает ls в каталоге и должна отображать файлы, которые она находит в нижнем списке binListBox, используя Append. После выбора элемента из нижнего списка ListBox окно закрывается.wxPython Событие 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() 

EDIT: self.actListBox.Bind(wx.EVT_LISTBOX, self.actListBoxList) исправили проблему.

+1

попробовать self.actListBox.Bind (wx.EVT_LISTBOX, self.actListBoxList) вместо – user2682863

+0

, который работает! добавьте его в качестве ответа, и я соглашусь –

ответ

2

вызова self.Bind (... связывает событие родительского окна, который почему вы не видите событие называют Привязать к ListBox вместо:.

self.actListBox.Bind(wx.EVT_LISTBOX, self.actListBoxList) 
Смежные вопросы