有没有办法覆盖 wx.EditableListBox 编辑按钮动作?

问题描述

我正在尝试实现一个 wx.avd.EditableListBox 版本,其中使用 DirDialog 完成项目编辑(以便管理路径列表)。这是我到目前为止所做的。我确信这是最干净的方式,tbh。 It almost works,but when a directory is selected and the dialog closes,the item in the list is still editable as a string.如何阻止来自 EditableListBox 的项目版本?

编辑:解释问题的一些截图 重新编辑:找出问题所在。这是对 event.Skip()调用删除它可以解决这个问题。

点击这个按钮:

enter image description here

使 apprear 成为一个目录选择器(因为这是我的代码打算做的):

enter image description here

但是在选择一个目录后,列表中的项目作为字符串处于编辑模式,就像在 EditableListBox 中一样:

enter image description here

我想做的是避免这种情况并将其恢复到正常状态,使用在目录对话框中选择的路径:

enter image description here

import wx,wx.adv
import wx.lib.inspection

class EditableDirBox(wx.adv.EditableListBox):
    def __init__(self,parent):
        super().__init__(parent)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED,self.OnSelectLine)
        self.SetStrings([".",".."])
        self.GetEditButton().Bind(wx.EVT_BUTTON,self.OnButtonEdit)
        self.selectedindex=0
        
    def OnButtonEdit(self,event) :
        if self.selectedindex != -1:
            lines = self.GetStrings()
            path = lines[self.selectedindex]
            dialog = wx.DirDialog (None,"Choose input directory","",wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST)

            if dialog.ShowModal() == wx.ID_OK:
                dirname = dialog.GetPath()
                lines[self.selectedindex] = dirname
                self.SetStrings(lines)
        event.Skip()

    def OnSelectLine(self,event) :
        lines=self.GetStrings()
        index = lines.index(event.GetText())
        self.selectedindex = index
        print()
        event.Skip()


app = wx.App(False)
frame = wx.Frame(None,wx.ID_ANY,"Hello World",size=(500,500))
panel = wx.Panel(frame)
sizer = wx.BoxSizer(wx.HORIZONTAL)
panel.SetSizer(sizer)

widget = EditableDirBox(panel)
sizer.Add(widget,flag=wx.ALIGN_CENTER)

frame.Show(True)     # Show the frame.
app.MainLoop()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)