#!/usr/bin/python #### AT END OF SONG INCREMENT currentsong import wx,os, glob, pygame, time [wxID_SKIPBUTTON,wxID_SELECTBUTTON, wxID_SONGLISTBOX,wxID_STOPBUTTON, wxID_EXITBUTTON, wxID_DOWNBUTTON,wxID_FRAME1, wxID_UPBUTTON, wxID_FRAME1BUTTON1, wxID_SELECTALLBUTTON, wxID_PLAYBUTTON, wxID_FRAME1BUTTON2, wxID_FRAME1LISTBOX1,wxID_PAUSE,] = [wx.NewId() for _init_ctrls in range(14)] myevent = 123 running = 1 pygame.display.init() pygame.mixer.music.set_endevent(pygame.constants.USEREVENT) pygame.event.set_allowed(pygame.constants.USEREVENT) def create(parent): return Frame1(parent) class Frame1(wx.Frame): def _init_ctrls(self,prnt): screensize = wx.DisplaySize() screensize = wx.Size(800,480) wx.Frame.__init__(self, id=wxID_FRAME1, name='My Music', parent=prnt,pos=wx.Point(358, 184), size=screensize, style=wx.DEFAULT_FRAME_STYLE, title=u'MyMusic') screen = wx.Bitmap("loading.jpg",wx.BITMAP_TYPE_JPEG) # mysplash = wx.SplashScreen(screen,wx.SPLASH_CENTER_ON_SCREEN | wx.SPLASH_TIMEOUT,1500,parent) #self.mysplasy.Show(true) wx.Yield() # self.SetClientSize(wx.Size(291, 347)) # self.SetBackgroundColour(wx.Colour(0, 128, 0)) font = wx.Font(18, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.BOLD) self.home_dir = os.path.expanduser("~") if (not os.path.exists(".mymusic")): os.makedirs(self.home_dir + "/.mymusic") f = open(self.home_dir + "/.mymusic/settings",'ar+') settings = f.readline() settingsa = [] if (settings == ""): f.write("None,PAUSED,\n") settingsa = ["None","PAUSED",""] else: settingsa = settings.split(",") f.close() self.SetFont(font) wx.StaticText(self, -1, "Folders", pos=(15,20)) self.pausedtext =wx.StaticText(self, -1, " ", pos=(700,20)) self.dirroot = '/music/' self.toplevel ='/music/' self.olddir = '/music/' self.currentsong = 0 self.paused = 0 if settingsa[1]=="PAUSED": self.pausedtext.SetLabel("PAUSED") self.paused = 1 print "starting paused" self.playing = 0 self.selName = settingsa[0] pygame.mixer.pre_init(44100, -16, 2, 4096) pygame.mixer.init() pygame.mixer.music.set_volume(1) self.songList = [] self.text1 = wx.StaticText(self, -1, "", pos=(3,480)) self.dirList = os.listdir('/music/') self.SelectAll(self.dirroot) found = 0 count = 0 for i in self.songList: if (i == os.path.normpath(self.selName)): found = 1 self.currentsong = count elif (not found): count += 1 # self.selectbutton = wx.ToggleButton(id=wxID_SELECTBUTTON, label=u'Select Mode', name='selectbutton', parent=self, pos=wx.Point(238, 20), style=0) self.upbutton = wx.Button(id=wxID_UPBUTTON, label=u'^', name='upbutton', parent=self, pos=wx.Point(108, 400), size=wx.Size(80, 80), style=0) self.stopbutton = wx.Button(id=wxID_STOPBUTTON, label=u'STOP', name='stopbutton', parent=self, pos=wx.Point(400, 320), size=wx.Size(80,80), style=0) self.skipbutton = wx.Button(id=wxID_SKIPBUTTON, label=u'SKIP', name='skipbutton', parent=self, pos=wx.Point(600, 320), size=wx.Size(80,80), style=0) self.downbutton = wx.Button(id=wxID_DOWNBUTTON, label=u'>', name='downbutton', parent=self, pos=wx.Point(208, 400), size=wx.Size(80, 80), style=0) self.selectall = wx.Button(id=wxID_SELECTALLBUTTON, label=u'Select All', name='selectall', parent=self, pos=wx.Point(8, 400), size=wx.Size(90,80), style=0) self.exit = wx.Button(id=wxID_EXITBUTTON, label=u'EXIT', name='exit', parent=self, pos=wx.Point(700, 400), size=wx.Size(80,80), style=0) self.pause = wx.Button(id=wxID_PAUSE, label=u'PAUSE', name='pause', parent=self, pos=wx.Point(700,320), size=wx.Size(80,80), style=0) self.playbutton = wx.Button(id=wxID_PLAYBUTTON, label=u'Play', name='play', parent=self, pos=wx.Point(500, 320), size=wx.Size(80,80), style=0) self.listBox1 = wx.ListBox(choices=[], id=wxID_FRAME1LISTBOX1, name='listBox1', parent=self, pos=wx.Point(8, 48), size=wx.Size(300, 320), style=0) self.songlistbox = wx.ListBox(choices=[], id=wxID_SONGLISTBOX, name='songlistbox', parent=self, pos=wx.Point(400, 48), size=wx.Size(384, 256), style=0) self.listBox1.SetBackgroundColour(wx.Colour(255, 255, 128)) self.selectall.Bind(wx.EVT_BUTTON, self.OnButton, id=wxID_SELECTALLBUTTON) # self.selectbutton.Bind(wx.EVT_BUTTON, self.OnButton, id=wxID_SELECTBUTTON) self.exit.Bind(wx.EVT_BUTTON, self.Exit, id=wxID_EXITBUTTON) self.pause.Bind(wx.EVT_BUTTON, self.OnButton, id=wxID_PAUSE) self.stopbutton.Bind(wx.EVT_BUTTON, self.OnButton, id=wxID_STOPBUTTON) self.skipbutton.Bind(wx.EVT_BUTTON, self.OnButton, id=wxID_SKIPBUTTON) self.downbutton.Bind(wx.EVT_BUTTON, self.OnButton, id=wxID_DOWNBUTTON) self.playbutton.Bind(wx.EVT_BUTTON, self.OnButton,id=wxID_PLAYBUTTON) self.upbutton.Bind(wx.EVT_BUTTON, self.OnButton,id=wxID_UPBUTTON) self.listBox1.Bind(wx.EVT_LISTBOX, self.OnListBox1Listbox,id=wxID_FRAME1LISTBOX1) self.songlistbox.Bind(wx.EVT_LISTBOX, self.OnSongListbox,id=wxID_SONGLISTBOX) def OnSongListbox(self,event): self.selName = self.songlistbox.GetStringSelection() if (self.songList == []): self.songList.append(os.path.normpath(self.dirroot + "/" + self.selName)) self.currentsong = 0 return if self.playing: count = -1 else: count = 0 found = 0 for i in self.songList: if (i == os.path.normpath(self.dirroot + "/" + self.selName)): found = 1 self.currentsong = count elif (not found): count += 1 if self.currentsong <0: self.currentsong = 0 if (not found): self.songList.append(os.path.normpath(self.dirroot + "/" + self.selName)) # self.currentsong = len(self.songList) self.currentsong = 0 def Exit(self,event): pygame.mixer.music.stop() pygame.mixer.quit() os._exit(0) def OnButton(self,event): if (event.GetId() == wxID_STOPBUTTON): self.playing = 0 pygame.mixer.music.stop() self.currentsong +=1 return if (event.GetId() == wxID_PAUSE): if self.paused: pygame.mixer.music.unpause() self.paused = 0 f = open(self.home_dir + "/.mymusic/settings",'w') f.write(self.songList[self.currentsong]+",PLAYING,\n") f.close() self.pausedtext.SetLabel(" ") else: self.pausedtext.SetLabel("PAUSED") f = open(self.home_dir + "/.mymusic/settings",'w') f.write(self.songList[self.currentsong]+",PAUSED,\n") f.close() pygame.mixer.music.pause() self.paused = 1 if (event.GetId() == wxID_SKIPBUTTON): print "skipping" #self.currentsong +=1 if self.currentsong > len(self.songList) -1: self.currentsong = 0 pygame.mixer.music.stop() return if (event.GetId() == wxID_DOWNBUTTON): self.selName = self.listBox1.GetStringSelection() if (not self.selName): return self.olddir= self.dirroot self.dirroot = self.dirroot + "/" + self.selName self.get_dir(self.dirroot) return if (event.GetId() == wxID_PLAYBUTTON): if (not self.songList == []): self.Play() return if (event.GetId() == wxID_UPBUTTON): if (self.toplevel == self.dirroot): return self.dirroot = os.path.normpath(os.path.dirname(self.dirroot + "/../..")) self.dirroot = self.dirroot + "/" self.get_dir(self.dirroot) return if (event.GetId() == wxID_SELECTALLBUTTON): #self.SelectAll(self.dirroot) return return def Play(self): if self.paused == 1: print "paused so stop" return if (self.songList == []): print "nothing to play" return pygame.mixer.music.stop() if self.playing == 1: return self.playing = 1 while self.playing: data = (self.songList[self.currentsong]) self.SetTitle(os.path.basename(self.songList[self.currentsong])) song = self.songList[self.currentsong] font1 = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Comic Sans MS') print "Playing", data self.text1.SetLabel(data) pygame.mixer.music.load(song) pygame.mixer.music.play() print "Next song", self.songList[self.currentsong+1] self.playsongs() print "Done playing",self.songList[self.currentsong] self.currentsong +=1 if (self.currentsong > len(self.songList) -1 ): self.currentsong = 0 f = open(self.home_dir + "/.mymusic/settings",'w') f.write(self.songList[self.currentsong]+",PLAYING,\n") f.close() def playsongs(self): while (pygame.mixer.music.get_busy()): wx.Yield() pass return def OnListBox1Listbox(self, event): #set or reset selection return def SelectOnlyFiles(self,direct): mydir = os.listdir(direct) for infile in mydir: if (not os.path.isdir(direct + "/"+ infile)): self.songList.append(os.path.normpath(direct + "/" + infile)) return def SelectAll(self,direct): mydir = os.listdir(direct) for infile in mydir: if (os.path.isdir(direct + "/"+ infile)): self.SelectAll(direct + "/" + infile) else: self.songList.append(os.path.normpath(direct + "/" + infile)) return def get_dir(self,direct): self.listBox1.Clear() self.songlistbox.Clear() mydir = os.listdir(direct) for infile in mydir: if (os.path.isdir(self.dirroot + "/"+ infile)): self.listBox1.Append(infile) else: self.songlistbox.Append(infile) # self.songList.append(os.path.normpath(direct + "/" + infile)) return def __init__(self,parent): self._init_ctrls(parent) print "loading music" self.get_dir(self.dirroot) print "music loaded" if __name__ == '__main__': app = wx.PySimpleApp() wx.InitAllImageHandlers() frame = create(None) frame.Show() frame.Play() app.MainLoop()