Adding menus for albums and track selection

Now, we are going to create a file called menu_item.py in the musicterminal/client/ directory and we will start by importing some functions that we will need:

from uuid import uuid1

We only need to import the uuid1 function from the uuid module because, like the panels, we are going to create an id (GUID) for every menu item in the list.

Let's start by adding the class and the constructor:

class MenuItem:    def __init__(self, label, data, selected=False):        self.id = str(uuid1())        self.data = data        self.label = label        def return_id():            return self.data['id'], self.data['uri']        self.action = return_id        self.selected = selected

The MenuItem initializer gets three arguments, the label item, the data which will ...

Get Python Programming Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.