def output_handler(): scroller = Scroller() last_mouse_movement = datetime.datetime(1970, 1, 1) last_show_menu = False while True: try: global mouse_movement, launch_playlist, hotkey_map, menu_showing, last_menu_showing, playlists, playlists_index, syncing # ----------------------------------------- mpd_lock.acquire() playlist_entries = len(mpd.playlist()) current_song = copy.copy(mpd.currentsong()) status = mpd.status() mpd_lock.release() # ----------------------------------------- artist = '' album = '' pos = '' title = '' name = '' tfile = '' if 'artist' in current_song: artist = current_song['artist'] if 'album' in current_song: album = current_song['album'] if 'pos' in current_song: pos = current_song['pos'] if 'title' in current_song: title = current_song['title'] if 'name' in current_song: name = current_song['name'] if 'file' in current_song: tfile = current_song['file'] if len(current_song) > 0: if album == '' and artist == '': scroller.set_line(0, name, tfile) else: if artist != '': if album != '': scroller.set_line(0, artist + ': ' + album, tfile) else: scroller.set_line(0, artist, tfile) line2 = title if playlist_entries > 1 and pos != '': line2 = str(int(pos) + 1) + '. ' + line2 scroller.set_line(1, line2, tfile) else: scroller.clear() if 'state' in status: scroller.set_paused(status['state'] == 'pause') scroller.set_busy(syncing) elapsed = '' if 'elapsed' in status: elapsed = float(status['elapsed']) minutes = int(elapsed // 60) seconds = int(elapsed - minutes * 60) elapsed = "%d:%02d" % (minutes, seconds) scroller.set_elapsed(elapsed) #scroller.set_line(0, 'ABCD (E) FGHIJKLMNOPQRSTUVWXYZ') #scroller.set_line(1, '-> Eule findet den Beat') mouse_movement_lock.acquire() current_movement = copy.copy(mouse_movement) mouse_movement = [0, 0] mouse_movement_lock.release() menu_showing_lock.acquire() if current_movement[1] != 0: last_mouse_movement = datetime.datetime.now() else: if (menu_showing != None) and (menu_showing != last_menu_showing): last_mouse_movement = datetime.datetime.now() last_menu_showing = menu_showing menu_showing_lock.release() this_show_menu = ((datetime.datetime.now() - last_mouse_movement).seconds < 5) if last_show_menu == True and this_show_menu == False: menu_showing_lock.acquire() menu_showing = None menu_showing_lock.release() if last_show_menu == False and this_show_menu == True: mpd_lock.acquire() cycle_menu_showing() mpd_lock.release() current_movement = [0, 0] last_show_menu = this_show_menu launch_playlist_lock.acquire() this_launch_playlist = launch_playlist launch_playlist = False launch_playlist_lock.release() if this_show_menu: if current_movement[1] != 0: if current_movement[0] == 1: playlists_index = (playlists_index + len(playlists) + current_movement[1]) % len(playlists) elif current_movement[0] == 0: first_letter = playlists[playlists_index][0].lower() this_first_letter = first_letter # skip to another letter while first_letter == this_first_letter: playlists_index = (playlists_index + len(playlists) + current_movement[1]) % len(playlists) first_letter = playlists[playlists_index][0].lower() # skip to first entry with this letter while True: temp_playlists_index = (playlists_index + len(playlists) - 1) % len(playlists) test_letter = playlists[temp_playlists_index][0].lower() if test_letter != first_letter: break else: playlists_index = temp_playlists_index letters = ''.join([chr(x + 65) for x in range(26)]) + '?' letter_index = ord(playlists[playlists_index][0].lower()) - ord('a') if letter_index not in range(26): letter_index = 26 letters = letters[:letter_index] + ' [' + letters[letter_index] + '] ' + letters[(letter_index + 1):] letters = ' ~=] ' + letters + ' [=~' scroller.set_line(0, letters) line2 = playlists[playlists_index] menu_showing_lock.acquire() if menu_showing == 'artist': line2 = '[Artist] ' + line2 elif menu_showing == 'album': line2 = '[Album] ' + line2 elif menu_showing[0:13] == 'artist-album-': line2 = '[Album] ' + line2 menu_showing_lock.release() scroller.set_line(1, line2, line2) if this_launch_playlist: menu_showing_lock.acquire() previous_menu_showing = menu_showing menu_showing = None menu_showing_lock.release() mpd_lock.acquire() if previous_menu_showing == 'playlist': mpd.clear() mpd.load(playlists[playlists_index]) mpd.play() elif previous_menu_showing == 'artist': cycle_menu_showing('artist-album-' + playlists[playlists_index]) menu_showing_lock.acquire() last_menu_showing = None menu_showing_lock.release() elif previous_menu_showing == 'album': album = playlists[playlists_index] mpd.clear() mpd.findadd('album', album) mpd.play() elif previous_menu_showing[0:13] == 'artist-album-': artist = previous_menu_showing[13:] album = playlists[playlists_index] mpd.clear() if album == '(all titles)': mpd.findadd('artist', artist) else: mpd.findadd('artist', artist, 'album', album) mpd.play() mpd_lock.release() last_mouse_movement = datetime.datetime(1970, 1, 1) scroller.render() scroller.animate() #print(current_song) except: raise pass time.sleep(0.05)