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 __add_station(self, uri): uri = uri.strip() try: stations = parse_uri(uri) if not stations: return except IOError: blaguiutils.error_dialog( "Invalid URL", "Failed to open location %s." % uri) else: model = self.__treeview.get_model() iterators = [model.append([None, station]) for station in stations] self.emit("count_changed", blaconst.VIEW_RADIO, len(model)) self.__treeview.set_cursor(model.get_path(iterators[0])) select_path = self.__treeview.get_selection().select_path map(select_path, map(model.get_path, iterators))
def __update_directory(self, directory=None, refresh=False, add_to_history=True): if not refresh: if directory is None: print_w("Directory must not be None") return False directory = os.path.expanduser(directory) # Got a relative path? if not os.path.isabs(directory): directory = os.path.join(self.__directory, directory) if not os.path.exists(directory): blaguiutils.error_dialog( "Could not find \"%s\"." % directory, "Please check the spelling and try again.") return False self.__directory = directory self.__entry.set_text(self.__directory) blacfg.set("general", "filesystem.directory", self.__directory) if add_to_history: self.__history.add(self.__directory) # FIXME: don't use gtk's model filter capabilities # TODO: keep the selection after updating the model model = self.__filt.get_model() self.__treeview.freeze_child_notify() model.clear() for dirpath, dirnames, filenames in os.walk(self.__directory): for d in sorted(dirnames, key=str.lower): if d.startswith("."): continue path = os.path.join(self.__directory, d) model.append([path, self.__pixbufs["directory"], d]) for f in sorted(filenames, key=str.lower): if f.startswith("."): continue path = os.path.join(self.__directory, f) # TODO: use this instead (profile the overhead first though): # f = gio.File(path) # info = f.query_info("standard::content-type") # mimetype = info.get_content_type() mimetype = gio.content_type_guess(path) try: pb = self.__pixbufs[mimetype] except KeyError: icon_names = gio.content_type_get_icon(mimetype) pb = self.__pixbufs["file"] if icon_names: for icon_name in icon_names.get_names(): pb_new = self.__get_pixbuf(icon_name) if pb_new: self.__pixbufs[mimetype] = pb_new pb = pb_new model.append([path, pb, f]) break try: self.__monitor.cancel() except AttributeError: pass # FIXME: this seems to cease working after handling an event self.__monitor = gio.File(self.__directory).monitor_directory( flags=gio.FILE_MONITOR_NONE) self.__monitor.connect("changed", self.__process_event) self.__treeview.thaw_child_notify() return False