Ejemplo n.º 1
0
    def first(self):
        app = self.app
        self.buttonbox = Gtk.Box(spacing=5)
        self.pack_start(self.buttonbox, False, False, 0)
        button_home = Gtk.Button(_('MV'))
        button_home.connect('clicked', self.on_button_home_clicked)
        self.buttonbox.pack_start(button_home, False, False, 0)
        self.label = Gtk.Label('')
        self.buttonbox.pack_start(self.label, False, False, 0)

        # pic, name, artist, album, rid, artistid, albumid, tooltip
        self.liststore_songs = Gtk.ListStore(GdkPixbuf.Pixbuf, str, str, str,
                                             int, int, int, str)
        self.mv_control_box = Widgets.MVControlBox(self.liststore_songs,
                                                   self.app)
        self.buttonbox.pack_end(self.mv_control_box, False, False, 0)

        self.scrolled_nodes = Gtk.ScrolledWindow()
        self.pack_start(self.scrolled_nodes, True, True, 0)
        # logo, name, nid, info, tooltip
        self.liststore_nodes = Gtk.ListStore(GdkPixbuf.Pixbuf, str, int, str,
                                             str)
        iconview_nodes = Widgets.IconView(self.liststore_nodes, tooltip=4)
        iconview_nodes.connect('item_activated',
                               self.on_iconview_nodes_item_activated)
        self.scrolled_nodes.add(iconview_nodes)

        self.scrolled_songs = Gtk.ScrolledWindow()
        self.pack_start(self.scrolled_songs, True, True, 0)
        iconview_songs = Widgets.IconView(self.liststore_songs,
                                          info_pos=2,
                                          tooltip=7)
        iconview_songs.connect('item_activated',
                               self.on_iconview_songs_item_activated)
        self.scrolled_songs.add(iconview_songs)

        self.show_all()
        self.buttonbox.hide()
        self.scrolled_songs.hide()

        nid = 3
        nodes_wrap = Net.get_index_nodes(nid)
        if not nodes_wrap:
            return
        nodes = nodes_wrap['child']
        self.liststore_nodes.clear()
        urls = []
        tree_iters = []
        for node in nodes:
            tree_iter = self.liststore_nodes.append([
                self.app.theme['anonymous'],
                Widgets.unescape(node['disname']),
                int(node['sourceid']),
                Widgets.unescape(node['info']),
                Widgets.set_tooltip(node['disname'], node['info']),
            ])
            tree_iters.append(tree_iter)
            urls.append(node['pic'])
        self.liststore_nodes.timestamp = time.time()
        Net.update_liststore_images(self.liststore_nodes, 0, tree_iters, urls)
Ejemplo n.º 2
0
    def first(self):
        if not self.first_run:
            return
        self.first_run = False

        app = self.app

        home_button = Gtk.Button(_('Artists'))
        home_button.connect('clicked', self.on_home_button_clicked)
        self.buttonbox.pack_start(home_button, False, False, 0)
        self.artist_button = Gtk.Button('')
        self.artist_button.connect('clicked', self.on_artist_button_clicked)
        self.buttonbox.pack_start(self.artist_button, False, False, 0)
        # to show artist name or album name
        self.label = Gtk.Label('')
        self.buttonbox.pack_start(self.label, False, False, 20)

        # control_box for artist's songs
        artist_songs_treeview = Widgets.TreeViewSongs(app)
        self.artist_songs_liststore = artist_songs_treeview.liststore
        self.artist_control_box = Widgets.ControlBox(
            self.artist_songs_liststore, app)
        self.buttonbox.pack_end(self.artist_control_box, False, False, 0)

        # control box for artist's mv
        # pic, name, artist, album, rid, artistid, albumid, tooltip
        # FIXME: check formats column
        self.artist_mv_liststore = Gtk.ListStore(GdkPixbuf.Pixbuf, str, str,
                                                 str, int, int, int, str)
        self.artist_mv_control_box = Widgets.MVControlBox(
            self.artist_mv_liststore, app)
        self.buttonbox.pack_end(self.artist_mv_control_box, False, False, 0)

        # control box for artist's albums
        album_songs_treeview = Widgets.TreeViewSongs(app)
        self.album_songs_liststore = album_songs_treeview.liststore
        self.album_control_box = Widgets.ControlBox(self.album_songs_liststore,
                                                    app)
        self.buttonbox.pack_end(self.album_control_box, False, False, 0)

        # main notebook
        self.notebook = Gtk.Notebook()
        self.notebook.set_show_tabs(False)
        self.pack_start(self.notebook, True, True, 0)

        # Artists tab (tab 0)
        self.artists_tab = Gtk.Box()
        self.notebook.append_page(self.artists_tab, Gtk.Label(_('Artists')))
        #self.pack_start(self.box_artists, True, True, 0)

        # left panel of artists tab
        artists_left_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.artists_tab.pack_start(artists_left_box, False, False, 0)
        # artists categories
        # name, id
        self.cate_liststore = Gtk.ListStore(str, int)
        self.cate_treeview = Gtk.TreeView(model=self.cate_liststore)
        self.cate_treeview.props.headers_visible = False
        name = Gtk.CellRendererText()
        col_name = Gtk.TreeViewColumn('Name', name, text=0)
        self.cate_treeview.append_column(col_name)
        artists_left_box.pack_start(self.cate_treeview, False, False, 0)

        # artists prefix
        # disname, prefix
        self.pref_liststore = Gtk.ListStore(str, str)
        self.pref_combo = Gtk.ComboBox(model=self.pref_liststore)
        cell_name = Gtk.CellRendererText()
        self.pref_combo.pack_start(cell_name, True)
        self.pref_combo.add_attribute(cell_name, 'text', 0)
        self.pref_combo.props.margin_top = 15
        artists_left_box.pack_start(self.pref_combo, False, False, 0)

        # favirote artists
        self.fav_yes_img = Gtk.Image.new_from_icon_name(
            'favorite', Gtk.IconSize.BUTTON)
        self.fav_no_img = Gtk.Image.new_from_icon_name(
            'emblem-favorite-symbolic', Gtk.IconSize.BUTTON)
        fav_artists_btn = Gtk.Button(_('Favorite'))
        fav_artists_btn.props.margin_top = 20
        fav_artists_btn.props.image = self.fav_yes_img
        if not Config.GTK_LE_36:
            fav_artists_btn.props.always_show_image = True
        fav_artists_btn.connect('clicked', self.on_fav_artists_btn_clicked)
        artists_left_box.pack_start(fav_artists_btn, False, False, 0)

        # main window of artists
        self.artists_win = Gtk.ScrolledWindow()
        adjustment = self.artists_win.get_vadjustment()
        adjustment.connect('value-changed', self.on_artists_win_scrolled)
        self.artists_tab.pack_start(self.artists_win, True, True, 0)
        # icon, artist name, artist id, num of songs, tooltip
        self.artists_liststore = Gtk.ListStore(GdkPixbuf.Pixbuf, str, int, str,
                                               str)
        artists_iconview = Widgets.IconView(self.artists_liststore, tooltip=4)
        artists_iconview.connect('item_activated',
                                 self.on_artists_iconview_item_activated)
        self.artists_win.add(artists_iconview)

        # Artist tab (tab 1)
        self.artist_tab = Gtk.Box()
        self.notebook.append_page(self.artist_tab, Gtk.Label(_('Artist')))

        # left panel of artist
        self.artist_buttons = Gtk.Box(spacing=5,
                                      orientation=Gtk.Orientation.VERTICAL)
        self.artist_buttons.props.margin_top = 15
        self.artist_tab.pack_start(self.artist_buttons, False, False, 0)

        self.artist_songs_button = ArtistButton(self, _('Songs'), None, 0)
        self.artist_albums_button = ArtistButton(self, _('Albums'),
                                                 self.artist_songs_button, 1)
        self.artist_mv_button = ArtistButton(self, _('MV'),
                                             self.artist_songs_button, 2)
        self.artist_similar_button = ArtistButton(self, _('Similar'),
                                                  self.artist_songs_button, 3)
        self.artist_info_button = ArtistButton(self, _('Info'),
                                               self.artist_songs_button, 4)

        # Add fav_btn to artist_tab
        fav_curr_artist_btn = Gtk.Button()
        fav_curr_artist_btn.props.margin_top = 15
        fav_curr_artist_btn.props.halign = Gtk.Align.CENTER
        fav_curr_artist_btn.props.image = self.fav_no_img
        if not Config.GTK_LE_36:
            fav_curr_artist_btn.props.always_show_image = True
        fav_curr_artist_btn.set_tooltip_text(_('Add to favorite artists list'))
        fav_curr_artist_btn.connect('clicked',
                                    self.on_fav_curr_artist_btn_clicked)
        self.artist_buttons.pack_start(fav_curr_artist_btn, False, False, 0)
        self.fav_curr_artist_btn = fav_curr_artist_btn

        # main window of artist tab
        self.artist_notebook = Gtk.Notebook()
        self.artist_notebook.set_show_tabs(False)
        self.artist_tab.pack_start(self.artist_notebook, True, True, 0)

        # songs tab for artist (tab 0)
        self.artist_songs_tab = Gtk.ScrolledWindow()
        self.artist_notebook.append_page(self.artist_songs_tab,
                                         Gtk.Label(_('Songs')))
        self.artist_songs_tab.add(artist_songs_treeview)

        # albums tab for artist (tab 1)
        self.artist_albums_tab = Gtk.ScrolledWindow()
        self.artist_notebook.append_page(self.artist_albums_tab,
                                         Gtk.Label(_('Albums')))
        # pic, album, albumid, artist, artistid, info/tooltip
        self.artist_albums_liststore = Gtk.ListStore(GdkPixbuf.Pixbuf, str,
                                                     int, str, int, str)
        artist_albums_iconview = Widgets.IconView(self.artist_albums_liststore,
                                                  tooltip=5)
        artist_albums_iconview.connect(
            'item_activated', self.on_artist_albums_iconview_item_activated)
        self.artist_albums_tab.add(artist_albums_iconview)

        # MVs tab for artist (tab 2)
        self.artist_mv_tab = Gtk.ScrolledWindow()
        self.artist_notebook.append_page(self.artist_mv_tab,
                                         Gtk.Label(_('MV')))
        artist_mv_iconview = Widgets.IconView(self.artist_mv_liststore,
                                              info_pos=2,
                                              tooltip=7)
        artist_mv_iconview.connect('item_activated',
                                   self.on_artist_mv_iconview_item_activated)
        self.artist_mv_tab.add(artist_mv_iconview)

        # Similar tab for artist (tab 3)
        self.artist_similar_tab = Gtk.ScrolledWindow()
        self.artist_notebook.append_page(self.artist_similar_tab,
                                         Gtk.Label(_('Similar')))
        # pic, artist name, artist id, num of songs, tooltip
        self.artist_similar_liststore = Gtk.ListStore(GdkPixbuf.Pixbuf, str,
                                                      int, str, str)
        artist_similar_iconview = Widgets.IconView(
            self.artist_similar_liststore, tooltip=4)
        artist_similar_iconview.connect(
            'item_activated', self.on_artist_similar_iconview_item_activated)
        self.artist_similar_tab.add(artist_similar_iconview)

        # Info tab for artist (tab 4)
        artist_info_tab = Gtk.ScrolledWindow()
        artist_info_tab_vp = Gtk.Viewport()
        artist_info_tab.add(artist_info_tab_vp)
        artist_info_tab.props.margin_left = 20
        artist_info_tab.props.margin_top = 5
        self.artist_notebook.append_page(artist_info_tab, Gtk.Label(_('Info')))
        artist_info_box = Gtk.Box(spacing=10,
                                  orientation=Gtk.Orientation.VERTICAL)
        artist_info_box.props.margin_right = 10
        artist_info_box.props.margin_bottom = 10
        artist_info_tab_vp.add(artist_info_box)

        artist_info_hbox = Gtk.Box(spacing=20)
        artist_info_box.pack_start(artist_info_hbox, False, False, 0)

        self.artist_info_pic = Gtk.Image()
        self.artist_info_pic.set_from_pixbuf(Config.ANONYMOUS_PIXBUF)
        self.artist_info_pic.props.xalign = 0
        self.artist_info_pic.props.yalign = 0
        artist_info_hbox.pack_start(self.artist_info_pic, False, False, 0)
        artist_info_grid = Gtk.Grid()
        artist_info_grid.props.row_spacing = 10
        artist_info_grid.props.column_spacing = 30
        self.artist_info_name = InfoLabel(artist_info_grid, _('Name'), 0, 0)
        self.artist_info_birthday = InfoLabel(artist_info_grid, _('Birthday'),
                                              0, 1)
        self.artist_info_birthplace = InfoLabel(artist_info_grid,
                                                _('Birthplace'), 1, 1)
        self.artist_info_height = InfoLabel(artist_info_grid, _('Height'), 0,
                                            2)
        self.artist_info_weight = InfoLabel(artist_info_grid, _('Weight'), 1,
                                            2)
        self.artist_info_country = InfoLabel(artist_info_grid, _('Country'), 0,
                                             3)
        self.artist_info_language = InfoLabel(artist_info_grid, _('Language'),
                                              1, 3)
        self.artist_info_gender = InfoLabel(artist_info_grid, _('Gender'), 0,
                                            4)
        self.artist_info_constellation = InfoLabel(artist_info_grid,
                                                   _('Constellation'), 1, 4)
        artist_info_hbox.pack_start(artist_info_grid, False, False, 0)

        artist_info_textview = Gtk.TextView()
        self.artist_info_textbuffer = Gtk.TextBuffer()
        artist_info_textview.props.editable = False
        artist_info_textview.props.cursor_visible = False
        artist_info_textview.props.wrap_mode = Gtk.WrapMode.CHAR
        artist_info_textview.set_buffer(self.artist_info_textbuffer)
        artist_info_box.pack_start(artist_info_textview, True, True, 0)

        # Album tab (tab 2)
        album_songs_tab = Gtk.ScrolledWindow()
        self.notebook.append_page(album_songs_tab, Gtk.Label(_('Album')))
        album_songs_tab.add(album_songs_treeview)

        # Favorite artists tab (tab 3)
        fav_artists_tab = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.notebook.append_page(fav_artists_tab, Gtk.Label(_('Favorite')))
        fav_buttons = Gtk.Box(spacing=5)
        fav_artists_tab.pack_start(fav_buttons, False, False, 0)
        fav_main_btn = Gtk.Button(_('Artists'))
        fav_main_btn.connect('clicked', self.on_fav_main_btn_clicked)
        fav_buttons.pack_start(fav_main_btn, False, False, 0)
        fav_label = Gtk.Label(_('Favorite Artists'))
        fav_buttons.pack_start(fav_label, False, False, 0)
        fav_win = Gtk.ScrolledWindow()
        fav_artists_tab.pack_start(fav_win, True, True, 0)
        # icon, artist name, artist id, tooltip
        self.fav_artists_liststore = Gtk.ListStore(GdkPixbuf.Pixbuf, str, int,
                                                   str)
        fav_artists_iconview = Widgets.IconView(self.fav_artists_liststore,
                                                info_pos=None,
                                                tooltip=3)
        fav_artists_iconview.connect(
            'item_activated', self.on_fav_artists_iconview_item_activated)
        fav_win.add(fav_artists_iconview)

        prefs = (
            (_('All'), ''),
            ('A', 'a'),
            ('B', 'b'),
            ('C', 'c'),
            ('D', 'd'),
            ('E', 'e'),
            ('F', 'f'),
            ('G', 'g'),
            ('H', 'h'),
            ('I', 'i'),
            ('J', 'j'),
            ('K', 'k'),
            ('L', 'l'),
            ('M', 'm'),
            ('N', 'n'),
            ('O', 'o'),
            ('P', 'p'),
            ('Q', 'q'),
            ('R', 'r'),
            ('S', 's'),
            ('T', 't'),
            ('U', 'u'),
            ('V', 'v'),
            ('W', 'w'),
            ('X', 'x'),
            ('Y', 'y'),
            ('Z', 'z'),
            ('#', '%26'),
        )
        for pref in prefs:
            self.pref_liststore.append(pref)
        self.pref_combo.set_active(0)
        self.pref_combo.connect('changed', self.on_cate_changed)

        cates = (
            (_('Hot Artists'), 0),
            (_('Chinese Male'), 1),
            (_('Chinese Female'), 2),
            (_('Chinese Band'), 3),
            (_('Japanese Male'), 4),
            (_('Japanese Female'), 5),
            (_('Japanese Band'), 6),
            (_('European Male'), 7),
            (_('European Female'), 8),
            (_('European Band'), 9),
            (_('Others'), 10),
        )
        for cate in cates:
            self.cate_liststore.append(cate)
        selection = self.cate_treeview.get_selection()
        self.cate_treeview.connect('row_activated', self.on_cate_changed)
        selection.connect('changed', self.on_cate_changed)
        selection.select_path(0)

        # load current favorite artists list
        self.load_fav_artists()
        self.show_all()
        self.buttonbox.hide()