def handle_line(self, app, line): """Parses a command line and executes the command. Can not fail. Args: app (Application) line (fsnative) Returns: fsnative or None """ assert isinstance(line, fsnative) # only one arg supported atm parts = line.split(" ", 1) command = parts[0] args = parts[1:] print_d("command: %r(*%r)" % (command, args)) try: return self.run(app, command, *args) except CommandError as e: print_e(e) except: util.print_exc()
def _bus_message(self, bus, message): if message.type == Gst.MessageType.TAG: tags = message.parse_tag() ok, value = tags.get_double(Gst.TAG_TRACK_GAIN) if ok: self._current.gain = value ok, value = tags.get_double(Gst.TAG_TRACK_PEAK) if ok: self._current.peak = value ok, value = tags.get_double(Gst.TAG_ALBUM_GAIN) if ok: self._album.gain = value ok, value = tags.get_double(Gst.TAG_ALBUM_PEAK) if ok: self._album.peak = value self._emit_update() elif message.type == Gst.MessageType.EOS: self._next_song() elif message.type == Gst.MessageType.ERROR: gerror, debug = message.parse_error() if gerror: print_e(gerror.message) print_e(debug) self._current.error = True self._next_song()
def _try_to_update_song(self, song_wrapper): try: song_wrapper._needs_write = True self._write_tags_to_files([song_wrapper]) except Exception as e: print_e(e) self._error_msg(WRITE_ERROR_FMT % song_wrapper._song)
def enabled(self): if system() != "Linux": print_e(self.PLUGIN_NAME + " plugin requires a Linux environment.") return try: self._dev = open(CONFIG.lcd_dev, 'wb', buffering=0) except: print_e("Matrix Orbital LCD device not found at " + CONFIG.lcd_dev) return self.reset_lcd() # Ready horizontal bars. self.write_bytes(b"\xFEh") # Turn backlight on. self.write_bytes(b"\xFEB\x00") self._write_header() self._npld = NowPlayingLCDData(self) self._tracker = TimeTracker(app.player) self._tracker.connect('tick', self._npld.on_tracker_tick) self._tracker.set_interval(int(CONFIG.lcd_interval))
def __about_to_finish(self, playbin): print_d("About to finish (async)") try: uri = self._runner.call(self.__about_to_finish_sync, priority=GLib.PRIORITY_HIGH, timeout=0.5) except MainRunnerTimeoutError as e: # Due to some locks being held during this signal we can get # into a deadlock when a seek or state change event happens # in the mainloop before our function gets scheduled. # In this case abort and do nothing, which results # in a non-gapless transition. print_e("About to finish (async): %s" % e) return except MainRunnerAbortedError as e: print_e("About to finish (async): %s" % e) return except MainRunnerError: util.print_exc() return if uri is not None: print_d("About to finish (async): setting uri") self._set_uri(uri) print_d("About to finish (async): done")
def _show_sync_error(self, title, message): """ Show an error message whenever a synchronization error occurs. :param title: The title of the message popup. :param message: The error message. """ qltk.ErrorMessage(self.main_vbox, title, message).run() print_e(title)
def Menu(self, library, songs): songs = ListWrapper(songs) attrs = [ 'plugin_song', 'plugin_songs', 'plugin_album', 'plugin_albums' ] if len(songs) == 1: attrs.append('plugin_single_song') last = (songs and songs[-1]) or None for song in songs: if song.album_key != last.album_key: break last = song else: attrs.append('plugin_single_album') items = [] kinds = self.__plugins kinds.sort(key=lambda plugin: plugin.PLUGIN_ID) for Kind in kinds: usable = any(callable(getattr(Kind, s)) for s in attrs) if usable: try: items.append(Kind(songs, library)) except: print_e( "Couldn't initialise song plugin %s. Stack trace:" % Kind) errorhook() items = [i for i in items if i.initialized] if items: menu = Gtk.Menu() for item in items: try: menu.append(item) args = (library, songs) if item.get_submenu(): for subitem in item.get_submenu().get_children(): subitem.connect('activate', self.__on_activate, item, *args) else: item.connect('activate', self.__on_activate, item, *args) except: errorhook() item.destroy() menu.append(SeparatorMenuItem()) prefs = Gtk.MenuItem(label=_("Configure Plugins…")) prefs.connect("activate", lambda _: PluginWindow().show()) menu.append(prefs) else: menu = None return menu
def _add_location(app, value): if os.path.isfile(value): ret = app.library.add_filename(value) if not ret: print_e("Couldn't add file to library") elif os.path.isdir(value): copool.add(app.library.scan, [value], cofuncid="library", funcid="library") else: print_e("Invalid location")
def Menu(self, library, songs): songs = ListWrapper(songs) attrs = ['plugin_song', 'plugin_songs', 'plugin_album', 'plugin_albums'] if len(songs) == 1: attrs.append('plugin_single_song') last = (songs and songs[-1]) or None for song in songs: if song.album_key != last.album_key: break last = song else: attrs.append('plugin_single_album') items = [] kinds = self.__plugins kinds.sort(key=lambda plugin: plugin.PLUGIN_ID) for Kind in kinds: usable = any(callable(getattr(Kind, s)) for s in attrs) if usable: try: items.append(Kind(songs, library)) except: print_e("Couldn't initialise song plugin %s. Stack trace:" % Kind) print_exc() items = [i for i in items if i.initialized] if items: menu = Gtk.Menu() for item in items: try: menu.append(item) args = (library, songs) if item.get_submenu(): for subitem in item.get_submenu().get_children(): subitem.connect( 'activate', self.__on_activate, item, *args) else: item.connect( 'activate', self.__on_activate, item, *args) except: print_exc() item.destroy() menu.append(SeparatorMenuItem()) prefs = Gtk.MenuItem(label=_("Configure Plugins…")) prefs.connect("activate", lambda _: PluginWindow().show()) menu.append(prefs) else: menu = None return menu
def _print_pipeline(self): """Print debug information for the active pipeline to stdout (elements, formats, ...) """ if self.bin: # self.bin is just a wrapper, so get the real one for line in bin_debug([self.bin.bin]): print_(line) else: print_e("No active pipeline.")
def handle_line(self, app, line): """Parses a command line and executes the command. Can not fail. """ # only one arg supported atm parts = line.split(" ", 1) command = parts[0] args = parts[1:] print_d("command: %s(*%r)" % (command, args)) try: return self.run(app, command, *args) except CommandError as e: print_e(str(e)) except: util.print_exc()
def get_config(): try: config_str = config.get("plugins", "equalizer_levels", "[]") config_dict = ast.literal_eval(config_str) if isinstance(config_dict, list): print_w("Converting old EQ config to new format.") config_dict = {"Current": config_dict} if not isinstance(config_dict, dict): raise ValueError("Saved config is of wrong type.") if not "Current" in config_dict.keys(): raise ValueError("Saved config was malformed.") # Run through the values to check everything is of correct type. for key in config_dict.keys(): [float(s) for s in config_dict[key]] return config_dict except (config.Error, ValueError) as e: print_e(str(e)) return {"Current": []}
def _update_album_if_fully_rated(self, album_key): album = app.library.albums.get(album_key, None) if album is None: return songs = album.songs # first check for ratings to avoid costly file checks if not songs or not all(song.has_rating for song in songs): return songs = [s for s in songs if s.supports_rating_and_play_count_in_file] if not songs: return email = config.get("editing", "save_email", const.EMAIL).strip() if all(s.has_rating_and_playcount_in_file(email) for s in songs): return # at least one song has no ratings or play counts stored in files try: self._update_album(songs) except Exception as e: print_e(e) self._error_msg(WRITE_ERROR_FMT % album_key)
def _failed_initialization(self): if not hasattr(self, "_dev"): print_e("Matrix Orbital LCD plugin not initialized correctly.") return True return False