Пример #1
0
    def __init__(self):
        builder = gtk.Builder()
        builder.add_from_file("gmbd.glade")
        self.window = builder.get_object("window")

        self.playlist_panel = builder.get_object("playlist_panel")

        self._setup_playlist_panel()

        self.playlist_panel.connect('row-activated', self.on_playlist_activated)

        notebook = builder.get_object("playlist_notebook")
        self.tabs = TabManager(notebook, Tab)
        
        self.tabs.connect("opentab", self.on_tab_open)
        self.tabs.connect("switchtab", self.on_tab_switch)
        self.tabs.connect("closetab", self.on_tab_closed)
Пример #2
0
class GUI:
    def __init__(self):
        builder = gtk.Builder()
        builder.add_from_file("gmbd.glade")
        self.window = builder.get_object("window")

        self.playlist_panel = builder.get_object("playlist_panel")

        self._setup_playlist_panel()

        self.playlist_panel.connect('row-activated', self.on_playlist_activated)

        notebook = builder.get_object("playlist_notebook")
        self.tabs = TabManager(notebook, Tab)
        
        self.tabs.connect("opentab", self.on_tab_open)
        self.tabs.connect("switchtab", self.on_tab_switch)
        self.tabs.connect("closetab", self.on_tab_closed)


    def _setup_playlist_panel(self):
        config = ConfigParser(dict_type = OrderedDict)
        config.read('data.ini')

        self.treestore = self.playlist_panel.get_model()

        for section_type, section_name in config.items('types'):
            section = self.treestore.append(None, [section_name, section_type, True])
            for id_, name in config.items(section_name):
                self.treestore.append(section, [name, id_, True])
            
            if section_type == "topiclisting":
                results = client.topiclistingdir()
                for node in results.directory.node:
                    self.treestore.append(section, [node.name._text, node.id._text, True])



    def on_playlist_activated(self, treeview, path, treecolumn):
        model = treeview.get_model()
        row_iter = model.get_iter(path)

        if len(path) == 2:
            name = model.get_value(row_iter, 0)
            id_ = model.get_value(row_iter, 1)
            parent_iter = model.iter_parent(row_iter)
            type_ = model.get_value(parent_iter, 1)
            
            self.tabs.switch_to(name, (type_, id_))

    
    def on_tab_open(self, manager, display_name, type_, id_):
        model = self.treestore

        parent_iter = model.get_iter_first()
        while parent_iter:
            if model.get_value(parent_iter, 1) == type_:
                iter_ = model.iter_children(parent_iter)
                while iter_:
                    if model.get_value(iter_, 1) == id_:
                        return
                    iter_ = model.iter_next(iter_)
                
                model.append(parent_iter, [display_name, id_, False])
                                
                break
            parent_iter = model.iter_next(parent_iter)

    def on_tab_switch(self, manager, type_, id_):
        model = self.treestore

        parent_iter = model.get_iter_first()
        while parent_iter:
            if model.get_value(parent_iter, 1) == type_:
                iter_ = model.iter_children(parent_iter)
                while iter_:
                    if model.get_value(iter_, 1) == id_:
                        path = model.get_path(iter_)
                        self.playlist_panel.expand_to_path(path)
                        self.playlist_panel.set_cursor(path)
                        break
                    iter_ = model.iter_next(iter_)      
                break
            parent_iter = model.iter_next(parent_iter)    
    
    
    def on_tab_closed(self, manager, type_, id_):
        model = self.treestore

        parent_iter = model.get_iter_first()
        while parent_iter:
            if model.get_value(parent_iter, 1) == type_:
                iter_ = model.iter_children(parent_iter)
                while iter_:
                    if model.get_value(iter_, 1) == id_:
                        if model.get_value(iter_, 2) == False:
                            model.remove(iter_)
                        break
                    iter_ = model.iter_next(iter_)      
                break
            parent_iter = model.iter_next(parent_iter)