How to change the combo box lists as my wish

Cliff Wells clifford.wells at comcast.net
Mon Nov 1 20:56:03 EST 2004


On Mon, 2004-11-01 at 13:48 +0800, Austin wrote:
> .................
> self.diskList = ['3','4','5']
> self.cB = wxComboBox(self,-1,wxDefaultPosition,wxDefaultSize,self.diskList)
> .................
> 
> The code is executed initially.
> If i want to update only the diskList, what could i do?

I take it you want the list and the wxComboBox tied together so that
updating the python list automatically updates the wxComboBox.  There is
no built-in way to do this.  However, you could do something like this:

import wx

class CBList(list):
    def __init__(self, combobox):
        list.__init__(self)
        self.combobox = combobox
        
    def __setitem__(self, key, value):
        list.__setitem__(self, key, value)
        self.combobox.SetString(key, value)
        
    def __delitem__(self, key):
        list.__delitem__(self, key)
        self.combobox.Delete(key)
                
    def append(self, value):
        list.append(self, value)
        self.combobox.Append(value)


class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)
        cb = wx.ComboBox(self, -1)
        choices = CBList(cb)

        choices.append('test 1')
        choices.append('test 2')
        choices[0] = 'replace test 1'
        del choices[1]
            
if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = MyFrame(None, -1, 'test')
    frame.Show(True)
    app.MainLoop ()


Regards,
Cliff

-- 
Cliff Wells <clifford.wells at comcast.net>




More information about the Python-list mailing list