Ejemplo n.º 1
0
    def __init__(self, root):
        # lists containing library and playlist names
        self.library = []
        self.playlists = []

        # currently selected listbox elements
        self.currLibrIndex = 0
        self.curPListIndex = 0

        # variable containing song finished check
        self.currPlayThread = None

        # user terminated boolean
        self.exitFlag = False

        # configure row/cols
        root.columnconfigure(1, weight=1)
        root.rowconfigure(1, weight=1)
        root.rowconfigure(2, weight=1)

        # instantiate GUI elements
        self.player = Commands()
        self.menuBar = Menu(root)

        self.queuePopup = Menu(root, tearoff=False)
        self.appendMenu = Menu(root, tearoff=False)
        self.mergeMenu = Menu(root, tearoff=False)
        self.queuePopup.add_cascade(label="append to playlist",
                                    menu=self.appendMenu)
        self.queuePopup.add_cascade(label="merge to playlist",
                                    menu=self.mergeMenu)

        self.popup = Menu(root, tearoff=False)
        self.playListMenu = Menu(root)
        self.popup.add_cascade(label="add to playlist", menu=self.playListMenu)
        self.popupFrame = Frame(root)

        self.playListBox = Listbox(root)
        self.libraryBox = Listbox(root)
        self.playListLabel = Label(root, text="Playlists")
        self.newPlaylist = Button(root, text="New playlist")
        self.libraryLabel = Label(root, text="Library")
        self.albArtCanvas = Canvas(root, height=150, width=150)
        self.queue = Listbox(root)
        self.photo = ImageTk.PhotoImage(file="defaultImage.png")
        self.songString = StringVar()
        self.songString.set("title\nartist\nalbum")
        self.songInfo = Label(root, textvariable=self.songString, justify=LEFT)
        self.currentImg = self.albArtCanvas.create_image(0,
                                                         0,
                                                         image=self.photo,
                                                         anchor=NW)
        self.musicControl = Frame(root)
        self.shuffle = Button(self.musicControl, text="Shuffle")
        self.playToggle = Button(self.musicControl,
                                 text="play/pause",
                                 command=self.playtrack)
        self.nextTrack = Button(self.musicControl,
                                text="next",
                                command=self.playNext)
        self.filemenu = Menu(self.menuBar, tearoff=0)

        # configure GUI element positions

        self.libraryLabel.grid(row=0, column=1, sticky=W)
        self.playListBox.grid(row=1, column=0, sticky=N + S, rowspan=4)
        self.libraryBox.grid(row=1, column=1, sticky=N + S + E + W, rowspan=5)
        self.playListLabel.grid(row=0, column=0, sticky=W)
        self.newPlaylist.grid(row=3, column=0, sticky=W)
        self.albArtCanvas.grid(row=0, column=2, sticky=N + E, rowspan=4)
        self.songInfo.grid(row=1, column=2, sticky=S + W, pady=(25, 0))
        self.shuffle.grid(row=0, column=0)
        self.playToggle.grid(row=0, column=1)
        self.nextTrack.grid(row=0, column=2)
        self.musicControl.grid(row=3, column=2, sticky=N + W + E)
        self.queue.grid(row=2, column=2, sticky=N + S + E + W)

        # Instanciate menu bar
        self.menuBar.add_cascade(label="File", menu=self.filemenu)
        self.filemenu.add_command(label="load library",
                                  command=self.getlibrary)
        self.filemenu.add_separator()
        self.filemenu.add_command(label="Exit", command=root.quit)

        # bind functions to GUI elements
        self.shuffle.bind("<Button-1>", self.shufflePlist)
        self.playListBox.bind("<Button-3>", self.showQueueMenu)
        self.popup.bind('<<MENU-SELECT>>', self.addToPlayList)
        self.mergeMenu.bind('<<MENU-SELECT>>', self.mergePlist)
        self.appendMenu.bind('<<MENU-SELECT>>', self.appendPlist)
        self.playListBox.bind('<Double-Button-1>', self.loadPlayList)
        self.libraryBox.bind("<Button-3>", self.showLibraryMenu)
        self.newPlaylist.bind("<Button-1>", self.createPlayList)

        #set windows properties
        root.resizable(width=FALSE, height=FALSE)
        root.geometry('{}x{}'.format(800, 500))
        root.config(menu=self.menuBar)
        root.protocol("WM_DELETE_WINDOW", self.setExitCondition())

        self.initSession()