def __init__(self, library, player, pattern_filename): super(SongInfo, self).__init__() self._pattern_filename = pattern_filename self.set_visible_window(False) align = Align(halign=Gtk.Align.START, valign=Gtk.Align.START) label = Gtk.Label() label.set_ellipsize(Pango.EllipsizeMode.MIDDLE) label.set_track_visited_links(False) label.set_selectable(True) align.add(label) label.set_alignment(0.0, 0.0) self._label = label connect_destroy(library, 'changed', self._on_library_changed, player) connect_destroy(player, 'song-started', self._on_song_started) label.connect('populate-popup', self._on_label_popup, player, library) self.connect('button-press-event', self._on_button_press_event, player, library) try: with open(self._pattern_filename, "rb") as h: self._pattern = h.read().strip().decode("utf-8") except (EnvironmentError, UnicodeDecodeError): pass self._compiled = XMLFromMarkupPattern(self._pattern) align.show_all() self.add(align)
def Frame(name, widget): f = Gtk.Frame() f.set_shadow_type(Gtk.ShadowType.NONE) l = Gtk.Label() l.set_markup("<u><b>%s</b></u>" % name) f.set_label_widget(l) a = Align(top=3, left=12) f.add(a) a.add(widget) return f
def pack(self, songpane): self._main_box.pack1(self, True, False) self._rh_box = rhbox = Gtk.VBox(spacing=6) align = Align(self._sb_box, left=0, right=6, top=6) rhbox.pack_start(align, False, True, 0) rhbox.pack_start(songpane, True, True, 0) self._main_box.pack2(rhbox, True, False) rhbox.show() align.show_all() return self._main_box
def Frame(name, widget): def hx(value): return hex(int(value * 255))[2:] f = Gtk.Frame() qltk.add_css(f, '* {opacity: 0.9}') l = Gtk.Label() l.set_markup(util.escape(name)) qltk.add_css(l, " * {opacity: 0.6; padding: 0px 2px;}") f.set_label_widget(l) a = Align(top=6, left=12, bottom=6, right=6) f.add(a) a.add(widget) return f
def __configure_buttons(self, library): new_pl = qltk.Button(_("_New"), Icons.DOCUMENT_NEW, Gtk.IconSize.MENU) new_pl.connect('clicked', self.__new_playlist, library) import_pl = qltk.Button(_("_Import"), Icons.LIST_ADD, Gtk.IconSize.MENU) import_pl.connect('clicked', self.__import, library) hb = Gtk.HBox(spacing=6) hb.set_homogeneous(False) hb.pack_start(new_pl, True, True, 0) hb.pack_start(import_pl, True, True, 0) hb2 = Gtk.HBox(spacing=0) hb2.pack_start(hb, True, True, 0) hb2.pack_start(PreferencesButton(self), False, False, 6) self.pack_start(Align(hb2, left=3, bottom=3), False, False, 0)
def __init__(self, parent, player, library): super(TopBar, self).__init__() # play controls control_item = Gtk.ToolItem() self.insert(control_item, 0) t = PlayControls(player, library.librarian) self.volume = t.volume # only restore the volume in case it is managed locally, otherwise # this could affect the system volume if not player.has_external_volume: player.volume = config.getfloat("memory", "volume") self.volume.connect("value-changed", self._on_volume_changed) control_item.add(t) self.insert(Gtk.SeparatorToolItem(), 1) info_item = Gtk.ToolItem() self.insert(info_item, 2) info_item.set_expand(True) box = Gtk.Box(spacing=6) info_item.add(box) qltk.add_css(self, "GtkToolbar {padding: 3px;}") # song text info_pattern_path = os.path.join(const.USERDIR, "songinfo") text = SongInfo(library.librarian, player, info_pattern_path) box.pack_start(Align(text, border=3), True, True, 0) # cover image self.image = CoverImage(resize=True) connect_destroy(player, 'song-started', self.__new_song) # FIXME: makes testing easier if app.cover_manager: connect_destroy(app.cover_manager, 'cover-changed', self.__song_art_changed, library) self.image.props.margin = 2 box.pack_start(self.image, False, True, 0) for child in self.get_children(): child.show_all() context = self.get_style_context() context.add_class("primary-toolbar")
def __init__(self, paths): super().__init__(label=_("Files:")) self.set_resize_toplevel(True) paths = [fsn2text(unexpand(p)) for p in paths] lab = Gtk.Label(label="\n".join(paths)) lab.set_alignment(0.0, 0.0) lab.set_selectable(True) win = Gtk.ScrolledWindow() win.add_with_viewport(Align(lab, border=6)) win.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) win.set_shadow_type(Gtk.ShadowType.ETCHED_OUT) win.set_size_request(-1, 100) self.add(win) win.show_all()
def _create_searchbar(self, library): completion = LibraryTagCompletion(library) self.accelerators = Gtk.AccelGroup() search = SearchBarBox(completion=completion, validator=SoundcloudQuery.validator, accel_group=self.accelerators, timeout=3000) self.__searchbar = search search.connect('query-changed', self.__query_changed) def focus(widget, *args): qltk.get_top_parent(widget).songlist.grab_focus() search.connect('focus-out', focus) self._searchbox = Align(search, left=0, right=6, top=6) self._searchbox.show_all()
def __init__(self, library): super(PanedBrowser, self).__init__() self._register_instance() self._filter = lambda s: False self._library = library self.set_spacing(6) self.set_orientation(Gtk.Orientation.VERTICAL) completion = LibraryTagCompletion(library.librarian) self.accelerators = Gtk.AccelGroup() sbb = SearchBarBox(completion=completion, accel_group=self.accelerators) sbb.connect('query-changed', self.__text_parse) sbb.connect('focus-out', self.__focus) sbb.connect('key-press-event', self.__sb_key_pressed) self._sb_box = sbb align = Align(sbb, left=6, right=6, top=6) self.pack_start(align, False, True, 0) keyval, mod = Gtk.accelerator_parse("<Primary>Home") self.accelerators.connect(keyval, mod, 0, self.__select_all) select = Gtk.Button(label=_("Select _All"), use_underline=True) select.connect('clicked', self.__select_all) sbb.pack_start(select, False, True, 0) prefs = PreferencesButton(self) sbb.pack_start(prefs, False, True, 0) connect_destroy(library, 'changed', self.__changed) connect_destroy(library, 'added', self.__added) connect_destroy(library, 'removed', self.__removed) self.connect('destroy', self.__destroy) # contains the panes and the song list self.main_box = qltk.ConfigRPaned("browsers", "panedbrowser_pos", 0.4) self.pack_start(self.main_box, True, True, 0) self.multi_paned = ConfigMultiRHPaned("browsers", "panedbrowser_pane_widths") self.refresh_panes() for child in self.get_children(): child.show_all()
def __init__(self, task_controller): super().__init__() self.__dirty = False self.set_spacing(12) self.task_controller = task_controller self.task_controller.parent = self self.default_label = Gtk.Label(selectable=True) self.default_label.set_ellipsize(Pango.EllipsizeMode.END) self.pack_start(Align(self.default_label, halign=Gtk.Align.END), True, True, 0) self.task_widget = TaskWidget(task_controller) self.pack_start(self.task_widget, True, True, 0) self.show_all() self.set_no_show_all(True) self.__set_shown('default') self.connect("destroy", self.__destroy)
def __init__(self, library): super(AudioFeeds, self).__init__(spacing=6) self.set_orientation(Gtk.Orientation.VERTICAL) self.__view = view = AllTreeView() self.__render = render = Gtk.CellRendererText() render.set_property('ellipsize', Pango.EllipsizeMode.END) col = Gtk.TreeViewColumn("Audio Feeds", render) col.set_cell_data_func(render, AudioFeeds.cell_data) view.append_column(col) view.set_model(self.__feeds) view.set_rules_hint(True) view.set_headers_visible(False) swin = ScrolledWindow() swin.set_shadow_type(Gtk.ShadowType.IN) swin.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) swin.add(view) self.pack_start(swin, True, True, 0) new = Button(_("_New"), Icons.LIST_ADD, Gtk.IconSize.MENU) new.connect('clicked', self.__new_feed) view.get_selection().connect('changed', self.__changed) view.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE) view.connect('popup-menu', self.__popup_menu) targets = [ ("text/uri-list", 0, DND_URI_LIST), ("text/x-moz-url", 0, DND_MOZ_URL) ] targets = [Gtk.TargetEntry.new(*t) for t in targets] view.drag_dest_set(Gtk.DestDefaults.ALL, targets, Gdk.DragAction.COPY) view.connect('drag-data-received', self.__drag_data_received) view.connect('drag-motion', self.__drag_motion) view.connect('drag-leave', self.__drag_leave) connect_obj(self, 'destroy', self.__save, view) self.pack_start(Align(new, left=3, bottom=3), False, True, 0) for child in self.get_children(): child.show_all()
def __init__(self, task_controller): super(StatusBar, self).__init__() self.__dirty = False self.set_spacing(12) self.task_controller = task_controller self.task_controller.parent = self self.default_label = Gtk.Label(selectable=True) self.default_label.set_ellipsize(Pango.EllipsizeMode.END) self.pack_start(Align(self.default_label, halign=Gtk.Align.END), True, True, 0) self.task_widget = TaskWidget(task_controller) self.pack_start(self.task_widget, True, True, 0) # The history button will eventually hold the full list of running # tasks, as well as the list of previous notifications. #self.history_btn = Gtk.Button() #self.pack_start(self.history_btn, False, True, 0) self.show_all() self.set_no_show_all(True) self.__set_shown('default') self.connect("destroy", self.__destroy)
def __init__(self, parent, song): super().__init__() self.song = song self.dirname = song("~dirname") self.main_win = parent self.data_cache = [] self.current_data = None self.current_pixbuf = None self.image = Gtk.Image() self.button = Button(_("_Save"), Icons.DOCUMENT_SAVE_AS) self.button.set_sensitive(False) self.button.connect('clicked', self.__save) close_button = Button(_("_Close"), Icons.WINDOW_CLOSE) close_button.connect('clicked', lambda x: self.main_win.destroy()) self.window_fit = self.ConfigCheckButton(_('Fit image to _window'), 'fit', True) self.window_fit.connect('toggled', self.__scale_pixbuf) self.name_combo = Gtk.ComboBoxText() self.name_combo.set_tooltip_text( _("See '[plugins] cover_filenames' config entry " + "for image filename strings")) self.cmd = qltk.entry.ValidatingEntry(iscommand) # Both labels label_open = Gtk.Label(label=_('_Program:')) label_open.set_use_underline(True) label_open.set_mnemonic_widget(self.cmd) label_open.set_justify(Gtk.Justification.LEFT) self.open_check = self.ConfigCheckButton(_('_Edit image after saving'), 'edit', False) label_name = Gtk.Label(label=_('File_name:'), use_underline=True) label_name.set_use_underline(True) label_name.set_mnemonic_widget(self.name_combo) label_name.set_justify(Gtk.Justification.LEFT) self.cmd.set_text(self.config_get('edit_cmd', 'gimp')) # populate the filename combo box fn_list = self.config_get_stringlist( 'filenames', ["cover.jpg", "folder.jpg", ".folder.jpg"]) # Issue 374 - add dynamic file names fn_dynlist = [] artist = song("artist") alartist = song("albumartist") album = song("album") labelid = song("labelid") if album: fn_dynlist.append("<album>.jpg") if alartist: fn_dynlist.append("<albumartist> - <album>.jpg") else: fn_dynlist.append("<artist> - <album>.jpg") else: print_w(u"No album for \"%s\". Could be difficult " u"finding art…" % song("~filename")) title = song("title") if title and artist: fn_dynlist.append("<artist> - <title>.jpg") if labelid: fn_dynlist.append("<labelid>.jpg") # merge unique fn_list.extend(s for s in fn_dynlist if s not in fn_list) set_fn = self.config_get('filename', fn_list[0]) for i, fn in enumerate(fn_list): self.name_combo.append_text(fn) if fn == set_fn: self.name_combo.set_active(i) if self.name_combo.get_active() < 0: self.name_combo.set_active(0) self.config_set('filename', self.name_combo.get_active_text()) table = Gtk.Table(n_rows=2, n_columns=2, homogeneous=False) table.props.expand = False table.set_row_spacing(0, 5) table.set_row_spacing(1, 5) table.set_col_spacing(0, 5) table.set_col_spacing(1, 5) table.attach(label_open, 0, 1, 0, 1) table.attach(label_name, 0, 1, 1, 2) table.attach(self.cmd, 1, 2, 0, 1) table.attach(self.name_combo, 1, 2, 1, 2) self.scrolled = Gtk.ScrolledWindow() self.scrolled.add_with_viewport(self.image) self.scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) bbox = Gtk.HButtonBox() bbox.set_spacing(6) bbox.set_layout(Gtk.ButtonBoxStyle.END) bbox.pack_start(self.button, True, True, 0) bbox.pack_start(close_button, True, True, 0) bb_align = Align(valign=Gtk.Align.END, right=6) bb_align.add(bbox) main_hbox = Gtk.HBox() main_hbox.pack_start(table, False, True, 6) main_hbox.pack_start(bb_align, True, True, 0) top_hbox = Gtk.HBox() top_hbox.pack_start(self.open_check, True, True, 0) top_hbox.pack_start(self.window_fit, False, True, 0) main_vbox = Gtk.VBox() main_vbox.pack_start(top_hbox, True, True, 2) main_vbox.pack_start(main_hbox, True, True, 0) self.pack_start(self.scrolled, True, True, 0) self.pack_start(main_vbox, False, True, 5) # 5 MB image cache size self.max_cache_size = 1024 * 1024 * 5 # For managing fast selection switches of covers.. self.stop_loading = False self.loading = False self.current_job = 0 self.connect('destroy', self.__save_config)
def add_sidebar_to_layout(self, widget): print_d("Recreating sidebar") align = Align(widget, top=6, bottom=3) self.__paned.pack2(align, shrink=True) align.show_all()
def __init__(self, library, dir=None): super(ExFalsoWindow, self).__init__(dialog=False) self.set_title("Ex Falso") self.set_default_size(750, 475) self.enable_window_tracking("exfalso") self.__library = library hp = ConfigRHPaned("memory", "exfalso_paned_position", 1.0) hp.set_border_width(0) hp.set_position(250) hp.show() self.add(hp) vb = Gtk.VBox() bbox = Gtk.HBox(spacing=6) about = Gtk.Button() about.add( Gtk.Image.new_from_stock(Gtk.STOCK_ABOUT, Gtk.IconSize.BUTTON)) connect_obj(about, 'clicked', self.__show_about, self) bbox.pack_start(about, False, True, 0) prefs = Gtk.Button() prefs.add( Gtk.Image.new_from_stock(Gtk.STOCK_PREFERENCES, Gtk.IconSize.BUTTON)) def prefs_cb(button): window = PreferencesWindow(self) window.show() prefs.connect('clicked', prefs_cb) bbox.pack_start(prefs, False, True, 0) plugins = qltk.Button(_("_Plugins"), Gtk.STOCK_EXECUTE) def plugin_window_cb(button): window = PluginWindow(self) window.show() plugins.connect('clicked', plugin_window_cb) bbox.pack_start(plugins, False, True, 0) l = Gtk.Label() l.set_alignment(1.0, 0.5) l.set_ellipsize(Pango.EllipsizeMode.END) bbox.pack_start(l, True, True, 0) fs = MainFileSelector() vb.pack_start(fs, True, True, 0) vb.pack_start(Align(bbox, border=6), False, True, 0) vb.show_all() hp.pack1(vb, resize=True, shrink=False) nb = qltk.Notebook() nb.props.scrollable = True nb.show() for Page in [EditTags, TagsFromPath, RenameFiles, TrackNumbers]: page = Page(self, self.__library) page.show() nb.append_page(page) align = Align(nb, top=3) align.show() hp.pack2(align, resize=True, shrink=False) fs.connect('changed', self.__changed, l) if dir: fs.go_to(dir) connect_destroy(self.__library, 'changed', self.__library_changed, fs) self.__save = None connect_obj(self, 'changed', self.set_pending, None) for c in fs.get_children(): c.get_child().connect('button-press-event', self.__pre_selection_changed, fs, nb) c.get_child().connect('focus', self.__pre_selection_changed, fs, nb) fs.get_children()[1].get_child().connect('popup-menu', self.__popup_menu, fs) self.emit('changed', []) self.get_child().show() self.__ag = Gtk.AccelGroup() key, mod = Gtk.accelerator_parse("<control>Q") self.__ag.connect(key, mod, 0, lambda *x: self.destroy()) self.add_accel_group(self.__ag)
class InternetRadio(Browser, util.InstanceTracker): __stations = None __fav_stations = None __librarian = None __filter = None name = _("Internet Radio") accelerated_name = _("_Internet Radio") keys = ["InternetRadio"] priority = 16 uses_main_library = False headers = "title artist ~people grouping genre website ~format " \ "channel-mode".split() TYPE, ICON_NAME, KEY, NAME = range(4) TYPE_FILTER, TYPE_ALL, TYPE_FAV, TYPE_SEP, TYPE_NOCAT = range(5) STAR = ["artist", "title", "website", "genre", "comment"] @classmethod def _init(klass, library): klass.__librarian = library.librarian klass.__stations = SongLibrary("iradio-remote") klass.__stations.load(STATIONS_ALL) klass.__fav_stations = SongLibrary("iradio") klass.__fav_stations.load(STATIONS_FAV) klass.filters = GenreFilter() @classmethod def _destroy(klass): if klass.__stations.dirty: klass.__stations.save() klass.__stations.destroy() klass.__stations = None if klass.__fav_stations.dirty: klass.__fav_stations.save() klass.__fav_stations.destroy() klass.__fav_stations = None klass.__librarian = None klass.filters = None def finalize(self, restored): if not restored: # Select "All Stations" by default def sel_all(row): return row[self.TYPE] == self.TYPE_ALL self.view.select_by_func(sel_all, one=True) def __inhibit(self): self.view.get_selection().handler_block(self.__changed_sig) def __uninhibit(self): self.view.get_selection().handler_unblock(self.__changed_sig) def __destroy(self, *args): if not self.instances(): self._destroy() def __init__(self, library): super(InternetRadio, self).__init__(spacing=12) self.set_orientation(Gtk.Orientation.VERTICAL) if not self.instances(): self._init(library) self._register_instance() self.connect('destroy', self.__destroy) completion = LibraryTagCompletion(self.__stations) self.accelerators = Gtk.AccelGroup() self.__searchbar = search = SearchBarBox(completion=completion, accel_group=self.accelerators) search.connect('query-changed', self.__filter_changed) menu = Gtk.Menu() new_item = MenuItem(_(u"_New Station…"), Icons.LIST_ADD) new_item.connect('activate', self.__add) menu.append(new_item) update_item = MenuItem(_("_Update Stations"), Icons.VIEW_REFRESH) update_item.connect('activate', self.__update) menu.append(update_item) menu.show_all() button = MenuButton(SymbolicIconImage(Icons.EMBLEM_SYSTEM, Gtk.IconSize.MENU), arrow=True) button.set_menu(menu) def focus(widget, *args): qltk.get_top_parent(widget).songlist.grab_focus() search.connect('focus-out', focus) # treeview scrolled_window = ScrolledWindow() scrolled_window.show() scrolled_window.set_shadow_type(Gtk.ShadowType.IN) self.view = view = AllTreeView() view.show() view.set_headers_visible(False) scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scrolled_window.add(view) model = Gtk.ListStore(int, str, str, str) model.append( row=[self.TYPE_ALL, Icons.FOLDER, "__all", _("All Stations")]) model.append(row=[self.TYPE_SEP, Icons.FOLDER, "", ""]) #Translators: Favorite radio stations model.append( row=[self.TYPE_FAV, Icons.FOLDER, "__fav", _("Favorites")]) model.append(row=[self.TYPE_SEP, Icons.FOLDER, "", ""]) filters = self.filters for text, k in sorted([(filters.text(k), k) for k in filters.keys()]): model.append(row=[self.TYPE_FILTER, Icons.EDIT_FIND, k, text]) model.append( row=[self.TYPE_NOCAT, Icons.FOLDER, "nocat", _("No Category")]) def separator(model, iter, data): return model[iter][self.TYPE] == self.TYPE_SEP view.set_row_separator_func(separator, None) def search_func(model, column, key, iter, data): return key.lower() not in model[iter][column].lower() view.set_search_column(self.NAME) view.set_search_equal_func(search_func, None) column = Gtk.TreeViewColumn("genres") column.set_sizing(Gtk.TreeViewColumnSizing.FIXED) renderpb = Gtk.CellRendererPixbuf() renderpb.props.xpad = 3 column.pack_start(renderpb, False) column.add_attribute(renderpb, "icon-name", self.ICON_NAME) render = Gtk.CellRendererText() render.set_property('ellipsize', Pango.EllipsizeMode.END) view.append_column(column) column.pack_start(render, True) column.add_attribute(render, "text", self.NAME) view.set_model(model) # selection selection = view.get_selection() selection.set_mode(Gtk.SelectionMode.MULTIPLE) self.__changed_sig = connect_destroy( selection, 'changed', util.DeferredSignal(lambda x: self.activate())) box = Gtk.HBox(spacing=6) box.pack_start(search, True, True, 0) box.pack_start(button, False, True, 0) self._searchbox = Align(box, left=0, right=6, top=6) self._searchbox.show_all() def qbar_response(infobar, response_id): if response_id == infobar.RESPONSE_LOAD: self.__update() self.qbar = QuestionBar() self.qbar.connect("response", qbar_response) if self._is_library_empty(): self.qbar.show() pane = qltk.ConfigRHPaned("browsers", "internetradio_pos", 0.4) pane.show() pane.pack1(scrolled_window, resize=False, shrink=False) songbox = Gtk.VBox(spacing=6) songbox.pack_start(self._searchbox, False, True, 0) self._songpane_container = Gtk.VBox() self._songpane_container.show() songbox.pack_start(self._songpane_container, True, True, 0) songbox.pack_start(self.qbar, False, True, 0) songbox.show() pane.pack2(songbox, resize=True, shrink=False) self.pack_start(pane, True, True, 0) self.show() def _is_library_empty(self): return not len(self.__stations) and not len(self.__fav_stations) def pack(self, songpane): container = Gtk.VBox() container.add(self) self._songpane_container.add(songpane) return container def unpack(self, container, songpane): self._songpane_container.remove(songpane) container.remove(self) def __update(self, *args): self.qbar.hide() copool.add(download_taglist, self.__update_done, cofuncid="radio-load", funcid="radio-load") def __update_done(self, stations): if not stations: print_w("Loading remote station list failed.") return # filter stations based on quality, listenercount def filter_stations(station): peak = station.get("~#listenerpeak", 0) if peak < 10: return False aac = "AAC" in station("~format") bitrate = station("~#bitrate", 50) if (aac and bitrate < 40) or (not aac and bitrate < 60): return False return True stations = filter(filter_stations, stations) # group them based on the title groups = {} for s in stations: key = s("~title~artist") groups.setdefault(key, []).append(s) # keep at most 2 URLs for each group stations = [] for key, sub in groups.items(): sub.sort(key=lambda s: s.get("~#listenerpeak", 0), reverse=True) stations.extend(sub[:2]) # only keep the ones in at least one category all_ = [self.filters.query(k) for k in self.filters.keys()] assert all_ anycat_filter = reduce(lambda x, y: x | y, all_) stations = list(filter(anycat_filter.search, stations)) # remove listenerpeak for s in stations: s.pop("~#listenerpeak", None) # update the libraries stations = dict(((s.key, s) for s in stations)) # don't add ones that are in the fav list for fav in self.__fav_stations.keys(): stations.pop(fav, None) # separate o, n = set(self.__stations.keys()), set(stations) to_add, to_change, to_remove = n - o, o & n, o - n del o, n # migrate stats to_change = [stations.pop(k) for k in to_change] for new in to_change: old = self.__stations[new.key] # clear everything except stats AudioFile.reload(old) # add new metadata except stats for k in (x for x in new.keys() if x not in MIGRATE): old[k] = new[k] to_add = [stations.pop(k) for k in to_add] to_remove = [self.__stations[k] for k in to_remove] self.__stations.remove(to_remove) self.__stations.changed(to_change) self.__stations.add(to_add) def __filter_changed(self, bar, text, restore=False): self.__filter = Query(text, self.STAR) if not restore: self.activate() def __get_selected_libraries(self): """Returns the libraries to search in depending on the filter selection""" selection = self.view.get_selection() model, rows = selection.get_selected_rows() types = [model[row][self.TYPE] for row in rows] libs = [self.__fav_stations] if types != [self.TYPE_FAV]: libs.append(self.__stations) return libs def __get_selection_filter(self): """Returns a filter object for the current selection or None if nothing should be filtered""" selection = self.view.get_selection() model, rows = selection.get_selected_rows() filter_ = None for row in rows: type_ = model[row][self.TYPE] if type_ == self.TYPE_FILTER: key = model[row][self.KEY] current_filter = self.filters.query(key) if current_filter: if filter_: filter_ |= current_filter else: filter_ = current_filter elif type_ == self.TYPE_NOCAT: # if notcat is selected, combine all filters, negate and merge all_ = [self.filters.query(k) for k in self.filters.keys()] nocat_filter = all_ and -reduce(lambda x, y: x | y, all_) if nocat_filter: if filter_: filter_ |= nocat_filter else: filter_ = nocat_filter elif type_ == self.TYPE_ALL: filter_ = None break return filter_ def unfilter(self): self.filter_text("") def __add_fav(self, songs): songs = [s for s in songs if s in self.__stations] type(self).__librarian.move(songs, self.__stations, self.__fav_stations) def __remove_fav(self, songs): songs = [s for s in songs if s in self.__fav_stations] type(self).__librarian.move(songs, self.__fav_stations, self.__stations) def __add(self, button): parent = qltk.get_top_parent(self) uri = (AddNewStation(parent).run(clipboard=True) or "").strip() if uri != "": self.__add_station(uri) def __add_station(self, uri): try: irfs = _get_stations_from(uri) except EnvironmentError as e: print_d("Got %s from %s" % (e, uri)) msg = ("Couldn't add URL: <b>%s</b>)\n\n<tt>%s</tt>" % (escape(str(e)), escape(uri))) ErrorMessage(None, _("Unable to add station"), msg).run() return if not irfs: ErrorMessage( None, _("No stations found"), _("No Internet radio stations were found at %s.") % util.escape(uri)).run() return irfs = set(irfs) - set(self.__fav_stations) if not irfs: WarningMessage( None, _("Unable to add station"), _("All stations listed are already in your library.")).run() if irfs: self.__fav_stations.add(irfs) def Menu(self, songs, library, items): in_fav = False in_all = False for song in songs: if song in self.__fav_stations: in_fav = True elif song in self.__stations: in_all = True if in_fav and in_all: break iradio_items = [] button = MenuItem(_("Add to Favorites"), Icons.LIST_ADD) button.set_sensitive(in_all) connect_obj(button, 'activate', self.__add_fav, songs) iradio_items.append(button) button = MenuItem(_("Remove from Favorites"), Icons.LIST_REMOVE) button.set_sensitive(in_fav) connect_obj(button, 'activate', self.__remove_fav, songs) iradio_items.append(button) items.append(iradio_items) menu = SongsMenu(self.__librarian, songs, playlists=False, remove=True, queue=False, items=items) return menu def restore(self): text = config.gettext("browsers", "query_text") self.__searchbar.set_text(text) if Query(text).is_parsable: self.__filter_changed(self.__searchbar, text, restore=True) keys = config.get("browsers", "radio").splitlines() def select_func(row): return row[self.TYPE] != self.TYPE_SEP and row[self.KEY] in keys self.__inhibit() view = self.view if not view.select_by_func(select_func): for row in view.get_model(): if row[self.TYPE] == self.TYPE_FAV: view.set_cursor(row.path) break self.__uninhibit() def __get_filter(self): filter_ = self.__get_selection_filter() text_filter = self.__filter or Query("") if filter_: filter_ &= text_filter else: filter_ = text_filter return filter_ def can_filter_text(self): return True def filter_text(self, text): self.__searchbar.set_text(text) if Query(text).is_parsable: self.__filter_changed(self.__searchbar, text) self.activate() def get_filter_text(self): return self.__searchbar.get_text() def activate(self): filter_ = self.__get_filter() libs = self.__get_selected_libraries() songs = filter_.filter(itertools.chain(*libs)) self.songs_selected(songs) def active_filter(self, song): for lib in self.__get_selected_libraries(): if song in lib: break else: return False filter_ = self.__get_filter() if filter_: return filter_.search(song) return True def save(self): text = self.__searchbar.get_text() config.settext("browsers", "query_text", text) selection = self.view.get_selection() model, rows = selection.get_selected_rows() names = filter(None, [model[row][self.KEY] for row in rows]) config.set("browsers", "radio", "\n".join(names)) def scroll(self, song): # nothing we care about if song not in self.__stations and song not in self.__fav_stations: return path = None for row in self.view.get_model(): if row[self.TYPE] == self.TYPE_FILTER: if self.filters.query(row[self.KEY]).search(song): path = row.path break else: # in case nothing matches, select all path = (0, ) self.view.set_cursor(path) self.view.scroll_to_cell(path, use_align=True, row_align=0.5) def status_text(self, count, time=None): return numeric_phrase("%(count)d station", "%(count)d stations", count, 'count')
def tag_editing_vbox(self): """Returns a new VBox containing all tag editing widgets""" vbox = Gtk.VBox(spacing=6) cb = CCB(_("Auto-save tag changes"), 'editing', 'auto_save_changes', populate=True, tooltip=_("Save changes to tags without confirmation " "when editing multiple files")) vbox.pack_start(cb, False, True, 0) split_entry = UndoEntry() split_entry.set_text(config.get("editing", "split_on")) split_entry.connect('changed', self.__changed, 'editing', 'split_on') split_entry.set_tooltip_text( _("A set of separators to use when splitting tag values " "in the tag editor. " "The list is space-separated.")) split_entry.props.expand = True sub_entry = UndoEntry() sub_entry.set_text(config.get("editing", "sub_split_on")) sub_entry.connect('changed', self.__changed, 'editing', 'sub_split_on') sub_entry.set_tooltip_text( _("A set of separators to use when extracting subtags from " "tags in the tag editor. " "The list is space-separated, and each entry must only " "contain two characters.")) sub_entry.props.expand = True def do_revert_split(button, entry, section, option): config.reset(section, option) entry.set_text(config.get(section, option)) split_revert = Button(_("_Revert"), Icons.DOCUMENT_REVERT) split_revert.connect("clicked", do_revert_split, split_entry, "editing", "split_on") split_label = Gtk.Label(label=_("Split _tag on:")) split_label.set_use_underline(True) split_label.set_mnemonic_widget(split_entry) sub_revert = Button(_("_Revert"), Icons.DOCUMENT_REVERT) sub_revert.connect("clicked", do_revert_split, sub_entry, "editing", "sub_split_on") sub_label = Gtk.Label(label=_("Split _subtag on:")) sub_label.set_use_underline(True) sub_label.set_mnemonic_widget(split_entry) split_align = Align(halign=Gtk.Align.START) split_align.add(split_label) sub_align = Align(halign=Gtk.Align.START) sub_align.add(sub_label) grid = Gtk.Grid(column_spacing=6, row_spacing=6) grid.add(split_align) grid.add(split_entry) grid.add(split_revert) grid.attach(sub_align, 0, 1, 1, 1) grid.attach(sub_entry, 1, 1, 1, 1) grid.attach(sub_revert, 2, 1, 1, 1) grid.props.expand = False vbox.pack_start(grid, False, False, 6) return vbox
def __init__(self, library, player, headless=False, restore_cb=None): super(QuodLibetWindow, self).__init__(dialog=False) self.last_dir = get_home_dir() self.__destroyed = False self.__update_title(player) self.set_default_size(550, 450) main_box = Gtk.VBox() self.add(main_box) # create main menubar, load/restore accelerator groups self.__library = library ui = self.__create_menu(player, library) accel_group = ui.get_accel_group() self.add_accel_group(accel_group) def scroll_and_jump(*args): self.__jump_to_current(True, True) keyval, mod = Gtk.accelerator_parse("<control><shift>J") accel_group.connect(keyval, mod, 0, scroll_and_jump) # dbus app menu # Unity puts the app menu next to our menu bar. Since it only contains # menu items also available in the menu bar itself, don't add it. if not util.is_unity(): AppMenu(self, ui.get_action_groups()[0]) # custom accel map accel_fn = os.path.join(quodlibet.get_user_dir(), "accels") Gtk.AccelMap.load(accel_fn) # save right away so we fill the file with example comments of all # accels Gtk.AccelMap.save(accel_fn) menubar = ui.get_widget("/Menu") # Since https://git.gnome.org/browse/gtk+/commit/?id=b44df22895c79 # toplevel menu items show an empty 16x16 image. While we don't # need image items there UIManager creates them by default. # Work around by removing the empty GtkImages for child in menubar.get_children(): if isinstance(child, Gtk.ImageMenuItem): child.set_image(None) main_box.pack_start(menubar, False, True, 0) # get the playlist up before other stuff self.songlist = MainSongList(library, player) self.songlist.show_all() self.songlist.connect("key-press-event", self.__songlist_key_press) self.songlist.connect_after('drag-data-received', self.__songlist_drag_data_recv) self.song_scroller = SongListScroller( ui.get_widget("/Menu/View/SongList")) self.song_scroller.add(self.songlist) self.qexpander = QueueExpander(ui.get_widget("/Menu/View/Queue"), library, player) self.playlist = PlaylistMux(player, self.qexpander.model, self.songlist.model) top_bar = TopBar(self, player, library) main_box.pack_start(top_bar, False, True, 0) self.top_bar = top_bar self.__browserbox = Align(bottom=3) main_box.pack_start(self.__browserbox, True, True, 0) statusbox = StatusBarBox(self.songlist.model, player) self.order = statusbox.order self.repeat = statusbox.repeat self.statusbar = statusbox.statusbar main_box.pack_start(Align(statusbox, border=3, top=-3, right=3), False, True, 0) self.songpane = ConfigRVPaned("memory", "queue_position", 0.75) self.songpane.pack1(self.song_scroller, resize=True, shrink=False) self.songpane.pack2(self.qexpander, resize=True, shrink=False) self.__handle_position = self.songpane.get_property("position") def songpane_button_press_cb(pane, event): """If we start to drag the pane handle while the queue expander is unexpanded, expand it and move the handle to the bottom, so we can 'drag' the queue out """ if event.window != pane.get_handle_window(): return False if not self.qexpander.get_expanded(): self.qexpander.set_expanded(True) pane.set_relative(1.0) return False self.songpane.connect("button-press-event", songpane_button_press_cb) self.song_scroller.connect('notify::visible', self.__show_or) self.qexpander.connect('notify::visible', self.__show_or) self.qexpander.connect('notify::expanded', self.__expand_or) self.qexpander.connect('draw', self.__qex_size_allocate) self.songpane.connect('notify', self.__moved_pane_handle) try: orders = [] for e in config.getstringlist('memory', 'sortby', []): orders.append((e[1:], int(e[0]))) except ValueError: pass else: self.songlist.set_sort_orders(orders) self.browser = None self.ui = ui main_box.show_all() self._playback_error_dialog = None connect_destroy(player, 'song-started', self.__song_started) connect_destroy(player, 'paused', self.__update_paused, True) connect_destroy(player, 'unpaused', self.__update_paused, False) # make sure we redraw all error indicators before opening # a dialog (blocking the main loop), so connect after default handlers connect_after_destroy(player, 'error', self.__player_error) # connect after to let SongTracker update stats connect_after_destroy(player, "song-ended", self.__song_ended) # set at least the playlist. the song should be restored # after the browser emits the song list player.setup(self.playlist, None, 0) self.__restore_cb = restore_cb self.__first_browser_set = True restore_browser = not headless try: self.select_browser(self, config.get("memory", "browser"), library, player, restore_browser) except: config.set("memory", "browser", browsers.name(0)) config.save() raise self.showhide_playlist(ui.get_widget("/Menu/View/SongList")) self.showhide_playqueue(ui.get_widget("/Menu/View/Queue")) self.songlist.connect('popup-menu', self.__songs_popup_menu) self.songlist.connect('columns-changed', self.__cols_changed) self.songlist.connect('columns-changed', self.__hide_headers) self.songlist.info.connect("changed", self.__set_time) lib = library.librarian connect_destroy(lib, 'changed', self.__song_changed, player) targets = [("text/uri-list", Gtk.TargetFlags.OTHER_APP, DND_URI_LIST)] targets = [Gtk.TargetEntry.new(*t) for t in targets] self.drag_dest_set(Gtk.DestDefaults.ALL, targets, Gdk.DragAction.COPY) self.connect('drag-data-received', self.__drag_data_received) if not headless: on_first_map(self, self.__configure_scan_dirs, library) if config.getboolean('library', 'refresh_on_start'): self.__rebuild(None, False) self.connect("key-press-event", self.__key_pressed, player) self.connect("destroy", self.__destroy) self.enable_window_tracking("quodlibet")
def set_slider_widget(self, widget): self._box.pack_start(Align(widget, border=6, left=-3), False, True, 0)
def __init__(self): super().__init__(spacing=12) self.set_border_width(12) self.title = _("Playback") # player backend if app.player and hasattr(app.player, 'PlayerPreferences'): player_prefs = app.player.PlayerPreferences() f = qltk.Frame(_("Output Configuration"), child=player_prefs) self.pack_start(f, False, True, 0) # replaygain fallback_gain = config.getfloat("player", "fallback_gain", 0.0) adj = Gtk.Adjustment.new(fallback_gain, -12.0, 12.0, 0.5, 0.5, 0.0) fb_spin = Gtk.SpinButton(adjustment=adj) fb_spin.set_digits(1) fb_spin.connect('changed', self.__changed, 'player', 'fallback_gain') fb_spin.set_tooltip_text( _("If no Replay Gain information is available " "for a song, scale the volume by this value")) fb_label = Gtk.Label(label=_("_Fall-back gain (dB):")) fb_label.set_use_underline(True) fb_label.set_mnemonic_widget(fb_spin) pre_amp_gain = config.getfloat("player", "pre_amp_gain", 0.0) adj = Gtk.Adjustment.new(pre_amp_gain, -12, 12, 0.5, 0.5, 0.0) adj.connect('value-changed', self.__changed, 'player', 'pre_amp_gain') pre_spin = Gtk.SpinButton(adjustment=adj) pre_spin.set_digits(1) pre_spin.set_tooltip_text( _("Scale volume for all songs by this value, " "as long as the result will not clip")) pre_label = Gtk.Label(label=_("_Pre-amp gain (dB):")) pre_label.set_use_underline(True) pre_label.set_mnemonic_widget(pre_spin) widgets = [pre_label, pre_spin, fb_label, fb_spin] c = CCB(_("_Enable Replay Gain volume adjustment"), "player", "replaygain", populate=True) c.connect('toggled', self.__toggled_gain, widgets) # packing table = Gtk.Table.new(3, 2, False) table.set_col_spacings(6) table.set_row_spacings(6) table.attach(c, 0, 2, 0, 1) fb_label.set_alignment(0, 0.5) table.attach(fb_label, 0, 1, 1, 2, xoptions=Gtk.AttachOptions.FILL) pre_label.set_alignment(0, 0.5) table.attach(pre_label, 0, 1, 2, 3, xoptions=Gtk.AttachOptions.FILL) fb_align = Align(halign=Gtk.Align.START) fb_align.add(fb_spin) table.attach(fb_align, 1, 2, 1, 2) pre_align = Align(halign=Gtk.Align.START) pre_align.add(pre_spin) table.attach(pre_align, 1, 2, 2, 3) f = qltk.Frame(_("Replay Gain Volume Adjustment"), child=table) c.emit('toggled') self.pack_start(f, False, True, 0) vbox = Gtk.VBox() c = CCB(_("_Continue playback on startup"), "player", "restore_playing", populate=True, tooltip=_("If music is playing on shutdown, automatically " "start playing on next startup")) vbox.pack_start(c, False, False, 0) f = qltk.Frame(_("Startup"), child=vbox) self.pack_start(f, False, True, 0) for child in self.get_children(): child.show_all()
def __init__(self, library, dir=None): super(ExFalsoWindow, self).__init__(dialog=False) self.set_title("Ex Falso") self.set_default_size(750, 475) self.enable_window_tracking("exfalso") self.__library = library hp = ConfigRHPaned("memory", "exfalso_paned_position", 1.0) hp.set_border_width(0) hp.set_position(250) hp.show() self.add(hp) vb = Gtk.VBox() bbox = Gtk.HBox(spacing=6) about = Gtk.Button() about.add( Gtk.Image.new_from_icon_name(Icons.HELP_ABOUT, Gtk.IconSize.BUTTON)) connect_obj(about, 'clicked', self.__show_about, self) bbox.pack_start(about, False, True, 0) def prefs_cb(*args): window = PreferencesWindow(self) window.show() def plugin_window_cb(*args): window = PluginWindow(self) window.show() menu = Gtk.Menu() plugin_item = MenuItem(_("_Plugins"), Icons.SYSTEM_RUN) plugin_item.connect("activate", plugin_window_cb) menu.append(plugin_item) pref_item = MenuItem(_("_Preferences"), Icons.PREFERENCES_SYSTEM) pref_item.connect("activate", prefs_cb) menu.append(pref_item) menu.show_all() menu_button = MenuButton(SymbolicIconImage(Icons.EMBLEM_SYSTEM, Gtk.IconSize.BUTTON), arrow=True, down=False) menu_button.set_menu(menu) bbox.pack_start(menu_button, False, True, 0) l = Gtk.Label() l.set_alignment(1.0, 0.5) l.set_ellipsize(Pango.EllipsizeMode.END) bbox.pack_start(l, True, True, 0) fs = MainFileSelector() vb.pack_start(fs, True, True, 0) vb.pack_start(Align(bbox, border=6), False, True, 0) vb.show_all() hp.pack1(vb, resize=True, shrink=False) nb = qltk.Notebook() nb.props.scrollable = True nb.show() for Page in [EditTags, TagsFromPath, RenameFiles, TrackNumbers]: page = Page(self, self.__library) page.show() nb.append_page(page) hp.pack2(nb, resize=True, shrink=False) fs.connect('changed', self.__changed, l) if dir: fs.go_to(dir) connect_destroy(self.__library, 'changed', self.__library_changed, fs) self.__save = None connect_obj(self, 'changed', self.set_pending, None) for c in fs.get_children(): c.get_child().connect('button-press-event', self.__pre_selection_changed, fs, nb) c.get_child().connect('focus', self.__pre_selection_changed, fs, nb) fs.get_children()[1].get_child().connect('popup-menu', self.__popup_menu, fs) self.emit('changed', []) self.get_child().show() self.__ag = Gtk.AccelGroup() key, mod = Gtk.accelerator_parse("<Primary>Q") self.__ag.connect(key, mod, 0, lambda *x: self.destroy()) self.add_accel_group(self.__ag) # GtkosxApplication assumes the menu bar is mapped, so add # it but don't show it. self._dummy_osx_menu_bar = Gtk.MenuBar() vb.pack_start(self._dummy_osx_menu_bar, False, False, 0)
def __init__(self, parent=None): if self.is_not_unique(): return super(PluginWindow, self).__init__() self.set_title(_("Plugins")) self.set_border_width(12) self.set_default_size(655, 404) self.set_transient_for(parent) paned = Paned() vbox = Gtk.VBox(spacing=6) sw = Gtk.ScrolledWindow() sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.ALWAYS) model = ObjectStore() filter_model = ObjectModelFilter(child_model=model) tv = PluginListView() tv.set_model(filter_model) tv.set_rules_hint(True) tv.connect("plugin-toggled", self.__plugin_toggled) fb = Gtk.HBox(spacing=6) filter_combo = PluginFilterCombo() filter_combo.connect("changed", lambda s: filter_model.refilter()) fb.pack_start(filter_combo, False, True, 0) filter_entry = ClearEntry() filter_entry.connect("changed", lambda s: filter_model.refilter()) filter_entry.enable_clear_button() fb.pack_start(filter_entry, True, True, 0) sw.add(tv) sw.set_shadow_type(Gtk.ShadowType.IN) sw.set_size_request(200, -1) bbox = Gtk.HBox(homogeneous=True, spacing=12) errors = qltk.Button(_("Show _Errors"), Icons.DIALOG_WARNING) errors.set_focus_on_click(False) errors.connect('clicked', self.__show_errors) errors.set_no_show_all(True) bbox.pack_start(errors, True, True, 0) pref_box = PluginPreferencesContainer() if const.DEBUG: refresh = qltk.Button(_("_Refresh"), Icons.VIEW_REFRESH) refresh.set_focus_on_click(False) refresh.connect('clicked', self.__refresh, tv, pref_box, errors, filter_combo) bbox.pack_start(refresh, True, True, 0) vbox.pack_start(fb, False, True, 0) vbox.pack_start(sw, True, True, 0) vbox.pack_start(bbox, False, True, 0) paned.pack1(vbox, True, False) close = qltk.Button(_("_Close"), Icons.WINDOW_CLOSE) close.connect('clicked', lambda *x: self.destroy()) bb_align = Align(halign=Gtk.Align.END, valign=Gtk.Align.END) bb = Gtk.HButtonBox() bb.set_layout(Gtk.ButtonBoxStyle.END) bb.pack_start(close, True, True, 0) bb_align.add(bb) selection = tv.get_selection() selection.connect('changed', self.__selection_changed, pref_box) selection.emit('changed') right_box = Gtk.VBox(spacing=12) right_box.pack_start(pref_box, True, True, 0) self.use_header_bar() if not self.has_close_button(): right_box.pack_start(bb_align, True, True, 0) paned.pack2(Align(right_box, left=6), True, False) paned.set_position(250) self.add(paned) self.__refill(tv, pref_box, errors, filter_combo) self.connect('destroy', self.__destroy) filter_model.set_visible_func( self.__filter, (filter_entry, filter_combo)) self.get_child().show_all() filter_entry.grab_focus() restore_id = config.get("memory", "plugin_selection") tv.select_by_plugin_id(restore_id)
def __init__(self, parent=None): if self.is_not_unique(): return super(PluginWindow, self).__init__() self.set_title(_("Plugins")) self.set_default_size(700, 500) self.set_transient_for(parent) self.enable_window_tracking("plugin_prefs") paned = Paned() vbox = Gtk.VBox() sw = ScrolledWindow() sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.ALWAYS) model = ObjectStore() filter_model = ObjectModelFilter(child_model=model) self._list_view = tv = PluginListView() tv.set_model(filter_model) tv.set_rules_hint(True) tv.connect("plugin-toggled", self.__plugin_toggled) fb = Gtk.HBox(spacing=6) enabled_combo = PluginEnabledFilterCombo() enabled_combo.connect("changed", lambda s: filter_model.refilter()) enabled_combo.set_tooltip_text(_("Filter by plugin state / tag")) fb.pack_start(enabled_combo, True, True, 0) self._enabled_combo = enabled_combo type_combo = PluginTypeFilterCombo() type_combo.connect("changed", lambda s: filter_model.refilter()) type_combo.set_tooltip_text(_("Filter by plugin type")) fb.pack_start(type_combo, True, True, 0) self._type_combo = type_combo filter_entry = UndoSearchEntry() filter_entry.set_tooltip_text( _("Filter by plugin name or description")) filter_entry.connect("changed", lambda s: filter_model.refilter()) self._filter_entry = filter_entry sw.add(tv) sw.set_shadow_type(Gtk.ShadowType.IN) bbox = Gtk.VBox() errors = qltk.Button(_("Show _Errors"), Icons.DIALOG_WARNING) errors.set_focus_on_click(False) errors.connect('clicked', self.__show_errors) errors.show() errors = Align(errors, top=6, bottom=6) errors.set_no_show_all(True) bbox.pack_start(errors, True, True, 0) pref_box = PluginPreferencesContainer() if const.DEBUG: refresh = qltk.Button(_("_Refresh"), Icons.VIEW_REFRESH) refresh.set_focus_on_click(False) refresh.connect('clicked', self.__refresh, tv, pref_box, errors, enabled_combo) bbox.pack_start(refresh, True, True, 0) filter_box = Gtk.VBox(spacing=6) filter_box.pack_start(fb, False, True, 0) filter_box.pack_start(filter_entry, False, True, 0) vbox.pack_start(Align(filter_box, border=6, right=-6), False, False, 0) vbox.pack_start(sw, True, True, 0) vbox.pack_start(Align(bbox, left=6), False, True, 0) paned.pack1(vbox, False, False) close = qltk.Button(_("_Close"), Icons.WINDOW_CLOSE) close.connect('clicked', lambda *x: self.destroy()) bb_align = Align(halign=Gtk.Align.END, valign=Gtk.Align.END) bb = Gtk.HButtonBox() bb.set_layout(Gtk.ButtonBoxStyle.END) bb.pack_start(close, True, True, 0) bb_align.add(bb) selection = tv.get_selection() selection.connect('changed', self.__selection_changed, pref_box) selection.emit('changed') right_box = Gtk.VBox(spacing=12) right_box.pack_start(pref_box, True, True, 0) self.use_header_bar() if not self.has_close_button(): right_box.pack_start(bb_align, True, True, 0) paned.pack2(Align(right_box, border=12), True, False) paned.set_position(275) self.add(paned) self.__refill(tv, pref_box, errors, enabled_combo) self.connect('destroy', self.__destroy) filter_model.set_visible_func( self.__filter, (filter_entry, enabled_combo, type_combo)) self.get_child().show_all() filter_entry.grab_focus() restore_id = config.get("memory", "plugin_selection") tv.select_by_plugin_id(restore_id)
def __init__(self, library, player, headless=False, restore_cb=None): super(QuodLibetWindow, self).__init__(dialog=False) self.last_dir = get_home_dir() self.__destroyed = False self.__update_title(player) self.set_default_size(550, 450) main_box = Gtk.VBox() self.add(main_box) # create main menubar, load/restore accelerator groups self.__library = library ui = self.__create_menu(player, library) accel_group = ui.get_accel_group() self.add_accel_group(accel_group) def scroll_and_jump(*args): self.__jump_to_current(True, True) keyval, mod = Gtk.accelerator_parse("<control><shift>J") accel_group.connect(keyval, mod, 0, scroll_and_jump) # dbus app menu # Unity puts the app menu next to our menu bar. Since it only contains # menu items also available in the menu bar itself, don't add it. if not util.is_unity(): AppMenu(self, ui.get_action_groups()[0]) # custom accel map accel_fn = os.path.join(quodlibet.get_user_dir(), "accels") Gtk.AccelMap.load(accel_fn) # save right away so we fill the file with example comments of all # accels Gtk.AccelMap.save(accel_fn) menubar = ui.get_widget("/Menu") # Since https://git.gnome.org/browse/gtk+/commit/?id=b44df22895c79 # toplevel menu items show an empty 16x16 image. While we don't # need image items there UIManager creates them by default. # Work around by removing the empty GtkImages for child in menubar.get_children(): if isinstance(child, Gtk.ImageMenuItem): child.set_image(None) main_box.pack_start(menubar, False, True, 0) # get the playlist up before other stuff self.songlist = MainSongList(library, player) self.songlist.show_all() self.songlist.connect("key-press-event", self.__songlist_key_press) self.songlist.connect_after( 'drag-data-received', self.__songlist_drag_data_recv) self.song_scroller = SongListScroller( ui.get_widget("/Menu/View/SongList")) self.song_scroller.add(self.songlist) self.qexpander = QueueExpander( ui.get_widget("/Menu/View/Queue"), library, player) self.playlist = PlaylistMux( player, self.qexpander.model, self.songlist.model) top_bar = TopBar(self, player, library) main_box.pack_start(top_bar, False, True, 0) self.top_bar = top_bar self.__browserbox = Align(bottom=3) main_box.pack_start(self.__browserbox, True, True, 0) statusbox = StatusBarBox(self.songlist.model, player) self.order = statusbox.order self.repeat = statusbox.repeat self.statusbar = statusbox.statusbar main_box.pack_start( Align(statusbox, border=3, top=-3, right=3), False, True, 0) self.songpane = ConfigRVPaned("memory", "queue_position", 0.75) self.songpane.pack1(self.song_scroller, resize=True, shrink=False) self.songpane.pack2(self.qexpander, resize=True, shrink=False) self.__handle_position = self.songpane.get_property("position") def songpane_button_press_cb(pane, event): """If we start to drag the pane handle while the queue expander is unexpanded, expand it and move the handle to the bottom, so we can 'drag' the queue out """ if event.window != pane.get_handle_window(): return False if not self.qexpander.get_expanded(): self.qexpander.set_expanded(True) pane.set_relative(1.0) return False self.songpane.connect("button-press-event", songpane_button_press_cb) self.song_scroller.connect('notify::visible', self.__show_or) self.qexpander.connect('notify::visible', self.__show_or) self.qexpander.connect('notify::expanded', self.__expand_or) self.qexpander.connect('draw', self.__qex_size_allocate) self.songpane.connect('notify', self.__moved_pane_handle) try: orders = [] for e in config.getstringlist('memory', 'sortby', []): orders.append((e[1:], int(e[0]))) except ValueError: pass else: self.songlist.set_sort_orders(orders) self.browser = None self.ui = ui main_box.show_all() self._playback_error_dialog = None connect_destroy(player, 'song-started', self.__song_started) connect_destroy(player, 'paused', self.__update_paused, True) connect_destroy(player, 'unpaused', self.__update_paused, False) # make sure we redraw all error indicators before opening # a dialog (blocking the main loop), so connect after default handlers connect_after_destroy(player, 'error', self.__player_error) # connect after to let SongTracker update stats connect_after_destroy(player, "song-ended", self.__song_ended) # set at least the playlist. the song should be restored # after the browser emits the song list player.setup(self.playlist, None, 0) self.__restore_cb = restore_cb self.__first_browser_set = True restore_browser = not headless try: self.select_browser( self, config.get("memory", "browser"), library, player, restore_browser) except: config.set("memory", "browser", browsers.name(0)) config.save() raise self.showhide_playlist(ui.get_widget("/Menu/View/SongList")) self.showhide_playqueue(ui.get_widget("/Menu/View/Queue")) self.songlist.connect('popup-menu', self.__songs_popup_menu) self.songlist.connect('columns-changed', self.__cols_changed) self.songlist.connect('columns-changed', self.__hide_headers) self.songlist.info.connect("changed", self.__set_time) lib = library.librarian connect_destroy(lib, 'changed', self.__song_changed, player) targets = [("text/uri-list", Gtk.TargetFlags.OTHER_APP, DND_URI_LIST)] targets = [Gtk.TargetEntry.new(*t) for t in targets] self.drag_dest_set( Gtk.DestDefaults.ALL, targets, Gdk.DragAction.COPY) self.connect('drag-data-received', self.__drag_data_received) if not headless: on_first_map(self, self.__configure_scan_dirs, library) if config.getboolean('library', 'refresh_on_start'): self.__rebuild(None, False) self.connect("key-press-event", self.__key_pressed, player) self.connect("destroy", self.__destroy) self.enable_window_tracking("quodlibet")
class QuodLibetWindow(Window, PersistentWindowMixin): def __init__(self, library, player, headless=False, restore_cb=None): super(QuodLibetWindow, self).__init__(dialog=False) self.last_dir = get_home_dir() self.__destroyed = False self.__update_title(player) self.set_default_size(550, 450) main_box = Gtk.VBox() self.add(main_box) # create main menubar, load/restore accelerator groups self.__library = library ui = self.__create_menu(player, library) accel_group = ui.get_accel_group() self.add_accel_group(accel_group) def scroll_and_jump(*args): self.__jump_to_current(True, True) keyval, mod = Gtk.accelerator_parse("<control><shift>J") accel_group.connect(keyval, mod, 0, scroll_and_jump) # dbus app menu # Unity puts the app menu next to our menu bar. Since it only contains # menu items also available in the menu bar itself, don't add it. if not util.is_unity(): AppMenu(self, ui.get_action_groups()[0]) # custom accel map accel_fn = os.path.join(quodlibet.get_user_dir(), "accels") Gtk.AccelMap.load(accel_fn) # save right away so we fill the file with example comments of all # accels Gtk.AccelMap.save(accel_fn) menubar = ui.get_widget("/Menu") # Since https://git.gnome.org/browse/gtk+/commit/?id=b44df22895c79 # toplevel menu items show an empty 16x16 image. While we don't # need image items there UIManager creates them by default. # Work around by removing the empty GtkImages for child in menubar.get_children(): if isinstance(child, Gtk.ImageMenuItem): child.set_image(None) main_box.pack_start(menubar, False, True, 0) # get the playlist up before other stuff self.songlist = MainSongList(library, player) self.songlist.show_all() self.songlist.connect("key-press-event", self.__songlist_key_press) self.songlist.connect_after( 'drag-data-received', self.__songlist_drag_data_recv) self.song_scroller = SongListScroller( ui.get_widget("/Menu/View/SongList")) self.song_scroller.add(self.songlist) self.qexpander = QueueExpander( ui.get_widget("/Menu/View/Queue"), library, player) self.playlist = PlaylistMux( player, self.qexpander.model, self.songlist.model) top_bar = TopBar(self, player, library) main_box.pack_start(top_bar, False, True, 0) self.top_bar = top_bar self.__browserbox = Align(bottom=3) main_box.pack_start(self.__browserbox, True, True, 0) statusbox = StatusBarBox(self.songlist.model, player) self.order = statusbox.order self.repeat = statusbox.repeat self.statusbar = statusbox.statusbar main_box.pack_start( Align(statusbox, border=3, top=-3, right=3), False, True, 0) self.songpane = ConfigRVPaned("memory", "queue_position", 0.75) self.songpane.pack1(self.song_scroller, resize=True, shrink=False) self.songpane.pack2(self.qexpander, resize=True, shrink=False) self.__handle_position = self.songpane.get_property("position") def songpane_button_press_cb(pane, event): """If we start to drag the pane handle while the queue expander is unexpanded, expand it and move the handle to the bottom, so we can 'drag' the queue out """ if event.window != pane.get_handle_window(): return False if not self.qexpander.get_expanded(): self.qexpander.set_expanded(True) pane.set_relative(1.0) return False self.songpane.connect("button-press-event", songpane_button_press_cb) self.song_scroller.connect('notify::visible', self.__show_or) self.qexpander.connect('notify::visible', self.__show_or) self.qexpander.connect('notify::expanded', self.__expand_or) self.qexpander.connect('draw', self.__qex_size_allocate) self.songpane.connect('notify', self.__moved_pane_handle) try: orders = [] for e in config.getstringlist('memory', 'sortby', []): orders.append((e[1:], int(e[0]))) except ValueError: pass else: self.songlist.set_sort_orders(orders) self.browser = None self.ui = ui main_box.show_all() self._playback_error_dialog = None connect_destroy(player, 'song-started', self.__song_started) connect_destroy(player, 'paused', self.__update_paused, True) connect_destroy(player, 'unpaused', self.__update_paused, False) # make sure we redraw all error indicators before opening # a dialog (blocking the main loop), so connect after default handlers connect_after_destroy(player, 'error', self.__player_error) # connect after to let SongTracker update stats connect_after_destroy(player, "song-ended", self.__song_ended) # set at least the playlist. the song should be restored # after the browser emits the song list player.setup(self.playlist, None, 0) self.__restore_cb = restore_cb self.__first_browser_set = True restore_browser = not headless try: self.select_browser( self, config.get("memory", "browser"), library, player, restore_browser) except: config.set("memory", "browser", browsers.name(0)) config.save() raise self.showhide_playlist(ui.get_widget("/Menu/View/SongList")) self.showhide_playqueue(ui.get_widget("/Menu/View/Queue")) self.songlist.connect('popup-menu', self.__songs_popup_menu) self.songlist.connect('columns-changed', self.__cols_changed) self.songlist.connect('columns-changed', self.__hide_headers) self.songlist.info.connect("changed", self.__set_time) lib = library.librarian connect_destroy(lib, 'changed', self.__song_changed, player) targets = [("text/uri-list", Gtk.TargetFlags.OTHER_APP, DND_URI_LIST)] targets = [Gtk.TargetEntry.new(*t) for t in targets] self.drag_dest_set( Gtk.DestDefaults.ALL, targets, Gdk.DragAction.COPY) self.connect('drag-data-received', self.__drag_data_received) if not headless: on_first_map(self, self.__configure_scan_dirs, library) if config.getboolean('library', 'refresh_on_start'): self.__rebuild(None, False) self.connect("key-press-event", self.__key_pressed, player) self.connect("destroy", self.__destroy) self.enable_window_tracking("quodlibet") def set_as_osx_window(self, osx_app): assert osx_app menu = self.ui.get_widget("/Menu") menu.hide() osx_app.set_menu_bar(menu) # Reparent some items to the "Application" menu item = self.ui.get_widget('/Menu/Help/About') osx_app.insert_app_menu_item(item, 0) osx_app.insert_app_menu_item(Gtk.SeparatorMenuItem(), 1) item = self.ui.get_widget('/Menu/Music/Preferences') osx_app.insert_app_menu_item(item, 2) quit_item = self.ui.get_widget('/Menu/Music/Quit') quit_item.hide() def get_osx_is_persistent(self): return True def __player_error(self, player, song, player_error): # it's modal, but mmkeys etc. can still trigger new ones if self._playback_error_dialog: self._playback_error_dialog.destroy() dialog = PlaybackErrorDialog(self, player_error) self._playback_error_dialog = dialog dialog.run() self._playback_error_dialog = None def __configure_scan_dirs(self, library): """Get user to configure scan dirs, if none is set up""" if not get_scan_dirs() and not len(library) and \ quodlibet.is_first_session("quodlibet"): print_d("Couldn't find any scan dirs") resp = ConfirmLibDirSetup(self).run() if resp == ConfirmLibDirSetup.RESPONSE_SETUP: prefs = PreferencesWindow(self) prefs.set_page("library") prefs.show() def __add_bookmark(self, librarian, player): if player.song: position = player.get_position() // 1000 bookmarks = player.song.bookmarks new_mark = (position, _("Bookmark Name")) if new_mark not in bookmarks: bookmarks.append(new_mark) player.song.bookmarks = bookmarks def __edit_bookmarks(self, librarian, player): if player.song: window = EditBookmarks(self, librarian, player) window.show() def __key_pressed(self, widget, event, player): if not player.song: return def seek_relative(seconds): current = player.get_position() current += seconds * 1000 current = min(player.song("~#length") * 1000 - 1, current) current = max(0, current) player.seek(current) if qltk.is_accel(event, "<alt>Right"): seek_relative(10) return True elif qltk.is_accel(event, "<alt>Left"): seek_relative(-10) return True def __destroy(self, *args): self.playlist.destroy() # The tray icon plugin tries to unhide QL because it gets disabled # on Ql exit. The window should stay hidden after destroy. self.show = lambda: None self.present = self.show def __drag_data_received(self, widget, ctx, x, y, sel, tid, etime): assert tid == DND_URI_LIST uris = sel.get_uris() dirs = [] error = False for uri in uris: try: uri = URI(uri) except ValueError: continue if uri.is_filename: loc = os.path.normpath(uri.filename) if os.path.isdir(loc): dirs.append(loc) else: loc = os.path.realpath(loc) if loc not in self.__library: self.__library.add_filename(loc) elif app.player.can_play_uri(uri): if uri not in self.__library: self.__library.add([RemoteFile(uri)]) else: error = True break Gtk.drag_finish(ctx, not error, False, etime) if error: ErrorMessage( self, _("Unable to add songs"), _("%s uses an unsupported protocol.") % util.bold(uri)).run() else: if dirs: copool.add( self.__library.scan, dirs, cofuncid="library", funcid="library") def __songlist_key_press(self, songlist, event): return self.browser.key_pressed(event) def __songlist_drag_data_recv(self, view, *args): if self.browser.can_reorder: songs = view.get_songs() self.browser.reordered(songs) self.songlist.clear_sort() def __show_or(self, widget, prop): ssv = self.song_scroller.get_property('visible') qxv = self.qexpander.get_property('visible') self.songpane.set_property('visible', ssv or qxv) if not ssv: self.qexpander.set_expanded(True) self.__expand_or(widget, prop) def __expand_or(self, widget, prop): if self.qexpander.get_property('expanded'): self.songpane.set_property("position", self.__handle_position) def __moved_pane_handle(self, widget, prop): if self.qexpander.get_property('expanded'): self.__handle_position = self.songpane.get_property("position") def __qex_size_allocate(self, event, param=None): if not self.qexpander.get_property('expanded'): p_max = self.songpane.get_property("max-position") p_cur = self.songpane.get_property("position") if p_max != p_cur: self.songpane.set_property("position", p_max) def __create_menu(self, player, library): ag = Gtk.ActionGroup.new('QuodLibetWindowActions') actions = [ ('Music', None, _("_Music")), ('AddFolders', Gtk.STOCK_ADD, _(u'_Add a Folder…'), "<control>O", None, self.open_chooser), ('AddFiles', Gtk.STOCK_ADD, _(u'_Add a File…'), None, None, self.open_chooser), ('AddLocation', Gtk.STOCK_ADD, _(u'_Add a Location…'), None, None, self.open_location), ('BrowseLibrary', Gtk.STOCK_FIND, _('Open _Browser'), ""), ("Preferences", Gtk.STOCK_PREFERENCES, None, None, None, self.__preferences), ("Plugins", Gtk.STOCK_EXECUTE, _("_Plugins"), None, None, self.__plugins), ("Quit", Gtk.STOCK_QUIT, None, None, None, lambda *x: self.destroy()), ("Control", None, _("_Control")), ("EditTags", Gtk.STOCK_PROPERTIES, _("Edit _Tags"), "", None, self.__current_song_prop), ("Information", Gtk.STOCK_INFO, None, None, None, self.__current_song_info), ("Jump", Gtk.STOCK_JUMP_TO, _("_Jump to Playing Song"), "<control>J", None, self.__jump_to_current), ("View", None, _("_View")), ("Help", None, _("_Help")), ] actions.append(("Previous", Gtk.STOCK_MEDIA_PREVIOUS, None, "<control>comma", None, self.__previous_song)) actions.append(("PlayPause", Gtk.STOCK_MEDIA_PLAY, None, "<control>space", None, self.__play_pause)) actions.append(("Next", Gtk.STOCK_MEDIA_NEXT, None, "<control>period", None, self.__next_song)) ag.add_actions(actions) act = Gtk.ToggleAction.new("StopAfter", _("Stop After This Song"), None, "") ag.add_action_with_accel(act, "<shift>space") # access point for the tray icon self.stop_after = act act = Gtk.Action.new( "AddBookmark", _("Add Bookmark"), None, Gtk.STOCK_ADD) connect_obj(act, 'activate', self.__add_bookmark, library.librarian, player) ag.add_action_with_accel(act, "<ctrl>D") act = Gtk.Action.new("EditBookmarks", _(u"Edit Bookmarks…"), None, "") connect_obj(act, 'activate', self.__edit_bookmarks, library.librarian, player) ag.add_action_with_accel(act, "<ctrl>B") act = Gtk.Action.new("About", None, None, Gtk.STOCK_ABOUT) connect_obj(act, 'activate', self.__show_about, player) ag.add_action_with_accel(act, None) act = Gtk.Action.new( "OnlineHelp", _("Online Help"), None, Gtk.STOCK_HELP) def website_handler(*args): util.website(const.ONLINE_HELP) act.connect('activate', website_handler) ag.add_action_with_accel(act, "F1") act = Gtk.Action.new("SearchHelp", _("Search Help"), None, "") def search_help_handler(*args): util.website(const.SEARCH_HELP) act.connect('activate', search_help_handler) ag.add_action_with_accel(act, None) act = Gtk.Action.new( "RefreshLibrary", _("Re_fresh Library"), None, Gtk.STOCK_REFRESH) act.connect('activate', self.__rebuild, False) ag.add_action_with_accel(act, None) ag.add_toggle_actions([ ("SongList", None, _("Song _List"), None, None, self.showhide_playlist, config.getboolean("memory", "songlist"))]) ag.add_toggle_actions([ ("Queue", None, _("_Queue"), None, None, self.showhide_playqueue, config.getboolean("memory", "queue"))]) view_actions = [] for i, Kind in enumerate(browsers.browsers): action = "View" + Kind.__name__ label = Kind.accelerated_name view_actions.append((action, None, label, None, None, i)) current = browsers.index(config.get("memory", "browser")) def action_callback(view_action, current): self.select_browser(view_action, current, library, player) ag.add_radio_actions( view_actions, current, action_callback, None) for Kind in browsers.browsers: if not Kind.in_menu: continue action = "Browser" + Kind.__name__ label = Kind.accelerated_name act = Gtk.Action.new(action, label, None, None) def browser_activate(action, Kind): LibraryBrowser.open(Kind, library, player) act.connect('activate', browser_activate, Kind) ag.add_action_with_accel(act, None) ui = Gtk.UIManager() ui.insert_action_group(ag, -1) ui.add_ui_from_string( MAIN_MENU % {"browsers": browsers.BrowseLibrary()}) self._filter_menu = FilterMenu(library, player, ui) menustr = MENU % { "views": browsers.ViewBrowser(), } ui.add_ui_from_string(menustr) # Cute. So. UIManager lets you attach tooltips, but when they're # for menu items, they just get ignored. So here I get to actually # attach them. ui.get_widget("/Menu/Music/RefreshLibrary").set_tooltip_text( _("Check for changes in your library")) return ui def __show_about(self, player): about = AboutQuodLibet(self, player) about.run() about.destroy() def select_browser(self, activator, current, library, player, restore=False): if isinstance(current, Gtk.RadioAction): current = current.get_current_value() Browser = browsers.get(current) config.set("memory", "browser", Browser.__name__) if self.browser: if not (self.browser.uses_main_library and Browser.uses_main_library): self.songlist.clear() container = self.browser.__container self.browser.unpack(container, self.songpane) if self.browser.accelerators: self.remove_accel_group(self.browser.accelerators) container.destroy() self.browser.destroy() self.browser = Browser(library) self.browser.connect('songs-selected', self.__browser_cb, library, player) self.browser.connect('songs-activated', self.__browser_activate) if restore: self.browser.restore() self.browser.activate() self.browser.finalize(restore) if self.browser.can_reorder: self.songlist.enable_drop() elif self.browser.dropped: self.songlist.enable_drop(False) else: self.songlist.disable_drop() if self.browser.accelerators: self.add_accel_group(self.browser.accelerators) container = self.browser.__container = self.browser.pack(self.songpane) player.replaygain_profiles[1] = self.browser.replaygain_profiles player.reset_replaygain() self.__browserbox.add(container) container.show() self._filter_menu.set_browser(self.browser) self.__hide_headers() self.__refresh_size() def __update_paused(self, player, paused): menu = self.ui.get_widget("/Menu/Control/PlayPause") if paused: key = Gtk.STOCK_MEDIA_PLAY else: key = Gtk.STOCK_MEDIA_PAUSE text = Gtk.stock_lookup(key).label menu.get_image().set_from_stock(key, Gtk.IconSize.MENU) menu.set_label(text) menu.set_use_underline(True) def __song_ended(self, player, song, stopped): # check if the song should be removed base on the # active filter of the current browser active_filter = self.browser.active_filter if song and active_filter and not active_filter(song): iter_ = self.songlist.model.find(song) if iter_: self.songlist.remove_iters([iter_]) if self.stop_after.get_active(): player.paused = True self.stop_after.set_active(False) def __song_changed(self, library, songs, player): if player.info in songs: self.__update_title(player) def __update_title(self, player): song = player.info title = "Quod Libet" if song: title = song.comma("~title~version~~people") + " - " + title self.set_title(title) def __song_started(self, player, song): self.__update_title(player) for wid in ["Jump", "Next", "EditTags", "Information", "EditBookmarks", "AddBookmark", "StopAfter"]: self.ui.get_widget( '/Menu/Control/' + wid).set_sensitive(bool(song)) # don't jump on stream changes (player.info != player.song) if song and player.song is song and not self.songlist._activated and \ config.getboolean("settings", "jump") and self.songlist.sourced: self.__jump_to_current(False) def __refresh_size(self): ssv = self.song_scroller.get_property('visible') qex = self.qexpander.get_property('visible') if ssv or qex: return # Handle more later if needed.. if not isinstance(self.browser, Gtk.Box): return # If a child expands the browser will take the new space for child in self.browser.get_children(): if self.browser.query_child_packing(child)[0]: break else: # no expanding child, make the window smaller instead width, height = self.get_size() height = self.size_request().height self.resize(width, height) def showhide_playlist(self, toggle): self.song_scroller.set_property('visible', toggle.get_active()) self.__refresh_size() def showhide_playqueue(self, toggle): self.qexpander.set_property('visible', toggle.get_active()) self.__refresh_size() def __play_pause(self, *args): if app.player.song is None: app.player.reset() else: app.player.paused ^= True def __jump_to_current(self, explicit, force_scroll=False): """Select/scroll to the current playing song in the playlist. If it can't be found tell the browser to properly fill the playlist with an appropriate selection containing the song. explicit means that the jump request comes from the user and not from an event like song-started. force_scroll will ask the browser to refill the playlist in any case. """ def idle_jump_to(song, select): ok = self.songlist.jump_to_song(song, select=select) if ok: self.songlist.grab_focus() return False song = app.player.song # We are not playing a song if song is None: return if not force_scroll: ok = self.songlist.jump_to_song(song, select=explicit) else: assert explicit ok = False if ok: self.songlist.grab_focus() elif explicit: # if we can't find it and the user requested it, try harder self.browser.scroll(song) # We need to wait until the browser has finished # scrolling/filling and the songlist is ready. # Not perfect, but works for now. GLib.idle_add( idle_jump_to, song, explicit, priority=GLib.PRIORITY_LOW) def __next_song(self, *args): app.player.next() def __previous_song(self, *args): app.player.previous() def __rebuild(self, activator, force): scan_library(self.__library, force) # Set up the preferences window. def __preferences(self, activator): window = PreferencesWindow(self) window.show() def __plugins(self, activator): window = PluginWindow(self) window.show() def open_location(self, action): name = GetStringDialog(self, _("Add a Location"), _("Enter the location of an audio file:"), okbutton=Gtk.STOCK_ADD).run() if name: if not util.uri_is_valid(name): ErrorMessage( self, _("Unable to add location"), _("%s is not a valid location.") % ( util.bold(util.escape(name)))).run() elif not app.player.can_play_uri(name): ErrorMessage( self, _("Unable to add location"), _("%s uses an unsupported protocol.") % ( util.bold(util.escape(name)))).run() else: if name not in self.__library: self.__library.add([RemoteFile(name)]) def open_chooser(self, action): last_dir = self.last_dir if not os.path.exists(last_dir): last_dir = get_home_dir() class MusicFolderChooser(FolderChooser): def __init__(self, parent, init_dir): super(MusicFolderChooser, self).__init__( parent, _("Add Music"), init_dir) cb = Gtk.CheckButton(_("Watch this folder for new songs")) # enable if no folders are being watched cb.set_active(not get_scan_dirs()) cb.show() self.set_extra_widget(cb) def run(self): fns = super(MusicFolderChooser, self).run() cb = self.get_extra_widget() return fns, cb.get_active() class MusicFileChooser(FileChooser): def __init__(self, parent, init_dir): super(MusicFileChooser, self).__init__( parent, _("Add Music"), formats.filter, init_dir) if action.get_name() == "AddFolders": dialog = MusicFolderChooser(self, last_dir) fns, do_watch = dialog.run() dialog.destroy() if fns: fns = map(glib2fsnative, fns) # scan them self.last_dir = fns[0] copool.add(self.__library.scan, fns, cofuncid="library", funcid="library") # add them as library scan directory if do_watch: dirs = get_scan_dirs() for fn in fns: if fn not in dirs: dirs.append(fn) set_scan_dirs(dirs) else: dialog = MusicFileChooser(self, last_dir) fns = dialog.run() dialog.destroy() if fns: fns = map(glib2fsnative, fns) self.last_dir = os.path.dirname(fns[0]) for filename in map(os.path.realpath, fns): self.__library.add_filename(filename) def __songs_popup_menu(self, songlist): path, col = songlist.get_cursor() header = col.header_name menu = self.songlist.Menu(header, self.browser, self.__library) if menu is not None: return self.songlist.popup_menu(menu, 0, Gtk.get_current_event_time()) def __current_song_prop(self, *args): song = app.player.song if song: librarian = self.__library.librarian window = SongProperties(librarian, [song], parent=self) window.show() def __current_song_info(self, *args): song = app.player.song if song: librarian = self.__library.librarian window = Information(librarian, [song], self) window.show() def __browser_activate(self, browser): app.player.reset() def __browser_cb(self, browser, songs, sorted, library, player): if browser.background: bg = background_filter() if bg: songs = filter(bg, songs) self.songlist.set_songs(songs, sorted) # After the first time the browser activates, which should always # happen if we start up and restore, restore the playing song. # Because the browser has send us songs we can be sure it has # registered all its libraries. if self.__first_browser_set: self.__first_browser_set = False song = library.librarian.get(config.get("memory", "song")) seek_pos = config.getfloat("memory", "seek", 0) config.set("memory", "seek", 0) if song is not None: player.setup(self.playlist, song, seek_pos) if self.__restore_cb: self.__restore_cb() self.__restore_cb = None def __hide_headers(self, activator=None): for column in self.songlist.get_columns(): if self.browser.headers is None: column.set_visible(True) else: for tag in util.tagsplit(column.header_name): if tag in self.browser.headers: column.set_visible(True) break else: column.set_visible(False) def __cols_changed(self, songlist): headers = [col.header_name for col in songlist.get_columns()] try: headers.remove('~current') except ValueError: pass if len(headers) == len(get_columns()): # Not an addition or removal (handled separately) set_columns(headers) SongList.headers = headers def __make_query(self, query): if self.browser.can_filter_text(): self.browser.filter_text(query.encode('utf-8')) self.browser.activate() def __set_time(self, info, songs): i = len(songs) length = sum(song.get("~#length", 0) for song in songs) t = self.browser.statusbar(i) % { 'count': i, 'time': util.format_time_long(length)} self.statusbar.set_default_text(t)
def __init__(self, library): super(MediaDevices, self).__init__(spacing=6) self.set_orientation(Gtk.Orientation.VERTICAL) self._register_instance() self.__cache = {} # Device list on the left pane swin = ScrolledWindow() swin.set_shadow_type(Gtk.ShadowType.IN) swin.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self.pack_start(swin, True, True, 0) self.__view = view = AllTreeView() view.set_model(self.__devices) view.set_rules_hint(True) view.set_headers_visible(False) view.get_selection().set_mode(Gtk.SelectionMode.BROWSE) connect_obj(view.get_selection(), 'changed', self.__refresh, False) view.connect('popup-menu', self.__popup_menu, library) view.connect('row-activated', lambda *a: self.songs_activated()) swin.add(view) col = Gtk.TreeViewColumn("Devices") view.append_column(col) render = Gtk.CellRendererPixbuf() col.pack_start(render, False) col.add_attribute(render, 'icon-name', 1) self.__render = render = Gtk.CellRendererText() render.set_property('ellipsize', Pango.EllipsizeMode.END) render.connect('edited', self.__edited) col.pack_start(render, True) col.set_cell_data_func(render, MediaDevices.cell_data) hbox = Gtk.HBox(spacing=6) hbox.set_homogeneous(True) self.pack_start(Align(hbox, left=3, bottom=3), False, True, 0) # refresh button refresh = Button(_("_Refresh"), Icons.VIEW_REFRESH, Gtk.IconSize.MENU) self.__refresh_button = refresh connect_obj(refresh, 'clicked', self.__refresh, True) refresh.set_sensitive(False) hbox.pack_start(refresh, True, True, 0) # eject button eject = Button(_("_Eject"), Icons.MEDIA_EJECT, Gtk.IconSize.MENU) self.__eject_button = eject eject.connect('clicked', self.__eject) eject.set_sensitive(False) hbox.pack_start(eject, True, True, 0) # Device info on the right pane self.__header = table = Gtk.Table() table.set_col_spacings(8) self.__device_icon = icon = Gtk.Image() icon.set_size_request(48, 48) table.attach(icon, 0, 1, 0, 2, 0) self.__device_name = label = Gtk.Label() label.set_ellipsize(Pango.EllipsizeMode.END) label.set_alignment(0, 0) table.attach(label, 1, 3, 0, 1) self.__device_space = label = Gtk.Label() label.set_ellipsize(Pango.EllipsizeMode.END) label.set_alignment(0, 0.5) table.attach(label, 1, 2, 1, 2) self.__progress = progress = Gtk.ProgressBar() progress.set_size_request(150, -1) table.attach(progress, 2, 3, 1, 2, xoptions=0, yoptions=0) self.accelerators = Gtk.AccelGroup() key, mod = Gtk.accelerator_parse('F2') self.accelerators.connect(key, mod, 0, self.__rename) self.__statusbar = WaitLoadBar() for child in self.get_children(): child.show_all()
def __init__(self, parent=None): if self.is_not_unique(): return super(PluginWindow, self).__init__() self.set_title(_("Plugins")) self.set_default_size(700, 500) self.set_transient_for(parent) self.enable_window_tracking("plugin_prefs") paned = Paned() vbox = Gtk.VBox() sw = ScrolledWindow() sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.ALWAYS) model = ObjectStore() filter_model = ObjectModelFilter(child_model=model) tv = PluginListView() tv.set_model(filter_model) tv.set_rules_hint(True) tv.connect("plugin-toggled", self.__plugin_toggled) fb = Gtk.HBox(spacing=6) filter_combo = PluginFilterCombo() filter_combo.connect("changed", lambda s: filter_model.refilter()) fb.pack_start(filter_combo, False, True, 0) filter_entry = ClearEntry() filter_entry.connect("changed", lambda s: filter_model.refilter()) filter_entry.enable_clear_button() fb.pack_start(filter_entry, True, True, 0) sw.add(tv) sw.set_shadow_type(Gtk.ShadowType.IN) sw.set_size_request(200, -1) bbox = Gtk.HBox(homogeneous=True, spacing=12) errors = qltk.Button(_("Show _Errors"), Icons.DIALOG_WARNING) errors.set_focus_on_click(False) errors.connect('clicked', self.__show_errors) errors.set_no_show_all(True) bbox.pack_start(Align(errors, border=6, right=-6), True, True, 0) pref_box = PluginPreferencesContainer() if const.DEBUG: refresh = qltk.Button(_("_Refresh"), Icons.VIEW_REFRESH) refresh.set_focus_on_click(False) refresh.connect('clicked', self.__refresh, tv, pref_box, errors, filter_combo) bbox.pack_start(Align(refresh, border=6), True, True, 0) vbox.pack_start(Align(fb, border=6, right=-6), False, True, 0) vbox.pack_start(sw, True, True, 0) vbox.pack_start(bbox, False, True, 0) paned.pack1(vbox, False, False) close = qltk.Button(_("_Close"), Icons.WINDOW_CLOSE) close.connect('clicked', lambda *x: self.destroy()) bb_align = Align(halign=Gtk.Align.END, valign=Gtk.Align.END) bb = Gtk.HButtonBox() bb.set_layout(Gtk.ButtonBoxStyle.END) bb.pack_start(close, True, True, 0) bb_align.add(bb) selection = tv.get_selection() selection.connect('changed', self.__selection_changed, pref_box) selection.emit('changed') right_box = Gtk.VBox(spacing=12) right_box.pack_start(pref_box, True, True, 0) self.use_header_bar() if not self.has_close_button(): right_box.pack_start(bb_align, True, True, 0) paned.pack2(Align(right_box, border=12), True, False) paned.set_position(250) self.add(paned) self.__refill(tv, pref_box, errors, filter_combo) self.connect('destroy', self.__destroy) filter_model.set_visible_func(self.__filter, (filter_entry, filter_combo)) self.get_child().show_all() filter_entry.grab_focus() restore_id = config.get("memory", "plugin_selection") tv.select_by_plugin_id(restore_id)
def __init__(self, library): Browser.__init__(self, spacing=6) self.set_orientation(Gtk.Orientation.VERTICAL) self.songcontainer = qltk.paned.ConfigRVPaned( "browsers", "covergrid_pos", 0.4) if config.getboolean("browsers", "covergrid_wide", False): self.songcontainer.set_orientation(Gtk.Orientation.HORIZONTAL) self._register_instance() if self.__model is None: self._init_model(library) self._cover_cancel = Gio.Cancellable() self.scrollwin = sw = ScrolledWindow() sw.set_shadow_type(Gtk.ShadowType.IN) model_sort = AlbumSortModel(model=self.__model) model_filter = AlbumFilterModel(child_model=model_sort) self.view = view = IconView(model_filter) #view.set_item_width(get_cover_size() + 12) self.view.set_row_spacing(config.getint("browsers", "row_spacing", 6)) self.view.set_column_spacing(config.getint("browsers", "column_spacing", 6)) self.view.set_item_padding(config.getint("browsers", "item_padding", 6)) self.view.set_has_tooltip(True) self.view.connect("query-tooltip", self._show_tooltip) self.__bg_filter = background_filter() self.__filter = None model_filter.set_visible_func(self.__parse_query) mag = config.getfloat("browsers", "covergrid_magnification", 3.) self.view.set_item_width(get_cover_size() * mag + 8) self.__cover = render = Gtk.CellRendererPixbuf() render.set_property('width', get_cover_size() * mag + 8) render.set_property('height', get_cover_size() * mag + 8) view.pack_start(render, False) def cell_data_pb(view, cell, model, iter_, no_cover): item = model.get_value(iter_) if item.album is None: surface = None elif item.cover: pixbuf = item.cover pixbuf = add_border_widget(pixbuf, self.view) surface = get_surface_for_pixbuf(self, pixbuf) # don't cache, too much state has an effect on the result self.__last_render_surface = None else: surface = no_cover if self.__last_render_surface == surface: return self.__last_render_surface = surface cell.set_property("surface", surface) view.set_cell_data_func(render, cell_data_pb, self._no_cover) self.__text_cells = render = Gtk.CellRendererText() render.set_visible(config.getboolean("browsers", "album_text", True)) render.set_property('alignment', Pango.Alignment.CENTER) render.set_property('xalign', 0.5) render.set_property('ellipsize', Pango.EllipsizeMode.END) view.pack_start(render, False) def cell_data(view, cell, model, iter_, data): album = model.get_album(iter_) if album is None: text = "<b>%s</b>" % _("All Albums") text += "\n" + ngettext("%d album", "%d albums", len(model) - 1) % (len(model) - 1) markup = text else: markup = self.display_pattern % album if self.__last_render == markup: return self.__last_render = markup cell.markup = markup cell.set_property('markup', markup) view.set_cell_data_func(render, cell_data, None) view.set_selection_mode(Gtk.SelectionMode.MULTIPLE) sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) sw.add(view) view.connect('item-activated', self.__play_selection, None) self.__sig = connect_destroy( view, 'selection-changed', util.DeferredSignal(self.__update_songs, owner=self)) targets = [("text/x-quodlibet-songs", Gtk.TargetFlags.SAME_APP, 1), ("text/uri-list", 0, 2)] targets = [Gtk.TargetEntry.new(*t) for t in targets] view.drag_source_set( Gdk.ModifierType.BUTTON1_MASK, targets, Gdk.DragAction.COPY) view.connect("drag-data-get", self.__drag_data_get) # NOT WORKING connect_obj(view, 'button-press-event', self.__rightclick, view, library) connect_obj(view, 'popup-menu', self.__popup, view, library) self.accelerators = Gtk.AccelGroup() search = SearchBarBox(completion=AlbumTagCompletion(), accel_group=self.accelerators) search.connect('query-changed', self.__update_filter) connect_obj(search, 'focus-out', lambda w: w.grab_focus(), view) self.__search = search prefs = PreferencesButton(self, model_sort) search.pack_start(prefs, False, True, 0) self.pack_start(Align(search, left=6, top=6), False, True, 0) self.pack_start(sw, True, True, 0) self.connect("destroy", self.__destroy) self.enable_row_update(view, sw, self.view) self.__update_filter() self.connect('key-press-event', self.__key_pressed, library.librarian) if app.cover_manager: connect_destroy( app.cover_manager, "cover-changed", self._cover_changed) self.show_all()
def __init__(self, library): super(AlbumList, self).__init__(spacing=6) self.set_orientation(Gtk.Orientation.VERTICAL) self._register_instance() if self.__model is None: self._init_model(library) self._cover_cancel = Gio.Cancellable() sw = ScrolledWindow() sw.set_shadow_type(Gtk.ShadowType.IN) self.view = view = AllTreeView() view.set_headers_visible(False) model_sort = AlbumSortModel(model=self.__model) model_filter = AlbumFilterModel(child_model=model_sort) self.__bg_filter = background_filter() self.__filter = None model_filter.set_visible_func(self.__parse_query) render = Gtk.CellRendererPixbuf() self.__cover_column = column = Gtk.TreeViewColumn("covers", render) column.set_visible(config.getboolean("browsers", "album_covers")) column.set_sizing(Gtk.TreeViewColumnSizing.FIXED) column.set_fixed_width(get_cover_size() + 12) render.set_property('height', get_cover_size() + 8) render.set_property('width', get_cover_size() + 8) def cell_data_pb(column, cell, model, iter_, no_cover): item = model.get_value(iter_) if item.album is None: surface = None elif item.cover: pixbuf = item.cover pixbuf = add_border_widget(pixbuf, self.view) surface = get_surface_for_pixbuf(self, pixbuf) # don't cache, too much state has an effect on the result self.__last_render_surface = None else: surface = no_cover if self.__last_render_surface == surface: return self.__last_render_surface = surface cell.set_property("surface", surface) column.set_cell_data_func(render, cell_data_pb, self._no_cover) view.append_column(column) render = Gtk.CellRendererText() column = Gtk.TreeViewColumn("albums", render) column.set_sizing(Gtk.TreeViewColumnSizing.FIXED) if view.supports_hints(): render.set_property('ellipsize', Pango.EllipsizeMode.END) def cell_data(column, cell, model, iter_, data): album = model.get_album(iter_) if album is None: text = "<b>%s</b>\n" % _("All Albums") text += numeric_phrase("%d album", "%d albums", len(model) - 1) markup = text else: markup = self.display_pattern % album if self.__last_render == markup: return self.__last_render = markup cell.markup = markup cell.set_property('markup', markup) column.set_cell_data_func(render, cell_data) view.append_column(column) view.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE) view.set_rules_hint(True) view.set_search_equal_func(self.__search_func, None) view.set_search_column(0) view.set_model(model_filter) sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) sw.add(view) view.connect('row-activated', self.__play_selection) self.__sig = view.connect( 'selection-changed', util.DeferredSignal(self.__update_songs, owner=view)) targets = [("text/x-quodlibet-songs", Gtk.TargetFlags.SAME_APP, 1), ("text/uri-list", 0, 2)] targets = [Gtk.TargetEntry.new(*t) for t in targets] view.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, targets, Gdk.DragAction.COPY) view.connect("drag-data-get", self.__drag_data_get) connect_obj(view, 'popup-menu', self.__popup, view, library) self.accelerators = Gtk.AccelGroup() search = SearchBarBox(completion=AlbumTagCompletion(), accel_group=self.accelerators) search.connect('query-changed', self.__update_filter) connect_obj(search, 'focus-out', lambda w: w.grab_focus(), view) self.__search = search prefs = PreferencesButton(self, model_sort) search.pack_start(prefs, False, True, 0) self.pack_start(Align(search, left=6, top=6), False, True, 0) self.pack_start(sw, True, True, 0) self.connect("destroy", self.__destroy) self.enable_row_update(view, sw, self.__cover_column) self.connect('key-press-event', self.__key_pressed, library.librarian) if app.cover_manager: connect_destroy(app.cover_manager, "cover-changed", self._cover_changed) self.show_all()
def ratings_vbox(self): """Returns a new VBox containing all ratings widgets""" vb = Gtk.VBox(spacing=6) # Default Rating model = Gtk.ListStore(float) default_combo = Gtk.ComboBox(model=model) default_lab = Gtk.Label(label=_("_Default rating:")) default_lab.set_use_underline(True) default_lab.set_alignment(0, 0.5) def draw_rating(column, cell, model, it, data): num = model[it][0] text = "%0.2f: %s" % (num, util.format_rating(num)) cell.set_property('text', text) def default_rating_changed(combo, model): it = combo.get_active_iter() if it is None: return RATINGS.default = model[it][0] qltk.redraw_all_toplevels() def populate_default_rating_model(combo, num): model = combo.get_model() model.clear() deltas = [] default = RATINGS.default precision = RATINGS.precision for i in range(0, num + 1): r = i * precision model.append(row=[r]) deltas.append((abs(default - r), i)) active = sorted(deltas)[0][1] print_d("Choosing #%d (%.2f), closest to current %.2f" % (active, precision * active, default)) combo.set_active(active) cell = Gtk.CellRendererText() default_combo.pack_start(cell, True) default_combo.set_cell_data_func(cell, draw_rating, None) default_combo.connect('changed', default_rating_changed, model) default_lab.set_mnemonic_widget(default_combo) def refresh_default_combo(num): populate_default_rating_model(default_combo, num) # Rating Scale model = Gtk.ListStore(int) scale_combo = Gtk.ComboBox(model=model) scale_lab = Gtk.Label(label=_("Rating _scale:")) scale_lab.set_use_underline(True) scale_lab.set_mnemonic_widget(scale_combo) cell = Gtk.CellRendererText() scale_combo.pack_start(cell, False) num = RATINGS.number for i in [1, 2, 3, 4, 5, 6, 8, 10]: it = model.append(row=[i]) if i == num: scale_combo.set_active_iter(it) def draw_rating_scale(column, cell, model, it, data): num_stars = model[it][0] text = "%d: %s" % (num_stars, RATINGS.full_symbol * num_stars) cell.set_property('text', text) def rating_scale_changed(combo, model): it = combo.get_active_iter() if it is None: return RATINGS.number = num = model[it][0] refresh_default_combo(num) refresh_default_combo(RATINGS.number) scale_combo.set_cell_data_func(cell, draw_rating_scale, None) scale_combo.connect('changed', rating_scale_changed, model) default_align = Align(halign=Gtk.Align.START) default_align.add(default_lab) scale_align = Align(halign=Gtk.Align.START) scale_align.add(scale_lab) grid = Gtk.Grid(column_spacing=6, row_spacing=6) grid.add(scale_align) grid.add(scale_combo) grid.attach(default_align, 0, 1, 1, 1) grid.attach(default_combo, 1, 1, 1, 1) vb.pack_start(grid, False, False, 6) # Bayesian Factor bayesian_factor = config.getfloat("settings", "bayesian_rating_factor", 0.0) adj = Gtk.Adjustment.new(bayesian_factor, 0.0, 10.0, 0.5, 0.5, 0.0) bayes_spin = Gtk.SpinButton(adjustment=adj, numeric=True) bayes_spin.set_digits(1) bayes_spin.connect('changed', self.__changed_and_signal_library, 'settings', 'bayesian_rating_factor') bayes_spin.set_tooltip_text( _("Bayesian Average factor (C) for aggregated ratings.\n" "0 means a conventional average, higher values mean that " "albums with few tracks will have less extreme ratings. " "Changing this value triggers a re-calculation for all " "albums.")) bayes_label = Gtk.Label(label=_("_Bayesian averaging amount:")) bayes_label.set_use_underline(True) bayes_label.set_mnemonic_widget(bayes_spin) # Save Ratings hb = Gtk.HBox(spacing=6) hb.pack_start(bayes_label, False, True, 0) hb.pack_start(bayes_spin, False, True, 0) vb.pack_start(hb, True, True, 0) cb = CCB(_("Save ratings and play _counts in tags"), "editing", "save_to_songs", populate=True) def update_entry(widget, email_entry): email_entry.set_sensitive(widget.get_active()) vb.pack_start(cb, True, True, 0) hb = Gtk.HBox(spacing=6) lab = Gtk.Label(label=_("_Email:")) entry = UndoEntry() entry.set_tooltip_text(_("Ratings and play counts will be saved " "in tags for this email address")) entry.set_text(config.get("editing", "save_email")) entry.connect('changed', self.__changed, 'editing', 'save_email') # Disable the entry if not saving to tags cb.connect('clicked', update_entry, entry) update_entry(cb, entry) hb.pack_start(lab, False, True, 0) hb.pack_start(entry, True, True, 0) lab.set_mnemonic_widget(entry) lab.set_use_underline(True) vb.pack_start(hb, True, True, 0) return vb
def __init__(self): super(PreferencesWindow.Player, self).__init__(spacing=12) self.set_border_width(12) self.title = _("Playback") # player backend if app.player and hasattr(app.player, 'PlayerPreferences'): player_prefs = app.player.PlayerPreferences() f = qltk.Frame(_("Output Configuration"), child=player_prefs) self.pack_start(f, False, True, 0) # replaygain fallback_gain = config.getfloat("player", "fallback_gain", 0.0) adj = Gtk.Adjustment.new(fallback_gain, -12.0, 12.0, 0.5, 0.5, 0.0) fb_spin = Gtk.SpinButton(adjustment=adj) fb_spin.set_digits(1) fb_spin.connect('changed', self.__changed, 'player', 'fallback_gain') fb_spin.set_tooltip_text( _("If no Replay Gain information is available " "for a song, scale the volume by this value")) fb_label = Gtk.Label(label=_("_Fall-back gain (dB):")) fb_label.set_use_underline(True) fb_label.set_mnemonic_widget(fb_spin) pre_amp_gain = config.getfloat("player", "pre_amp_gain", 0.0) adj = Gtk.Adjustment.new(pre_amp_gain, -6, 6, 0.5, 0.5, 0.0) adj.connect('value-changed', self.__changed, 'player', 'pre_amp_gain') pre_spin = Gtk.SpinButton(adjustment=adj) pre_spin.set_digits(1) pre_spin.set_tooltip_text( _("Scale volume for all songs by this value, " "as long as the result will not clip")) pre_label = Gtk.Label(label=_("_Pre-amp gain (dB):")) pre_label.set_use_underline(True) pre_label.set_mnemonic_widget(pre_spin) widgets = [pre_label, pre_spin, fb_label, fb_spin] c = CCB(_("_Enable Replay Gain volume adjustment"), "player", "replaygain", populate=True) c.connect('toggled', self.__toggled_gain, widgets) # packing table = Gtk.Table.new(3, 2, False) table.set_col_spacings(6) table.set_row_spacings(6) table.attach(c, 0, 2, 0, 1) fb_label.set_alignment(0, 0.5) table.attach(fb_label, 0, 1, 1, 2, xoptions=Gtk.AttachOptions.FILL) pre_label.set_alignment(0, 0.5) table.attach(pre_label, 0, 1, 2, 3, xoptions=Gtk.AttachOptions.FILL) fb_align = Align(halign=Gtk.Align.START) fb_align.add(fb_spin) table.attach(fb_align, 1, 2, 1, 2) pre_align = Align(halign=Gtk.Align.START) pre_align.add(pre_spin) table.attach(pre_align, 1, 2, 2, 3) f = qltk.Frame(_("Replay Gain Volume Adjustment"), child=table) c.emit('toggled') self.pack_start(f, False, True, 0) for child in self.get_children(): child.show_all()
class QuodLibetWindow(Window, PersistentWindowMixin): def __init__(self, library, player, headless=False, restore_cb=None): super(QuodLibetWindow, self).__init__(dialog=False) self.last_dir = get_home_dir() self.__destroyed = False self.__update_title(player) self.set_default_size(550, 450) main_box = Gtk.VBox() self.add(main_box) # create main menubar, load/restore accelerator groups self.__library = library ui = self.__create_menu(player, library) accel_group = ui.get_accel_group() self.add_accel_group(accel_group) def scroll_and_jump(*args): self.__jump_to_current(True, True) keyval, mod = Gtk.accelerator_parse("<control><shift>J") accel_group.connect(keyval, mod, 0, scroll_and_jump) # dbus app menu # Unity puts the app menu next to our menu bar. Since it only contains # menu items also available in the menu bar itself, don't add it. if not util.is_unity(): AppMenu(self, ui.get_action_groups()[0]) # custom accel map accel_fn = os.path.join(quodlibet.get_user_dir(), "accels") Gtk.AccelMap.load(accel_fn) # save right away so we fill the file with example comments of all # accels Gtk.AccelMap.save(accel_fn) menubar = ui.get_widget("/Menu") # Since https://git.gnome.org/browse/gtk+/commit/?id=b44df22895c79 # toplevel menu items show an empty 16x16 image. While we don't # need image items there UIManager creates them by default. # Work around by removing the empty GtkImages for child in menubar.get_children(): if isinstance(child, Gtk.ImageMenuItem): child.set_image(None) main_box.pack_start(menubar, False, True, 0) # get the playlist up before other stuff self.songlist = MainSongList(library, player) self.songlist.show_all() self.songlist.connect("key-press-event", self.__songlist_key_press) self.songlist.connect_after('drag-data-received', self.__songlist_drag_data_recv) self.song_scroller = SongListScroller( ui.get_widget("/Menu/View/SongList")) self.song_scroller.add(self.songlist) self.qexpander = QueueExpander(ui.get_widget("/Menu/View/Queue"), library, player) self.playlist = PlaylistMux(player, self.qexpander.model, self.songlist.model) top_bar = TopBar(self, player, library) main_box.pack_start(top_bar, False, True, 0) self.top_bar = top_bar self.__browserbox = Align(bottom=3) main_box.pack_start(self.__browserbox, True, True, 0) statusbox = StatusBarBox(self.songlist.model, player) self.order = statusbox.order self.repeat = statusbox.repeat self.statusbar = statusbox.statusbar main_box.pack_start(Align(statusbox, border=3, top=-3, right=3), False, True, 0) self.songpane = ConfigRVPaned("memory", "queue_position", 0.75) self.songpane.pack1(self.song_scroller, resize=True, shrink=False) self.songpane.pack2(self.qexpander, resize=True, shrink=False) self.__handle_position = self.songpane.get_property("position") def songpane_button_press_cb(pane, event): """If we start to drag the pane handle while the queue expander is unexpanded, expand it and move the handle to the bottom, so we can 'drag' the queue out """ if event.window != pane.get_handle_window(): return False if not self.qexpander.get_expanded(): self.qexpander.set_expanded(True) pane.set_relative(1.0) return False self.songpane.connect("button-press-event", songpane_button_press_cb) self.song_scroller.connect('notify::visible', self.__show_or) self.qexpander.connect('notify::visible', self.__show_or) self.qexpander.connect('notify::expanded', self.__expand_or) self.qexpander.connect('draw', self.__qex_size_allocate) self.songpane.connect('notify', self.__moved_pane_handle) try: orders = [] for e in config.getstringlist('memory', 'sortby', []): orders.append((e[1:], int(e[0]))) except ValueError: pass else: self.songlist.set_sort_orders(orders) self.browser = None self.ui = ui main_box.show_all() self._playback_error_dialog = None connect_destroy(player, 'song-started', self.__song_started) connect_destroy(player, 'paused', self.__update_paused, True) connect_destroy(player, 'unpaused', self.__update_paused, False) # make sure we redraw all error indicators before opening # a dialog (blocking the main loop), so connect after default handlers connect_after_destroy(player, 'error', self.__player_error) # connect after to let SongTracker update stats connect_after_destroy(player, "song-ended", self.__song_ended) # set at least the playlist. the song should be restored # after the browser emits the song list player.setup(self.playlist, None, 0) self.__restore_cb = restore_cb self.__first_browser_set = True restore_browser = not headless try: self.select_browser(self, config.get("memory", "browser"), library, player, restore_browser) except: config.set("memory", "browser", browsers.name(0)) config.save() raise self.showhide_playlist(ui.get_widget("/Menu/View/SongList")) self.showhide_playqueue(ui.get_widget("/Menu/View/Queue")) self.songlist.connect('popup-menu', self.__songs_popup_menu) self.songlist.connect('columns-changed', self.__cols_changed) self.songlist.connect('columns-changed', self.__hide_headers) self.songlist.info.connect("changed", self.__set_time) lib = library.librarian connect_destroy(lib, 'changed', self.__song_changed, player) targets = [("text/uri-list", Gtk.TargetFlags.OTHER_APP, DND_URI_LIST)] targets = [Gtk.TargetEntry.new(*t) for t in targets] self.drag_dest_set(Gtk.DestDefaults.ALL, targets, Gdk.DragAction.COPY) self.connect('drag-data-received', self.__drag_data_received) if not headless: on_first_map(self, self.__configure_scan_dirs, library) if config.getboolean('library', 'refresh_on_start'): self.__rebuild(None, False) self.connect("key-press-event", self.__key_pressed, player) self.connect("destroy", self.__destroy) self.enable_window_tracking("quodlibet") def set_as_osx_window(self, osx_app): assert osx_app menu = self.ui.get_widget("/Menu") menu.hide() osx_app.set_menu_bar(menu) # Reparent some items to the "Application" menu item = self.ui.get_widget('/Menu/Help/About') osx_app.insert_app_menu_item(item, 0) osx_app.insert_app_menu_item(Gtk.SeparatorMenuItem(), 1) item = self.ui.get_widget('/Menu/Music/Preferences') osx_app.insert_app_menu_item(item, 2) quit_item = self.ui.get_widget('/Menu/Music/Quit') quit_item.hide() def get_osx_is_persistent(self): return True def __player_error(self, player, song, player_error): # it's modal, but mmkeys etc. can still trigger new ones if self._playback_error_dialog: self._playback_error_dialog.destroy() dialog = PlaybackErrorDialog(self, player_error) self._playback_error_dialog = dialog dialog.run() self._playback_error_dialog = None def __configure_scan_dirs(self, library): """Get user to configure scan dirs, if none is set up""" if not get_scan_dirs() and not len(library) and \ quodlibet.is_first_session("quodlibet"): print_d("Couldn't find any scan dirs") resp = ConfirmLibDirSetup(self).run() if resp == ConfirmLibDirSetup.RESPONSE_SETUP: prefs = PreferencesWindow(self) prefs.set_page("library") prefs.show() def __add_bookmark(self, librarian, player): if player.song: position = player.get_position() // 1000 bookmarks = player.song.bookmarks new_mark = (position, _("Bookmark Name")) if new_mark not in bookmarks: bookmarks.append(new_mark) player.song.bookmarks = bookmarks def __edit_bookmarks(self, librarian, player): if player.song: window = EditBookmarks(self, librarian, player) window.show() def __key_pressed(self, widget, event, player): if not player.song: return def seek_relative(seconds): current = player.get_position() current += seconds * 1000 current = min(player.song("~#length") * 1000 - 1, current) current = max(0, current) player.seek(current) if qltk.is_accel(event, "<alt>Right"): seek_relative(10) return True elif qltk.is_accel(event, "<alt>Left"): seek_relative(-10) return True def __destroy(self, *args): self.playlist.destroy() # The tray icon plugin tries to unhide QL because it gets disabled # on Ql exit. The window should stay hidden after destroy. self.show = lambda: None self.present = self.show def __drag_data_received(self, widget, ctx, x, y, sel, tid, etime): assert tid == DND_URI_LIST uris = sel.get_uris() dirs = [] error = False for uri in uris: try: uri = URI(uri) except ValueError: continue if uri.is_filename: loc = os.path.normpath(uri.filename) if os.path.isdir(loc): dirs.append(loc) else: loc = os.path.realpath(loc) if loc not in self.__library: self.__library.add_filename(loc) elif app.player.can_play_uri(uri): if uri not in self.__library: self.__library.add([RemoteFile(uri)]) else: error = True break Gtk.drag_finish(ctx, not error, False, etime) if error: ErrorMessage( self, _("Unable to add songs"), _("%s uses an unsupported protocol.") % util.bold(uri)).run() else: if dirs: copool.add(self.__library.scan, dirs, cofuncid="library", funcid="library") def __songlist_key_press(self, songlist, event): return self.browser.key_pressed(event) def __songlist_drag_data_recv(self, view, *args): if self.browser.can_reorder: songs = view.get_songs() self.browser.reordered(songs) self.songlist.clear_sort() def __show_or(self, widget, prop): ssv = self.song_scroller.get_property('visible') qxv = self.qexpander.get_property('visible') self.songpane.set_property('visible', ssv or qxv) if not ssv: self.qexpander.set_expanded(True) self.__expand_or(widget, prop) def __expand_or(self, widget, prop): if self.qexpander.get_property('expanded'): self.songpane.set_property("position", self.__handle_position) def __moved_pane_handle(self, widget, prop): if self.qexpander.get_property('expanded'): self.__handle_position = self.songpane.get_property("position") def __qex_size_allocate(self, event, param=None): if not self.qexpander.get_property('expanded'): p_max = self.songpane.get_property("max-position") p_cur = self.songpane.get_property("position") if p_max != p_cur: self.songpane.set_property("position", p_max) def __create_menu(self, player, library): ag = Gtk.ActionGroup.new('QuodLibetWindowActions') actions = [ ('Music', None, _("_Music")), ('AddFolders', Gtk.STOCK_ADD, _(u'_Add a Folder…'), "<control>O", None, self.open_chooser), ('AddFiles', Gtk.STOCK_ADD, _(u'_Add a File…'), None, None, self.open_chooser), ('AddLocation', Gtk.STOCK_ADD, _(u'_Add a Location…'), None, None, self.open_location), ('BrowseLibrary', Gtk.STOCK_FIND, _('Open _Browser'), ""), ("Preferences", Gtk.STOCK_PREFERENCES, None, None, None, self.__preferences), ("Plugins", Gtk.STOCK_EXECUTE, _("_Plugins"), None, None, self.__plugins), ("Quit", Gtk.STOCK_QUIT, None, None, None, lambda *x: self.destroy()), ("Control", None, _("_Control")), ("EditTags", Gtk.STOCK_PROPERTIES, _("Edit _Tags"), "", None, self.__current_song_prop), ("Information", Gtk.STOCK_INFO, None, None, None, self.__current_song_info), ("Jump", Gtk.STOCK_JUMP_TO, _("_Jump to Playing Song"), "<control>J", None, self.__jump_to_current), ("View", None, _("_View")), ("Help", None, _("_Help")), ] actions.append(("Previous", Gtk.STOCK_MEDIA_PREVIOUS, None, "<control>comma", None, self.__previous_song)) actions.append(("PlayPause", Gtk.STOCK_MEDIA_PLAY, None, "<control>space", None, self.__play_pause)) actions.append(("Next", Gtk.STOCK_MEDIA_NEXT, None, "<control>period", None, self.__next_song)) ag.add_actions(actions) act = Gtk.ToggleAction.new("StopAfter", _("Stop After This Song"), None, "") ag.add_action_with_accel(act, "<shift>space") # access point for the tray icon self.stop_after = act act = Gtk.Action.new("AddBookmark", _("Add Bookmark"), None, Gtk.STOCK_ADD) connect_obj(act, 'activate', self.__add_bookmark, library.librarian, player) ag.add_action_with_accel(act, "<ctrl>D") act = Gtk.Action.new("EditBookmarks", _(u"Edit Bookmarks…"), None, "") connect_obj(act, 'activate', self.__edit_bookmarks, library.librarian, player) ag.add_action_with_accel(act, "<ctrl>B") act = Gtk.Action.new("About", None, None, Gtk.STOCK_ABOUT) connect_obj(act, 'activate', self.__show_about, player) ag.add_action_with_accel(act, None) act = Gtk.Action.new("OnlineHelp", _("Online Help"), None, Gtk.STOCK_HELP) def website_handler(*args): util.website(const.ONLINE_HELP) act.connect('activate', website_handler) ag.add_action_with_accel(act, "F1") act = Gtk.Action.new("SearchHelp", _("Search Help"), None, "") def search_help_handler(*args): util.website(const.SEARCH_HELP) act.connect('activate', search_help_handler) ag.add_action_with_accel(act, None) act = Gtk.Action.new("RefreshLibrary", _("Re_fresh Library"), None, Gtk.STOCK_REFRESH) act.connect('activate', self.__rebuild, False) ag.add_action_with_accel(act, None) ag.add_toggle_actions([("SongList", None, _("Song _List"), None, None, self.showhide_playlist, config.getboolean("memory", "songlist"))]) ag.add_toggle_actions([("Queue", None, _("_Queue"), None, None, self.showhide_playqueue, config.getboolean("memory", "queue"))]) view_actions = [] for i, Kind in enumerate(browsers.browsers): action = "View" + Kind.__name__ label = Kind.accelerated_name view_actions.append((action, None, label, None, None, i)) current = browsers.index(config.get("memory", "browser")) def action_callback(view_action, current): self.select_browser(view_action, current, library, player) ag.add_radio_actions(view_actions, current, action_callback, None) for Kind in browsers.browsers: if not Kind.in_menu: continue action = "Browser" + Kind.__name__ label = Kind.accelerated_name act = Gtk.Action.new(action, label, None, None) def browser_activate(action, Kind): LibraryBrowser.open(Kind, library, player) act.connect('activate', browser_activate, Kind) ag.add_action_with_accel(act, None) ui = Gtk.UIManager() ui.insert_action_group(ag, -1) ui.add_ui_from_string(MAIN_MENU % {"browsers": browsers.BrowseLibrary()}) self._filter_menu = FilterMenu(library, player, ui) menustr = MENU % { "views": browsers.ViewBrowser(), } ui.add_ui_from_string(menustr) # Cute. So. UIManager lets you attach tooltips, but when they're # for menu items, they just get ignored. So here I get to actually # attach them. ui.get_widget("/Menu/Music/RefreshLibrary").set_tooltip_text( _("Check for changes in your library")) return ui def __show_about(self, player): about = AboutQuodLibet(self, player) about.run() about.destroy() def select_browser(self, activator, current, library, player, restore=False): if isinstance(current, Gtk.RadioAction): current = current.get_current_value() Browser = browsers.get(current) config.set("memory", "browser", Browser.__name__) if self.browser: if not (self.browser.uses_main_library and Browser.uses_main_library): self.songlist.clear() container = self.browser.__container self.browser.unpack(container, self.songpane) if self.browser.accelerators: self.remove_accel_group(self.browser.accelerators) container.destroy() self.browser.destroy() self.browser = Browser(library) self.browser.connect('songs-selected', self.__browser_cb, library, player) self.browser.connect('songs-activated', self.__browser_activate) if restore: self.browser.restore() self.browser.activate() self.browser.finalize(restore) if self.browser.can_reorder: self.songlist.enable_drop() elif self.browser.dropped: self.songlist.enable_drop(False) else: self.songlist.disable_drop() if self.browser.accelerators: self.add_accel_group(self.browser.accelerators) container = self.browser.__container = self.browser.pack(self.songpane) player.replaygain_profiles[1] = self.browser.replaygain_profiles player.reset_replaygain() self.__browserbox.add(container) container.show() self._filter_menu.set_browser(self.browser) self.__hide_headers() self.__refresh_size() def __update_paused(self, player, paused): menu = self.ui.get_widget("/Menu/Control/PlayPause") if paused: key = Gtk.STOCK_MEDIA_PLAY else: key = Gtk.STOCK_MEDIA_PAUSE text = Gtk.stock_lookup(key).label menu.get_image().set_from_stock(key, Gtk.IconSize.MENU) menu.set_label(text) menu.set_use_underline(True) def __song_ended(self, player, song, stopped): # check if the song should be removed base on the # active filter of the current browser active_filter = self.browser.active_filter if song and active_filter and not active_filter(song): iter_ = self.songlist.model.find(song) if iter_: self.songlist.remove_iters([iter_]) if self.stop_after.get_active(): player.paused = True self.stop_after.set_active(False) def __song_changed(self, library, songs, player): if player.info in songs: self.__update_title(player) def __update_title(self, player): song = player.info title = "Quod Libet" if song: title = song.comma("~title~version~~people") + " - " + title self.set_title(title) def __song_started(self, player, song): self.__update_title(player) for wid in [ "Jump", "Next", "EditTags", "Information", "EditBookmarks", "AddBookmark", "StopAfter" ]: self.ui.get_widget('/Menu/Control/' + wid).set_sensitive( bool(song)) # don't jump on stream changes (player.info != player.song) if song and player.song is song and not self.songlist._activated and \ config.getboolean("settings", "jump") and self.songlist.sourced: self.__jump_to_current(False) def __refresh_size(self): ssv = self.song_scroller.get_property('visible') qex = self.qexpander.get_property('visible') if ssv or qex: return # Handle more later if needed.. if not isinstance(self.browser, Gtk.Box): return # If a child expands the browser will take the new space for child in self.browser.get_children(): if self.browser.query_child_packing(child)[0]: break else: # no expanding child, make the window smaller instead width, height = self.get_size() height = self.size_request().height self.resize(width, height) def showhide_playlist(self, toggle): self.song_scroller.set_property('visible', toggle.get_active()) self.__refresh_size() def showhide_playqueue(self, toggle): self.qexpander.set_property('visible', toggle.get_active()) self.__refresh_size() def __play_pause(self, *args): if app.player.song is None: app.player.reset() else: app.player.paused ^= True def __jump_to_current(self, explicit, force_scroll=False): """Select/scroll to the current playing song in the playlist. If it can't be found tell the browser to properly fill the playlist with an appropriate selection containing the song. explicit means that the jump request comes from the user and not from an event like song-started. force_scroll will ask the browser to refill the playlist in any case. """ def idle_jump_to(song, select): ok = self.songlist.jump_to_song(song, select=select) if ok: self.songlist.grab_focus() return False song = app.player.song # We are not playing a song if song is None: return if not force_scroll: ok = self.songlist.jump_to_song(song, select=explicit) else: assert explicit ok = False if ok: self.songlist.grab_focus() elif explicit: # if we can't find it and the user requested it, try harder self.browser.scroll(song) # We need to wait until the browser has finished # scrolling/filling and the songlist is ready. # Not perfect, but works for now. GLib.idle_add(idle_jump_to, song, explicit, priority=GLib.PRIORITY_LOW) def __next_song(self, *args): app.player.next() def __previous_song(self, *args): app.player.previous() def __rebuild(self, activator, force): scan_library(self.__library, force) # Set up the preferences window. def __preferences(self, activator): window = PreferencesWindow(self) window.show() def __plugins(self, activator): window = PluginWindow(self) window.show() def open_location(self, action): name = GetStringDialog(self, _("Add a Location"), _("Enter the location of an audio file:"), okbutton=Gtk.STOCK_ADD).run() if name: if not util.uri_is_valid(name): ErrorMessage( self, _("Unable to add location"), _("%s is not a valid location.") % (util.bold(util.escape(name)))).run() elif not app.player.can_play_uri(name): ErrorMessage( self, _("Unable to add location"), _("%s uses an unsupported protocol.") % (util.bold(util.escape(name)))).run() else: if name not in self.__library: self.__library.add([RemoteFile(name)]) def open_chooser(self, action): last_dir = self.last_dir if not os.path.exists(last_dir): last_dir = get_home_dir() class MusicFolderChooser(FolderChooser): def __init__(self, parent, init_dir): super(MusicFolderChooser, self).__init__(parent, _("Add Music"), init_dir) cb = Gtk.CheckButton(_("Watch this folder for new songs")) # enable if no folders are being watched cb.set_active(not get_scan_dirs()) cb.show() self.set_extra_widget(cb) def run(self): fns = super(MusicFolderChooser, self).run() cb = self.get_extra_widget() return fns, cb.get_active() class MusicFileChooser(FileChooser): def __init__(self, parent, init_dir): super(MusicFileChooser, self).__init__(parent, _("Add Music"), formats.filter, init_dir) if action.get_name() == "AddFolders": dialog = MusicFolderChooser(self, last_dir) fns, do_watch = dialog.run() dialog.destroy() if fns: fns = map(glib2fsnative, fns) # scan them self.last_dir = fns[0] copool.add(self.__library.scan, fns, cofuncid="library", funcid="library") # add them as library scan directory if do_watch: dirs = get_scan_dirs() for fn in fns: if fn not in dirs: dirs.append(fn) set_scan_dirs(dirs) else: dialog = MusicFileChooser(self, last_dir) fns = dialog.run() dialog.destroy() if fns: fns = map(glib2fsnative, fns) self.last_dir = os.path.dirname(fns[0]) for filename in map(os.path.realpath, fns): self.__library.add_filename(filename) def __songs_popup_menu(self, songlist): path, col = songlist.get_cursor() header = col.header_name menu = self.songlist.Menu(header, self.browser, self.__library) if menu is not None: return self.songlist.popup_menu(menu, 0, Gtk.get_current_event_time()) def __current_song_prop(self, *args): song = app.player.song if song: librarian = self.__library.librarian window = SongProperties(librarian, [song], parent=self) window.show() def __current_song_info(self, *args): song = app.player.song if song: librarian = self.__library.librarian window = Information(librarian, [song], self) window.show() def __browser_activate(self, browser): app.player.reset() def __browser_cb(self, browser, songs, sorted, library, player): if browser.background: bg = background_filter() if bg: songs = filter(bg, songs) self.songlist.set_songs(songs, sorted) # After the first time the browser activates, which should always # happen if we start up and restore, restore the playing song. # Because the browser has send us songs we can be sure it has # registered all its libraries. if self.__first_browser_set: self.__first_browser_set = False song = library.librarian.get(config.get("memory", "song")) seek_pos = config.getfloat("memory", "seek", 0) config.set("memory", "seek", 0) if song is not None: player.setup(self.playlist, song, seek_pos) if self.__restore_cb: self.__restore_cb() self.__restore_cb = None def __hide_headers(self, activator=None): for column in self.songlist.get_columns(): if self.browser.headers is None: column.set_visible(True) else: for tag in util.tagsplit(column.header_name): if tag in self.browser.headers: column.set_visible(True) break else: column.set_visible(False) def __cols_changed(self, songlist): headers = [col.header_name for col in songlist.get_columns()] try: headers.remove('~current') except ValueError: pass if len(headers) == len(get_columns()): # Not an addition or removal (handled separately) set_columns(headers) SongList.headers = headers def __make_query(self, query): if self.browser.can_filter_text(): self.browser.filter_text(query.encode('utf-8')) self.browser.activate() def __set_time(self, info, songs): i = len(songs) length = sum(song.get("~#length", 0) for song in songs) t = self.browser.statusbar(i) % { 'count': i, 'time': util.format_time_long(length) } self.statusbar.set_default_text(t)
class InternetRadio(Browser, util.InstanceTracker): __stations = None __fav_stations = None __librarian = None __filter = None name = _("Internet Radio") accelerated_name = _("_Internet Radio") keys = ["InternetRadio"] priority = 16 uses_main_library = False headers = "title artist ~people grouping genre website ~format " "channel-mode".split() TYPE, ICON_NAME, KEY, NAME = range(4) TYPE_FILTER, TYPE_ALL, TYPE_FAV, TYPE_SEP, TYPE_NOCAT = range(5) STAR = ["artist", "title", "website", "genre", "comment"] @classmethod def _init(klass, library): klass.__librarian = library.librarian klass.__stations = SongLibrary("iradio-remote") klass.__stations.load(STATIONS_ALL) klass.__fav_stations = SongLibrary("iradio") klass.__fav_stations.load(STATIONS_FAV) klass.filters = GenreFilter() @classmethod def _destroy(klass): if klass.__stations.dirty: klass.__stations.save() klass.__stations.destroy() klass.__stations = None if klass.__fav_stations.dirty: klass.__fav_stations.save() klass.__fav_stations.destroy() klass.__fav_stations = None klass.__librarian = None klass.filters = None def __inhibit(self): self.view.get_selection().handler_block(self.__changed_sig) def __uninhibit(self): self.view.get_selection().handler_unblock(self.__changed_sig) def __destroy(self, *args): if not self.instances(): self._destroy() def __init__(self, library): super(InternetRadio, self).__init__(spacing=12) self.set_orientation(Gtk.Orientation.VERTICAL) if not self.instances(): self._init(library) self._register_instance() self.connect("destroy", self.__destroy) completion = LibraryTagCompletion(self.__stations) self.accelerators = Gtk.AccelGroup() self.__searchbar = search = SearchBarBox(completion=completion, accel_group=self.accelerators) search.connect("query-changed", self.__filter_changed) menu = Gtk.Menu() new_item = MenuItem(_(u"_New Station…"), Icons.LIST_ADD) new_item.connect("activate", self.__add) menu.append(new_item) update_item = MenuItem(_("_Update Stations"), Icons.VIEW_REFRESH) update_item.connect("activate", self.__update) menu.append(update_item) menu.show_all() button = MenuButton(SymbolicIconImage(Icons.EMBLEM_SYSTEM, Gtk.IconSize.MENU), arrow=True) button.set_menu(menu) def focus(widget, *args): qltk.get_top_parent(widget).songlist.grab_focus() search.connect("focus-out", focus) # treeview scrolled_window = ScrolledWindow() scrolled_window.show() scrolled_window.set_shadow_type(Gtk.ShadowType.IN) self.view = view = AllTreeView() view.show() view.set_headers_visible(False) scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scrolled_window.add(view) model = Gtk.ListStore(int, str, str, str) model.append(row=[self.TYPE_ALL, Icons.FOLDER, "__all", _("All Stations")]) model.append(row=[self.TYPE_SEP, Icons.FOLDER, "", ""]) # Translators: Favorite radio stations model.append(row=[self.TYPE_FAV, Icons.FOLDER, "__fav", _("Favorites")]) model.append(row=[self.TYPE_SEP, Icons.FOLDER, "", ""]) filters = self.filters for text, k in sorted([(filters.text(k), k) for k in filters.keys()]): model.append(row=[self.TYPE_FILTER, Icons.EDIT_FIND, k, text]) model.append(row=[self.TYPE_NOCAT, Icons.FOLDER, "nocat", _("No Category")]) def separator(model, iter, data): return model[iter][self.TYPE] == self.TYPE_SEP view.set_row_separator_func(separator, None) def search_func(model, column, key, iter, data): return key.lower() not in model[iter][column].lower() view.set_search_column(self.NAME) view.set_search_equal_func(search_func, None) column = Gtk.TreeViewColumn("genres") column.set_sizing(Gtk.TreeViewColumnSizing.FIXED) renderpb = Gtk.CellRendererPixbuf() renderpb.props.xpad = 3 column.pack_start(renderpb, False) column.add_attribute(renderpb, "icon-name", self.ICON_NAME) render = Gtk.CellRendererText() render.set_property("ellipsize", Pango.EllipsizeMode.END) view.append_column(column) column.pack_start(render, True) column.add_attribute(render, "text", self.NAME) view.set_model(model) # selection selection = view.get_selection() selection.set_mode(Gtk.SelectionMode.MULTIPLE) self.__changed_sig = connect_destroy(selection, "changed", util.DeferredSignal(lambda x: self.activate())) box = Gtk.HBox(spacing=6) box.pack_start(search, True, True, 0) box.pack_start(button, False, True, 0) self._searchbox = Align(box, left=0, right=6, top=6) self._searchbox.show_all() def qbar_response(infobar, response_id): if response_id == infobar.RESPONSE_LOAD: self.__update() self.qbar = QuestionBar() self.qbar.connect("response", qbar_response) if self._is_library_empty(): self.qbar.show() pane = qltk.ConfigRHPaned("browsers", "internetradio_pos", 0.4) pane.show() pane.pack1(scrolled_window, resize=False, shrink=False) songbox = Gtk.VBox(spacing=6) songbox.pack_start(self._searchbox, False, True, 0) self._songpane_container = Gtk.VBox() self._songpane_container.show() songbox.pack_start(self._songpane_container, True, True, 0) songbox.pack_start(self.qbar, False, True, 0) songbox.show() pane.pack2(songbox, resize=True, shrink=False) self.pack_start(pane, True, True, 0) self.show() def _is_library_empty(self): return not len(self.__stations) and not len(self.__fav_stations) def pack(self, songpane): container = Gtk.VBox() container.add(self) self._songpane_container.add(songpane) return container def unpack(self, container, songpane): self._songpane_container.remove(songpane) container.remove(self) def __update(self, *args): self.qbar.hide() copool.add(download_taglist, self.__update_done, cofuncid="radio-load", funcid="radio-load") def __update_done(self, stations): if not stations: print_w("Loading remote station list failed.") return # filter stations based on quality, listenercount def filter_stations(station): peak = station.get("~#listenerpeak", 0) if peak < 10: return False aac = "AAC" in station("~format") bitrate = station("~#bitrate", 50) if (aac and bitrate < 40) or (not aac and bitrate < 60): return False return True stations = filter(filter_stations, stations) # group them based on the title groups = {} for s in stations: key = s("~title~artist") groups.setdefault(key, []).append(s) # keep at most 2 URLs for each group stations = [] for key, sub in groups.iteritems(): sub.sort(key=lambda s: s.get("~#listenerpeak", 0), reverse=True) stations.extend(sub[:2]) # only keep the ones in at least one category all_ = [self.filters.query(k) for k in self.filters.keys()] assert all_ anycat_filter = reduce(lambda x, y: x | y, all_) stations = filter(anycat_filter.search, stations) # remove listenerpeak for s in stations: s.pop("~#listenerpeak", None) # update the libraries stations = dict(((s.key, s) for s in stations)) # don't add ones that are in the fav list for fav in self.__fav_stations.iterkeys(): stations.pop(fav, None) # separate o, n = set(self.__stations.iterkeys()), set(stations) to_add, to_change, to_remove = n - o, o & n, o - n del o, n # migrate stats to_change = [stations.pop(k) for k in to_change] for new in to_change: old = self.__stations[new.key] # clear everything except stats AudioFile.reload(old) # add new metadata except stats for k in (x for x in new.iterkeys() if x not in MIGRATE): old[k] = new[k] to_add = [stations.pop(k) for k in to_add] to_remove = [self.__stations[k] for k in to_remove] self.__stations.remove(to_remove) self.__stations.changed(to_change) self.__stations.add(to_add) def __filter_changed(self, bar, text, restore=False): self.__filter = Query(text, self.STAR) if not restore: self.activate() def __get_selected_libraries(self): """Returns the libraries to search in depending on the filter selection""" selection = self.view.get_selection() model, rows = selection.get_selected_rows() types = [model[row][self.TYPE] for row in rows] libs = [self.__fav_stations] if types != [self.TYPE_FAV]: libs.append(self.__stations) return libs def __get_selection_filter(self): """Retuns a filter object for the current selection or None if nothing should be filtered""" selection = self.view.get_selection() model, rows = selection.get_selected_rows() filter_ = None for row in rows: type_ = model[row][self.TYPE] if type_ == self.TYPE_FILTER: key = model[row][self.KEY] current_filter = self.filters.query(key) if current_filter: if filter_: filter_ |= current_filter else: filter_ = current_filter elif type_ == self.TYPE_NOCAT: # if notcat is selected, combine all filters, negate and merge all_ = [self.filters.query(k) for k in self.filters.keys()] nocat_filter = all_ and -reduce(lambda x, y: x | y, all_) if nocat_filter: if filter_: filter_ |= nocat_filter else: filter_ = nocat_filter elif type_ == self.TYPE_ALL: filter_ = None break return filter_ def __add_fav(self, songs): songs = [s for s in songs if s in self.__stations] type(self).__librarian.move(songs, self.__stations, self.__fav_stations) def __remove_fav(self, songs): songs = [s for s in songs if s in self.__fav_stations] type(self).__librarian.move(songs, self.__fav_stations, self.__stations) def __add(self, button): parent = qltk.get_top_parent(self) uri = (AddNewStation(parent).run(clipboard=True) or "").strip() if uri != "": self.__add_station(uri) def __add_station(self, uri): irfs = add_station(uri) if not irfs: qltk.ErrorMessage( None, _("No stations found"), _("No Internet radio stations were found at %s.") % util.escape(uri) ).run() return irfs = filter(lambda station: station not in self.__fav_stations, irfs) if not irfs: qltk.WarningMessage( None, _("Unable to add station"), _("All stations listed are already in your library.") ).run() if irfs: self.__fav_stations.add(irfs) def Menu(self, songs, library, items): in_fav = False in_all = False for song in songs: if song in self.__fav_stations: in_fav = True elif song in self.__stations: in_all = True if in_fav and in_all: break iradio_items = [] button = MenuItem(_("Add to Favorites"), Icons.LIST_ADD) button.set_sensitive(in_all) connect_obj(button, "activate", self.__add_fav, songs) iradio_items.append(button) button = MenuItem(_("Remove from Favorites"), Icons.LIST_REMOVE) button.set_sensitive(in_fav) connect_obj(button, "activate", self.__remove_fav, songs) iradio_items.append(button) items.append(iradio_items) menu = SongsMenu(self.__librarian, songs, playlists=False, remove=True, queue=False, devices=False, items=items) return menu def restore(self): text = config.get("browsers", "query_text").decode("utf-8") self.__searchbar.set_text(text) if Query.is_parsable(text): self.__filter_changed(self.__searchbar, text, restore=True) keys = config.get("browsers", "radio").splitlines() def select_func(row): return row[self.TYPE] != self.TYPE_SEP and row[self.KEY] in keys self.__inhibit() view = self.view if not view.select_by_func(select_func): for row in view.get_model(): if row[self.TYPE] == self.TYPE_FAV: view.set_cursor(row.path) break self.__uninhibit() def __get_filter(self): filter_ = self.__get_selection_filter() text_filter = self.__filter or Query("") if filter_: filter_ &= text_filter else: filter_ = text_filter return filter_ def can_filter_text(self): return True def filter_text(self, text): self.__searchbar.set_text(text) if Query.is_parsable(text): self.__filter_changed(self.__searchbar, text) self.activate() def get_filter_text(self): return self.__searchbar.get_text() def activate(self): filter_ = self.__get_filter() libs = self.__get_selected_libraries() songs = filter_.filter(itertools.chain(*libs)) self.songs_selected(songs) def active_filter(self, song): for lib in self.__get_selected_libraries(): if song in lib: break else: return False filter_ = self.__get_filter() if filter_: return filter_.search(song) return True def save(self): text = self.__searchbar.get_text().encode("utf-8") config.set("browsers", "query_text", text) selection = self.view.get_selection() model, rows = selection.get_selected_rows() names = filter(None, [model[row][self.KEY] for row in rows]) config.set("browsers", "radio", "\n".join(names)) def scroll(self, song): # nothing we care about if song not in self.__stations and song not in self.__fav_stations: return path = None for row in self.view.get_model(): if row[self.TYPE] == self.TYPE_FILTER: if self.filters.query(row[self.KEY]).search(song): path = row.path break else: # in case nothing matches, select all path = (0,) self.view.set_cursor(path) self.view.scroll_to_cell(path, use_align=True, row_align=0.5) def statusbar(self, i): return ngettext("%(count)d station", "%(count)d stations", i)
def __init__(self, prop, library): super().__init__(spacing=6) self.title = _("Track Numbers") self.set_border_width(12) label_start = Gtk.Label(label=_("Start fro_m:"), halign=Gtk.Align.END) label_start.set_use_underline(True) spin_start = Gtk.SpinButton() spin_start.set_range(0, 999) spin_start.set_increments(1, 10) spin_start.set_value(1) label_start.set_mnemonic_widget(spin_start) label_total = Gtk.Label(label=_("_Total tracks:"), halign=Gtk.Align.END) label_total.set_use_underline(True) spin_total = Gtk.SpinButton() spin_total.set_range(0, 999) spin_total.set_increments(1, 10) label_total.set_mnemonic_widget(spin_total) preview = qltk.Button(_("_Preview"), Icons.VIEW_REFRESH) grid = Gtk.Grid(row_spacing=4, column_spacing=4) grid.add(label_start) grid.attach_next_to(spin_start, label_start, Gtk.PositionType.RIGHT, 1, 1) grid.attach_next_to(label_total, label_start, Gtk.PositionType.BOTTOM, 1, 1) grid.attach_next_to(spin_total, label_total, Gtk.PositionType.RIGHT, 1, 1) grid.attach_next_to(Align(preview, halign=Gtk.Align.END), spin_start, Gtk.PositionType.RIGHT, 1, 1) preview.props.hexpand = True model = ObjectStore() view = HintedTreeView(model=model) self.pack_start(grid, False, True, 0) render = Gtk.CellRendererText() column = TreeViewColumn(title=_('File')) column.pack_start(render, True) column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) def cell_data_file(column, cell, model, iter_, data): entry = model.get_value(iter_) cell.set_property("text", entry.name) column.set_cell_data_func(render, cell_data_file) view.append_column(column) render = Gtk.CellRendererText() render.set_property('editable', True) column = TreeViewColumn(title=_('Track')) column.pack_start(render, True) column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) def cell_data_track(column, cell, model, iter_, data): entry = model.get_value(iter_) cell.set_property("text", entry.tracknumber) column.set_cell_data_func(render, cell_data_track) view.append_column(column) view.set_reorderable(True) w = Gtk.ScrolledWindow() w.set_shadow_type(Gtk.ShadowType.IN) w.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) w.add(view) self.pack_start(w, True, True, 0) bbox = Gtk.HButtonBox() bbox.set_spacing(6) bbox.set_layout(Gtk.ButtonBoxStyle.END) save = Button(_("_Save"), Icons.DOCUMENT_SAVE) self.save = save connect_obj(save, 'clicked', self.__save_files, prop, model, library) revert = Button(_("_Revert"), Icons.DOCUMENT_REVERT) self.revert = revert bbox.pack_start(revert, True, True, 0) bbox.pack_start(save, True, True, 0) self.pack_start(bbox, False, True, 0) preview_args = [spin_start, spin_total, model, save, revert] preview.connect('clicked', self.__preview_tracks, *preview_args) connect_obj(revert, 'clicked', self.__update, None, *preview_args[1:]) spin_total.connect('value-changed', self.__preview_tracks, *preview_args) spin_start.connect('value-changed', self.__preview_tracks, *preview_args) connect_obj(view, 'drag-end', self.__class__.__preview_tracks, self, *preview_args) render.connect('edited', self.__row_edited, model, preview, save) connect_obj(prop, 'changed', self.__class__.__update, self, spin_total, model, save, revert) for child in self.get_children(): child.show_all()
def __init__(self, parent, song): super(CoverArea, self).__init__() self.song = song self.dirname = song("~dirname") self.main_win = parent self.data_cache = [] self.current_data = None self.current_pixbuf = None self.image = Gtk.Image() self.button = Button(_("_Save"), Icons.DOCUMENT_SAVE) self.button.set_sensitive(False) self.button.connect('clicked', self.__save) close_button = Button(_("_Close"), Icons.WINDOW_CLOSE) close_button.connect('clicked', lambda x: self.main_win.destroy()) self.window_fit = self.ConfigCheckButton(_('Fit image to _window'), 'fit', True) self.window_fit.connect('toggled', self.__scale_pixbuf) self.name_combo = Gtk.ComboBoxText() self.cmd = qltk.entry.ValidatingEntry(iscommand) # Both labels label_open = Gtk.Label(label=_('_Program:')) label_open.set_use_underline(True) label_open.set_mnemonic_widget(self.cmd) label_open.set_justify(Gtk.Justification.LEFT) self.open_check = self.ConfigCheckButton(_('_Edit image after saving'), 'edit', False) label_name = Gtk.Label(label=_('File_name:'), use_underline=True) label_name.set_use_underline(True) label_name.set_mnemonic_widget(self.name_combo) label_name.set_justify(Gtk.Justification.LEFT) self.cmd.set_text(self.config_get('edit_cmd', 'gimp')) # Create the filename combo box fn_list = ['cover.jpg', 'folder.jpg', '.folder.jpg'] # Issue 374 - add dynamic file names artist = song("artist") alartist = song("albumartist") album = song("album") labelid = song("labelid") if album: fn_list.append("<album>.jpg") if alartist: fn_list.append("<albumartist> - <album>.jpg") else: fn_list.append("<artist> - <album>.jpg") else: print_w(u"No album for \"%s\". Could be difficult " u"finding art…" % song("~filename")) title = song("title") if title and artist: fn_list.append("<artist> - <title>.jpg") if labelid: fn_list.append("<labelid>.jpg") set_fn = self.config_get('fn', fn_list[0]) for i, fn in enumerate(fn_list): self.name_combo.append_text(fn) if fn == set_fn: self.name_combo.set_active(i) if self.name_combo.get_active() < 0: self.name_combo.set_active(0) table = Gtk.Table(n_rows=2, n_columns=2, homogeneous=False) table.set_row_spacing(0, 5) table.set_row_spacing(1, 5) table.set_col_spacing(0, 5) table.set_col_spacing(1, 5) table.attach(label_open, 0, 1, 0, 1) table.attach(label_name, 0, 1, 1, 2) table.attach(self.cmd, 1, 2, 0, 1) table.attach(self.name_combo, 1, 2, 1, 2) self.scrolled = Gtk.ScrolledWindow() self.scrolled.add_with_viewport(self.image) self.scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) bbox = Gtk.HButtonBox() bbox.set_spacing(6) bbox.set_layout(Gtk.ButtonBoxStyle.END) bbox.pack_start(self.button, True, True, 0) bbox.pack_start(close_button, True, True, 0) bb_align = Align(valign=Gtk.Align.END, right=6) bb_align.add(bbox) main_hbox = Gtk.HBox() main_hbox.pack_start(table, False, True, 6) main_hbox.pack_start(bb_align, True, True, 0) top_hbox = Gtk.HBox() top_hbox.pack_start(self.open_check, True, True, 0) top_hbox.pack_start(self.window_fit, False, True, 0) main_vbox = Gtk.VBox() main_vbox.pack_start(top_hbox, True, True, 2) main_vbox.pack_start(main_hbox, True, True, 0) self.pack_start(self.scrolled, True, True, 0) self.pack_start(main_vbox, False, True, 5) # 5 MB image cache size self.max_cache_size = 1024 * 1024 * 5 # For managing fast selection switches of covers.. self.stop_loading = False self.loading = False self.current_job = 0 self.connect('destroy', self.__save_config)
def ratings_vbox(self): """Returns a new VBox containing all ratings widgets""" vb = Gtk.VBox(spacing=6) # Default Rating model = Gtk.ListStore(float) default_combo = Gtk.ComboBox(model=model) default_lab = Gtk.Label(label=_("_Default rating:")) default_lab.set_use_underline(True) default_lab.set_alignment(0, 0.5) def draw_rating(column, cell, model, it, data): num = model[it][0] text = "%0.2f: %s" % (num, util.format_rating(num)) cell.set_property('text', text) def default_rating_changed(combo, model): it = combo.get_active_iter() if it is None: return RATINGS.default = model[it][0] qltk.redraw_all_toplevels() def populate_default_rating_model(combo, num): model = combo.get_model() model.clear() deltas = [] default = RATINGS.default precision = RATINGS.precision for i in range(0, num + 1): r = i * precision model.append(row=[r]) deltas.append((abs(default - r), i)) active = sorted(deltas)[0][1] print_d("Choosing #%d (%.2f), closest to current %.2f" % (active, precision * active, default)) combo.set_active(active) cell = Gtk.CellRendererText() default_combo.pack_start(cell, True) default_combo.set_cell_data_func(cell, draw_rating, None) default_combo.connect('changed', default_rating_changed, model) default_lab.set_mnemonic_widget(default_combo) def refresh_default_combo(num): populate_default_rating_model(default_combo, num) # Rating Scale model = Gtk.ListStore(int) scale_combo = Gtk.ComboBox(model=model) scale_lab = Gtk.Label(label=_("Rating _scale:")) scale_lab.set_use_underline(True) scale_lab.set_mnemonic_widget(scale_combo) cell = Gtk.CellRendererText() scale_combo.pack_start(cell, False) num = RATINGS.number for i in [1, 2, 3, 4, 5, 6, 8, 10]: it = model.append(row=[i]) if i == num: scale_combo.set_active_iter(it) def draw_rating_scale(column, cell, model, it, data): num_stars = model[it][0] text = "%d: %s" % (num_stars, RATINGS.full_symbol * num_stars) cell.set_property('text', text) def rating_scale_changed(combo, model): it = combo.get_active_iter() if it is None: return RATINGS.number = num = model[it][0] refresh_default_combo(num) refresh_default_combo(RATINGS.number) scale_combo.set_cell_data_func(cell, draw_rating_scale, None) scale_combo.connect('changed', rating_scale_changed, model) default_align = Align(halign=Gtk.Align.START) default_align.add(default_lab) scale_align = Align(halign=Gtk.Align.START) scale_align.add(scale_lab) grid = Gtk.Grid(column_spacing=6, row_spacing=6) grid.add(scale_align) grid.add(scale_combo) grid.attach(default_align, 0, 1, 1, 1) grid.attach(default_combo, 1, 1, 1, 1) vb.pack_start(grid, False, False, 6) # Bayesian Factor bayesian_factor = config.getfloat("settings", "bayesian_rating_factor", 0.0) adj = Gtk.Adjustment.new(bayesian_factor, 0.0, 10.0, 0.5, 0.5, 0.0) bayes_spin = Gtk.SpinButton(adjustment=adj, numeric=True) bayes_spin.set_digits(1) bayes_spin.connect('changed', self.__changed_and_signal_library, 'settings', 'bayesian_rating_factor') bayes_spin.set_tooltip_text( _("Bayesian Average factor (C) for aggregated ratings.\n" "0 means a conventional average, higher values mean that " "albums with few tracks will have less extreme ratings. " "Changing this value triggers a re-calculation for all " "albums.")) bayes_label = Gtk.Label(label=_("_Bayesian averaging amount:")) bayes_label.set_use_underline(True) bayes_label.set_mnemonic_widget(bayes_spin) # Save Ratings hb = Gtk.HBox(spacing=6) hb.pack_start(bayes_label, False, True, 0) hb.pack_start(bayes_spin, False, True, 0) vb.pack_start(hb, True, True, 0) cb = CCB(_("Save ratings and play _counts"), "editing", "save_to_songs", populate=True) vb.pack_start(cb, True, True, 0) hb = Gtk.HBox(spacing=6) lab = Gtk.Label(label=_("_Email:")) entry = UndoEntry() entry.set_tooltip_text(_("Ratings and play counts will be set " "for this email address")) entry.set_text(config.get("editing", "save_email")) entry.connect('changed', self.__changed, 'editing', 'save_email') hb.pack_start(lab, False, True, 0) hb.pack_start(entry, True, True, 0) lab.set_mnemonic_widget(entry) lab.set_use_underline(True) vb.pack_start(hb, True, True, 0) return vb
class SoundcloudBrowser(Browser, util.InstanceTracker): background = False __librarian = None __filter = None name = _("Soundcloud Browser") accelerated_name = _("Sound_cloud") keys = ["Soundcloud"] priority = 30 uses_main_library = False headers = ("artist ~people title genre ~#length ~mtime ~bitrate date " "website comment ~rating " "~#playback_count ~#favoritings_count ~#likes_count").split() @enum class ModelIndex(int): TYPE, ICON_NAME, NAME, QUERY, ALWAYS_ENABLE = range(5) login_state = State.LOGGED_OUT STAR = [tag for tag in headers if not tag.startswith("~#")] @classmethod def _init(klass, library): klass.__librarian = library.librarian klass.filters = [ (_("Search"), (FilterType.SEARCH, Icons.EDIT_FIND, "", True)), # TODO: support for ~#rating=!None etc (#1940) (_("Favorites"), (FilterType.FAVORITES, Icons.FAVORITE, "#(rating = 1.0)", False)), (_("My tracks"), (FilterType.MINE, Icons.MEDIA_RECORD, "soundcloud_user_id=%s", False)), ] try: if klass.library: return except AttributeError: pass klass.api_client = SoundcloudApiClient() klass.library = SoundcloudLibrary(klass.api_client, app.player) @classmethod def _destroy(klass): klass.__librarian = None klass.filters = {} klass.library.destroy() klass.library = None def __inhibit(self): self.view.get_selection().handler_block(self.__changed_sig) def __uninhibit(self): self.view.get_selection().handler_unblock(self.__changed_sig) def __destroy(self, *args): print_d(f"Destroying Soundcloud Browser {self}") if not self.instances(): self._destroy() def __init__(self, library): print_d(f"Creating Soundcloud Browser {self}") super().__init__(spacing=12) self.set_orientation(Gtk.Orientation.VERTICAL) if not self.instances(): self._init(library) self._register_instance() self.connect('destroy', self.__destroy) self.connect('uri-received', self.__handle_incoming_uri) connect_destroy(self.api_client, 'authenticated', self.__on_authenticated) connect_destroy(self.library, 'changed', self.__changed) self.login_state = (State.LOGGED_IN if self.online else State.LOGGED_OUT) self._create_searchbar(self.library) vbox = Gtk.VBox() vbox.pack_start(self._create_footer(), False, False, 6) vbox.pack_start(self._create_category_widget(), True, True, 0) vbox.pack_start(self.create_login_button(), False, False, 6) vbox.show() pane = qltk.ConfigRHPaned("browsers", "soundcloud_pos", 0.4) pane.show() pane.pack1(vbox, resize=False, shrink=False) self._songs_box = songs_box = Gtk.VBox(spacing=6) songs_box.pack_start(self._searchbox, False, True, 0) songs_box.show() pane.pack2(songs_box, resize=True, shrink=False) self.pack_start(pane, True, True, 0) self.show() def Menu(self, songs, library, items): return SongsMenu(library, songs, download=True, items=items) @property def online(self): return self.api_client.online def _create_footer(self): hbox = Gtk.HBox() button = Gtk.Button(always_show_image=True, relief=Gtk.ReliefStyle.NONE) button.connect('clicked', lambda _: website(SITE_URL)) button.set_tooltip_text(_("Go to %s" % SITE_URL)) button.add(self._logo_image) hbox.pack_start(button, True, True, 6) hbox.show_all() return hbox def _create_searchbar(self, library): completion = LibraryTagCompletion(library) self.accelerators = Gtk.AccelGroup() search = SearchBarBox(completion=completion, validator=SoundcloudQuery.validator, accel_group=self.accelerators, timeout=3000) self.__searchbar = search search.connect('query-changed', self.__query_changed) def focus(widget, *args): qltk.get_top_parent(widget).songlist.grab_focus() search.connect('focus-out', focus) self._searchbox = Align(search, left=0, right=6, top=6) self._searchbox.show_all() def update_connect_button(self): but = self.login_button but.set_sensitive(False) tooltip, icon = self._login_state_data[self.login_state] but.set_tooltip_text(tooltip) child = but.get_child() if child: print_d("Removing old image...") but.remove(child) but.add(icon if icon else Gtk.Label(tooltip)) but.get_child().show() but.set_sensitive(True) but.show() def create_login_button(self): def clicked_login(*args): # TODO: use a magic enum next() method, or similar state = self.login_state if state == State.LOGGED_IN: self.api_client.log_out() # Reset the selection, lest it get stuck... sel = self.view.get_selection() sel.unselect_all() first_path = self.view.get_model()[0].path.copy() self.view.set_cursor(first_path) sel.select_path(first_path) self._refresh_online_filters() self.login_state = State.LOGGED_OUT elif state == State.LOGGING_IN: dialog = EnterAuthCodeDialog(app.window) value = dialog.run(clipboard=True) if value: self.login_state = State.LOGGED_IN print_d("Got a user token value of '%s'" % value) self.api_client.get_tokens(value) elif state == State.LOGGED_OUT: self.api_client.authenticate_user() self.login_state = State.LOGGING_IN self.update_connect_button() hbox = Gtk.HBox() self.login_button = login = Gtk.Button(always_show_image=True, relief=Gtk.ReliefStyle.NONE) self.update_connect_button() login.connect('clicked', clicked_login) hbox.pack_start(login, True, False, 0) hbox.show_all() return hbox def _create_category_widget(self): scrolled_window = ScrolledWindow() scrolled_window.show() scrolled_window.set_shadow_type(Gtk.ShadowType.IN) self.view = view = RCMHintedTreeView() view.show() view.set_headers_visible(False) scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scrolled_window.add(view) model = Gtk.ListStore(int, str, str, str, bool) filters = self.filters for (i, (name, data)) in enumerate(filters): filter_type, icon, query, always = data enabled = always model.append(row=[filter_type, icon, name, query, enabled]) def search_func(model, column, key, iter, data): return key.lower() not in model[iter][column].lower() view.set_search_column(self.ModelIndex.NAME) view.set_search_equal_func(search_func, None) column = Gtk.TreeViewColumn("Songs") column.set_sizing(Gtk.TreeViewColumnSizing.FIXED) renderpb = Gtk.CellRendererPixbuf() renderpb.props.xpad = 6 renderpb.props.ypad = 6 column.pack_start(renderpb, False) column.add_attribute(renderpb, "icon-name", self.ModelIndex.ICON_NAME) render = Gtk.CellRendererText() render.set_property('ellipsize', Pango.EllipsizeMode.END) def cdf(column, cell, model, iter_, user_data): on = (self.login_state == State.LOGGED_IN or model[iter_][self.ModelIndex.ALWAYS_ENABLE]) cell.set_sensitive(on) column.set_cell_data_func(render, cdf) column.set_cell_data_func(renderpb, cdf) view.append_column(column) column.pack_start(render, True) column.add_attribute(render, "text", self.ModelIndex.NAME) view.set_model(model) selection = view.get_selection() def select_func(sel, model, path, value): return (self.login_state == State.LOGGED_IN or model[model.get_iter(path)][self.ModelIndex.ALWAYS_ENABLE]) selection.set_select_function(select_func) selection.select_iter(model.get_iter_first()) self._refresh_online_filters() self.__changed_sig = connect_destroy(selection, 'changed', DeferredSignal(self._on_select)) return scrolled_window def _on_select(self, sel): model, paths = sel.get_selected_rows() if not paths: return row = model[paths[0]] query_text = row[self.ModelIndex.QUERY] filter_type = row[self.ModelIndex.TYPE] if filter_type == FilterType.SEARCH: self.__searchbar.set_enabled() elif filter_type == FilterType.FAVORITES: print_d("Getting favorites...") self.api_client.get_favorites() self.__searchbar.set_enabled(False) elif filter_type == FilterType.MINE: print_d("Getting user tracks...") self.api_client.get_my_tracks() self.__searchbar.set_enabled(False) query_text = query_text % self.api_client.user_id self.__searchbar.set_text(query_text) self.activate() def pack(self, songpane): container = Gtk.VBox() container.add(self) self._songs_box.add(songpane) return container def unpack(self, container, songpane): self._songs_box.remove(songpane) container.remove(self) def __changed(self, library, songs): print_d("Updating view") self.activate() def __query_changed(self, bar, text, restore=False): try: self.__filter = SoundcloudQuery(text, self.STAR) self.library.query_with_refresh(self.__filter) except SoundcloudQuery.Error as e: print_d("Couldn't parse query: %s" % e) else: print_d("Got terms from query: %s" % (self.__filter.terms, )) if not restore: self.activate() def __get_selected_libraries(self): """Returns the libraries to search in depending on the filter selection""" return [self.library] def restore(self): filter_type = config.getint("browsers", "soundcloud_selection", FilterType.SEARCH) model = self.view.get_model() it = model.get_iter_first() while it: if model.get_value(it, 0) == filter_type: break it = model.iter_next(it) if filter_type == FilterType.SEARCH: self.__searchbar.set_enabled() self.__inhibit() self.view.get_selection().select_iter(it) self.__uninhibit() text = config.gettext("browsers", "query_text") self.__searchbar.set_text(text) self.__query_changed(None, text, restore=True) def __get_filter(self): return self.__filter or SoundcloudQuery("") def can_filter_text(self): return True def filter_text(self, text): model = self.view.get_model() it = model.get_iter_first() selected = False while it: typ = model.get_value(it, 0) if typ == FilterType.SEARCH: search_it = it elif ((typ == FilterType.FAVORITES and text == "#(rating = 1.0)") or (typ == FilterType.MINE and text == "soundcloud_user_id=%s" % self.api_client.user_id)): self.view.get_selection().select_iter(it) selected = True break it = model.iter_next(it) if not selected: # We don't want the selection to be cleared, so inhibit # the selection callback method self.__inhibit() self.view.get_selection().select_iter(search_it) self.__uninhibit() self.__searchbar.set_enabled() self.__searchbar.set_text(text) self.__query_changed(None, text) if SoundcloudQuery(text).is_parsable: self.activate() else: print_d("Not parsable: %s" % text) def get_filter_text(self): return self.__searchbar.get_text() def activate(self): print_d("Refreshing browser for query \"%r\"" % self.__filter) songs = self.library.query(self.get_filter_text()) self.songs_selected(songs) def active_filter(self, song): for lib in self.__get_selected_libraries(): if song in lib: filter_ = self.__get_filter() if filter_: return filter_.search(song) return True else: return False def save(self): text = self.__searchbar.get_text() config.settext("browsers", "query_text", text) self.api_client.save_auth() model, paths = self.view.get_selection().get_selected_rows() if paths: row = model[paths[0]] filter_type = row[self.ModelIndex.TYPE] config.set("browsers", "soundcloud_selection", filter_type) def _refresh_online_filters(self): model = self.view.get_model() for row in model: model.row_changed(row.path, model.get_iter(row.path)) def __handle_incoming_uri(self, obj, uri): if not PROCESS_QL_URLS: print_w("Processing of quodlibet:// URLs is disabled. (%s)" % uri) return uri = urlparse(uri) if (uri.scheme == 'quodlibet' and uri.netloc == 'callbacks' and uri.path == '/soundcloud'): try: code = parse_qs(uri.query)["code"][0] except IndexError: print_w("Malformed response in callback URI: %s" % uri) return print_d("Processing Soundcloud callback (%s)" % (uri, )) self.api_client.get_tokens(code) else: print_w("Unknown URL format (%s)" % (uri, )) def __on_authenticated(self, obj, data): name = data.username self.login_state = State.LOGGED_IN self.update_connect_button() self.activate() msg = Message(Gtk.MessageType.INFO, app.window, _("Connected"), _("Quod Libet is now connected, %s!") % name) msg.run() @cached_property def _logo_image(self): return WebImage( "https://developers.soundcloud.com/assets/logo_black.png", 104, 16) @cached_property def _login_state_data(self): """Login-state-based data for configuring actions (e.g. the button)""" return { State.LOGGED_IN: (_("Log out of %s") % SOUNDCLOUD_NAME, sc_btn_image('disconnect-l', 140, 29)), State.LOGGING_IN: (_("Enter code…"), None), State.LOGGED_OUT: (_("Log in to %s") % SOUNDCLOUD_NAME, sc_btn_image('connect-l', 124, 29)), }
def __init__(self, library): super(InternetRadio, self).__init__(spacing=12) self.set_orientation(Gtk.Orientation.VERTICAL) if not self.instances(): self._init(library) self._register_instance() self.connect("destroy", self.__destroy) completion = LibraryTagCompletion(self.__stations) self.accelerators = Gtk.AccelGroup() self.__searchbar = search = SearchBarBox(completion=completion, accel_group=self.accelerators) search.connect("query-changed", self.__filter_changed) menu = Gtk.Menu() new_item = MenuItem(_(u"_New Station…"), Icons.LIST_ADD) new_item.connect("activate", self.__add) menu.append(new_item) update_item = MenuItem(_("_Update Stations"), Icons.VIEW_REFRESH) update_item.connect("activate", self.__update) menu.append(update_item) menu.show_all() button = MenuButton(SymbolicIconImage(Icons.EMBLEM_SYSTEM, Gtk.IconSize.MENU), arrow=True) button.set_menu(menu) def focus(widget, *args): qltk.get_top_parent(widget).songlist.grab_focus() search.connect("focus-out", focus) # treeview scrolled_window = ScrolledWindow() scrolled_window.show() scrolled_window.set_shadow_type(Gtk.ShadowType.IN) self.view = view = AllTreeView() view.show() view.set_headers_visible(False) scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scrolled_window.add(view) model = Gtk.ListStore(int, str, str, str) model.append(row=[self.TYPE_ALL, Icons.FOLDER, "__all", _("All Stations")]) model.append(row=[self.TYPE_SEP, Icons.FOLDER, "", ""]) # Translators: Favorite radio stations model.append(row=[self.TYPE_FAV, Icons.FOLDER, "__fav", _("Favorites")]) model.append(row=[self.TYPE_SEP, Icons.FOLDER, "", ""]) filters = self.filters for text, k in sorted([(filters.text(k), k) for k in filters.keys()]): model.append(row=[self.TYPE_FILTER, Icons.EDIT_FIND, k, text]) model.append(row=[self.TYPE_NOCAT, Icons.FOLDER, "nocat", _("No Category")]) def separator(model, iter, data): return model[iter][self.TYPE] == self.TYPE_SEP view.set_row_separator_func(separator, None) def search_func(model, column, key, iter, data): return key.lower() not in model[iter][column].lower() view.set_search_column(self.NAME) view.set_search_equal_func(search_func, None) column = Gtk.TreeViewColumn("genres") column.set_sizing(Gtk.TreeViewColumnSizing.FIXED) renderpb = Gtk.CellRendererPixbuf() renderpb.props.xpad = 3 column.pack_start(renderpb, False) column.add_attribute(renderpb, "icon-name", self.ICON_NAME) render = Gtk.CellRendererText() render.set_property("ellipsize", Pango.EllipsizeMode.END) view.append_column(column) column.pack_start(render, True) column.add_attribute(render, "text", self.NAME) view.set_model(model) # selection selection = view.get_selection() selection.set_mode(Gtk.SelectionMode.MULTIPLE) self.__changed_sig = connect_destroy(selection, "changed", util.DeferredSignal(lambda x: self.activate())) box = Gtk.HBox(spacing=6) box.pack_start(search, True, True, 0) box.pack_start(button, False, True, 0) self._searchbox = Align(box, left=0, right=6, top=6) self._searchbox.show_all() def qbar_response(infobar, response_id): if response_id == infobar.RESPONSE_LOAD: self.__update() self.qbar = QuestionBar() self.qbar.connect("response", qbar_response) if self._is_library_empty(): self.qbar.show() pane = qltk.ConfigRHPaned("browsers", "internetradio_pos", 0.4) pane.show() pane.pack1(scrolled_window, resize=False, shrink=False) songbox = Gtk.VBox(spacing=6) songbox.pack_start(self._searchbox, False, True, 0) self._songpane_container = Gtk.VBox() self._songpane_container.show() songbox.pack_start(self._songpane_container, True, True, 0) songbox.pack_start(self.qbar, False, True, 0) songbox.show() pane.pack2(songbox, resize=True, shrink=False) self.pack_start(pane, True, True, 0) self.show()
def __init__(self, library, player, headless=False, restore_cb=None): super(QuodLibetWindow, self).__init__(dialog=False) self.__destroyed = False self.__update_title(player) self.set_default_size(600, 480) main_box = Gtk.VBox() self.add(main_box) self.side_book = qltk.Notebook() # get the playlist up before other stuff self.songlist = MainSongList(library, player) self.songlist.connect("key-press-event", self.__songlist_key_press) self.songlist.connect_after( 'drag-data-received', self.__songlist_drag_data_recv) self.song_scroller = ScrolledWindow() self.song_scroller.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.song_scroller.set_shadow_type(Gtk.ShadowType.IN) self.song_scroller.add(self.songlist) self.qexpander = QueueExpander(library, player) self.qexpander.set_no_show_all(True) self.qexpander.set_visible(config.getboolean("memory", "queue")) def on_queue_visible(qex, param): config.set("memory", "queue", str(qex.get_visible())) self.qexpander.connect("notify::visible", on_queue_visible) self.playlist = PlaylistMux( player, self.qexpander.model, self.songlist.model) self.__player = player # create main menubar, load/restore accelerator groups self.__library = library ui = self.__create_menu(player, library) accel_group = ui.get_accel_group() self.add_accel_group(accel_group) def scroll_and_jump(*args): self.__jump_to_current(True, None, True) keyval, mod = Gtk.accelerator_parse("<Primary><shift>J") accel_group.connect(keyval, mod, 0, scroll_and_jump) # custom accel map accel_fn = os.path.join(quodlibet.get_user_dir(), "accels") Gtk.AccelMap.load(accel_fn) # save right away so we fill the file with example comments of all # accels Gtk.AccelMap.save(accel_fn) menubar = ui.get_widget("/Menu") # Since https://git.gnome.org/browse/gtk+/commit/?id=b44df22895c79 # toplevel menu items show an empty 16x16 image. While we don't # need image items there UIManager creates them by default. # Work around by removing the empty GtkImages for child in menubar.get_children(): if isinstance(child, Gtk.ImageMenuItem): child.set_image(None) main_box.pack_start(menubar, False, True, 0) top_bar = TopBar(self, player, library) main_box.pack_start(top_bar, False, True, 0) self.top_bar = top_bar self.__browserbox = Align(bottom=3) self.__paned = paned = ConfigRHPaned("memory", "sidebar_pos", 0.25) paned.pack1(self.__browserbox, resize=True) # We'll pack2 when necessary (when the first sidebar plugin is set up) main_box.pack_start(paned, True, True, 0) play_order = PlayOrderWidget(self.songlist.model, player) statusbox = StatusBarBox(play_order, self.qexpander) self.order = play_order self.statusbar = statusbox.statusbar main_box.pack_start( Align(statusbox, border=3, top=-3), False, True, 0) self.songpane = SongListPaned(self.song_scroller, self.qexpander) self.songpane.show_all() try: orders = [] for e in config.getstringlist('memory', 'sortby', []): orders.append((e[1:], int(e[0]))) except ValueError: pass else: self.songlist.set_sort_orders(orders) self.browser = None self.ui = ui main_box.show_all() self._playback_error_dialog = None connect_destroy(player, 'song-started', self.__song_started) connect_destroy(player, 'paused', self.__update_paused, True) connect_destroy(player, 'unpaused', self.__update_paused, False) # make sure we redraw all error indicators before opening # a dialog (blocking the main loop), so connect after default handlers connect_after_destroy(player, 'error', self.__player_error) # connect after to let SongTracker update stats connect_after_destroy(player, "song-ended", self.__song_ended) # set at least the playlist. the song should be restored # after the browser emits the song list player.setup(self.playlist, None, 0) self.__restore_cb = restore_cb self.__first_browser_set = True restore_browser = not headless try: self._select_browser( self, config.get("memory", "browser"), library, player, restore_browser) except: config.set("memory", "browser", browsers.name(browsers.default)) config.save() raise self.songlist.connect('popup-menu', self.__songs_popup_menu) self.songlist.connect('columns-changed', self.__cols_changed) self.songlist.connect('columns-changed', self.__hide_headers) self.songlist.info.connect("changed", self.__set_totals) lib = library.librarian connect_destroy(lib, 'changed', self.__song_changed, player) targets = [("text/uri-list", Gtk.TargetFlags.OTHER_APP, DND_URI_LIST)] targets = [Gtk.TargetEntry.new(*t) for t in targets] self.drag_dest_set( Gtk.DestDefaults.ALL, targets, Gdk.DragAction.COPY) self.connect('drag-data-received', self.__drag_data_received) if not headless: on_first_map(self, self.__configure_scan_dirs, library) if config.getboolean('library', 'refresh_on_start'): self.__rebuild(None, False) self.connect("key-press-event", self.__key_pressed, player) self.connect("destroy", self.__destroy) self.enable_window_tracking("quodlibet")
def __init__(self, library): super(InternetRadio, self).__init__(spacing=12) self.set_orientation(Gtk.Orientation.VERTICAL) if not self.instances(): self._init(library) self._register_instance() self.connect('destroy', self.__destroy) completion = LibraryTagCompletion(self.__stations) self.accelerators = Gtk.AccelGroup() self.__searchbar = search = SearchBarBox(completion=completion, accel_group=self.accelerators) search.connect('query-changed', self.__filter_changed) menu = Gtk.Menu() new_item = MenuItem(_(u"_New Station…"), Icons.LIST_ADD) new_item.connect('activate', self.__add) menu.append(new_item) update_item = MenuItem(_("_Update Stations"), Icons.VIEW_REFRESH) update_item.connect('activate', self.__update) menu.append(update_item) menu.show_all() button = MenuButton(SymbolicIconImage(Icons.EMBLEM_SYSTEM, Gtk.IconSize.MENU), arrow=True) button.set_menu(menu) def focus(widget, *args): qltk.get_top_parent(widget).songlist.grab_focus() search.connect('focus-out', focus) # treeview scrolled_window = ScrolledWindow() scrolled_window.show() scrolled_window.set_shadow_type(Gtk.ShadowType.IN) self.view = view = AllTreeView() view.show() view.set_headers_visible(False) scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scrolled_window.add(view) model = Gtk.ListStore(int, str, str, str) model.append( row=[self.TYPE_ALL, Icons.FOLDER, "__all", _("All Stations")]) model.append(row=[self.TYPE_SEP, Icons.FOLDER, "", ""]) #Translators: Favorite radio stations model.append( row=[self.TYPE_FAV, Icons.FOLDER, "__fav", _("Favorites")]) model.append(row=[self.TYPE_SEP, Icons.FOLDER, "", ""]) filters = self.filters for text, k in sorted([(filters.text(k), k) for k in filters.keys()]): model.append(row=[self.TYPE_FILTER, Icons.EDIT_FIND, k, text]) model.append( row=[self.TYPE_NOCAT, Icons.FOLDER, "nocat", _("No Category")]) def separator(model, iter, data): return model[iter][self.TYPE] == self.TYPE_SEP view.set_row_separator_func(separator, None) def search_func(model, column, key, iter, data): return key.lower() not in model[iter][column].lower() view.set_search_column(self.NAME) view.set_search_equal_func(search_func, None) column = Gtk.TreeViewColumn("genres") column.set_sizing(Gtk.TreeViewColumnSizing.FIXED) renderpb = Gtk.CellRendererPixbuf() renderpb.props.xpad = 3 column.pack_start(renderpb, False) column.add_attribute(renderpb, "icon-name", self.ICON_NAME) render = Gtk.CellRendererText() render.set_property('ellipsize', Pango.EllipsizeMode.END) view.append_column(column) column.pack_start(render, True) column.add_attribute(render, "text", self.NAME) view.set_model(model) # selection selection = view.get_selection() selection.set_mode(Gtk.SelectionMode.MULTIPLE) self.__changed_sig = connect_destroy( selection, 'changed', util.DeferredSignal(lambda x: self.activate())) box = Gtk.HBox(spacing=6) box.pack_start(search, True, True, 0) box.pack_start(button, False, True, 0) self._searchbox = Align(box, left=0, right=6, top=6) self._searchbox.show_all() def qbar_response(infobar, response_id): if response_id == infobar.RESPONSE_LOAD: self.__update() self.qbar = QuestionBar() self.qbar.connect("response", qbar_response) if self._is_library_empty(): self.qbar.show() pane = qltk.ConfigRHPaned("browsers", "internetradio_pos", 0.4) pane.show() pane.pack1(scrolled_window, resize=False, shrink=False) songbox = Gtk.VBox(spacing=6) songbox.pack_start(self._searchbox, False, True, 0) self._songpane_container = Gtk.VBox() self._songpane_container.show() songbox.pack_start(self._songpane_container, True, True, 0) songbox.pack_start(self.qbar, False, True, 0) songbox.show() pane.pack2(songbox, resize=True, shrink=False) self.pack_start(pane, True, True, 0) self.show()
def __init__(self, parent=None): if self.is_not_unique(): return on_top = config.getboolean("settings", "plugins_window_on_top", False) super().__init__(dialog=on_top) self.set_title(_("Plugins")) self.set_default_size(750, 500) if parent and on_top: self.set_transient_for(parent) self.set_type_hint(Gdk.WindowTypeHint.NORMAL) self.enable_window_tracking("plugin_prefs") model = ObjectStore() filter_model = ObjectModelFilter(child_model=model) self._list_view = plv = PluginListView() plv.set_model(filter_model) plv.set_rules_hint(True) plv.connect("plugin-toggled", self.__plugin_toggled) sw = ScrolledWindow() sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.ALWAYS) sw.add(plv) sw.set_shadow_type(Gtk.ShadowType.IN) fb = Gtk.HBox(spacing=6) enabled_combo = PluginEnabledFilterCombo() enabled_combo.connect("changed", lambda s: filter_model.refilter()) enabled_combo.set_tooltip_text(_("Filter by plugin state / tag")) fb.pack_start(enabled_combo, True, True, 0) self._enabled_combo = enabled_combo type_combo = PluginTypeFilterCombo() type_combo.connect("changed", lambda s: filter_model.refilter()) type_combo.set_tooltip_text(_("Filter by plugin type")) fb.pack_start(type_combo, True, True, 0) self._type_combo = type_combo self._filter_entry = fe = UndoSearchEntry() fe.set_tooltip_text(_("Filter by plugin name or description")) fe.connect("changed", lambda s: filter_model.refilter()) errors = qltk.Button(_("Show _Errors"), Icons.DIALOG_WARNING) errors.set_focus_on_click(False) errors.connect('clicked', self.__show_errors) errors.show() errors = Align(errors, top=6, bottom=6) errors.set_no_show_all(True) bbox = Gtk.VBox() bbox.pack_start(errors, True, True, 0) pref_box = PluginPreferencesContainer() if const.DEBUG: refresh = qltk.Button(_("_Refresh"), Icons.VIEW_REFRESH) refresh.set_focus_on_click(False) refresh.connect('clicked', self.__refresh, plv, pref_box, errors, enabled_combo) bbox.pack_start(refresh, True, True, 0) filter_box = Gtk.VBox(spacing=6) filter_box.pack_start(fb, False, True, 0) filter_box.pack_start(fe, False, True, 0) vbox = Gtk.VBox() vbox.pack_start(Align(filter_box, border=6, right=-6), False, False, 0) vbox.pack_start(sw, True, True, 0) vbox.pack_start(Align(bbox, left=3, right=3, top=0), False, False, 3) paned = Paned() paned.pack1(vbox, False, False) close = qltk.Button(_("_Close"), Icons.WINDOW_CLOSE) close.connect('clicked', lambda *x: self.destroy()) bb_align = Align(halign=Gtk.Align.END, valign=Gtk.Align.END) bb = Gtk.HButtonBox() bb.set_layout(Gtk.ButtonBoxStyle.END) bb.pack_start(close, True, True, 0) bb_align.add(bb) selection = plv.get_selection() selection.connect('changed', self.__selection_changed, pref_box) selection.emit('changed') right_box = Gtk.VBox() right_box.pack_start(pref_box, True, True, 0) if not self.has_close_button(): right_box.pack_start(bb_align, True, True, 0) align = Align(right_box, left=6, right=15, top=12, bottom=3) paned.pack2(align, True, False) paned.set_position(290) self.add(paned) self.__refill(plv, pref_box, errors, enabled_combo) self.connect('destroy', self.__destroy) filter_model.set_visible_func( self.__filter, (fe, enabled_combo, type_combo)) self.get_child().show_all() fe.grab_focus() restore_id = config.get("memory", "plugin_selection") plv.select_by_plugin_id(restore_id)
def __init__(self, library, dir=None): super(ExFalsoWindow, self).__init__(dialog=False) self.set_title("Ex Falso") self.set_default_size(750, 475) self.enable_window_tracking("exfalso") self.__library = library hp = ConfigRHPaned("memory", "exfalso_paned_position", 1.0) hp.set_border_width(0) hp.set_position(250) hp.show() self.add(hp) vb = Gtk.VBox() bbox = Gtk.HBox(spacing=6) about = Gtk.Button() about.add(Gtk.Image.new_from_stock( Gtk.STOCK_ABOUT, Gtk.IconSize.BUTTON)) connect_obj(about, 'clicked', self.__show_about, self) bbox.pack_start(about, False, True, 0) prefs = Gtk.Button() prefs.add(Gtk.Image.new_from_stock( Gtk.STOCK_PREFERENCES, Gtk.IconSize.BUTTON)) def prefs_cb(button): window = PreferencesWindow(self) window.show() prefs.connect('clicked', prefs_cb) bbox.pack_start(prefs, False, True, 0) plugins = qltk.Button(_("_Plugins"), Gtk.STOCK_EXECUTE) def plugin_window_cb(button): window = PluginWindow(self) window.show() plugins.connect('clicked', plugin_window_cb) bbox.pack_start(plugins, False, True, 0) l = Gtk.Label() l.set_alignment(1.0, 0.5) l.set_ellipsize(Pango.EllipsizeMode.END) bbox.pack_start(l, True, True, 0) fs = MainFileSelector() vb.pack_start(fs, True, True, 0) vb.pack_start(Align(bbox, border=6), False, True, 0) vb.show_all() hp.pack1(vb, resize=True, shrink=False) nb = qltk.Notebook() nb.props.scrollable = True nb.show() for Page in [EditTags, TagsFromPath, RenameFiles, TrackNumbers]: page = Page(self, self.__library) page.show() nb.append_page(page) align = Align(nb, top=3) align.show() hp.pack2(align, resize=True, shrink=False) fs.connect('changed', self.__changed, l) if dir: fs.go_to(dir) connect_destroy(self.__library, 'changed', self.__library_changed, fs) self.__save = None connect_obj(self, 'changed', self.set_pending, None) for c in fs.get_children(): c.get_child().connect('button-press-event', self.__pre_selection_changed, fs, nb) c.get_child().connect('focus', self.__pre_selection_changed, fs, nb) fs.get_children()[1].get_child().connect('popup-menu', self.__popup_menu, fs) self.emit('changed', []) self.get_child().show() self.__ag = Gtk.AccelGroup() key, mod = Gtk.accelerator_parse("<control>Q") self.__ag.connect(key, mod, 0, lambda *x: self.destroy()) self.add_accel_group(self.__ag)
def __init__(self, library): super(CollectionBrowser, self).__init__(spacing=6) self.set_orientation(Gtk.Orientation.VERTICAL) self._register_instance() if self.__model is None: self._init_model(library) sw = ScrolledWindow() sw.set_shadow_type(Gtk.ShadowType.IN) self.view = view = CollectionView() view.set_headers_visible(False) model_sort = CollectionSortModel(model=self.__model) model_filter = CollectionFilterModel(child_model=model_sort) self.__filter = None self.__bg_filter = background_filter() model_filter.set_visible_func(self.__parse_query) view.set_model(model_filter) def cmpa(a, b): """Like cmp but treats values that evaluate to false as inf""" if not a and b: return 1 if not b and a: return -1 return cmp(a, b) def cmp_rows(model, i1, i2, data): t1, t2 = model[i1][0], model[i2][0] pos1 = _ORDERING.get(t1, 0) pos2 = _ORDERING.get(t2, 0) if pos1 or pos2: return cmp(pos1, pos2) if not isinstance(t1, AlbumNode): return cmp(util.human_sort_key(t1), util.human_sort_key(t2)) a1, a2 = t1.album, t2.album return (cmpa(a1.peoplesort, a2.peoplesort) or cmpa(a1.date, a2.date) or cmpa(a1.sort, a2.sort) or cmp(a1.key, a2.key)) model_sort.set_sort_func(0, cmp_rows) model_sort.set_sort_column_id(0, Gtk.SortType.ASCENDING) column = Gtk.TreeViewColumn("albums") def cell_data(column, cell, model, iter_, data): markup = model.get_markup(self.__model.tags, iter_) cell.markup = markup cell.set_property('markup', markup) def get_scaled_cover(item): if item.scanned: return item.cover scale_factor = self.get_scale_factor() item.scan_cover(scale_factor=scale_factor) return item.cover def cell_data_pb(column, cell, model, iter_, data): album = model.get_album(iter_) if album is None: cell.set_property('icon-name', Icons.FOLDER) else: item = model.get_value(iter_) cover = get_scaled_cover(item) if cover: cover = add_border_widget(cover, view) surface = get_surface_for_pixbuf(self, cover) cell.set_property("surface", surface) else: cell.set_property('icon-name', Icons.MEDIA_OPTICAL) imgrender = Gtk.CellRendererPixbuf() render = Gtk.CellRendererText() if view.supports_hints(): render.set_property('ellipsize', Pango.EllipsizeMode.END) column.pack_start(imgrender, False) column.pack_start(render, True) column.set_cell_data_func(render, cell_data) column.set_cell_data_func(imgrender, cell_data_pb) view.append_column(column) sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) sw.add(view) hbox = Gtk.HBox(spacing=6) prefs = Gtk.Button() prefs.add(SymbolicIconImage(Icons.EMBLEM_SYSTEM, Gtk.IconSize.MENU)) prefs.connect('clicked', lambda *x: Preferences(self)) self.accelerators = Gtk.AccelGroup() search = SearchBarBox(completion=AlbumTagCompletion(), accel_group=self.accelerators) search.connect('query-changed', self.__update_filter) connect_obj(search, 'focus-out', lambda w: w.grab_focus(), view) self.__search = search hbox.pack_start(search, True, True, 0) hbox.pack_start(prefs, False, True, 0) self.pack_start(Align(hbox, left=6, top=6), False, True, 0) self.pack_start(sw, True, True, 0) view.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE) self.__sig = view.get_selection().connect('changed', self.__selection_changed) view.connect('row-activated', self.__play) connect_obj(view, 'popup-menu', self.__popup, view, library) targets = [("text/x-quodlibet-songs", Gtk.TargetFlags.SAME_APP, 1), ("text/uri-list", 0, 2)] targets = [Gtk.TargetEntry.new(*t) for t in targets] view.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, targets, Gdk.DragAction.COPY) view.connect("drag-data-get", self.__drag_data_get) self.connect("destroy", self.__destroy) self.show_all()
class QuodLibetWindow(Window, PersistentWindowMixin, AppWindow): def __init__(self, library, player, headless=False, restore_cb=None): super().__init__(dialog=False) self.__destroyed = False self.__update_title(player) self.set_default_size(600, 480) main_box = Gtk.VBox() self.add(main_box) self.side_book = qltk.Notebook() # get the playlist up before other stuff self.songlist = MainSongList(library, player) self.songlist.connect("key-press-event", self.__songlist_key_press) self.songlist.connect_after('drag-data-received', self.__songlist_drag_data_recv) self.song_scroller = ScrolledWindow() self.song_scroller.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.song_scroller.set_shadow_type(Gtk.ShadowType.IN) self.song_scroller.add(self.songlist) self.qexpander = QueueExpander(library, player) self.qexpander.set_no_show_all(True) self.qexpander.set_visible(config.getboolean("memory", "queue")) def on_queue_visible(qex, param): config.set("memory", "queue", str(qex.get_visible())) self.qexpander.connect("notify::visible", on_queue_visible) self.playlist = PlaylistMux(player, self.qexpander.model, self.songlist.model) self.__player = player # create main menubar, load/restore accelerator groups self.__library = library ui = self.__create_menu(player, library) accel_group = ui.get_accel_group() self.add_accel_group(accel_group) def scroll_and_jump(*args): self.__jump_to_current(True, None, True) keyval, mod = Gtk.accelerator_parse("<Primary><shift>J") accel_group.connect(keyval, mod, 0, scroll_and_jump) # custom accel map accel_fn = os.path.join(quodlibet.get_user_dir(), "accels") Gtk.AccelMap.load(accel_fn) # save right away so we fill the file with example comments of all # accels Gtk.AccelMap.save(accel_fn) menubar = ui.get_widget("/Menu") # Since https://git.gnome.org/browse/gtk+/commit/?id=b44df22895c79 # toplevel menu items show an empty 16x16 image. While we don't # need image items there UIManager creates them by default. # Work around by removing the empty GtkImages for child in menubar.get_children(): if isinstance(child, Gtk.ImageMenuItem): child.set_image(None) main_box.pack_start(menubar, False, True, 0) top_bar = TopBar(self, player, library) main_box.pack_start(top_bar, False, True, 0) self.top_bar = top_bar self.__browserbox = Align(bottom=3) self.__paned = paned = ConfigRHPaned("memory", "sidebar_pos", 0.25) paned.pack1(self.__browserbox, resize=True) # We'll pack2 when necessary (when the first sidebar plugin is set up) main_box.pack_start(paned, True, True, 0) play_order = PlayOrderWidget(self.songlist.model, player) statusbox = StatusBarBox(play_order, self.qexpander) self.order = play_order self.statusbar = statusbox.statusbar main_box.pack_start(Align(statusbox, border=3, top=-3), False, True, 0) self.songpane = SongListPaned(self.song_scroller, self.qexpander) self.songpane.show_all() try: orders = [] for e in config.getstringlist('memory', 'sortby', []): orders.append((e[1:], int(e[0]))) except ValueError: pass else: self.songlist.set_sort_orders(orders) self.browser = None self.ui = ui main_box.show_all() self._playback_error_dialog = None connect_destroy(player, 'song-started', self.__song_started) connect_destroy(player, 'paused', self.__update_paused, True) connect_destroy(player, 'unpaused', self.__update_paused, False) # make sure we redraw all error indicators before opening # a dialog (blocking the main loop), so connect after default handlers connect_after_destroy(player, 'error', self.__player_error) # connect after to let SongTracker update stats connect_after_destroy(player, "song-ended", self.__song_ended) # set at least the playlist. the song should be restored # after the browser emits the song list player.setup(self.playlist, None, 0) self.__restore_cb = restore_cb self.__first_browser_set = True restore_browser = not headless try: self._select_browser(self, config.get("memory", "browser"), library, player, restore_browser) except: config.set("memory", "browser", browsers.name(browsers.default)) config.save() raise self.songlist.connect('popup-menu', self.__songs_popup_menu) self.songlist.connect('columns-changed', self.__cols_changed) self.songlist.connect('columns-changed', self.__hide_headers) self.songlist.info.connect("changed", self.__set_totals) lib = library.librarian connect_destroy(lib, 'changed', self.__song_changed, player) targets = [("text/uri-list", Gtk.TargetFlags.OTHER_APP, DND_URI_LIST)] targets = [Gtk.TargetEntry.new(*t) for t in targets] self.drag_dest_set(Gtk.DestDefaults.ALL, targets, Gdk.DragAction.COPY) self.connect('drag-data-received', self.__drag_data_received) if not headless: on_first_map(self, self.__configure_scan_dirs, library) if config.getboolean('library', 'refresh_on_start'): self.__rebuild(None, False) self.connect("key-press-event", self.__key_pressed, player) self.connect("destroy", self.__destroy) self.enable_window_tracking("quodlibet") def hide_side_book(self): self.side_book.hide() def add_sidebar(self, box, name): vbox = Gtk.Box(margin=0) vbox.pack_start(box, True, True, 0) vbox.show() if self.side_book_empty: self.add_sidebar_to_layout(self.side_book) self.side_book.append_page(vbox, label=name) self.side_book.set_tab_detachable(vbox, False) self.side_book.show_all() return vbox def remove_sidebar(self, widget): self.side_book.remove_page(self.side_book.page_num(widget)) if self.side_book_empty: print_d("Hiding sidebar") self.__paned.remove(self.__paned.get_children()[1]) def add_sidebar_to_layout(self, widget): print_d("Recreating sidebar") align = Align(widget, top=6, bottom=3) self.__paned.pack2(align, shrink=True) align.show_all() @property def side_book_empty(self): return not self.side_book.get_children() def set_seekbar_widget(self, widget): """Add an alternative seek bar widget. Args: widget (Gtk.Widget): a new widget or None to remove the current one """ self.top_bar.set_seekbar_widget(widget) def set_as_osx_window(self, osx_app): assert osx_app self._dock_menu = DockMenu(app) osx_app.set_dock_menu(self._dock_menu) menu = self.ui.get_widget("/Menu") menu.hide() osx_app.set_menu_bar(menu) # Reparent some items to the "Application" menu item = self.ui.get_widget('/Menu/Help/About') osx_app.insert_app_menu_item(item, 0) osx_app.insert_app_menu_item(Gtk.SeparatorMenuItem(), 1) item = self.ui.get_widget('/Menu/File/Preferences') osx_app.insert_app_menu_item(item, 2) quit_item = self.ui.get_widget('/Menu/File/Quit') quit_item.hide() def get_is_persistent(self): return True def open_file(self, filename): assert isinstance(filename, fsnative) song = self.__library.add_filename(filename, add=False) if song is not None: if self.__player.go_to(song): self.__player.paused = False return True else: return False def __player_error(self, player, song, player_error): # it's modal, but mmkeys etc. can still trigger new ones if self._playback_error_dialog: self._playback_error_dialog.destroy() dialog = PlaybackErrorDialog(self, player_error) self._playback_error_dialog = dialog dialog.run() self._playback_error_dialog = None def __configure_scan_dirs(self, library): """Get user to configure scan dirs, if none is set up""" if not get_scan_dirs() and not len(library) and \ quodlibet.is_first_session("quodlibet"): print_d("Couldn't find any scan dirs") resp = ConfirmLibDirSetup(self).run() if resp == ConfirmLibDirSetup.RESPONSE_SETUP: prefs = PreferencesWindow(self) prefs.set_page("library") prefs.show() def __keyboard_shortcuts(self, action): show_shortcuts(self) def __edit_bookmarks(self, librarian, player): if player.song: window = EditBookmarks(self, librarian, player) window.show() def __key_pressed(self, widget, event, player): if not player.song: return def seek_relative(seconds): current = player.get_position() current += seconds * 1000 current = min(player.song("~#length") * 1000 - 1, current) current = max(0, current) player.seek(current) if qltk.is_accel(event, "<alt>Right"): seek_relative(10) return True elif qltk.is_accel(event, "<alt>Left"): seek_relative(-10) return True def __destroy(self, *args): self.playlist.destroy() # The tray icon plugin tries to unhide QL because it gets disabled # on Ql exit. The window should stay hidden after destroy. self.show = lambda: None self.present = self.show def __drag_data_received(self, widget, ctx, x, y, sel, tid, etime): assert tid == DND_URI_LIST uris = sel.get_uris() dirs = [] error = False for uri in uris: try: filename = uri2fsn(uri) except ValueError: filename = None if filename is not None: loc = os.path.normpath(filename) if os.path.isdir(loc): dirs.append(loc) else: loc = os.path.realpath(loc) if loc not in self.__library: self.__library.add_filename(loc) elif app.player.can_play_uri(uri): if uri not in self.__library: self.__library.add([RemoteFile(uri)]) else: error = True break Gtk.drag_finish(ctx, not error, False, etime) if error: ErrorMessage( self, _("Unable to add songs"), _("%s uses an unsupported protocol.") % util.bold(uri)).run() else: if dirs: copool.add(self.__library.scan, dirs, cofuncid="library", funcid="library") def __songlist_key_press(self, songlist, event): return self.browser.key_pressed(event) def __songlist_drag_data_recv(self, view, *args): if self.browser.can_reorder: songs = view.get_songs() self.browser.reordered(songs) self.songlist.clear_sort() def __create_menu(self, player, library): def add_view_items(ag): act = Action(name="Information", label=_('_Information'), icon_name=Icons.DIALOG_INFORMATION) act.connect('activate', self.__current_song_info) ag.add_action(act) act = Action(name="Jump", label=_('_Jump to Playing Song'), icon_name=Icons.GO_JUMP) self.__jump_to_current(True, None, True) act.connect('activate', self.__jump_to_current) ag.add_action_with_accel(act, "<Primary>J") def add_top_level_items(ag): ag.add_action(Action(name="File", label=_("_File"))) ag.add_action(Action(name="Song", label=_("_Song"))) ag.add_action(Action(name="View", label=_('_View'))) ag.add_action(Action(name="Browse", label=_("_Browse"))) ag.add_action(Action(name="Control", label=_('_Control'))) ag.add_action(Action(name="Help", label=_('_Help'))) ag = Gtk.ActionGroup.new('QuodLibetWindowActions') add_top_level_items(ag) add_view_items(ag) act = Action(name="AddFolders", label=_(u'_Add a Folder…'), icon_name=Icons.LIST_ADD) act.connect('activate', self.open_chooser) ag.add_action_with_accel(act, "<Primary>O") act = Action(name="AddFiles", label=_(u'_Add a File…'), icon_name=Icons.LIST_ADD) act.connect('activate', self.open_chooser) ag.add_action(act) act = Action(name="AddLocation", label=_(u'_Add a Location…'), icon_name=Icons.LIST_ADD) act.connect('activate', self.open_location) ag.add_action(act) act = Action(name="BrowseLibrary", label=_('Open _Browser'), icon_name=Icons.EDIT_FIND) ag.add_action(act) act = Action(name="Preferences", label=_('_Preferences'), icon_name=Icons.PREFERENCES_SYSTEM) act.connect('activate', self.__preferences) ag.add_action(act) act = Action(name="Plugins", label=_('_Plugins'), icon_name=Icons.SYSTEM_RUN) act.connect('activate', self.__plugins) ag.add_action(act) act = Action(name="Quit", label=_('_Quit'), icon_name=Icons.APPLICATION_EXIT) act.connect('activate', lambda *x: self.destroy()) ag.add_action_with_accel(act, "<Primary>Q") act = Action(name="EditTags", label=_('Edit _Tags'), icon_name=Icons.DOCUMENT_PROPERTIES) act.connect('activate', self.__current_song_prop) ag.add_action(act) act = Action(name="EditBookmarks", label=_(u"Edit Bookmarks…")) connect_obj(act, 'activate', self.__edit_bookmarks, library.librarian, player) ag.add_action_with_accel(act, "<Primary>B") act = Action(name="Previous", label=_('Pre_vious'), icon_name=Icons.MEDIA_SKIP_BACKWARD) act.connect('activate', self.__previous_song) ag.add_action_with_accel(act, "<Primary>comma") act = Action(name="PlayPause", label=_('_Play'), icon_name=Icons.MEDIA_PLAYBACK_START) act.connect('activate', self.__play_pause) ag.add_action_with_accel(act, "<Primary>space") act = Action(name="Next", label=_('_Next'), icon_name=Icons.MEDIA_SKIP_FORWARD) act.connect('activate', self.__next_song) ag.add_action_with_accel(act, "<Primary>period") act = ToggleAction(name="StopAfter", label=_("Stop After This Song")) ag.add_action_with_accel(act, "<shift>space") # access point for the tray icon self.stop_after = act act = Action(name="Shortcuts", label=_("_Keyboard Shortcuts")) act.connect('activate', self.__keyboard_shortcuts) ag.add_action_with_accel(act, "<Primary>question") act = Action(name="About", label=_("_About"), icon_name=Icons.HELP_ABOUT) act.connect('activate', self.__show_about) ag.add_action_with_accel(act, None) act = Action(name="OnlineHelp", label=_("Online Help"), icon_name=Icons.HELP_BROWSER) def website_handler(*args): util.website(const.ONLINE_HELP) act.connect('activate', website_handler) ag.add_action_with_accel(act, "F1") act = Action(name="SearchHelp", label=_("Search Help")) def search_help_handler(*args): util.website(const.SEARCH_HELP) act.connect('activate', search_help_handler) ag.add_action_with_accel(act, None) act = Action(name="CheckUpdates", label=_("_Check for Updates…"), icon_name=Icons.NETWORK_SERVER) def check_updates_handler(*args): d = UpdateDialog(self) d.run() d.destroy() act.connect('activate', check_updates_handler) ag.add_action_with_accel(act, None) act = Action(name="RefreshLibrary", label=_("_Scan Library"), icon_name=Icons.VIEW_REFRESH) act.connect('activate', self.__rebuild, False) ag.add_action(act) current = config.get("memory", "browser") try: browsers.get(current) except ValueError: current = browsers.name(browsers.default) first_action = None for Kind in browsers.browsers: name = browsers.name(Kind) index = browsers.index(name) action_name = "View" + Kind.__name__ act = RadioAction(name=action_name, label=Kind.accelerated_name, value=index) act.join_group(first_action) first_action = first_action or act if name == current: act.set_active(True) ag.add_action_with_accel(act, "<Primary>%d" % ((index + 1) % 10, )) assert first_action self._browser_action = first_action def action_callback(view_action, current_action): current = browsers.name( browsers.get(current_action.get_current_value())) self._select_browser(view_action, current, library, player) first_action.connect("changed", action_callback) for Kind in browsers.browsers: action = "Browser" + Kind.__name__ label = Kind.accelerated_name name = browsers.name(Kind) index = browsers.index(name) act = Action(name=action, label=label) def browser_activate(action, Kind): LibraryBrowser.open(Kind, library, player) act.connect('activate', browser_activate, Kind) ag.add_action_with_accel(act, "<Primary><alt>%d" % ((index + 1) % 10, )) ui = Gtk.UIManager() ui.insert_action_group(ag, -1) menustr = MENU % { "views": browser_menu_items(), "browsers": secondary_browser_menu_items(), "filters_menu": FilterMenu.MENU } ui.add_ui_from_string(menustr) self._filter_menu = FilterMenu(library, player, ui) # Cute. So. UIManager lets you attach tooltips, but when they're # for menu items, they just get ignored. So here I get to actually # attach them. ui.get_widget("/Menu/File/RefreshLibrary").set_tooltip_text( _("Check for changes in your library")) return ui def __show_about(self, *args): about = AboutDialog(self, app) about.run() about.destroy() def select_browser(self, browser_key, library, player): """Given a browser name (see browsers.get()) changes the current browser. Returns True if the passed browser ID is known and the change was initiated. """ try: Browser = browsers.get(browser_key) except ValueError: return False action_name = "View%s" % Browser.__name__ for action in self._browser_action.get_group(): if action.get_name() == action_name: action.set_active(True) return True return False def _select_browser(self, activator, current, library, player, restore=False): Browser = browsers.get(current) window = self.get_window() if window: window.set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH)) # Wait for the cursor to update before continuing while Gtk.events_pending(): Gtk.main_iteration() config.set("memory", "browser", current) if self.browser: if not (self.browser.uses_main_library and Browser.uses_main_library): self.songlist.clear() container = self.browser.__container self.browser.unpack(container, self.songpane) if self.browser.accelerators: self.remove_accel_group(self.browser.accelerators) container.destroy() self.browser.destroy() self.browser = Browser(library) self.browser.connect('songs-selected', self.__browser_cb, library, player) self.browser.connect('songs-activated', self.__browser_activate) if restore: self.browser.restore() self.browser.activate() self.browser.finalize(restore) if not restore: self.browser.unfilter() if self.browser.can_reorder: self.songlist.enable_drop() elif self.browser.dropped: self.songlist.enable_drop(False) else: self.songlist.disable_drop() if self.browser.accelerators: self.add_accel_group(self.browser.accelerators) container = self.browser.__container = self.browser.pack(self.songpane) # Reset the cursor when done loading the browser if window: GLib.idle_add(window.set_cursor, None) player.replaygain_profiles[1] = self.browser.replaygain_profiles player.reset_replaygain() self.__browserbox.add(container) container.show() self._filter_menu.set_browser(self.browser) self.__hide_headers() def __update_paused(self, player, paused): menu = self.ui.get_widget("/Menu/Control/PlayPause") image = menu.get_image() if paused: label, icon = _("_Play"), Icons.MEDIA_PLAYBACK_START else: label, icon = _("P_ause"), Icons.MEDIA_PLAYBACK_PAUSE menu.set_label(label) image.set_from_icon_name(icon, Gtk.IconSize.MENU) def __song_ended(self, player, song, stopped): # Check if the song should be removed, based on the # active filter of the current browser. active_filter = self.browser.active_filter if song and active_filter and not active_filter(song): iter_ = self.songlist.model.find(song) if iter_: self.songlist.remove_iters([iter_]) if self.stop_after.get_active(): player.paused = True self.stop_after.set_active(False) def __song_changed(self, library, songs, player): if player.info in songs: self.__update_title(player) def __update_title(self, player): song = player.info title = "Quod Libet" if song: tag = config.gettext("settings", "window_title_pattern") if tag: title = song.comma(tag) + " - " + title self.set_title(title) def __song_started(self, player, song): self.__update_title(player) for wid in [ "Control/Next", "Control/StopAfter", "Song/EditTags", "Song/Information", "Song/EditBookmarks", "Song/Jump" ]: self.ui.get_widget('/Menu/' + wid).set_sensitive(bool(song)) # don't jump on stream changes (player.info != player.song) main_should_jump = (song and player.song is song and not self.songlist._activated and config.getboolean("settings", "jump") and self.songlist.sourced) queue_should_jump = (song and player.song is song and not self.qexpander.queue._activated and config.getboolean("settings", "jump") and self.qexpander.queue.sourced and config.getboolean("memory", "queue_keep_songs")) if main_should_jump: self.__jump_to_current(False, self.songlist) elif queue_should_jump: self.__jump_to_current(False, self.qexpander.queue) def __play_pause(self, *args): app.player.playpause() def __jump_to_current(self, explicit, songlist=None, force_scroll=False): """Select/scroll to the current playing song in the playlist. If it can't be found tell the browser to properly fill the playlist with an appropriate selection containing the song. explicit means that the jump request comes from the user and not from an event like song-started. songlist is the songlist to be jumped within. Usually the main song list or the queue. If None, the currently sourced songlist will be used. force_scroll will ask the browser to refill the playlist in any case. """ def idle_jump_to(song, select): ok = songlist.jump_to_song(song, select=select) if ok: songlist.grab_focus() return False if not songlist: if (config.getboolean("memory", "queue_keep_songs") and self.qexpander.queue.sourced): songlist = self.qexpander.queue else: songlist = self.songlist if app.player is None: return song = app.player.song # We are not playing a song if song is None: return if not force_scroll: ok = songlist.jump_to_song(song, select=explicit) else: assert explicit ok = False if ok: songlist.grab_focus() elif explicit: # if we can't find it and the user requested it, try harder self.browser.scroll(song) # We need to wait until the browser has finished # scrolling/filling and the songlist is ready. # Not perfect, but works for now. GLib.idle_add(idle_jump_to, song, explicit, priority=GLib.PRIORITY_LOW) def __next_song(self, *args): app.player.next() def __previous_song(self, *args): app.player.previous() def __rebuild(self, activator, force): scan_library(self.__library, force) # Set up the preferences window. def __preferences(self, activator): window = PreferencesWindow(self) window.show() def __plugins(self, activator): window = PluginWindow(self) window.show() def open_location(self, action): name = GetStringDialog(self, _("Add a Location"), _("Enter the location of an audio file:"), button_label=_("_Add"), button_icon=Icons.LIST_ADD).run() if name: if not uri_is_valid(name): ErrorMessage( self, _("Unable to add location"), _("%s is not a valid location.") % (util.bold(util.escape(name)))).run() elif not app.player.can_play_uri(name): ErrorMessage( self, _("Unable to add location"), _("%s uses an unsupported protocol.") % (util.bold(util.escape(name)))).run() else: if name not in self.__library: self.__library.add([RemoteFile(name)]) def open_chooser(self, action): if action.get_name() == "AddFolders": fns = choose_folders(self, _("Add Music"), _("_Add Folders")) if fns: # scan them copool.add(self.__library.scan, fns, cofuncid="library", funcid="library") else: patterns = ["*" + path2fsn(k) for k in formats.loaders.keys()] choose_filter = create_chooser_filter(_("Music Files"), patterns) fns = choose_files(self, _("Add Music"), _("_Add Files"), choose_filter) if fns: for filename in fns: self.__library.add_filename(filename) def __songs_popup_menu(self, songlist): path, col = songlist.get_cursor() header = col.header_name menu = self.songlist.Menu(header, self.browser, self.__library) if menu is not None: return self.songlist.popup_menu(menu, 0, Gtk.get_current_event_time()) def __current_song_prop(self, *args): song = app.player.song if song: librarian = self.__library.librarian window = SongProperties(librarian, [song], parent=self) window.show() def __current_song_info(self, *args): song = app.player.song if song: librarian = self.__library.librarian window = Information(librarian, [song], self) window.show() def __browser_activate(self, browser): app.player._reset() def __browser_cb(self, browser, songs, sorted, library, player): if browser.background: bg = background_filter() if bg: songs = list(filter(bg, songs)) self.songlist.set_songs(songs, sorted) # After the first time the browser activates, which should always # happen if we start up and restore, restore the playing song. # Because the browser has send us songs we can be sure it has # registered all its libraries. if self.__first_browser_set: self.__first_browser_set = False song = library.librarian.get(config.get("memory", "song")) seek_pos = config.getfloat("memory", "seek", 0) config.set("memory", "seek", 0) if song is not None: player.setup(self.playlist, song, seek_pos) if self.__restore_cb: self.__restore_cb() self.__restore_cb = None def __hide_headers(self, activator=None): for column in self.songlist.get_columns(): if self.browser.headers is None: column.set_visible(True) else: for tag in util.tagsplit(column.header_name): if tag in self.browser.headers: column.set_visible(True) break else: column.set_visible(False) def __cols_changed(self, songlist): headers = [col.header_name for col in songlist.get_columns()] try: headers.remove('~current') except ValueError: pass if len(headers) == len(get_columns()): # Not an addition or removal (handled separately) set_columns(headers) SongList.headers = headers def __make_query(self, query): if self.browser.can_filter_text(): self.browser.filter_text(query.encode('utf-8')) self.browser.activate() def __set_totals(self, info, songs): length = sum(song.get("~#length", 0) for song in songs) t = self.browser.status_text(count=len(songs), time=util.format_time_preferred(length)) self.statusbar.set_default_text(t)
class SoundcloudBrowser(Browser, util.InstanceTracker): background = False __librarian = None __filter = None name = _("Soundcloud Browser") accelerated_name = _("Sound_cloud") keys = ["Soundcloud"] priority = 30 uses_main_library = False headers = ("artist ~people title genre ~#length ~mtime ~bitrate date " "website comment ~rating " "~#playback_count ~#favoritings_count ~#likes_count").split() @enum class ModelIndex(int): TYPE, ICON_NAME, NAME, QUERY, ALWAYS_ENABLE = range(5) login_state = State.LOGGED_OUT STAR = [tag for tag in headers if not tag.startswith("~#")] @classmethod def _init(klass, library): klass.__librarian = library.librarian klass.filters = [ (_("Search"), (FilterType.SEARCH, Icons.EDIT_FIND, "", True)), # TODO: support for ~#rating=!None etc (#1940) (_("Favorites"), (FilterType.FAVORITES, Icons.FAVORITE, "#(rating = 1.0)", False)), (_("My tracks"), (FilterType.MINE, Icons.MEDIA_RECORD, "soundcloud_user_id=%s", False)), ] try: if klass.library: return except AttributeError: pass klass.api_client = SoundcloudApiClient() klass.library = SoundcloudLibrary(klass.api_client, app.player) @classmethod def _destroy(klass): klass.__librarian = None klass.filters = {} klass.library.destroy() klass.library = None def __inhibit(self): self.view.get_selection().handler_block(self.__changed_sig) def __uninhibit(self): self.view.get_selection().handler_unblock(self.__changed_sig) def __destroy(self, *args): self.api_client.disconnect(self.__auth_sig) if not self.instances(): self._destroy() def __init__(self, library): print_d("Creating Soundcloud Browser") super(SoundcloudBrowser, self).__init__(spacing=12) self.set_orientation(Gtk.Orientation.VERTICAL) if not self.instances(): self._init(library) self._register_instance() self.connect('destroy', self.__destroy) self.connect('uri-received', self.__handle_incoming_uri) self.__auth_sig = self.api_client.connect('authenticated', self.__on_authenticated) connect_destroy(self.library, 'changed', self.__changed) self.login_state = (State.LOGGED_IN if self.online else State.LOGGED_OUT) self._create_searchbar(self.library) vbox = Gtk.VBox() vbox.pack_start(self._create_footer(), False, False, 6) vbox.pack_start(self._create_category_widget(), True, True, 0) vbox.pack_start(self.create_login_button(), False, False, 6) vbox.show() pane = qltk.ConfigRHPaned("browsers", "soundcloud_pos", 0.4) pane.show() pane.pack1(vbox, resize=False, shrink=False) self._songs_box = songs_box = Gtk.VBox(spacing=6) songs_box.pack_start(self._searchbox, False, True, 0) songs_box.show() pane.pack2(songs_box, resize=True, shrink=False) self.pack_start(pane, True, True, 0) self.show() @property def online(self): return self.api_client.online def _create_footer(self): hbox = Gtk.HBox() button = Gtk.Button(always_show_image=True, relief=Gtk.ReliefStyle.NONE) button.connect('clicked', lambda _: website(SITE_URL)) button.set_tooltip_text(_("Go to %s" % SITE_URL)) button.add(self._logo_image) hbox.pack_start(button, True, True, 6) hbox.show_all() return hbox def _create_searchbar(self, library): completion = LibraryTagCompletion(library) self.accelerators = Gtk.AccelGroup() search = SearchBarBox(completion=completion, validator=SoundcloudQuery.validator, accel_group=self.accelerators, timeout=3000) self.__searchbar = search search.connect('query-changed', self.__query_changed) def focus(widget, *args): qltk.get_top_parent(widget).songlist.grab_focus() search.connect('focus-out', focus) self._searchbox = Align(search, left=0, right=6, top=6) self._searchbox.show_all() def update_connect_button(self): but = self.login_button but.set_sensitive(False) tooltip, icon = self._login_state_data[self.login_state] but.set_tooltip_text(tooltip) child = but.get_child() if child: print_d("Removing old image...") but.remove(child) but.add(icon if icon else Gtk.Label(tooltip)) but.get_child().show() but.set_sensitive(True) but.show() def create_login_button(self): def clicked_login(*args): # TODO: use a magic enum next() method, or similar state = self.login_state if state == State.LOGGED_IN: self.api_client.log_out() # Reset the selection, lest it get stuck... sel = self.view.get_selection() sel.unselect_all() first_path = self.view.get_model()[0].path.copy() self.view.set_cursor(first_path) sel.select_path(first_path) self._refresh_online_filters() self.login_state = State.LOGGED_OUT elif state == State.LOGGING_IN: dialog = EnterAuthCodeDialog(app.window) value = dialog.run(clipboard=True) if value: self.login_state = State.LOGGED_IN print_d("Got a user token value of '%s'" % value) self.api_client.get_token(value) elif state == State.LOGGED_OUT: self.api_client.authenticate_user() self.login_state = State.LOGGING_IN self.update_connect_button() hbox = Gtk.HBox() self.login_button = login = Gtk.Button(always_show_image=True, relief=Gtk.ReliefStyle.NONE) self.update_connect_button() login.connect('clicked', clicked_login) hbox.pack_start(login, True, False, 0) hbox.show_all() return hbox def _create_category_widget(self): scrolled_window = ScrolledWindow() scrolled_window.show() scrolled_window.set_shadow_type(Gtk.ShadowType.IN) self.view = view = RCMHintedTreeView() view.show() view.set_headers_visible(False) scrolled_window.set_policy( Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scrolled_window.add(view) model = Gtk.ListStore(int, str, str, str, bool) filters = self.filters for (i, (name, data)) in enumerate(filters): filter_type, icon, query, always = data enabled = always model.append(row=[filter_type, icon, name, query, enabled]) def search_func(model, column, key, iter, data): return key.lower() not in model[iter][column].lower() view.set_search_column(self.ModelIndex.NAME) view.set_search_equal_func(search_func, None) column = Gtk.TreeViewColumn("Songs") column.set_sizing(Gtk.TreeViewColumnSizing.FIXED) renderpb = Gtk.CellRendererPixbuf() renderpb.props.xpad = 6 renderpb.props.ypad = 6 column.pack_start(renderpb, False) column.add_attribute(renderpb, "icon-name", self.ModelIndex.ICON_NAME) render = Gtk.CellRendererText() render.set_property('ellipsize', Pango.EllipsizeMode.END) def cdf(column, cell, model, iter_, user_data): on = (self.login_state == State.LOGGED_IN or model[iter_][self.ModelIndex.ALWAYS_ENABLE]) cell.set_sensitive(on) column.set_cell_data_func(render, cdf) column.set_cell_data_func(renderpb, cdf) view.append_column(column) column.pack_start(render, True) column.add_attribute(render, "text", self.ModelIndex.NAME) view.set_model(model) selection = view.get_selection() def select_func(sel, model, path, value): return (self.login_state == State.LOGGED_IN or model[model.get_iter(path)][self.ModelIndex.ALWAYS_ENABLE]) selection.set_select_function(select_func) self._refresh_online_filters() self.__changed_sig = connect_destroy(selection, 'changed', DeferredSignal(self._on_select)) return scrolled_window def _on_select(self, sel): model, paths = sel.get_selected_rows() if not paths: return row = model[paths[0]] query_text = row[self.ModelIndex.QUERY] filter_type = row[self.ModelIndex.TYPE] if filter_type == FilterType.SEARCH: self.__searchbar.set_enabled() elif filter_type == FilterType.FAVORITES: print_d("Getting favorites...") self.api_client.get_favorites() self.__searchbar.set_enabled(False) elif filter_type == FilterType.MINE: print_d("Getting user tracks...") self.api_client.get_my_tracks() self.__searchbar.set_enabled(False) query_text = query_text % self.api_client.user_id self.__searchbar.set_text(query_text) self.activate() def pack(self, songpane): container = Gtk.VBox() container.add(self) self._songs_box.add(songpane) return container def unpack(self, container, songpane): self._songs_box.remove(songpane) container.remove(self) def __changed(self, library, songs): print_d("Updating view") self.activate() def __query_changed(self, bar, text, restore=False): try: self.__filter = SoundcloudQuery(text, self.STAR) self.library.query_with_refresh(text) except SoundcloudQuery.error as e: print_d("Couldn't parse query: %s" % e) else: print_d("Got terms from query: %s" % (self.__filter.terms,)) if not restore: self.activate() def __get_selected_libraries(self): """Returns the libraries to search in depending on the filter selection""" return [self.library] def restore(self): text = config.gettext("browsers", "query_text") self.__searchbar.set_text(text) self.__query_changed(None, text, restore=True) def __get_filter(self): return self.__filter or SoundcloudQuery("") def can_filter_text(self): return True def filter_text(self, text): self.__searchbar.set_text(text) if SoundcloudQuery(text).is_parsable: self.activate() else: print_d("Not parsable: %s" % text) def get_filter_text(self): return self.__searchbar.get_text() def activate(self): print_d("Refreshing browser for query \"%r\"" % self.__filter) songs = self.library.query(self.get_filter_text()) self.songs_selected(songs) def active_filter(self, song): for lib in self.__get_selected_libraries(): if song in lib: filter_ = self.__get_filter() if filter_: return filter_.search(song) return True else: return False def save(self): text = self.__searchbar.get_text() config.settext("browsers", "query_text", text) self.api_client.save_auth() def _refresh_online_filters(self): model = self.view.get_model() for row in model: model.row_changed(row.path, model.get_iter(row.path)) def __handle_incoming_uri(self, obj, uri): if not PROCESS_QL_URLS: print_w("Processing of quodlibet:// URLs is disabled. (%s)" % uri) return uri = urlparse(uri) if (uri.scheme == 'quodlibet' and uri.netloc == 'callbacks' and uri.path == '/soundcloud'): try: code = parse_qs(uri.query)["code"][0] except IndexError: print_w("Malformed response in callback URI: %s" % uri) return print_d("Processing Soundcloud callback (%s)" % (uri,)) self.api_client.get_token(code) else: print_w("Unknown URL format (%s)" % (uri,)) def __on_authenticated(self, obj, data): name = data.username self.login_state = State.LOGGED_IN self.update_connect_button() self._refresh_online_filters() msg = Message(Gtk.MessageType.INFO, app.window, _("Connected"), _("Quod Libet is now connected, <b>%s</b>!") % name) msg.run() @cached_property def _logo_image(self): return WebImage( "https://developers.soundcloud.com/assets/logo_black.png", 104, 16) @cached_property def _login_state_data(self): """Login-state-based data for configuring actions (e.g. the button)""" return { State.LOGGED_IN: (_("Log out of %s") % SOUNDCLOUD_NAME, sc_btn_image('disconnect-l', 140, 29)), State.LOGGING_IN: (_("Enter code…"), None), State.LOGGED_OUT: (_("Log in to %s") % SOUNDCLOUD_NAME, sc_btn_image('connect-l', 124, 29)), }
def __init__(self, library, player, headless=False, restore_cb=None): super().__init__(dialog=False) self.__destroyed = False self.__update_title(player) self.set_default_size(600, 480) main_box = Gtk.VBox() self.add(main_box) self.side_book = qltk.Notebook() # get the playlist up before other stuff self.songlist = MainSongList(library, player) self.songlist.connect("key-press-event", self.__songlist_key_press) self.songlist.connect_after('drag-data-received', self.__songlist_drag_data_recv) self.song_scroller = ScrolledWindow() self.song_scroller.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.song_scroller.set_shadow_type(Gtk.ShadowType.IN) self.song_scroller.add(self.songlist) self.qexpander = QueueExpander(library, player) self.qexpander.set_no_show_all(True) self.qexpander.set_visible(config.getboolean("memory", "queue")) def on_queue_visible(qex, param): config.set("memory", "queue", str(qex.get_visible())) self.qexpander.connect("notify::visible", on_queue_visible) self.playlist = PlaylistMux(player, self.qexpander.model, self.songlist.model) self.__player = player # create main menubar, load/restore accelerator groups self.__library = library ui = self.__create_menu(player, library) accel_group = ui.get_accel_group() self.add_accel_group(accel_group) def scroll_and_jump(*args): self.__jump_to_current(True, None, True) keyval, mod = Gtk.accelerator_parse("<Primary><shift>J") accel_group.connect(keyval, mod, 0, scroll_and_jump) # custom accel map accel_fn = os.path.join(quodlibet.get_user_dir(), "accels") Gtk.AccelMap.load(accel_fn) # save right away so we fill the file with example comments of all # accels Gtk.AccelMap.save(accel_fn) menubar = ui.get_widget("/Menu") # Since https://git.gnome.org/browse/gtk+/commit/?id=b44df22895c79 # toplevel menu items show an empty 16x16 image. While we don't # need image items there UIManager creates them by default. # Work around by removing the empty GtkImages for child in menubar.get_children(): if isinstance(child, Gtk.ImageMenuItem): child.set_image(None) main_box.pack_start(menubar, False, True, 0) top_bar = TopBar(self, player, library) main_box.pack_start(top_bar, False, True, 0) self.top_bar = top_bar self.__browserbox = Align(bottom=3) self.__paned = paned = ConfigRHPaned("memory", "sidebar_pos", 0.25) paned.pack1(self.__browserbox, resize=True) # We'll pack2 when necessary (when the first sidebar plugin is set up) main_box.pack_start(paned, True, True, 0) play_order = PlayOrderWidget(self.songlist.model, player) statusbox = StatusBarBox(play_order, self.qexpander) self.order = play_order self.statusbar = statusbox.statusbar main_box.pack_start(Align(statusbox, border=3, top=-3), False, True, 0) self.songpane = SongListPaned(self.song_scroller, self.qexpander) self.songpane.show_all() try: orders = [] for e in config.getstringlist('memory', 'sortby', []): orders.append((e[1:], int(e[0]))) except ValueError: pass else: self.songlist.set_sort_orders(orders) self.browser = None self.ui = ui main_box.show_all() self._playback_error_dialog = None connect_destroy(player, 'song-started', self.__song_started) connect_destroy(player, 'paused', self.__update_paused, True) connect_destroy(player, 'unpaused', self.__update_paused, False) # make sure we redraw all error indicators before opening # a dialog (blocking the main loop), so connect after default handlers connect_after_destroy(player, 'error', self.__player_error) # connect after to let SongTracker update stats connect_after_destroy(player, "song-ended", self.__song_ended) # set at least the playlist. the song should be restored # after the browser emits the song list player.setup(self.playlist, None, 0) self.__restore_cb = restore_cb self.__first_browser_set = True restore_browser = not headless try: self._select_browser(self, config.get("memory", "browser"), library, player, restore_browser) except: config.set("memory", "browser", browsers.name(browsers.default)) config.save() raise self.songlist.connect('popup-menu', self.__songs_popup_menu) self.songlist.connect('columns-changed', self.__cols_changed) self.songlist.connect('columns-changed', self.__hide_headers) self.songlist.info.connect("changed", self.__set_totals) lib = library.librarian connect_destroy(lib, 'changed', self.__song_changed, player) targets = [("text/uri-list", Gtk.TargetFlags.OTHER_APP, DND_URI_LIST)] targets = [Gtk.TargetEntry.new(*t) for t in targets] self.drag_dest_set(Gtk.DestDefaults.ALL, targets, Gdk.DragAction.COPY) self.connect('drag-data-received', self.__drag_data_received) if not headless: on_first_map(self, self.__configure_scan_dirs, library) if config.getboolean('library', 'refresh_on_start'): self.__rebuild(None, False) self.connect("key-press-event", self.__key_pressed, player) self.connect("destroy", self.__destroy) self.enable_window_tracking("quodlibet")
def __init__(self, library): super(CollectionBrowser, self).__init__(spacing=6) self.set_orientation(Gtk.Orientation.VERTICAL) self._register_instance() if self.__model is None: self._init_model(library) sw = ScrolledWindow() sw.set_shadow_type(Gtk.ShadowType.IN) self.view = view = CollectionView() view.set_headers_visible(False) model_sort = CollectionSortModel(model=self.__model) model_filter = CollectionFilterModel(child_model=model_sort) self.__filter = None self.__bg_filter = background_filter() model_filter.set_visible_func(self.__parse_query) view.set_model(model_filter) def sort(model, i1, i2, data): t1, t2 = model[i1][0], model[i2][0] if t1 is None or t2 is None: # FIXME: why? return 0 # FIXME: order this deterministically if t1 is MultiNode or t1 is UnknownNode or \ t2 is MultiNode or t2 is UnknownNode: return -cmp(t1, t2) if not isinstance(t1, Album): return cmp(util.human_sort_key(t1), util.human_sort_key(t2)) a1, a2 = t1, t2 return (cmp(a1.peoplesort and a1.peoplesort[0], a2.peoplesort and a2.peoplesort[0]) or cmp(a1.date or "ZZZZ", a2.date or "ZZZZ") or cmp((a1.sort, a1.key), (a2.sort, a2.key))) model_sort.set_sort_func(0, sort) model_sort.set_sort_column_id(0, Gtk.SortType.ASCENDING) column = Gtk.TreeViewColumn("albums") def cell_data(column, cell, model, iter_, data): markup = model.get_markup(self.__model.tags, iter_) cell.markup = markup cell.set_property('markup', markup) def get_scaled_cover(album): # XXX: Cache this somewhere else cover = None if not hasattr(album, "_scaled_cover"): scale_factor = self.get_scale_factor() album.scan_cover(scale_factor=scale_factor) if album.cover: s = 25 * scale_factor cover = scale(album.cover, (s, s)) album._scaled_cover = cover else: cover = album._scaled_cover return cover def cell_data_pb(column, cell, model, iter_, data): album = model.get_album(iter_) if album is None: cell.set_property('icon-name', Icons.FOLDER) else: cover = get_scaled_cover(album) if cover: cover = add_border_widget(cover, view) surface = get_surface_for_pixbuf(self, cover) cell.set_property("surface", surface) else: cell.set_property('icon-name', Icons.MEDIA_OPTICAL) imgrender = Gtk.CellRendererPixbuf() render = Gtk.CellRendererText() if view.supports_hints(): render.set_property('ellipsize', Pango.EllipsizeMode.END) column.pack_start(imgrender, False) column.pack_start(render, True) column.set_cell_data_func(render, cell_data) column.set_cell_data_func(imgrender, cell_data_pb) view.append_column(column) sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) sw.add(view) hbox = Gtk.HBox(spacing=6) prefs = Gtk.Button() prefs.add(SymbolicIconImage(Icons.EMBLEM_SYSTEM, Gtk.IconSize.MENU)) prefs.connect('clicked', lambda *x: Preferences(self)) search = SearchBarBox(completion=AlbumTagCompletion(), accel_group=self.accelerators) search.connect('query-changed', self.__update_filter) self.__search = search hbox.pack_start(search, True, True, 0) hbox.pack_start(prefs, False, True, 0) self.pack_start(Align(hbox, left=6, top=6), False, True, 0) self.pack_start(sw, True, True, 0) view.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE) self.__sig = view.get_selection().connect('changed', self.__selection_changed) view.connect('row-activated', self.__play) connect_obj(view, 'popup-menu', self.__popup, view, library) targets = [("text/x-quodlibet-songs", Gtk.TargetFlags.SAME_APP, 1), ("text/uri-list", 0, 2)] targets = [Gtk.TargetEntry.new(*t) for t in targets] view.drag_source_set( Gdk.ModifierType.BUTTON1_MASK, targets, Gdk.DragAction.COPY) view.connect("drag-data-get", self.__drag_data_get) self.connect("destroy", self.__destroy) self.show_all()
class QuodLibetWindow(Window, PersistentWindowMixin, AppWindow): def __init__(self, library, player, headless=False, restore_cb=None): super(QuodLibetWindow, self).__init__(dialog=False) self.__destroyed = False self.__update_title(player) self.set_default_size(600, 480) main_box = Gtk.VBox() self.add(main_box) self.side_book = qltk.Notebook() # get the playlist up before other stuff self.songlist = MainSongList(library, player) self.songlist.connect("key-press-event", self.__songlist_key_press) self.songlist.connect_after( 'drag-data-received', self.__songlist_drag_data_recv) self.song_scroller = ScrolledWindow() self.song_scroller.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.song_scroller.set_shadow_type(Gtk.ShadowType.IN) self.song_scroller.add(self.songlist) self.qexpander = QueueExpander(library, player) self.qexpander.set_no_show_all(True) self.qexpander.set_visible(config.getboolean("memory", "queue")) def on_queue_visible(qex, param): config.set("memory", "queue", str(qex.get_visible())) self.qexpander.connect("notify::visible", on_queue_visible) self.playlist = PlaylistMux( player, self.qexpander.model, self.songlist.model) self.__player = player # create main menubar, load/restore accelerator groups self.__library = library ui = self.__create_menu(player, library) accel_group = ui.get_accel_group() self.add_accel_group(accel_group) def scroll_and_jump(*args): self.__jump_to_current(True, None, True) keyval, mod = Gtk.accelerator_parse("<Primary><shift>J") accel_group.connect(keyval, mod, 0, scroll_and_jump) # custom accel map accel_fn = os.path.join(quodlibet.get_user_dir(), "accels") Gtk.AccelMap.load(accel_fn) # save right away so we fill the file with example comments of all # accels Gtk.AccelMap.save(accel_fn) menubar = ui.get_widget("/Menu") # Since https://git.gnome.org/browse/gtk+/commit/?id=b44df22895c79 # toplevel menu items show an empty 16x16 image. While we don't # need image items there UIManager creates them by default. # Work around by removing the empty GtkImages for child in menubar.get_children(): if isinstance(child, Gtk.ImageMenuItem): child.set_image(None) main_box.pack_start(menubar, False, True, 0) top_bar = TopBar(self, player, library) main_box.pack_start(top_bar, False, True, 0) self.top_bar = top_bar self.__browserbox = Align(bottom=3) self.__paned = paned = ConfigRHPaned("memory", "sidebar_pos", 0.25) paned.pack1(self.__browserbox, resize=True) # We'll pack2 when necessary (when the first sidebar plugin is set up) main_box.pack_start(paned, True, True, 0) play_order = PlayOrderWidget(self.songlist.model, player) statusbox = StatusBarBox(play_order, self.qexpander) self.order = play_order self.statusbar = statusbox.statusbar main_box.pack_start( Align(statusbox, border=3, top=-3), False, True, 0) self.songpane = SongListPaned(self.song_scroller, self.qexpander) self.songpane.show_all() try: orders = [] for e in config.getstringlist('memory', 'sortby', []): orders.append((e[1:], int(e[0]))) except ValueError: pass else: self.songlist.set_sort_orders(orders) self.browser = None self.ui = ui main_box.show_all() self._playback_error_dialog = None connect_destroy(player, 'song-started', self.__song_started) connect_destroy(player, 'paused', self.__update_paused, True) connect_destroy(player, 'unpaused', self.__update_paused, False) # make sure we redraw all error indicators before opening # a dialog (blocking the main loop), so connect after default handlers connect_after_destroy(player, 'error', self.__player_error) # connect after to let SongTracker update stats connect_after_destroy(player, "song-ended", self.__song_ended) # set at least the playlist. the song should be restored # after the browser emits the song list player.setup(self.playlist, None, 0) self.__restore_cb = restore_cb self.__first_browser_set = True restore_browser = not headless try: self._select_browser( self, config.get("memory", "browser"), library, player, restore_browser) except: config.set("memory", "browser", browsers.name(browsers.default)) config.save() raise self.songlist.connect('popup-menu', self.__songs_popup_menu) self.songlist.connect('columns-changed', self.__cols_changed) self.songlist.connect('columns-changed', self.__hide_headers) self.songlist.info.connect("changed", self.__set_totals) lib = library.librarian connect_destroy(lib, 'changed', self.__song_changed, player) targets = [("text/uri-list", Gtk.TargetFlags.OTHER_APP, DND_URI_LIST)] targets = [Gtk.TargetEntry.new(*t) for t in targets] self.drag_dest_set( Gtk.DestDefaults.ALL, targets, Gdk.DragAction.COPY) self.connect('drag-data-received', self.__drag_data_received) if not headless: on_first_map(self, self.__configure_scan_dirs, library) if config.getboolean('library', 'refresh_on_start'): self.__rebuild(None, False) self.connect("key-press-event", self.__key_pressed, player) self.connect("destroy", self.__destroy) self.enable_window_tracking("quodlibet") def hide_side_book(self): self.side_book.hide() def add_sidebar(self, box, name): vbox = Gtk.Box(margin=0) vbox.pack_start(box, True, True, 0) vbox.show() if self.side_book_empty: self.add_sidebar_to_layout(self.side_book) self.side_book.append_page(vbox, label=name) self.side_book.set_tab_detachable(vbox, False) self.side_book.show_all() return vbox def remove_sidebar(self, widget): self.side_book.remove_page(self.side_book.page_num(widget)) if self.side_book_empty: print_d("Hiding sidebar") self.__paned.remove(self.__paned.get_children()[1]) def add_sidebar_to_layout(self, widget): print_d("Recreating sidebar") align = Align(widget, top=6, bottom=3) self.__paned.pack2(align, shrink=True) align.show_all() @property def side_book_empty(self): return not self.side_book.get_children() def set_seekbar_widget(self, widget): """Add an alternative seek bar widget. Args: widget (Gtk.Widget): a new widget or None to remove the current one """ self.top_bar.set_seekbar_widget(widget) def set_as_osx_window(self, osx_app): assert osx_app self._dock_menu = DockMenu(app) osx_app.set_dock_menu(self._dock_menu) menu = self.ui.get_widget("/Menu") menu.hide() osx_app.set_menu_bar(menu) # Reparent some items to the "Application" menu item = self.ui.get_widget('/Menu/Help/About') osx_app.insert_app_menu_item(item, 0) osx_app.insert_app_menu_item(Gtk.SeparatorMenuItem(), 1) item = self.ui.get_widget('/Menu/File/Preferences') osx_app.insert_app_menu_item(item, 2) quit_item = self.ui.get_widget('/Menu/File/Quit') quit_item.hide() def get_is_persistent(self): return True def open_file(self, filename): assert isinstance(filename, fsnative) song = self.__library.add_filename(filename, add=False) if song is not None: if self.__player.go_to(song): self.__player.paused = False return True else: return False def __player_error(self, player, song, player_error): # it's modal, but mmkeys etc. can still trigger new ones if self._playback_error_dialog: self._playback_error_dialog.destroy() dialog = PlaybackErrorDialog(self, player_error) self._playback_error_dialog = dialog dialog.run() self._playback_error_dialog = None def __configure_scan_dirs(self, library): """Get user to configure scan dirs, if none is set up""" if not get_scan_dirs() and not len(library) and \ quodlibet.is_first_session("quodlibet"): print_d("Couldn't find any scan dirs") resp = ConfirmLibDirSetup(self).run() if resp == ConfirmLibDirSetup.RESPONSE_SETUP: prefs = PreferencesWindow(self) prefs.set_page("library") prefs.show() def __keyboard_shortcuts(self, action): show_shortcuts(self) def __edit_bookmarks(self, librarian, player): if player.song: window = EditBookmarks(self, librarian, player) window.show() def __key_pressed(self, widget, event, player): if not player.song: return def seek_relative(seconds): current = player.get_position() current += seconds * 1000 current = min(player.song("~#length") * 1000 - 1, current) current = max(0, current) player.seek(current) if qltk.is_accel(event, "<alt>Right"): seek_relative(10) return True elif qltk.is_accel(event, "<alt>Left"): seek_relative(-10) return True def __destroy(self, *args): self.playlist.destroy() # The tray icon plugin tries to unhide QL because it gets disabled # on Ql exit. The window should stay hidden after destroy. self.show = lambda: None self.present = self.show def __drag_data_received(self, widget, ctx, x, y, sel, tid, etime): assert tid == DND_URI_LIST uris = sel.get_uris() dirs = [] error = False for uri in uris: try: filename = uri2fsn(uri) except ValueError: filename = None if filename is not None: loc = os.path.normpath(filename) if os.path.isdir(loc): dirs.append(loc) else: loc = os.path.realpath(loc) if loc not in self.__library: self.__library.add_filename(loc) elif app.player.can_play_uri(uri): if uri not in self.__library: self.__library.add([RemoteFile(uri)]) else: error = True break Gtk.drag_finish(ctx, not error, False, etime) if error: ErrorMessage( self, _("Unable to add songs"), _("%s uses an unsupported protocol.") % util.bold(uri)).run() else: if dirs: copool.add( self.__library.scan, dirs, cofuncid="library", funcid="library") def __songlist_key_press(self, songlist, event): return self.browser.key_pressed(event) def __songlist_drag_data_recv(self, view, *args): if self.browser.can_reorder: songs = view.get_songs() self.browser.reordered(songs) self.songlist.clear_sort() def __create_menu(self, player, library): def add_view_items(ag): act = Action(name="Information", label=_('_Information'), icon_name=Icons.DIALOG_INFORMATION) act.connect('activate', self.__current_song_info) ag.add_action(act) act = Action(name="Jump", label=_('_Jump to Playing Song'), icon_name=Icons.GO_JUMP) self.__jump_to_current(True, None, True) act.connect('activate', self.__jump_to_current) ag.add_action_with_accel(act, "<Primary>J") def add_top_level_items(ag): ag.add_action(Action(name="File", label=_("_File"))) ag.add_action(Action(name="Song", label=_("_Song"))) ag.add_action(Action(name="View", label=_('_View'))) ag.add_action(Action(name="Browse", label=_("_Browse"))) ag.add_action(Action(name="Control", label=_('_Control'))) ag.add_action(Action(name="Help", label=_('_Help'))) ag = Gtk.ActionGroup.new('QuodLibetWindowActions') add_top_level_items(ag) add_view_items(ag) act = Action(name="AddFolders", label=_(u'_Add a Folder…'), icon_name=Icons.LIST_ADD) act.connect('activate', self.open_chooser) ag.add_action_with_accel(act, "<Primary>O") act = Action(name="AddFiles", label=_(u'_Add a File…'), icon_name=Icons.LIST_ADD) act.connect('activate', self.open_chooser) ag.add_action(act) act = Action(name="AddLocation", label=_(u'_Add a Location…'), icon_name=Icons.LIST_ADD) act.connect('activate', self.open_location) ag.add_action(act) act = Action(name="BrowseLibrary", label=_('Open _Browser'), icon_name=Icons.EDIT_FIND) ag.add_action(act) act = Action(name="Preferences", label=_('_Preferences'), icon_name=Icons.PREFERENCES_SYSTEM) act.connect('activate', self.__preferences) ag.add_action(act) act = Action(name="Plugins", label=_('_Plugins'), icon_name=Icons.SYSTEM_RUN) act.connect('activate', self.__plugins) ag.add_action(act) act = Action(name="Quit", label=_('_Quit'), icon_name=Icons.APPLICATION_EXIT) act.connect('activate', lambda *x: self.destroy()) ag.add_action_with_accel(act, "<Primary>Q") act = Action(name="EditTags", label=_('Edit _Tags'), icon_name=Icons.DOCUMENT_PROPERTIES) act.connect('activate', self.__current_song_prop) ag.add_action(act) act = Action(name="EditBookmarks", label=_(u"Edit Bookmarks…")) connect_obj(act, 'activate', self.__edit_bookmarks, library.librarian, player) ag.add_action_with_accel(act, "<Primary>B") act = Action(name="Previous", label=_('Pre_vious'), icon_name=Icons.MEDIA_SKIP_BACKWARD) act.connect('activate', self.__previous_song) ag.add_action_with_accel(act, "<Primary>comma") act = Action(name="PlayPause", label=_('_Play'), icon_name=Icons.MEDIA_PLAYBACK_START) act.connect('activate', self.__play_pause) ag.add_action_with_accel(act, "<Primary>space") act = Action(name="Next", label=_('_Next'), icon_name=Icons.MEDIA_SKIP_FORWARD) act.connect('activate', self.__next_song) ag.add_action_with_accel(act, "<Primary>period") act = ToggleAction(name="StopAfter", label=_("Stop After This Song")) ag.add_action_with_accel(act, "<shift>space") # access point for the tray icon self.stop_after = act act = Action(name="Shortcuts", label=_("_Keyboard Shortcuts")) act.connect('activate', self.__keyboard_shortcuts) ag.add_action_with_accel(act, "<Primary>question") act = Action(name="About", label=_("_About"), icon_name=Icons.HELP_ABOUT) act.connect('activate', self.__show_about) ag.add_action_with_accel(act, None) act = Action(name="OnlineHelp", label=_("Online Help"), icon_name=Icons.HELP_BROWSER) def website_handler(*args): util.website(const.ONLINE_HELP) act.connect('activate', website_handler) ag.add_action_with_accel(act, "F1") act = Action(name="SearchHelp", label=_("Search Help")) def search_help_handler(*args): util.website(const.SEARCH_HELP) act.connect('activate', search_help_handler) ag.add_action_with_accel(act, None) act = Action(name="CheckUpdates", label=_("_Check for Updates…"), icon_name=Icons.NETWORK_SERVER) def check_updates_handler(*args): d = UpdateDialog(self) d.run() d.destroy() act.connect('activate', check_updates_handler) ag.add_action_with_accel(act, None) act = Action( name="RefreshLibrary", label=_("_Scan Library"), icon_name=Icons.VIEW_REFRESH) act.connect('activate', self.__rebuild, False) ag.add_action(act) current = config.get("memory", "browser") try: browsers.get(current) except ValueError: current = browsers.name(browsers.default) first_action = None for Kind in browsers.browsers: name = browsers.name(Kind) index = browsers.index(name) action_name = "View" + Kind.__name__ act = RadioAction(name=action_name, label=Kind.accelerated_name, value=index) act.join_group(first_action) first_action = first_action or act if name == current: act.set_active(True) ag.add_action_with_accel(act, "<Primary>%d" % ((index + 1) % 10,)) assert first_action self._browser_action = first_action def action_callback(view_action, current_action): current = browsers.name( browsers.get(current_action.get_current_value())) self._select_browser(view_action, current, library, player) first_action.connect("changed", action_callback) for Kind in browsers.browsers: action = "Browser" + Kind.__name__ label = Kind.accelerated_name name = browsers.name(Kind) index = browsers.index(name) act = Action(name=action, label=label) def browser_activate(action, Kind): LibraryBrowser.open(Kind, library, player) act.connect('activate', browser_activate, Kind) ag.add_action_with_accel(act, "<Primary><alt>%d" % ((index + 1) % 10,)) ui = Gtk.UIManager() ui.insert_action_group(ag, -1) menustr = MENU % { "views": browser_menu_items(), "browsers": secondary_browser_menu_items(), "filters_menu": FilterMenu.MENU } ui.add_ui_from_string(menustr) self._filter_menu = FilterMenu(library, player, ui) # Cute. So. UIManager lets you attach tooltips, but when they're # for menu items, they just get ignored. So here I get to actually # attach them. ui.get_widget("/Menu/File/RefreshLibrary").set_tooltip_text( _("Check for changes in your library")) return ui def __show_about(self, *args): about = AboutDialog(self, app) about.run() about.destroy() def select_browser(self, browser_key, library, player): """Given a browser name (see browsers.get()) changes the current browser. Returns True if the passed browser ID is known and the change was initiated. """ try: Browser = browsers.get(browser_key) except ValueError: return False action_name = "View%s" % Browser.__name__ for action in self._browser_action.get_group(): if action.get_name() == action_name: action.set_active(True) return True return False def _select_browser(self, activator, current, library, player, restore=False): Browser = browsers.get(current) window = self.get_window() if window: window.set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH)) # Wait for the cursor to update before continuing while Gtk.events_pending(): Gtk.main_iteration() config.set("memory", "browser", current) if self.browser: if not (self.browser.uses_main_library and Browser.uses_main_library): self.songlist.clear() container = self.browser.__container self.browser.unpack(container, self.songpane) if self.browser.accelerators: self.remove_accel_group(self.browser.accelerators) container.destroy() self.browser.destroy() self.browser = Browser(library) self.browser.connect('songs-selected', self.__browser_cb, library, player) self.browser.connect('songs-activated', self.__browser_activate) if restore: self.browser.restore() self.browser.activate() self.browser.finalize(restore) if self.browser.can_reorder: self.songlist.enable_drop() elif self.browser.dropped: self.songlist.enable_drop(False) else: self.songlist.disable_drop() if self.browser.accelerators: self.add_accel_group(self.browser.accelerators) container = self.browser.__container = self.browser.pack(self.songpane) # Reset the cursor when done loading the browser if window: GLib.idle_add(window.set_cursor, None) player.replaygain_profiles[1] = self.browser.replaygain_profiles player.reset_replaygain() self.__browserbox.add(container) container.show() self._filter_menu.set_browser(self.browser) self.__hide_headers() def __update_paused(self, player, paused): menu = self.ui.get_widget("/Menu/Control/PlayPause") image = menu.get_image() if paused: label, icon = _("_Play"), Icons.MEDIA_PLAYBACK_START else: label, icon = _("P_ause"), Icons.MEDIA_PLAYBACK_PAUSE menu.set_label(label) image.set_from_icon_name(icon, Gtk.IconSize.MENU) def __song_ended(self, player, song, stopped): # Check if the song should be removed, based on the # active filter of the current browser. active_filter = self.browser.active_filter if song and active_filter and not active_filter(song): iter_ = self.songlist.model.find(song) if iter_: self.songlist.remove_iters([iter_]) if self.stop_after.get_active(): player.paused = True self.stop_after.set_active(False) def __song_changed(self, library, songs, player): if player.info in songs: self.__update_title(player) def __update_title(self, player): song = player.info title = "Quod Libet" if song: tag = config.gettext("settings", "window_title_pattern") if tag: title = song.comma(tag) + " - " + title self.set_title(title) def __song_started(self, player, song): self.__update_title(player) for wid in ["Control/Next", "Control/StopAfter", "Song/EditTags", "Song/Information", "Song/EditBookmarks", "Song/Jump"]: self.ui.get_widget('/Menu/' + wid).set_sensitive(bool(song)) # don't jump on stream changes (player.info != player.song) main_should_jump = (song and player.song is song and not self.songlist._activated and config.getboolean("settings", "jump") and self.songlist.sourced) queue_should_jump = (song and player.song is song and not self.qexpander.queue._activated and config.getboolean("settings", "jump") and self.qexpander.queue.sourced and config.getboolean("memory", "queue_keep_songs")) if main_should_jump: self.__jump_to_current(False, self.songlist) elif queue_should_jump: self.__jump_to_current(False, self.qexpander.queue) def __play_pause(self, *args): app.player.playpause() def __jump_to_current(self, explicit, songlist=None, force_scroll=False): """Select/scroll to the current playing song in the playlist. If it can't be found tell the browser to properly fill the playlist with an appropriate selection containing the song. explicit means that the jump request comes from the user and not from an event like song-started. songlist is the songlist to be jumped within. Usually the main song list or the queue. If None, the currently sourced songlist will be used. force_scroll will ask the browser to refill the playlist in any case. """ def idle_jump_to(song, select): ok = songlist.jump_to_song(song, select=select) if ok: songlist.grab_focus() return False if not songlist: if (config.getboolean("memory", "queue_keep_songs") and self.qexpander.queue.sourced): songlist = self.qexpander.queue else: songlist = self.songlist if app.player is None: return song = app.player.song # We are not playing a song if song is None: return if not force_scroll: ok = songlist.jump_to_song(song, select=explicit) else: assert explicit ok = False if ok: songlist.grab_focus() elif explicit: # if we can't find it and the user requested it, try harder self.browser.scroll(song) # We need to wait until the browser has finished # scrolling/filling and the songlist is ready. # Not perfect, but works for now. GLib.idle_add( idle_jump_to, song, explicit, priority=GLib.PRIORITY_LOW) def __next_song(self, *args): app.player.next() def __previous_song(self, *args): app.player.previous() def __rebuild(self, activator, force): scan_library(self.__library, force) # Set up the preferences window. def __preferences(self, activator): window = PreferencesWindow(self) window.show() def __plugins(self, activator): window = PluginWindow(self) window.show() def open_location(self, action): name = GetStringDialog(self, _("Add a Location"), _("Enter the location of an audio file:"), button_label=_("_Add"), button_icon=Icons.LIST_ADD).run() if name: if not uri_is_valid(name): ErrorMessage( self, _("Unable to add location"), _("%s is not a valid location.") % ( util.bold(util.escape(name)))).run() elif not app.player.can_play_uri(name): ErrorMessage( self, _("Unable to add location"), _("%s uses an unsupported protocol.") % ( util.bold(util.escape(name)))).run() else: if name not in self.__library: self.__library.add([RemoteFile(name)]) def open_chooser(self, action): if action.get_name() == "AddFolders": fns = choose_folders(self, _("Add Music"), _("_Add Folders")) if fns: # scan them copool.add(self.__library.scan, fns, cofuncid="library", funcid="library") else: patterns = ["*" + path2fsn(k) for k in formats.loaders.keys()] choose_filter = create_chooser_filter(_("Music Files"), patterns) fns = choose_files( self, _("Add Music"), _("_Add Files"), choose_filter) if fns: for filename in fns: self.__library.add_filename(filename) def __songs_popup_menu(self, songlist): path, col = songlist.get_cursor() header = col.header_name menu = self.songlist.Menu(header, self.browser, self.__library) if menu is not None: return self.songlist.popup_menu(menu, 0, Gtk.get_current_event_time()) def __current_song_prop(self, *args): song = app.player.song if song: librarian = self.__library.librarian window = SongProperties(librarian, [song], parent=self) window.show() def __current_song_info(self, *args): song = app.player.song if song: librarian = self.__library.librarian window = Information(librarian, [song], self) window.show() def __browser_activate(self, browser): app.player._reset() def __browser_cb(self, browser, songs, sorted, library, player): if browser.background: bg = background_filter() if bg: songs = list(filter(bg, songs)) self.songlist.set_songs(songs, sorted) # After the first time the browser activates, which should always # happen if we start up and restore, restore the playing song. # Because the browser has send us songs we can be sure it has # registered all its libraries. if self.__first_browser_set: self.__first_browser_set = False song = library.librarian.get(config.get("memory", "song")) seek_pos = config.getfloat("memory", "seek", 0) config.set("memory", "seek", 0) if song is not None: player.setup(self.playlist, song, seek_pos) if self.__restore_cb: self.__restore_cb() self.__restore_cb = None def __hide_headers(self, activator=None): for column in self.songlist.get_columns(): if self.browser.headers is None: column.set_visible(True) else: for tag in util.tagsplit(column.header_name): if tag in self.browser.headers: column.set_visible(True) break else: column.set_visible(False) def __cols_changed(self, songlist): headers = [col.header_name for col in songlist.get_columns()] try: headers.remove('~current') except ValueError: pass if len(headers) == len(get_columns()): # Not an addition or removal (handled separately) set_columns(headers) SongList.headers = headers def __make_query(self, query): if self.browser.can_filter_text(): self.browser.filter_text(query.encode('utf-8')) self.browser.activate() def __set_totals(self, info, songs): length = sum(song.get("~#length", 0) for song in songs) t = self.browser.status_text(count=len(songs), time=util.format_time_preferred(length)) self.statusbar.set_default_text(t)