Springe zum Hauptinhalt

12_treestore.py (Source)

# -*- coding: utf-8 -*-
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
class Handler:
    def on_window_destroy(self, *args):
    def on_button_clicked(self, widget):
        x.color = widget.get_label()
    def on_cellrenderer_note_edited(self, widget, row, edit):
        model, pos = x.obj("selection").get_selected()
        conv_iter = x.obj("treesort").convert_iter_to_child_iter(pos)
class Example:
    def __init__(self):
        self.builder = Gtk.Builder()
        self.obj = self.builder.get_object
        #read data from text file
        with open("12_capsicum.txt") as f:
            data = [line.strip("\n") for line in f]
        colors = set()
        species = set()
        varieties = []
        for line in data:
            variety = line.split(";")
            except IndexError:
        #append lines to 1st treestore
        for s in species:
            counter = 0
            row = self.obj("store").append(None,
                                            [None, None, None, None, 800, None],
            for v in varieties:
                if v[1] == s:
                                             [v[0], v[1], v[2], v[3], 400, None],
                    counter += 1
            self.obj("store").set_value(row, 0, "{} ({})".format(s, counter))
            self.obj("store").set_value(row, 5, counter)
        #append lines to 2nd treestore
        [self.obj("filterstore").append(None, [v[0], v[1], v[2]]) for v in varieties]
        #create buttons in buttonbox
        for c in colors:
            button = Gtk.Button.new_with_label(c)
        self.obj("treesort").set_sort_column_id(5, Gtk.SortType.DESCENDING)
    def color_filter_func(self, model, iter, data):
        if model[iter][2] == self.color:
            return True
            return False
    def main(self):
x = Example()