LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-10-2011, 01:02 AM   #1
Algis
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Rep: Reputation: 1
Python gtk.TreeView update ListStore


Hi. How can i delete from ListStore or get TreeView iter when i toggle renderer1? Maybe there is another way? Any ideas?

Code:
    def remove_fr_playlist(self, widget):
        TARGETS = [
                   ('MY_TREE_MODEL_ROW', gtk.TARGET_SAME_WIDGET, 0),
                   ('text/plain', 0, 1),
                   ('TEXT', 0, 2),
                   ('STRING', 0, 3),
                  ]
        root = gtk.Window(type=gtk.WINDOW_TOPLEVEL)
        root.set_position(gtk.WIN_POS_CENTER)
        root.set_size_request(800, 600)
        root.set_title("Pašalinti iš grojaraščio")
        root.set_icon_from_file("/usr/share/icons/gnome-colors-common/24x24/apps/stock_alarm.png")
        root.connect("destroy",  lambda w: root.destroy())

        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        list_store = gtk.ListStore(str, bool)

        for item in self.get_playlist():
            parent = list_store.append((item, False))

        view = gtk.TreeView(list_store)

        view.enable_model_drag_source( gtk.gdk.BUTTON1_MASK,
                                                TARGETS,
                                                gtk.gdk.ACTION_DEFAULT|
                                                gtk.gdk.ACTION_MOVE)
        view.enable_model_drag_dest(TARGETS,
                                             gtk.gdk.ACTION_DEFAULT)

        view.connect("drag_data_get", self.drag_data_get_data)
        view.connect("drag_data_received", self.drag_data_received_data)

        renderer = gtk.CellRendererText()
        renderer1 = gtk.CellRendererToggle()
        renderer1.set_property('activatable', True)
        model = list_store

        renderer1.connect( 'toggled', self.del_from_playlist, model, view )

        column0 = gtk.TreeViewColumn("Daina", renderer, text=0)
        column0.set_sort_column_id(0)
        column1 = gtk.TreeViewColumn("Pašalinti", renderer1 )
        column1.set_sort_column_id(0)
        column1.add_attribute( renderer1, "active", 1)

        view.append_column( column1 )
        view.append_column( column0 )

        sw.add(view)
        root.add(sw)
        root.show_all()

    def del_from_playlist( self, cell, path, model, view ):
        model[path][1] = not model[path][1]
        entry = model[path][0].split("'")[0]

        metadataList = []
        result = server.playlist_list_entries()
        result.wait()
        num = 0
        for test in result.value():
                result = server.medialib_get_info(test)
                result.wait()
                value = num, test
                metadataList.append( value )
                num = num + 1
        for pos in metadataList:
                if int(entry) == pos[1]:
                             result = server.playlist_remove_entry(pos[0], defaultpl, None)
                             result.wait()
        model = view.get_selection()
        return
 
Old 04-10-2011, 04:17 AM   #2
Algis
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Original Poster
Rep: Reputation: 1
Too many thoughts. After a break solved in a few minutes.

Code:
    def remove_fr_playlist(self, widget):
        TARGETS = [
                   ('MY_TREE_MODEL_ROW', gtk.TARGET_SAME_WIDGET, 0),
                   ('text/plain', 0, 1),
                   ('TEXT', 0, 2),
                   ('STRING', 0, 3),
                  ]
        root = gtk.Window(type=gtk.WINDOW_TOPLEVEL)
        root.set_position(gtk.WIN_POS_CENTER)
        root.set_size_request(800, 600)
        root.set_title("Pašalinti iš grojaraščio")
        root.set_icon_from_file("/usr/share/icons/gnome-colors-common/24x24/apps/stock_alarm.png")
        root.connect("destroy",  lambda w: root.destroy())

        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        list_store = gtk.ListStore(str, bool)

        for item in self.get_playlist():
            parent = list_store.append((item, False))

        view = gtk.TreeView(list_store)

        view.enable_model_drag_source( gtk.gdk.BUTTON1_MASK,
                                                TARGETS,
                                                gtk.gdk.ACTION_DEFAULT|
                                                gtk.gdk.ACTION_MOVE)
        view.enable_model_drag_dest(TARGETS,
                                             gtk.gdk.ACTION_DEFAULT)

        view.connect("drag_data_get", self.drag_data_get_data)
        view.connect("drag_data_received", self.drag_data_received_data)

        renderer = gtk.CellRendererText()
        renderer1 = gtk.CellRendererToggle()
        renderer1.set_property('activatable', True)

        model = list_store
        renderer1.connect( 'toggled', self.del_from_playlist, model, view,  list_store)

        column0 = gtk.TreeViewColumn("Daina", renderer, text=0)
        column0.set_sort_column_id(0)
        column1 = gtk.TreeViewColumn("Pašalinti", renderer1 )
        column1.set_sort_column_id(0)
        column1.add_attribute( renderer1, "active", 1)

        view.append_column( column1 )
        view.append_column( column0 )

        sw.add(view)
        root.add(sw)
        root.show_all()

    def del_from_playlist( self, cell, path, model, view,  list_store):
        model[path][1] = not model[path][1]
        entry = model[path][0].split("'")[0]

        metadataList = []
        result = server.playlist_list_entries()
        result.wait()
        num = 0
        for test in result.value():
                result = server.medialib_get_info(test)
                result.wait()
                value = num, test
                metadataList.append( value )
                num = num + 1
        for pos in metadataList:
                if int(entry) == pos[1]:
                             result = server.playlist_remove_entry(pos[0], defaultpl, None)
                             result.wait()
        model2 = view.get_model()
        iter = model2.get_iter(path)
        list_store.remove(iter)
        return
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python update - Unable to load GTK2 Python bindings: No module named gtk itpedersen Linux - Software 2 10-03-2008 03:44 AM
regarding gtk treeview swift2008 Programming 0 09-05-2008 12:18 AM
python: can you update the current shell from python? BrianK Programming 4 01-31-2008 12:18 AM
gtk.ListStore - python - retrieving the list values? vharishankar Programming 3 11-30-2006 09:15 PM
WineX, python-gnome, and python-gtk DrD Fedora 0 08-03-2004 12:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration