diff options
author | James <olpc@localhost.localdomain> | 2007-02-19 06:46:42 (GMT) |
---|---|---|
committer | James <olpc@localhost.localdomain> | 2007-02-19 06:46:42 (GMT) |
commit | 84f92212bc0caab6323a7ded4f189526eacf8914 (patch) | |
tree | c87e57c98a148f3dce6ac11a125897aafa8a3e38 /Util | |
parent | 85619d4504d98ee44a08ef0a1ae3a8c74dcaf9c8 (diff) | |
parent | 46e5643af049c1a225824838de6b9710d857a0d4 (diff) |
Merge branch 'master' of git+ssh://jaberg@dev.laptop.org/git/projects/tamtam
Diffstat (limited to 'Util')
-rw-r--r-- | Util/InstrumentsPanel.py | 111 | ||||
-rw-r--r-- | Util/NoteDB.py | 4 | ||||
-rw-r--r-- | Util/ThemeWidgets.py | 8 |
3 files changed, 117 insertions, 6 deletions
diff --git a/Util/InstrumentsPanel.py b/Util/InstrumentsPanel.py new file mode 100644 index 0000000..ceee92c --- /dev/null +++ b/Util/InstrumentsPanel.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python + +import pygtk +pygtk.require( '2.0' ) +import gtk + +import Config +from Util.ThemeWidgets import * + +class InstrumentsPanel(gtk.EventBox): + def __init__(self,setInstrument, playInstrument, enterMode = False): + gtk.EventBox.__init__(self) + + self.setInstrument = setInstrument + self.playInstrument = playInstrument + self.enterMode = enterMode + self.instTable = None + self.instDic = {} + + self.generateInstDic() + + self.mainVBox = RoundVBox(fillcolor = Config.PANEL_COLOR, bordercolor = Config.PANEL_COLOR, radius = Config.PANEL_RADIUS) + self.draw_toolbar() + self.draw_instruments_panel() + self.add(self.mainVBox) + self.show_all() + + def draw_toolbar(self): + toolbarBox = RoundHBox(fillcolor = Config.PANEL_COLOR, bordercolor = Config.PANEL_COLOR, radius = Config.PANEL_RADIUS) + for category in Config.CATEGORIES: + btn = gtk.Button(label=category) + btn.connect('clicked',self.handleToolbarBtnPress,category) + toolbarBox.add(btn) + + self.mainVBox.pack_start(toolbarBox,False,False) + + def handleToolbarBtnPress(self, widget, category): + self.draw_instruments_panel(category) + + def draw_mic_lab_box(self): + pass + + def draw_instruments_panel(self,category = 'all'): + + if self.instTable != None: + for child in self.instTable.get_children(): + self.instTable.remove(child) + self.instTable.destroy() + + instrumentNum = len(self.getInstrumentList(category)) + instruments = self.getInstrumentList(category) + + cols = 8 + if instrumentNum < cols: + cols = instrumentNum + rows = (instrumentNum // cols) + if instrumentNum % cols is not 0: #S'il y a un reste + rows = rows + 1 + + self.instTable = gtk.Table(rows,cols,True) + + for row in range(rows): + for col in range(cols): + if row*cols+col >= instrumentNum: + break + instBox = self.instDic[instruments[row*cols+col]] + self.instTable.attach(instBox, col, col+1, row, row+1, gtk.SHRINK, 0, gtk.SHRINK, 0) + + self.mainVBox.pack_start(self.instTable) + self.show_all() + + def generateInstDic(self): + self.firstInstButton = None + for instrument in self.getInstrumentList(): + instBox = RoundVBox(fillcolor = Config.INST_BCK_COLOR, bordercolor = Config.PANEL_COLOR, radius = Config.PANEL_RADIUS) + instBox.set_border_width(Config.PANEL_SPACING) + instButton = ImageRadioButton(self.firstInstButton, Config.IMAGE_ROOT + instrument + '.png' , Config.IMAGE_ROOT + instrument + 'sel.png', Config.IMAGE_ROOT + instrument + 'sel.png') + instButton.connect('clicked',self.handleInstrumentButtonClick, instrument) + if self.enterMode: + instButton.connect('enter',self.handleInstrumentButtonEnter, instrument) + instBox.pack_start(instButton) + self.instDic[instrument] = instBox + if self.firstInstButton == None: + self.firstInstButton = instButton + + def handleInstrumentButtonClick(self,widget,instrument): + if widget.get_active() is True: + self.setInstrument(instrument) + self.playInstrument(instrument) + if self.enterMode: + pass #Close the window + + def handleInstrumentButtonEnter(self,widget,instrument): + self.playInstrument(instrument) + + def getInstrumentList(self,category = 'all'): + instrumentList = [instrument for instrument in Config.INSTRUMENTS.keys() if instrument[0:4] != 'drum' and instrument[0:3] != 'mic' and instrument[0:3] != 'lab' and instrument[0:4] != 'guid'] + ['drum1kit', 'drum2kit', 'drum3kit'] + if category != 'all': + instrumentList = [instrument for instrument in Config.INSTRUMENTS.keys() if instrument[0:4] != 'drum' and instrument[0:3] != 'mic' and instrument[0:3] != 'lab' and instrument[0:4] != 'guid' and Config.INSTRUMENTS[instrument].category == category] + if category == 'percussions': + instrumentList = ['drum1kit', 'drum2kit', 'drum3kit'] + instrumentList + #instrumentList = instrumentList.sort(lambda g,l: cmp(Config.INSTRUMENTS[g].category, Config.INSTRUMENTS[l].category) ) + return instrumentList + +if __name__ == "__main__": + win = gtk.Window() + wc = InstrumentsPanel() + win.add(wc) + win.show() + #start the gtk event loop + gtk.main()
\ No newline at end of file diff --git a/Util/NoteDB.py b/Util/NoteDB.py index b7c18ce..37335d6 100644 --- a/Util/NoteDB.py +++ b/Util/NoteDB.py @@ -215,7 +215,7 @@ class NoteDB: while at > 0: onset = self.noteS[page][track][at-1].cs.onset if onset <= cs.onset: - if onset < cs.onset: break + if onset <= cs.onset: break elif self.noteS[page][track][at-1].cs.pitch <= cs.pitch: break at -= 1 last = len(self.noteS[page][track]) @@ -223,7 +223,7 @@ class NoteDB: onset = self.noteS[page][track][at].cs.onset if onset >= cs.onset: if onset > cs.onset: break - elif self.noteS[page][track][at].cs.pitch >= cs.pitch: break + elif self.noteS[page][track][at].cs.pitch > cs.pitch: break at += 1 self.noteS[page][track].insert( at, n ) diff --git a/Util/ThemeWidgets.py b/Util/ThemeWidgets.py index e4cdccd..026ced5 100644 --- a/Util/ThemeWidgets.py +++ b/Util/ThemeWidgets.py @@ -788,9 +788,9 @@ class ImageButton(gtk.Button): def expose(self, widget, event): if self.itype[self.curImage] == ITYPE.PIXBUF: - self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iwidthDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], gtk.gdk.RGB_DITHER_NONE) + self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], gtk.gdk.RGB_DITHER_NONE) else: - self.window.draw_drawable( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iwidthDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage] ) + self.window.draw_drawable( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage] ) return True def on_btn_press(self, widget, event): @@ -873,9 +873,9 @@ class ImageToggleButton(gtk.ToggleButton): def expose(self, widget, event): if self.itype[self.curImage] == ITYPE.PIXBUF: - self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iwidthDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], gtk.gdk.RGB_DITHER_NONE) + self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], gtk.gdk.RGB_DITHER_NONE) else: - self.window.draw_drawable( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iwidthDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage] ) + self.window.draw_drawable( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage] ) return True def toggleImage(self, widget, event): |