Найти - Пользователи
Полная версия: Получить индекс измененной ячейки объекта Gtk.ListStore. GTK3
Начало » GUI » Получить индекс измененной ячейки объекта Gtk.ListStore. GTK3
1
kozlo22
Я создал модель Gtk.ListStore c 5ю столбцами.
Необходимо, чтобы в 4 из них можно было вносить изменения.
В примере рассмотрен случай для двух столбцов, один из которых неимзеняемый.
Как добавить возможность редактирвоания нескольких столбцов?
class CellRendererTextWindow(Gtk.Window, Parse):
    def __init__(self):
        Gtk.Window.__init__(self, title="strekoza")
        self.set_default_size(400, 200)
        hb = Gtk.HeaderBar()
        hb.props.show_close_button = True
        hb.props.title = "Strekoza's parser"
        self.set_titlebar(hb)
        self.box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        self.button = Gtk.Button("Get rules")
        self.button.connect("clicked", self.on_click_me_clicked)
        self.box.pack_start(self.button, True, True, 0)
        self.liststore = Gtk.ListStore(str, str, str, str, str)
        treeview = Gtk.TreeView(model=self.liststore)
        renderer_text = Gtk.CellRendererText()
        column_text = Gtk.TreeViewColumn("id", renderer_text, text=0)
        treeview.append_column(column_text)
        renderer_editabletext = Gtk.CellRendererText()
        renderer_editabletext.set_property("editable", True)
        column_editabletext = Gtk.TreeViewColumn("link",
            renderer_editabletext, text=1)
        treeview.append_column(column_editabletext)
        
        column_editabletext = Gtk.TreeViewColumn("ruleLink",
            renderer_editabletext, text=2)
        treeview.append_column(column_editabletext)        
        column_editabletext = Gtk.TreeViewColumn("ruleTitle",
            renderer_editabletext, text=3)
        treeview.append_column(column_editabletext)
        column_editabletext = Gtk.TreeViewColumn("ruleDate",
            renderer_editabletext, text=4)
        treeview.append_column(column_editabletext)
        renderer_editabletext.connect("edited", self.text_edited)
        self.treeiter = self.liststore.append(list(self.getRules())) #вставляет данные из БД
        
        hb.pack_end(self.box)
        
        self.add(treeview)
    def text_edited(self, widget, path, text):
    	self.liststore[path][1] = text # вставляет измененный текст во второй столбец
kozlo22
Решил задачу. Вот быдлокод:
class CellRendererTextWindow(Gtk.Window, Parse):
    def __init__(self):
        Gtk.Window.__init__(self, title="strekoza")
        self.set_default_size(400, 200)
        hb = Gtk.HeaderBar()
        hb.props.show_close_button = True
        hb.props.title = "Strekoza's parser"
        self.set_titlebar(hb)
        self.box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        self.button = Gtk.Button("Get rules")
        self.button.connect("clicked", self.on_click_me_clicked)
        self.box.pack_start(self.button, True, True, 0)
        self.liststore = Gtk.ListStore(str, str, str, str, str)
        treeview = Gtk.TreeView(model=self.liststore)
        renderer_text = Gtk.CellRendererText()
        column_text = Gtk.TreeViewColumn("id", renderer_text, text=0)
        treeview.append_column(column_text)
        renderer_editabletext1 = Gtk.CellRendererText()
        renderer_editabletext1.set_property("editable", True)
        column_editabletext1 = Gtk.TreeViewColumn("link",
            renderer_editabletext1, text=1)
        treeview.append_column(column_editabletext1)
        renderer_editabletext1.connect("edited", self.text_edited1)
        renderer_editabletext2 = Gtk.CellRendererText()
        renderer_editabletext2.set_property("editable", True)
        column_editabletext2 = Gtk.TreeViewColumn("ruleLink",
            renderer_editabletext2, text=2)
        treeview.append_column(column_editabletext2)
        renderer_editabletext2.connect("edited", self.text_edited2)
        renderer_editabletext3 = Gtk.CellRendererText()
        renderer_editabletext3.set_property("editable", True)
        column_editabletext3 = Gtk.TreeViewColumn("ruleTitle",
            renderer_editabletext3, text=3)
        treeview.append_column(column_editabletext3)
        renderer_editabletext3.connect("edited", self.text_edited3)
        renderer_editabletext4 = Gtk.CellRendererText()
        renderer_editabletext4.set_property("editable", True)
        column_editabletext4 = Gtk.TreeViewColumn("ruleDate",
            renderer_editabletext4, text=4)
        treeview.append_column(column_editabletext4)
        renderer_editabletext4.connect("edited", self.text_edited4)
        self.treeiter = self.liststore.append(list(self.getRules())) #вставляет данные из БД
        
        hb.pack_end(self.box)
        
        self.add(treeview)
    def text_edited1(self, widget, path, text):
    	self.liststore[path][1] = text
    def text_edited2(self, widget, path, text):
    	self.liststore[path][2] = text
    def text_edited3(self, widget, path, text):
    	self.liststore[path][3] = text
    def text_edited4(self, widget, path, text):
    	self.liststore[path][4] = text
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB