本文介绍了当检查 CheckListCtrlMixin 中的项目时,wxPython 会发出什么事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 CheckListCtrlMixin 让用户为我的应用程序启用和禁用插件.我想在用户选中/取消选中列表中的项目后立即更新我的内部模型.检查项目时,CheckListCtrlMixin 会发出什么事件?

I am using the CheckListCtrlMixin to let a user enable and disable plugins for my application. I would like to update my internal model as soon as the user checks/unchecks an item in the list. What event is emitted by the CheckListCtrlMixin when an item is checked?

class CheckListCtrl(wx.ListCtrl,
                    CheckListCtrlMixin, ListCtrlAutoWidthMixin):
    def __init__(self, parent):
        wx.ListCtrl.__init__(self, parent, -1,
                             style=wx.LC_REPORT | wx.SUNKEN_BORDER)
        CheckListCtrlMixin.__init__(self)
        ListCtrlAutoWidthMixin.__init__(self)

当一个项目被选中或取消选中时,以下都不会发出:

Neither of the following emit when an item is checked or unchecked:

self.pluginlist = CheckListCtrl(win)

... add a bunch of items to the list ...

self.pluginlist.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_item_activated)
self.pluginlist.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_item_selected)

推荐答案

CheckListCtrlMixin 不会发出取消/检查项目的事件.相反,它调用了可覆盖的方法:

CheckListCtrlMixin does not emit an event for un/checking an item. Instead, it calls the overridable method:

def OnCheckItem(self, index, flag):
    "flag is True if the item was checked, False if unchecked"
    pass

要在 CheckListCtrl 类之外绑定"事件",您可以使用:

To 'bind' the 'event' outside your CheckListCtrl class, you can use:

self.pluginlist.OnCheckItem = self.on_check_item

这篇关于当检查 CheckListCtrlMixin 中的项目时,wxPython 会发出什么事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 20:55