1
我有一個簡單的GtkTreeView
和GtkEntry
用於過濾模型。 當我在輸入中輸入somehing時,software_list
被語言過濾。GtkTreeView過濾和選擇
software_list = [("Firefox", 2002, "C++"),
("Eclipse", 2004, "Java"),
("Netbeans", 1996, "Java"),
("Chrome", 2008, "C++"),
("GCC", 1987, "C"),
("Frostwire", 2004, "Java")]
class TreeViewFilterWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.curr_filter = ''
self.entry = Gtk.Entry()
self.entry.connect('changed', self.on_text_change)
self.software_liststore = Gtk.ListStore(str, int, str)
for software_ref in software_list:
self.software_liststore.append(list(software_ref))
self.filter = self.software_liststore.filter_new()
self.filter.set_visible_func(self.filter_func)
self.treeview = Gtk.TreeView.new_with_model(self.filter)
for i, column_title in enumerate(["Software", "Release Year", "Programming Language"]):
renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(column_title, renderer, text=i)
self.treeview.append_column(column)
self.treeview.get_selection().connect('changed', self.on_row_select)
# packing into boxes, showing components, starting main loop goes here
def on_text_change(self, entry):
self.curr_filter = entry.get_text()
self.filter.refilter()
def filter_func(self, model, iter, data):
if self.curr_filter:
return re.search(re.escape(self.curr_filter), model[iter][2])
else:
return True
的問題是,當我從列表中選擇即「鉻」,然後鍵入「Java」的進入入口,然後,很明顯,「鉻」得到隱藏的,但選擇更改爲一些其他的,隨機行。我更喜歡TreeView取消選擇隱藏的元素,而不是改變選擇。我怎樣才能做到這一點?
這是非常令人費解的代碼。你真的想在這裏完成什麼? 「那麼,顯然,」Chrome「隱藏起來」對我來說並不明顯。 – jcoppens