
import  wx
from wx.lib import newevent
import threading

evtStartZoek, EVT_START_ZOEK = newevent.NewEvent()
#---------------------------------------------------------------------------


#---------------------------------------------------------------------------

class TimeInstruction:
    def __init__(self, parent, lagtime, event):
        self.sendEvent = event
        self.parent = parent
        self.t = threading.Timer(lagtime, self.start, ())
        self.t.start()

    def cancel(self):
        self.t.cancel()

    def start(self):
        evt = self.sendEvent()
        wx.PostEvent(self.parent, evt)

class StartZoekDirect(TimeInstruction): pass

class TestFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, pos=(20,20), size=(400,400))
	self.lb = TestListBox(self)

class TestListBox(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)

	self.wxTestInput = wx.TextCtrl(self, -1, pos=(25,25), size = wx.Size(100,25), value='Something')
	self.wxTestInput.Bind(wx.EVT_CHAR, self.OnChar)
	self.Bind(EVT_START_ZOEK, self.bldListSelect)
	self.searchtime = 1

    def OnChar(self, event):
   	self.timedthread = StartZoekDirect(self,self.searchtime,evtStartZoek)
	event.Skip()

    def bldListSelect(self, event):
	Pos = self.wxTestInput.GetPositionTuple()
        sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
                      'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
                      'twelve', 'thirteen', 'fourteen']

	framepos = self.wxTestInput.ClientToScreen(wx.Point(Pos[0],Pos[1]+25))
	self.nwFrame = wx.Frame(self, -1, pos=framepos, size=wx.Size(100,70), style=wx.FRAME_NO_TASKBAR|wx.FRAME_FLOAT_ON_PARENT)
        self.lb1 = wx.ListBox(self.nwFrame, 60, pos=(100, 80), choices=sampleList, style=wx.LB_SINGLE)
        self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.lb1)
        self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, self.lb1)
        self.lb1.Select(3)
        self.lb1.Append("with data", "This one has data");
        self.lb1.SetClientData(2, "This one has data");
	self.nwFrame.Show(True)
	self.wxTestInput.SetFocus()

    def EvtListBox(self, event):
        lb = event.GetEventObject()
        data = lb.GetClientData(lb.GetSelection())

    def EvtListBoxDClick(self, event):
        self.lb1.Delete(self.lb1.GetSelection())


class tst(wx.App):
    def __init__(self):
        wx.App.__init__(self)

    def OnInit(self):
	h = TestFrame()
	h.Show(True)
	return True


if __name__ == '__main__':
    h = tst()
    h.MainLoop()

