开发者

Is it possible to make an accordion style check list in wxPython?

开发者 https://www.devze.com 2022-12-31 19:29 出处:网络
I want to make a checklist with a accordion style i开发者_如何学JAVAn a wxPython widget. I know about checklistbox, but I couldn\'t find anything in the official docs concerning it. Has anyone done th

I want to make a checklist with a accordion style i开发者_如何学JAVAn a wxPython widget. I know about checklistbox, but I couldn't find anything in the official docs concerning it. Has anyone done this?


You can use a wx.combo.ComboCtrl which allows any custom popup, and combine this with a wx.CheckListBox.

Here's what is could look like, folded:

Is it possible to make an accordion style check list in wxPython?

and unfolded:

Is it possible to make an accordion style check list in wxPython?

To get this, I started with the ComboCtrl example in the demo, and in the ListCtrlComboPopup list class I replaced ListCtrl with CheckListBox everywhere (and made a few other small changes to make the commands consistent with a CheckListBox control rather than a ListCtrl).


You have to use a wx.PreCheckListBox() for the two part initialization that is required for this.

Here's my implementation. Combine this with a ComboCtrl and you're all set.

import wx
from wx import combo

class checkListComboPopup(combo.ComboPopup):

def __init__(self):
    combo.ComboPopup.__init__(self)
    self.checklist = wx.PreCheckListBox()
    self._value = -1

def Init(self):
    self._value = -1

def Create(self, parent):
    return self.checklist.Create(parent, 1, wx.Point(0,0), wx.DefaultSize)

def GetControl(self):
    return self.checklist

def SetStringValue(self, s):
    pass

def GetStringValue(self):
    if (self._value >= 0):
        return self.checklist.GetItemText(self, self._value)
    else:
        return wx.EmptyString

def OnMouseMove(self, event):
    pass

def GetPreCheckList(self):
    return self.checklist

def OnMouseClick(self, event):
    pass

Two part creation

0

精彩评论

暂无评论...
验证码 换一张
取 消