|
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import gtk, gobject
- class Demo(gtk.Window):
- def __init__(self):
- gtk.Window.__init__(self)
- self.connect('destroy', lambda *w: gtk.main_quit())
- self.set_border_width(5)
- self.hbox = gtk.HBox(False, 2)
- self.add(self.hbox)
- self.find_combo_box_entry = FindComboBoxEntry()
- self.hbox.pack_start(self.find_combo_box_entry)
- self.find_button = gtk.Button('_Find', gtk.STOCK_FIND, True)
- self.find_button.connect('clicked', self.get_find_text)
- self.hbox.pack_start(self.find_button)
- self.show_all()
-
- def get_find_text(self, widget):
- keyword = self.find_combo_box_entry.get_child().get_text()
- self.find_combo_box_entry.add_history(keyword)
- print keyword
-
-
- class FindComboBoxEntry(gtk.ComboBoxEntry):
- def __init__(self):
- gtk.ComboBoxEntry.__init__(self)
- self.model = self.__create_model()
- self.set_model(self.model)
-
- def __create_model(self):
- model = gtk.ListStore(str)
- return model
-
- def add_history(self, data):
- model = self.get_model()
- # iter = model.get_iter((0,))
- # print model.get_value(iter, 0)
- model.append([data])
- #self.model.clear()
- self.set_model(model)
- #self.append_text(data)
- def main():
- Demo()
- gtk.main()
- if __name__ == '__main__':
- main()
-
复制代码
理论上更改了模型,然后设置模型,那么视图应该也会被动更新
事实是
def add_history(self, data):
函数无法工作…… |
|