class SongSearchUI(DialogBox): def __init__(self): DialogBox.__init__(self, _("Search"), 460, 300, DIALOG_MASK_SINGLE_PAGE, modal=False, window_hint=None, close_callback=self.hide_all) title_label = Label(_("Title:")) self.title_entry = TextEntry("") self.title_entry.set_size(300, 25) self.search_button = Button(_("Search")) self.search_button.connect("clicked", self.search_song) control_box = gtk.HBox(spacing=5) control_box.pack_start(title_label, False, False) control_box.pack_start(self.title_entry, False, False) control_box.pack_start(self.search_button, False, False) scrolled_window = ScrolledWindow(0, 0) scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) self.result_view = ListView() self.result_view.connect("double-click-item", self.double_click_cb) self.result_view.draw_mask = self.get_mask_func(self.result_view) self.result_view.add_titles([_("Title"), _("Artist"), _("Album"), _("Type"), _("Size")]) scrolled_window.add_child(self.result_view) self.prompt_label = Label("") download_button = Button(_("Download")) download_button.connect("clicked", self.download_song) cancel_button = Button(_("Close")) cancel_button.connect("clicked", lambda w: self.hide_all()) self.body_box.set_spacing(5) self.body_box.pack_start(control_box, False, False) self.body_box.pack_start(scrolled_window, True, True) self.left_button_box.set_buttons([self.prompt_label]) self.right_button_box.set_buttons([download_button, cancel_button]) def search_song(self, widget): self.result_view.clear() title = self.title_entry.entry.get_text() if not title.strip(): return self.prompt_label.set_text(_("Now searching")) # widget.set_sensitive(False) utils.ThreadRun(multi_ways_query_song, self.render_song_infos, [title]).start() @post_gui def render_song_infos(self, song_infos): if song_infos: try: items = [QueryInfoItem(song_info) for song_info in song_infos] except Exception, e: print e else: self.result_view.add_items(items) self.prompt_label.set_text(_("Finish!"))
class SearchUI(DialogBox): def __init__(self): DialogBox.__init__( self, _("Lyrics search"), 460, 300, DIALOG_MASK_MULTIPLE_PAGE, close_callback=self.hide_all, modal=False, window_hint=None, skip_taskbar_hint=False) self.artist_entry = InputEntry() self.artist_entry.set_size(130, 23) self.title_entry = InputEntry() self.title_entry.set_size(130, 23) artist_label = Label(_("Artist:")) title_label = Label(_("Title:")) right_align = gtk.Alignment() right_align.set(0, 0, 0, 1) search_button = Button(_("Search")) search_button.connect("clicked", self.search_lyric_cb) info_box = gtk.HBox(spacing=25) control_box = gtk.HBox(spacing=5) title_box = gtk.HBox(spacing=5) title_box.pack_start(title_label, False, False) title_box.pack_start(self.title_entry) artist_box = gtk.HBox(spacing=5) artist_box.pack_start(artist_label, False, False) artist_box.pack_start(self.artist_entry) control_box.pack_start(title_box, False, False) control_box.pack_start(artist_box, False, False) info_box.pack_start(control_box, False, False) info_box.pack_start(search_button, False, False) scrolled_window = ScrolledWindow(0, 0) scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) sort_items = [(lambda item: item.title, cmp), (lambda item: item.artist, cmp)] self.result_view = ListView(sort_items) self.result_view.connect("double-click-item", self.double_click_cb) self.result_view.add_titles([_("Title"), _("Artist")]) self.result_view.draw_mask = self.get_mask_func(self.result_view) scrolled_window.add_child(self.result_view) self.prompt_label = Label("") download_button = Button(_("Download")) download_button.connect("clicked", self.download_lyric_cb) cancel_button = Button(_("Close")) cancel_button.connect("clicked", lambda w: self.hide_all()) info_box_align = gtk.Alignment() info_box_align.set_padding(5, 0, 5, 0) info_box_align.add(info_box) self.body_box.set_spacing(5) self.body_box.pack_start(info_box_align, False, False) self.body_box.pack_start(scrolled_window, True, True) self.left_button_box.set_buttons([self.prompt_label]) self.right_button_box.set_buttons([download_button, cancel_button]) self.lrc_manager = LrcManager() def double_click_cb(self, widget, item, colume, x, y): self.download_lyric_cb(widget) def search_engine(self, artist, title): ttplayer_result = TTPlayer().request(artist, title) self.render_lyrics(ttplayer_result) duomi_result = DUOMI().request(artist, title) self.render_lyrics(duomi_result) soso_result = SOSO().request(artist, title) self.render_lyrics(soso_result, True) def search_lyric_cb(self, widget): self.result_view.clear() artist = self.artist_entry.entry.get_text() title = self.title_entry.entry.get_text() self.prompt_label.set_text(_("Now searching")) if artist == "" and title == "": self.prompt_label.set_text(_("Not found!")) return utils.ThreadLoad(self.search_engine, artist, title).start() @post_gui def render_lyrics(self, result, last=False): '''docs''' if result != None: try: items = [SearchItem(each_info) for each_info in result] except: pass else: self.result_view.add_items(items) self.prompt_label.set_text(_("%d lyrics found") % len(self.result_view.items)) else: if last: if len(self.result_view.items) > 0: self.prompt_label.set_text(_("%d lyrics found") % len(self.result_view.items)) else: self.prompt_label.set_text(_("Not found!")) def download_lyric_cb(self, widget): select_items = self.result_view.select_rows save_filepath = self.lrc_manager.get_lrc_filepath(Player.song) if len(select_items) > 0: self.prompt_label.set_text(_("Downloading lyrics")) item = self.result_view.items[select_items[0]] url = item.get_url() net_encode = item.get_netcode() utils.ThreadRun(utils.download, self.render_download, [url, save_filepath, net_encode]).start() @post_gui def render_download(self, result): if result: Dispatcher.reload_lrc(Player.song) self.prompt_label.set_text(_("File save to %s") % config.get("lyrics", "save_lrc_path")) else: self.prompt_label.set_text(_("Fail to download!"))
items_length = 1000 items = map(lambda index: ListItem( "豆浆油条 测试标题 %04d" % index, "林俊杰 %04d" % index, "10:%02d" % index, ), range(0, items_length)) list_view = ListView( [(lambda item: item.title, cmp), (lambda item: item.artist, cmp), (lambda item: item.length, cmp)]) list_view.set_expand_column(0) list_view.add_titles(["歌名", "歌手", "时间"]) list_view.add_items(items) list_view.connect("double-click-item", lambda listview, item, i, x, y: list_view.set_highlight(item)) # list_view.connect("button-press-item", print_button_press) # list_view.connect("double-click-item", print_double_click) # list_view.connect("single-click-item", print_single_click) # list_view.connect("motion-notify-item", print_motion_notify) scrolled_window.add_child(list_view) # Add volume button. volume_button = VolumeButton(100, 50) volume_frame = gtk.Alignment() volume_frame.set(0.0, 0.5, 0, 0) volume_frame.set_padding(0, 0, 10, 0) volume_frame.add(volume_button)