#Boa:Frame:Frame1

import wx
import wx.combo
from wx.lib.mixins.listctrl import CheckListCtrlMixin


def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1PANEL1, wxID_FRAME1STATICTEXT1, 
] = [wx.NewId() for _init_ctrls in range(3)]


class ListBoxComboPopup(wx.combo.ComboPopup):        
    def Create(self, parent):
        self.lb = wx.CheckListBox(choices=['apples', 'bananas', 'cantaloupe'],
              id=-1, name='checkListBox1',
              parent=parent, pos=wx.Point(0, 0), size=wx.Size(147, 63),
              style=0)
        
    def GetControl(self):
        return self.lb


class Frame1(wx.Frame):
    def _init_coll_boxSizer1_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.staticText1, 0, border=0, flag=0)

    def _init_sizers(self):
        # generated method, don't edit
        self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL)

        self._init_coll_boxSizer1_Items(self.boxSizer1)

        self.panel1.SetSizer(self.boxSizer1)

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(326, 123), size=wx.Size(478, 283),
              style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
        self.SetClientSize(wx.Size(470, 249))

        self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
              pos=wx.Point(0, 0), size=wx.Size(470, 249), style=0)

        self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
              label=u'Hit return to pop up a wxCheckListBox, but then 1) how \ncan you use keyboard to select checklist items? and 2) \nHow can you then close the popup via the keyboard?',
              name='staticText1', parent=self.panel1, pos=wx.Point(0, 0),
              size=wx.Size(401, 57), style=0)
        self.staticText1.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self._init_sizers()

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        self.SetUpCheckListBoxPopup()

        self.panel1.Layout()

    def SetUpCheckListBoxPopup(self,):
        self.cc1 = wx.combo.ComboCtrl(self.panel1, size=wx.Size(200,22), 
            value='')  
        self.lb = ListBoxComboPopup()
        self.cc1.SetPopupControl(self.lb)  
        self.cc1.Bind(wx.EVT_TEXT_ENTER, self.OnComboEnter, id=-1)

        self.boxSizer1.AddWindow(self.cc1, 0)

    def OnComboEnter(self, event):
        state = self.cc1.IsPopupShown()
        print "state = ", state
        if state == True:
            self.cc1.HidePopup()
        else:
            self.cc1.ShowPopup()
        self.cc1.ShowPopup()


if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = create(None)
    frame.Show()

    app.MainLoop()
