Documentation pi-jukebox code

screen_player.py: Playback screen.

class screen_player.Playlist(screen_rect)

Displays playlist information.

Parameters:screen_rect – The display’s rect where the library browser is drawn on.
show_playlist()

Display the playlist.

class screen_player.ScreenPlaying(screen_rect)

Screen cover art

Parameters:screen_rect – The display’s rectangle where the screen is drawn on.
show()

Displays the screen.

class screen_player.ScreenPlaylist(screen_rect)

The screen containing everything to control playback.

on_click(x, y)
Parameters:
  • x – The horizontal click position.
  • y – The vertical click position.
Returns:

Possibly returns a screen index number to switch to.

show()

Displays the screen.

class screen_player.ScreenVolume(screen_rect)

Screen setting volume

Parameters:screen_rect – The display’s rectangle where the screen is drawn on.

screen_library.py: MPD Library browsing screen

class screen_library.LetterBrowser(screen_rect)

The graphical control for selecting artists/albums/songs starting with a letter.

Parameters:screen_rect – The screen rect where the library browser is drawn on.
class screen_library.LibraryBrowser(screen_rect)

The component that displays mpd library entries.

Parameters:screen_rect – The screen rect where the library browser is drawn on.
first_letters_in_result_get()

Get’s the symbols that are first letters of the items in the result list.

Returns:List of letters
show_albums(search=None, only_start=True)

Displays all albums or based on the first letter or partial string match.

Parameters:
  • search – Search string, default = None
  • only_start – Boolean indicating whether the search string only matches the first letters, default = True
show_artists(search=None, only_start=True)

Displays all artists or based on the first letter or partial string match.

Parameters:
  • search – Search string, default = None
  • only_start – Boolean indicating whether the search string only matches the first letters, default = True
show_playlists(first_letter=None)

Displays all playlists or based on the first letter.

Parameters:first_letter – Search string, default = None
show_songs(search=None, only_start=True)

Displays all songs or based on the first letter or partial string match.

Parameters:
  • search – Search string, default = None
  • only_start – Boolean indicating whether the search string only matches the first letters, default = True
class screen_library.ScreenLibrary(screen_rect)

The screen where the user can browse in the MPD database and playlist_add items to playlists.

Parameters:screen_rect – The display’s rect where the library browser is drawn on.
find_first_letter()

Adjust current search type according to the letter clicked in the letter list.

find_text()

Find results according to part of the text. Launching a keyboard so that the user can specify the search string.

on_click(x, y)

Handles click event.

playlist_action()

Displays screen for follow-up actions when an item was selected from the library.

set_currently_showing(type_showing)

Switch icons to active dependent on which kind of searching is active.

Parameters:type_showing – The type of search results showing [artists, albums, songs, playlists].
class screen_library.ScreenSearch(screen_rect)

Screen used further searching based on an item selected from the library

Parameters:

screen_rect – The display’s rect where the library browser is drawn on.

Variables:
  • search_type – Searching for... [artist, album, song].
  • search_text – Partial text which should be searched for
action(tag_name)

Action that should be performed on a click.

Parameters:tag_name – The identifying tag_name of the clicked widget.
initialize()

Set-up screen controls.

class screen_library.ScreenSelected(screen_rect, selected_type, selected_title)

Screen for selecting playback actions with an item selected from the library.

Parameters:
  • screen_rect – The display’s rect where the library browser is drawn on.
  • selected_type – The selected library item [artists, albums, songs].
  • selected_title – The title of the selected library item.
action(tag_name)

Action that should be performed on a click.

initialize()

Set-up screen controls.

screen_settings.py: Settings screen

class screen_settings.ScreenSettings(screen_rect)

Screen for settings or quitting/shutting down

Parameters:screen_rect – The display’s rectangle where the screen is drawn on.
class screen_settings.ScreenSettingsMPD(screen_rect)

Screen for settings playback options

Parameters:screen_rect – The display’s rectangle where the screen is drawn on.
class screen_settings.ScreenSettingsPlayback(screen_rect)

Screen for settings playback options

Parameters:screen_rect – The display’s rectangle where the screen is drawn on.
class screen_settings.ScreenSettingsQuit(screen_rect)

Screen for quitting pi-jukebox.

Parameters:screen_rect – The display’s rectangle where the screen is drawn on.
class screen_settings.ScreenSystemInfo(screen_rect)

Screen for settings playback options

Parameters:screen_rect – The display’s rectangle where the screen is drawn on.

mpd_client.py: controlling and monitoring mpd via python-mpd2.

class mpd_client.MPDController

Controls playback and volume

album_songs_get(album_name)

Retrieves all song titles of an album.

Parameters:album_name – The name of the album
Returns:A list of song titles
albums_get(part=None, only_start=True)

Retrieves all album titles or matching by first letter(s) or partial search string.

Parameters:
  • part – Search string.
  • only_start – Only search as first letter(s).
Returns:

A list of matching album titles.

artist_albums_get(artist_name)

Retrieves artist’s albums.

Parameters:artist_name – The name of the artist to retrieve the albums of.
Returns:A list of album titles.
artist_songs_get(artist_name)

Retrieves artist’s songs.

Parameters:artist_name – The name of the artist to retrieve the songs of.
Returns:A list of song titles
artists_get(part=None, only_start=True)

Retrieves all artist names or matching by first letter(s) or partial search string.

Parameters:
  • part – Search string
  • only_start – Only search as first letter(s).
Returns:

A list of matching artist names.

connect()

Connects to mpd server.

Returns:Boolean indicating if successfully connected to mpd server.
consume_switch()

Switches playlist consuming on or off.

directory_list(path='', first_letter=None)

Retrieves the contents of a directory :param path: Subpath :param first_letter: Retrieve all directories starting with letter

directory_songs_get(path='')

Gets all files in the directory and from the directories below :param path: Directory which is searched recursively for files :return: list with files

disconnect()

Closes the connection to the mpd server.

library_rescan()

Rebuild library.

library_update()

Updates the mpd library

play_playlist_item(index)

Starts playing in playlist on item.

Parameters:index – Playlist item index
player_control_get()
Returns:Current playback mode.
player_control_set(play_status)

Controls playback

Parameters:play_status – Playback action [‘play’, ‘pause’, ‘stop’, ‘next’, ‘previous’].
playlist_add(tag_type, tag_name, play=False, clear_playlist=False)

Adds songs to the current playlist

Parameters:
  • tag_type – Kind of add you want to do [“artist”, “album”, song”title”].
  • tag_name – The name of the tag_type.
  • play – Boolean indicating whether you want to start playing what was just added.
  • clear_playlist – Boolean indicating whether to remove all previous entries from the current playlist.
playlist_add_album(album_name, play=False, clear_playlist=False)

Adds all album’s songs to the current playlist

Parameters:
  • album_name – The album name
  • play – Boolean indicating whether you want to start playing what was just added.
  • clear_playlist – Boolean indicating whether to remove all previous entries from the current playlist.
playlist_add_artist(artist_name, play=False, clear_playlist=False)

Adds all artist’s songs to the current playlist

Parameters:
  • artist_name – The name of the artist.
  • play – Boolean indicating whether you want to start playing what was just added.
  • clear_playlist – Boolean indicating whether to remove all previous entries from the current playlist.
playlist_add_directory(path, play=False, clear_playlist=False)

Adds all songs from the directory recursively to the playlist :param path: Directory :param play: Boolean indicating whether you want to start playing what was just added. :param clear_playlist: Boolean indicating whether to remove all previous entries from the current playlist.

playlist_add_file(uri, play=False, clear_playlist=False)

Adds file to the playlist :param uri: The file including path :param play: Boolean indicating whether you want to start playing what was just added. :param clear_playlist: Boolean indicating whether to remove all previous entries from the current playlist.

playlist_add_playlist(playlist_name, play=False, clear_playlist=False)

Adds a playlist to the current playlist

Parameters:
  • playlist_name – The playlist’s name
  • play – Boolean indicating whether you want to start playing what was just added.
  • clear_playlist – Boolean indicating whether to remove all previous entries from the current playlist.
playlist_add_song(song_name, play=False, clear_playlist=False)

Adds a song to the current playlist

Parameters:
  • song_name – The song’s name
  • play – Boolean indicating whether you want to start playing what was just added.
  • clear_playlist – Boolean indicating whether to remove all previous entries from the current playlist.
playlist_current_clear()

Removes everything from the current playlist

playlist_current_count()
Returns:The number of items in the current playlist
playlist_current_playing_index_get()
Returns:The track number playing on the current playlist.
playlist_current_playing_index_set(index)

Starts playing item _index_ of the current playlist.

Parameters:index – The track number to be played
Returns:The current playing index
playlists_get(first_letter=None)

Retrieves all playlists or those matching the first letter

Parameters:first_letter – Letter
Returns:A list of playlist names
random_switch()

Switches random playing on or off.

repeat_switch()

Switches repeat playing on or off.

songs_get(part=None, only_start=True)

Retrieves all song titles or matching by first letter(s) or partial search string

Parameters:
  • part – Search string
  • only_start – Only search as first letter(s)
Returns:

A list of matching song titles

status_get()

Updates mpc data, returns True when status data is updated. Wait at least ‘update_interval’ milliseconds before updating mpc status data.

Returns:Returns boolean whether updated or not.
volume_mute_switch()

Switches volume muting on or off.

volume_set(percentage)

Sets volume in absolute percentage.

Parameters:percentage – Percentage at which volume should be set.
volume_set_relative(percentage)

Sets volume relatively to current volume.

Parameters:percentage – Percentage point volume increase.
class mpd_client.MPDNowPlaying

Song information

interface_widgets.py: graphical widgets for the GUI

class gui_widgets.ButtonIcon(tag_name, screen_rect, image, x, y)

ButtonIcon class is a button that only displays an icon.

Parameters:
  • tag_name – Text identifying the widget,
  • screen_rect – The screen’s rectangle where the button should be drawn,
  • x – The horizontal position of the button,
  • y – The vertical position of the button,
Variables:
  • caption – The button’s caption,
  • image_file – The button’s icon image file name,
draw(icon_file=None)

Draws the button

set_image_file(file_name)

Sets the buttons icon.

Parameters:file_name – Points to the icon’s file name.
class gui_widgets.ButtonText(tag_name, screen_rect, x, y, width, height, text='')

ButtonText class is a button with text that uses two images for button rendering.

Parameters:
  • tag_name – Text identifying the widget,
  • screen_rect – The screen’s rectangle where the button should be drawn,
  • x – The horizontal position of the button,
  • y – The vertical position of the button,
  • width – The label’s rectangle width,
  • text – default “”, The label’s caption,
Variables:
  • transparent – Whether the label’s background is transparent, default = False,
  • font_color – The text font color,
  • alignment_horizontal – The button’s text horizontal alignment, default = :py:const:HOR_MID.
  • alignment_vertical – The button’s text vertical alignment, default = :py:const:VERT_MID,
class gui_widgets.ItemList(tag_name, screen_rect, x, y, width, height)

List of text items that can be clicked.

Parameters:
  • tag_name – Text identifying the list.
  • screen_rect – The screen’s rectangle where the list is drawn on.
  • x – The horizontal starting position of the list’s rectangle.
  • y – The vertical starting position of the list’s rectangle.
  • width – The width of the list’s rectangle.
  • height – The height of the list’s rectangle.
Variables:
  • list – List containing items for ItemList.
  • outline_visible – Indicates whether the outline of the list is visible, default = True.
  • item_height – The height of one list item, default = 25.
  • item_indent – The indent for the text of a list item, default = 2.
  • item_alignment_horizontal – Horizontal alignment of an item’s text, default = :py:const:HOR_LEFT.
  • item_alignment_vertical – Vertical alignment of an item’s text, default = :py:const:VERT_MID.
  • item_outline_visible – Boolean for displaying the rectangle of an item, default = False.
  • active_item_index – The index of the currently active list item. It differs from selected in that it is set by the program and not by the user, default = -1.
  • item_active_color – The active list item for color, default = :py:const:BLUE.
  • item_active_background_color – The active list item background color, default = :py:const:WHITE.
  • item_selected_index – The index of the selected list item, default = -1.
  • item_selected_color – The font color of a selected item, default = :py:const:BLUE.
  • item_selected_background_color – The selected list item background color, default = :py:const:WHITE.
clicked_item(x_pos, y_pos)

Determines which item, if any, was clicked.

Parameters:
  • x_pos – The click’s horizontal position
  • y_pos – The click’s vertical position
Returns:

The index of the selected list item

draw()

Draws the item list on screen.

draw_items()

Draws the list items.

draw_page_indicator()

Draws a ‘progress’ indicator on the list.

item_active_get()
Returns:active item text
item_selected_get()
Returns:selected item’s text
on_click(x_pos, y_pos)

Relays click action to a list item. :param x_pos: The horizontal click position. :param y_pos: The vertical click position.

Returns:return the ListItem’s tag_name.
pages_count()
Returns:The number of pages filled with list items.
set_item_alignment(horizontal, vertical)

Sets the alignment of the text of an item within the item’s rectangle.

show_next_items()

Shows next page of items.

show_prev_items()

Shows previous page of items.

class gui_widgets.LabelText(tag_name, screen_rect, x, y, width, height, text='')

LabelText is used to write text that needs to fit in a pre-defined rectangle.

Parameters:
  • tag_name – Text identifying the label.
  • screen_rect – The screen’s rectangle where the label is drawn on.
  • x – The horizontal starting position of the label’s rectangle.
  • y – The vertical starting position of the label’s rectangle.
  • width – The width of the label’s rectangle.
  • height – The height of the label’s rectangle.
  • text – The text to be displayed in the label, default= “”
draw()

Draws the label.

Parameters:text – default = “”, set’s the label’s text,
Returns:Text that couldn’t be fitted inside the label’s rectangle,
set_alignment(horizontal, vertical, hor_indent=0, vert_indent=0)

Sets the label’s horizontal and vertical alignment within the defined rectangle and/or the text horizontal/vertical indent.

Parameters:horizontal – Horizontal alignment [
transparent_set(value)

Turns background transparent or opaque.

class gui_widgets.Memo(tag_name, screen_rect, x, y, width, height, text='')

LabelText is used to write text that needs to fit in a pre-defined rectangle.

Parameters:
  • tag_name – Text identifying the memo field.
  • screen_rect – The screen’s rectangle where the memo field is drawn on.
  • x – The horizontal starting position of the memo field’s rectangle.
  • y – The vertical starting position of the memo field’s rectangle.
  • width – The width of the memo field’s rectangle.
  • height – The height of the memo field’s rectangle.
  • text – The text to be displayed in the memo, default= “”
set_alignment(horizontal, hor_indent=0)

Sets the horizontal alignment of the lines.

transparent_set(value)

Turns background transparent or opaque.

class gui_widgets.Picture(tag_name, screen_rect, x, y, width, height, image_file='')

Picture on screen

Parameters:
  • tag_name – Text identifying the picture.
  • screen_rect – The screen’s rectangle where the picture is drawn on.
  • x – The horizontal starting position of the picture’s rectangle.
  • y – The vertical starting position of the picture’s rectangle.
  • width – The width of the picture’s rectangle.
  • height – The height of the picture’s rectangle.
picture_set(file_name)

Sets the filename of the picture.

class gui_widgets.Rectangle(tag_name, screen_rect, x, y, width, height)

Drawing a rectangle on screen

Parameters:
  • tag_name – Text identifying the rectangle.
  • screen_rect – The screen’s rectangle where the rectangle is drawn on.
  • x – The horizontal starting position of the rectangle’s rectangle.
  • y – The vertical starting position of the rectangle’s rectangle.
  • width – The width of the rectangle’s rectangle.
  • height – The height of the rectangle’s rectangle.
draw()

Draws the label.

class gui_widgets.Slider(tag_name, screen_rect, x, y, width, height)

A slider control

Parameters:
  • tag_name – Text identifying the slider.
  • screen_rect – The screen’s rectangle where the slider is drawn on.
  • x – The horizontal starting position of the slider’s rectangle.
  • y – The vertical starting position of the slider’s rectangle.
  • width – The width of the slider’s rectangle.
  • height – The height of the slider’s rectangle.
on_click(x, y)

Sets the percentage of the slide by clicking.

progress_percentage_set(percentage)

Sets the slider’s percentage ‘full’.

Parameters:percentage – No need to explain. Right?
class gui_widgets.Slider2(tag_name, screen_rect, x, y, width, height)

A slider control with a different lay-out.

Parameters:
  • tag_name – Text identifying the slider.
  • screen_rect – The screen’s rectangle where the slider is drawn on.
  • x – The horizontal starting position of the slider’s rectangle.
  • y – The vertical starting position of the slider’s rectangle.
  • width – The width of the slider’s rectangle.
  • height – The height of the slider’s rectangle.
on_click(x, y)

Sets the percentage of the slide by clicking.

progress_percentage_set(percentage)

Sets the slider’s percentage ‘full’.

Parameters:percentage – No need to explain. Right?
class gui_widgets.Switch(tag_name, screen_rect, x, y)

An on/off control for settings

Parameters:
  • tag_name – Text identifying the widget,
  • screen_rect – The screen’s rectangle where the button should be drawn,
  • x – The horizontal position of the button,
  • y – The vertical position of the button,
get_on()

Retrieved the on status of the control.

Returns:Boolean indicating whether control has ‘on’ status
set_on(boolean)

Turns the control status to on or off.

Parameters:boolean – Boolean determining whether the control is in the ‘on’ state.
class gui_widgets.Widget(tag_name, screen_rect, x, y, width, height)

Widget is the base class of screen widgets and should not be instantiated by itself.

Parameters:
  • tag_name – Text identifying the widget.
  • screen_rect – The screen’s rectangle where the widget is drawn on.
  • x – The horizontal starting position of the widget’s rectangle.
  • y – The vertical starting position of the widget’s rectangle.
  • width – The width of the widget’s rectangle.
  • height – The height of the widget’s rectangle.
on_click(x, y)

The function called when a widget is clicked

class gui_widgets.WidgetContainer(tag_name, screen_rect, x, y, width, height)

Basic screen used for displaying widgets. This type of screen should be used for the entire program.

Parameters:

screen_rect – The screen’s rectangle where the screen is drawn on

Variables:
  • components – Dictionary holding the screen’s widgets with a tag_name as key and the widget as value
  • color – The screen’s background color, default = :py:const:BLACK
add_component(widget)

Adds components to component list, thus ensuring a component is found on a mouse event.

Parameters:widget – The widget that should be added to the dictionary.
draw()

Displays the screen.

on_click(x, y)

Determines which component was clicked and fires it’s click function in turn.

Parameters:
  • x – The horizontal click position.
  • y – The vertical click position.
Returns:

The tag_name of the clicked component.

on_swipe(x, y, swipe_type)

Relays swipe to ItemList components for next(up)/previous(down) swipes for ItemLists.

Parameters:
  • x – The horizontal start position of the swipe move.
  • y – The vertical start position of the swipe move.
  • swipe_type – The type of swipe movement done.

gui_screens.py: Building blocks for creating screens and dialogues

class gui_screens.GestureDetector

Class for detecint mouse gestures

capture_gesture(event)

Mouse event loop, runs from mouse down to mouse up event.

Parameters:event – pygame event.
class gui_screens.Screen(screen_rect)

Basic screen used for displaying widgets. This type of screen should be used for the entire program.

Parameters:

screen_rect – The screen’s rectangle where the screen is drawn on

Variables:
  • components – Dictionary holding the screen’s widgets with a tag_name as key and the widget as value
  • color – The screen’s background color, default = :py:const:BLACK
add_component(widget)

Adds components to component list, thus ensuring a component is found on a mouse event.

Parameters:widget – The widget that should be added to the dictionary.
on_click(x, y)

Determines which component was clicked and fires it’s click function in turn.

Parameters:
  • x – The horizontal click position.
  • y – The vertical click position.
Returns:

The tag_name of the clicked component.

on_swipe(x, y, swipe_type)

Relays swipe to ItemList components for next(up)/previous(down) swipes for ItemLists.

Parameters:
  • x – The horizontal start position of the swipe move.
  • y – The vertical start position of the swipe move.
  • swipe_type – The type of swipe movement done.
show()

Displays the screen.

class gui_screens.ScreenMessage(screen_rect, caption, text, message_type=None)

A screen that displays a message.

Parameters:
  • screen_rect – The display’s rectangle where the screen is drawn on.
  • caption – The title displayed at the top of the screen.
  • text – Text displayed in the screen.
  • message_type – Determines the lay-out of the screen [information, warning, error]
class gui_screens.ScreenModal(screen_rect, title)

Screen with its own event capture loop.

Parameters:
  • screen_rect – The display’s rectangle where the screen is drawn on.
  • title – The title displayed at the top of the screen.
Variables:

title – The title displayed at the top of the screen.

action(tag_name)

Virtual function for event-related execution.

close()

Closes event loop.

Returns:Window’s return object.
event_loop()

The window’s event loop

event_loop_hook()

Virtual function where you can add functions you want to execute during the event loop

show()

Displays screen and starts own event capture loop.

Returns:A return object.
class gui_screens.ScreenYesNo(screen_rect, caption, text)

A screen that displays a message.

Parameters:
  • screen_rect – The display’s rectangle where the screen is drawn on.
  • caption – The title displayed at the top of the screen.
  • text – Text displayed in the screen.
class gui_screens.Screens

Manages screens of type Screen. Handles screen switching, clicking and swiping and mpd status updating.

Variables:
  • screen_list – List containing all screen objects.
  • current_index – Points to current screen in screen_list.
  • mouse_down_pos – Mouse position on mouse down.
add_screen(screen)

Adds screen to list

process_mouse_event(event)

Processes mouse events.

show()

Show the current screen

screen_keyboard.py: On-screen keyboard

class screen_keyboard.Keyboard(screen_rect, caption, text='')

Called keyboard class that displays a text edit field with a letter or symbol keyboard.

Parameters:
  • screen_rect – The display’s rectangle where the keyboard is drawn on.
  • caption – The title displayed at the top of the screen.
  • text – The text that will be edited with the keyboard, default = “”.
show()

Loops until enter, cancel or escape on the keyboard is pressed.

Returns:The text as it was edited when return was pressed, or the original text in case of a cancellation.
class screen_keyboard.KeyboardBase(screen_rect, caption, text='')

The base class of a keyboard, should not be instantiated.

Parameters:
  • screen_rect – The display’s rectangle where the keyboard is drawn on.
  • caption – The title displayed at the top of the screen.
  • text – The text that will be edited with the keyboard, default = “”.
add_row_buttons(list_symbols, x, y)

Adds a list of symbol keys starting at x on y.

set_text(text)

Sets the edit box’s text.

Parameters:text – Text that needs to be edited using the keyboard
class screen_keyboard.KeyboardLetters(screen_rect, caption, text='')

Displays keyboard for letters.

class screen_keyboard.KeyboardSymbols(screen_rect, caption, text='')

Displays keyboard for numbers and symbols.