From: pin Date: Fri, 19 Mar 2010 11:43:00 +0000 (+0000) Subject: refactoring de la boîte de dialogue de sélection de la chanson (début). X-Git-Url: https://svn.cri.ensmp.fr/git/minwii.git/commitdiff_plain/8107325baba9dacf2d7721192c981714a262dc09 refactoring de la boîte de dialogue de sélection de la chanson (début). git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@96 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/app/config.py b/src/app/config.py index cbd44fb..34a5f7f 100755 --- a/src/app/config.py +++ b/src/app/config.py @@ -7,8 +7,10 @@ $URL$ """ import pygame +import os.path pygame.font.init() + # playingscreen FRAMERATE = 50 BORDER = 0 # 5px @@ -23,3 +25,13 @@ ON_COLUMN_ALPHA = 1 FONT = pygame.font.Font(None, 80) FONT_COLOR = (0,0,0) DEFAULT_MIDI_VELOCITY = 96 + +SONG_FILE_PATH = '../../chansons' + +# cuisine : ne pas modifier +_here = os.path.abspath(__file__).split(os.path.sep)[:-1] +SONG_FILE_PATH = SONG_FILE_PATH.split('/') +SONG_FILE_PATH = _here + SONG_FILE_PATH +SONG_FILE_PATH = os.path.abspath(os.path.sep.join(SONG_FILE_PATH)) + + diff --git a/src/app/minwii.py b/src/app/minwii.py index fe95f7e..b52657d 100755 --- a/src/app/minwii.py +++ b/src/app/minwii.py @@ -13,6 +13,7 @@ from widgets.playingscreen import SongPlayingScreen, PlayingScreen from synth import Synth from eventutils import EventDispatcher from musicxml import musicXml2Song +from config import SONG_FILE_PATH class MinWii(object): @@ -22,10 +23,10 @@ class MinWii(object): synth.program_select(0, 0, 0) if True : - #home = Home() - #home.connect(QUIT, app.quit) - #app.run(home) - #app.close(home) + home = Home(songPath=SONG_FILE_PATH) + home.connect(QUIT, app.quit) + app.run(home) + app.close(home) song = musicXml2Song('/Users/pinbe/dev/minwii/src/songs/chansons/etoile_neige.xml', printNotes=True) playingScreen = SongPlayingScreen(synth, song) diff --git a/src/app/widgets/home.py b/src/app/widgets/home.py index af0c0ee..391cb29 100755 --- a/src/app/widgets/home.py +++ b/src/app/widgets/home.py @@ -15,6 +15,7 @@ from pgu.gui import CLICK from pgu.gui import QUIT import pygame from gui.constants import reversedReadabilityDict, modeDict +from songfilebrowser import FileOpenDialog class Home(Table) : """ @@ -23,6 +24,7 @@ class Home(Table) : def __init__(self,**params): Table.__init__(self,**params) + self.songPath = params.get('songPath', '.') self.spaceSize = (100,100) self.font = pygame.font.Font(None,70) self._fill() @@ -82,6 +84,7 @@ class Home(Table) : self.td(Spacer(500,500)) def _initLocalListeners(self) : + self.browseButton.connect(CLICK, self.open_file_browser) self.quitButton.connect(CLICK, self._exitHome) def _exitHome(self, data=None) : @@ -93,6 +96,12 @@ class Home(Table) : w,h = self.font.size(text) label = Label(text,width=w,height=h,font = font) return(label) - + + def open_file_browser(self): + dlg = FileOpenDialog(self.songPath) + #d = MINWiiDialog(font = self.font,width = 800, height = 600,path = "../songs/smwis") + #d.connect(pguGui.CHANGE, self.handle_file_browser_closed, d) + dlg.open() + \ No newline at end of file diff --git a/src/app/widgets/songfilebrowser.py b/src/app/widgets/songfilebrowser.py new file mode 100755 index 0000000..b3acce8 --- /dev/null +++ b/src/app/widgets/songfilebrowser.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +""" +Boîte de dialogue pour sélection des chansons. + +$Id$ +$URL$ +""" + +from pgu.gui import FileDialog +import os + +class FileOpenDialog(FileDialog): + + + + def __init__(self, path): + FileDialog.__init__(self, + title_txt="Ouvrir une chanson", + button_txt="Ouvrir", + #cls="dialog", + #folderText = "Folder", + #fileText = "File", + path=path, + #customFont = None, + showCurDir = False + #customWidth = 350, + #customHeight = 150 + ) + + def _list_dir_(self): + self.input_dir.value = self.curdir + self.input_dir.pos = len(self.curdir) + self.input_dir.vpos = 0 + dirs = [] + files = [] + try: + for i in os.listdir(self.curdir): + if os.path.isdir(os.path.join(self.curdir, i)): dirs.append(i) + else: files.append(i) + except: + self.input_file.value = "Opps! no access" + #if '..' not in dirs: dirs.append('..') + dirs.sort() + dirs = ['..'] + dirs + + files.sort() + for i in dirs: + if i.startswith('.') and i != '..' : + continue + #item = ListItem(image=self.dir_img, text=i, value=i) + if self.customFont == None : + self.list.add(i,image=self.dir_img,value=i) + else : + label = basic.Label(i,font = self.customFont) + self.list.add(label,image=self.dir_img,value=i) + for i in files: + #item = ListItem(image=None, text=i, value=i) + if i.startswith('.') or (not i.endswith('.xml')) : + continue + if self.customFont == None : + self.list.add(i,value=i) + else: + label = basic.Label(i,font = self.customFont) + self.list.add(label,value=i) + #self.list.resize() + self.list.set_vertical_scroll(0) + #self.list.repaintall() +