GTK如何为1个Liststore创建3个不同的过滤器

时间:2016-11-25 00:36:30

标签: filter combobox gtk gtkentry

在GTK / Python中,我正在尝试构建一个带节点的接口。

这是photo of my interface

ChronoMap

我创建了一个liststore,我想过滤不同的东西。用户必须做两个动作,首先,他必须在组合框中选择他想要使用的过滤器类型,如果他想按节点的类型,节点的起始名称或其他来过滤。

然后在文本条目中,他决定要查看哪些信息。以节点类型为例。有3种不同类型的节点,节点类型1,节点类型2和节点类型3.作为用户,我只想看到节点类型1,所以我在节点条目中写入1。其实我有问题,这是我的过滤器不起作用。

我首先创建2个列表商店:

    def create_liststore(self):

    if len(self.FdessinCarto.pos) != 0:
                for i,node in enumerate(self.FdessinCarto.pos):
                    self.node_liststore.append([str(node.title),self.controller.model.string_from_numdate(int(node.start_time)),self.controller.model.string_from_numdate(int(node.end_time)),str(node.node_group),str(node.description),str(node.attachment_list)])

    self.edgelist = self.controller.get_edge_list()
    if len(self.edgelist) !=0:
        for i in self.edgelist: 
            edge_prop=self.controller.edge_data(i[0],i[1])
            self.edge_liststore.append([edge_prop['label'],str(i[0].title),str(i[1].title),edge_prop['description'],edge_prop['attachment_list']])        

    #creating the treeview for Node, making it use the filter as a model, and adding the columns
    self.treeviewNode = Gtk.TreeView.new_with_model(self.node_liststore)
    for i, column_title in enumerate(["Name", "Beginning date", "End date", "Type of node", "Description of node","files"]):
        self.Noderenderer = Gtk.CellRendererText()
        self.Noderenderer.set_property("editable", True)
        column = Gtk.TreeViewColumn(column_title, self.Noderenderer, text=i)
        column.set_sort_column_id(0)
        self.treeviewNode.append_column(column)


    #creating the treeview for edge
    self.treeviewEdge = Gtk.TreeView.new_with_model(self.edge_liststore)
    for i, column_title in enumerate(["Name", "Node 1", "Node 2", "Description of edge","file"]):
        self.Edgerenderer = Gtk.CellRendererText()
        self.Edgerenderer.set_property("editable", True)
        column = Gtk.TreeViewColumn(column_title, self.Edgerenderer, text=i)
        column.set_sort_column_id(0)
        self.treeviewEdge.append_column(column)

    self.SWViewListStore.add(self.treeviewNode)
    self.SWEdgeStore.add(self.treeviewEdge)
    self.SWViewListStore.show_all()
    self.SWEdgeStore.show_all()

我有3种不同的过滤器:

    #creating the filtre
    self.node_beginning_date_filter = self.node_liststore.filter_new()
    self.node_end_date_filter = self.node_liststore.filter_new()
    self.node_type_filter = self.node_liststore.filter_new()


    #setting the filter function, note that we're not using the
    self.node_end_date_filter.set_visible_func(self.node_end_date_filter_func)
    self.node_beginning_date_filter.set_visible_func(self.node_beginning_date_filter_func)
    self.node_type_filter.set_visible_func(self.node_type_filter_func)

一旦我更改了我的组合框,它将激活我的功能,它采用了combofilter的类型,然后是组合框的文本:

    def on_entryComboBox_changed(self,widget):
       textComboFilter = self.View.combo_filter.get_active_text()
       print("textComboFilter %s" %textComboFilter)
        if textComboFilter == "Filter by node's beginning date":
            #print("%s language selected!" % textComboFilter)
            self.View.current_filter = textComboFilter
            self.View.node_beginning_date_filter.refilter() 

        if textComboFilter == "Filter by node's end date":
            #print("%s language selected!" % textComboFilter)
            self.View.current_filter = textComboFilter
            self.View.node_end_date_filter.refilter() 

        if textComboFilter == "Filter by type of node":
            #print("%s language selected!" % textComboFilter)
            self.View.current_filter = textComboFilter
            self.View.node_type_filter.refilter() 

它不起作用。

0 个答案:

没有答案