# Copyright (c) 2004-5 Marek Hnilica. All rights reserved. # Provides 'wxComboBoxWithHistory' widget # Distributed under GPL version 2, or (at your option) later import wx class wxComboBoxWithHistory(wx.ComboBox): def __init__(self,parent,MyID=-1,default_value='',choices=[],HistoryLength=10,DeleteDuplicates=1): wx.ComboBox.__init__(self,parent,MyID,default_value,choices=choices) self.Choices=choices self.HistoryLength=HistoryLength self.DeleteDuplicates=DeleteDuplicates def AddToHistory(self,text): if self.DeleteDuplicates: while text in self.Choices: self.Choices.remove(text) self.Choices.insert(0,text) while len(self.Choices)>self.HistoryLength: del self.Choices[self.HistoryLength] while self.GetCount()!=0: self.Delete(0) for i in self.Choices: self.Append(i)