def __init__(self, radio_id, app): super().__init__() self.app = app self.parent = app.radio self.playlists = self.parent.playlists self.connect('button-press-event', self.on_button_pressed) # radio_info contains: # pic, name, radio_id, offset self.radio_id = radio_id self.expanded = False self.box = Gtk.Box() self.box.props.margin_top = 5 self.box.props.margin_bottom = 5 self.add(self.box) self.img = Gtk.Image() self.img_path = Net.get_image(self.playlists[self.radio_id]['pic']) self.small_pix = GdkPixbuf.Pixbuf.new_from_file_at_size(self.img_path, 50, 50) self.big_pix = GdkPixbuf.Pixbuf.new_from_file_at_size(self.img_path, 75, 75) self.img.set_from_pixbuf(self.small_pix) self.box.pack_start(self.img, False, False, 0) box_right = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.box.pack_start(box_right, True, True, 0) radio_name = Gtk.Label( Widgets.short_str(self.playlists[self.radio_id]['name'], 8)) box_right.pack_start(radio_name, True, True, 0) self.label = Gtk.Label(_('song name')) self.label.get_style_context().add_class('info-label') box_right.pack_start(self.label, False, False, 0) self.toolbar = Gtk.Toolbar() self.toolbar.set_style(Gtk.ToolbarStyle.ICONS) self.toolbar.set_show_arrow(False) self.toolbar.set_icon_size(1) box_right.pack_start(self.toolbar, False, False, 0) button_play = Gtk.ToolButton() button_play.set_label(_('Play')) button_play.set_icon_name('media-playback-start-symbolic') button_play.connect('clicked', self.on_button_play_clicked) self.toolbar.insert(button_play, 0) button_delete = Gtk.ToolButton() button_delete.set_label(_('Delete')) button_delete.set_icon_name('user-trash-symbolic') button_delete.connect('clicked', self.on_button_delete_clicked) self.toolbar.insert(button_delete, 1) self.show_all() self.label.hide() self.toolbar.hide() self.init_songs()
def update_label(self): index = self.get_index() radio = self.playlists[index] if radio['curr_song'] > 19: self.label.set_label('Song Name') return song = radio['songs'][radio['curr_song']] self.label.set_label(Widgets.short_str(song['name'], length=12)) Gdk.Window.process_all_updates() self.label.realize()
def update_label(self): if self.playlists[self.radio_id]['curr_song'] > 19: self.label.set_label('Song Name') return if not self.playlists[self.radio_id]['songs']: #self.load_more_songs() return curr_song = self.playlists[self.radio_id]['curr_song'] song = self.playlists[self.radio_id]['songs'][curr_song] self.label.set_label(Widgets.short_str(song['name'], length=12)) Gdk.Window.process_all_updates() self.label.realize()
def first(self): if self.first_show: return self.first_show = True app = self.app # left side panel scrolled_myradio = Gtk.ScrolledWindow() scrolled_myradio.props.hscrollbar_policy = Gtk.PolicyType.NEVER self.pack_start(scrolled_myradio, False, False, 0) # radios selected by user. self.box_myradio = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.box_myradio.props.margin_left = 10 scrolled_myradio.add(self.box_myradio) self.scrolled_radios = Gtk.ScrolledWindow() self.pack_start(self.scrolled_radios, True, True, 0) # pic, name, id, num of listeners, pic_url self.liststore_radios = Gtk.ListStore(GdkPixbuf.Pixbuf, str, int, str, str) iconview_radios = Widgets.IconView(self.liststore_radios) iconview_radios.connect('item_activated', self.on_iconview_radios_item_activated) self.scrolled_radios.add(iconview_radios) self.show_all() nid = 8 page = 0 radios, total_page = Net.get_nodes(nid, page) if total_page == 0: return i = 0 for radio in radios: self.liststore_radios.append([self.app.theme['anonymous'], Widgets.short_str(Widgets.unescape_html(radio['disname'])), int(radio['sourceid'].split(',')[0]), Widgets.unescape_html(radio['info']), radio['pic'], ]) Net.update_liststore_image(self.liststore_radios, i, 0, radio['pic']), i += 1 for radio in self.playlists: radio_item = RadioItem(radio, self.app) self.box_myradio.pack_start(radio_item, False, False, 0) GLib.timeout_add(300000, self.dump_playlists)