def __enable(self): try: from blaspectrum import BlaSpectrum except ImportError as exc: blaguiutils.error_dialog( "Failed to enable spectrum visualization", exc.message) self.__disable() return self.__spectrum = BlaSpectrum() self.__spectrum.set_width(self.get_allocation().width) self.__spectrum.update_colors(self.__drawing_area.get_style()) self.set_size_request(-1, self.__spectrum.height) self.__set_visible(True) self.__cid = player.connect_object( "new_buffer", BlaSpectrum.new_buffer, self.__spectrum) # TODO: Suspend during paused and stopped states. def queue_draw(): self.__drawing_area.queue_draw() return True gobject.source_remove(self.__tid_draw) self.__tid_draw = gobject.timeout_add( int(1000 / self.__rate), queue_draw) self.__tid_consume = gobject.timeout_add( int(1000 / self.__rate), self.__spectrum.consume_buffer) blacfg.setboolean("general", "show.visualization", True)
def __window_state_event(self, window, event): self.__maximized = bool( event.new_window_state & gtk.gdk.WINDOW_STATE_MAXIMIZED) if event.new_window_state & gtk.gdk.WINDOW_STATE_WITHDRAWN: return if self.__is_main_window: blacfg.setboolean("general", "maximized", self.__maximized and self.__was_maximized)
def __mute_toggled(self, button): state = button.get_active() blacfg.setboolean("player", "muted", state) if state: self.__volume = self.__scale.get_value() self.__scale.set_value(0) else: self.__scale.set_value(self.__volume)
def __disable(self): try: player.disconnect(self.__cid) except AttributeError: pass map(gobject.source_remove, [self.__tid_draw, self.__tid_consume]) self.__spectrum = None self.__set_visible(False) blacfg.setboolean("general", "show.visualization", False)
def __use_equalizer_changed(self, checkbutton): state = checkbutton.get_active() blacfg.setboolean("player", "use.equalizer", state) player.enable_equalizer(state) self.__button_box.set_sensitive(state) if state and not self.__profiles_box.get_model().get_iter_first(): self.__scale_box.set_sensitive(False) else: self.__scale_box.set_sensitive(state)
def set_visible(self, yes): super(BlaStatusbar, self).set_visible(yes) blacfg.setboolean("general", "statusbar", yes)
def __queue_remove(self, checkbutton): blacfg.setboolean("general", "queue.remove.when.activated", checkbutton.get_active())
def __follow_playback(self, checkbutton): blacfg.setboolean("general", "cursor.follows.playback", checkbutton.get_active())
def __nowplaying_changed(self, checkbutton): blacfg.setboolean("lastfm", "now.playing", checkbutton.get_active())
def __scrobble_changed(self, checkbutton): blacfg.setboolean("lastfm", "scrobble", checkbutton.get_active())
def tray_changed(checkbutton, key): blacfg.setboolean("general", key, checkbutton.get_active())
def __volume_scale_changed(self, checkbutton): blacfg.setboolean("player", "logarithmic.volume.scale", checkbutton.get_active()) player.set_volume(blacfg.getfloat("player", "volume") * 100)
def __custom_library_browser_changed(self, checkbutton): blacfg.setboolean( "library", "custom.browser", checkbutton.get_active())
def __tree_lines_changed(self, checkbutton): blacfg.setboolean( "library", "draw.tree.lines", checkbutton.get_active())
def __init__(self): super(BlaPreferences.LibraryBrowsersSettings, self).__init__( "Library/Browsers") restrict_string = blacfg.getstring("library", "restrict.to") exclude_string = blacfg.getstring("library", "exclude") def destroy(*args): if (restrict_string != blacfg.getstring("library", "restrict.to") or exclude_string != blacfg.getstring("library", "exclude")): library.sync() self.connect("destroy", destroy) hbox = gtk.HBox(spacing=10) model = gtk.ListStore(gobject.TYPE_STRING) treeview = gtk.TreeView(model) treeview.set_property("rules_hint", True) r = gtk.CellRendererText() treeview.insert_column_with_attributes( -1, "Directories", r, text=0) sw = BlaScrolledWindow() sw.set_shadow_type(gtk.SHADOW_IN) sw.set_size_request(-1, 140) sw.add(treeview) directories = blacfg.getdotliststr("library", "directories") for f in directories: model.append([f]) table = gtk.Table(rows=2, columns=1) items = [ ("Add...", self.__add_directory), ("Remove", self.__remove_directory), ("Rescan all", self.__rescan_all) ] for idx, (label, callback) in enumerate(items): button = gtk.Button(label) button.connect("clicked", callback, treeview) table.attach(button, 0, 1, idx, idx+1, yoptions=not gtk.EXPAND) hbox.pack_start(sw, expand=True) hbox.pack_start(table, expand=False, fill=False) # Update library checkbutton update_library = gtk.CheckButton("Update library on startup") update_library.set_active( blacfg.getboolean("library", "update.on.startup")) update_library.connect( "toggled", lambda cb: blacfg.setboolean("library", "update.on.startup", cb.get_active())) # The file types restrict_to_entry = gtk.Entry() restrict_to_entry.set_tooltip_text( "Comma-separated list, works on filenames") restrict_to_entry.set_text( blacfg.getstring("library", "restrict.to")) restrict_to_entry.connect( "changed", lambda entry: blacfg.set("library", "restrict.to", entry.get_text())) exclude_entry = gtk.Entry() exclude_entry.set_tooltip_text( "Comma-separated list, works on filenames") exclude_entry.set_text( blacfg.getstring("library", "exclude")) exclude_entry.connect( "changed", lambda entry: blacfg.set("library", "exclude", entry.get_text())) pairs = [ (blaconst.ACTION_SEND_TO_CURRENT, "send to current playlist"), (blaconst.ACTION_ADD_TO_CURRENT, "add to current playlist"), (blaconst.ACTION_SEND_TO_NEW, "send to new playlist"), (blaconst.ACTION_EXPAND_COLLAPSE, "expand/collapse") ] # FIXME: Ugly!! actions = [""] * 4 for idx, label in pairs: actions[idx] = label comboboxes = [] def cb_changed(combobox, key): blacfg.set("library", "%s.action" % key, combobox.get_active()) for key in ["doubleclick", "middleclick", "return"]: cb = gtk.combo_box_new_text() map(cb.append_text, actions) if key == "return": cb.remove_text(3) cb.set_active(blacfg.getint("library", "%s.action" % key)) cb.connect("changed", cb_changed, key) comboboxes.append(cb) widgets = [restrict_to_entry, exclude_entry] + comboboxes labels = ["Restrict to", "Exclude", "Double-click", "Middle-click", "Return"] action_table = gtk.Table(rows=len(labels), columns=2, homogeneous=False) count = 0 for label, widget in zip(labels, widgets): label = gtk.Label("%s:" % label) label.set_alignment(xalign=0.0, yalign=0.5) action_table.attach(label, 0, 1, count, count+1, xoptions=gtk.FILL, xpadding=5) action_table.attach(widget, 1, 2, count, count+1) count += 1 hbox2 = gtk.HBox(spacing=10) draw_tree_lines = gtk.CheckButton("Draw tree lines in browsers") draw_tree_lines.set_active( blacfg.getboolean("library", "draw.tree.lines")) draw_tree_lines.connect("toggled", self.__tree_lines_changed) custom_library_browser = gtk.CheckButton( "Use custom treeview as library browser") custom_library_browser.set_active( blacfg.getboolean("library", "custom.browser")) custom_library_browser.connect( "toggled", self.__custom_library_browser_changed) hbox2.pack_start(draw_tree_lines) hbox2.pack_start(custom_library_browser) self.pack_start(hbox, expand=False) self.pack_start(update_library, expand=False) self.pack_start(action_table, expand=False) self.pack_start(hbox2, expand=False)
def __search_after_timeout(self, checkbutton): blacfg.setboolean("general", "search.after.timeout", checkbutton.get_active())