From 9a498a0c7dd90af62c7e769cf9e397f034d5d4d3 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Fri, 18 Jan 2013 16:04:31 +0000 Subject: Partial port of TamTamMini With this commit, the activity starts, but not all the functionality is working. A massive amount of unneded or overcomplicated code was removed. More work is needed in the ThemeWidgets classes. Signed-off-by: Gonzalo Odiard --- (limited to 'Mini') diff --git a/Mini/InstrumentPanel.py b/Mini/InstrumentPanel.py index 9d33e63..ecabe2d 100644 --- a/Mini/InstrumentPanel.py +++ b/Mini/InstrumentPanel.py @@ -7,6 +7,7 @@ from common.Util.ThemeWidgets import * from common.Util import InstrumentDB from common.port.scrolledbox import HScrolledBox import sugar3.graphics.style as style + import logging @@ -33,13 +34,11 @@ class InstrumentPanel( Gtk.EventBox ): self.loaded = False self.loadData = {} - self.loadStage = [0,0,0] def grab_focus(self): if not self.instDic: return - for widget in self.instDic.values(): - button = widget.get_children()[0] + for button in self.instDic.values(): if button.props.active: button.grab_focus() break @@ -61,63 +60,28 @@ class InstrumentPanel( Gtk.EventBox ): if self.loaded: self.prepareInstrumentTable(self.category) - def load( self, timeout = -1 ): - if self.loaded: return True - if Config.DEBUG > 4: print "InstrumentPanel load", self.loadStage - - if self.loadStage[0] == 0: - color = Gdk.color_parse(Config.PANEL_BCK_COLOR) - self.modify_bg(Gtk.StateType.NORMAL, color) - self.loadStage[0] = 1 - if timeout >= 0 and time.time() > timeout: return False - - if self.loadStage[0] == 1: - self.loadStage[0] = 2 - if timeout >= 0 and time.time() > timeout: return False - - if self.loadStage[0] == 2: - self.instTable = None - self.recstate = False - self.lastInstrumentWidget = None - - self.mainVBox = Gtk.VBox() - self.loadStage[0] = 3 - if timeout >= 0 and time.time() > timeout: return False - - if self.loadStage[0] == 3: - if not self.loadInstrumentList( timeout, self.loadStage ): - return False - self.loadStage[0] = 4 - if timeout >= 0 and time.time() > timeout: return False - - if self.loadStage[0] == 4: - if not self.loadToolbar( timeout, self.loadStage ): - return False - self.loadStage[0] = 5 - if timeout >= 0 and time.time() > timeout: return False - - if self.loadStage[0] == 5: - if self.instDic == None: - self.instDic = {} - self.loadStage[0] = 5.1 - else: - self.loadStage[0] = 6 + def load(self): + if self.loaded: + return True + + color = Gdk.color_parse(Config.PANEL_BCK_COLOR) + self.modify_bg(Gtk.StateType.NORMAL, color) + self.instTable = None + self.recstate = False - if self.loadStage[0] == 5.1: - if not self.loadInstDic( self.instDic, timeout, self.loadStage ): - return False - self.loadStage[0] = 6 - if timeout >= 0 and time.time() > timeout: return False + self.mainVBox = Gtk.VBox() - if self.loadStage[0] == 6: - self.loadInstrumentViewport() - self.loadStage[0] = 7 - if timeout >= 0 and time.time() > timeout: return False + self.loadInstrumentList() + self.loadToolbar() - if self.loadStage[0] == 7: - self.prepareInstrumentTable() - self.loadStage[0] = 8 - if timeout >= 0 and time.time() > timeout: return False + if self.instDic == None: + self.instDic = {} + + self.loadInstDic(self.instDic) + + self.loadInstrumentViewport() + + self.prepareInstrumentTable() self.add(self.mainVBox) self.show_all() @@ -125,140 +89,76 @@ class InstrumentPanel( Gtk.EventBox ): self.loaded = True return True - def loadInstrumentList( self, timeout = -1, loadStage = [0,0,0] ): - - if loadStage[1] == 0: - self.instrumentList = { "all": [], "all.enterMode": [], "percussions.enterMode": [], "mysounds": [] } - for category in Config.CATEGORIES: - self.instrumentList[category] = [] - loadStage[1] = 1 - if timeout >= 0 and time.time() > timeout: return False - - if loadStage[1] == 1: - keys = self.instrumentDB.instNamed.keys() - for i in range(loadStage[2], len(keys)): - key = keys[i] - - instrument = self.instrumentDB.instNamed[key] - if not instrument.kitStage and not instrument.kit: - if not key.startswith('mic') and not key.startswith('lab'): - self.instrumentList["all"].append( key ) - self.instrumentList["all.enterMode"].append( key ) - self.instrumentList[instrument.category].append( key ) - if instrument.category == "percussions": - self.instrumentList["percussions.enterMode"].append( key ) - loadStage[2] += 1 - if timeout >= 0 and time.time() > timeout: return False - - loadStage[1] = 2 - loadStage[2] = 0 + def loadInstrumentList(self): + + self.instrumentList = { "all": [], "all.enterMode": [], "percussions.enterMode": [], "mysounds": [] } + for category in Config.CATEGORIES: + self.instrumentList[category] = [] + + keys = self.instrumentDB.instNamed.keys() + for i in range(len(keys)): + key = keys[i] + + instrument = self.instrumentDB.instNamed[key] + if not instrument.kitStage and not instrument.kit: + if not key.startswith('mic') and not key.startswith('lab'): + self.instrumentList["all"].append( key ) + self.instrumentList["all.enterMode"].append( key ) + self.instrumentList[instrument.category].append( key ) + if instrument.category == "percussions": + self.instrumentList["percussions.enterMode"].append( key ) self.instrumentList["mysounds"].sort() self.instrumentList["all"] += self.instrumentList["mysounds"] self.instrumentList["all.enterMode"] += self.instrumentList["mysounds"] - loadStage[1] = 0 - return True - - def loadToolbar( self, timeout = -1, loadStage = [0,0,0] ): - if loadStage[1] == 0: - self.toolbarBox = Gtk.HBox() + def loadToolbar(self): + self.toolbarBox = Gtk.HBox() - scrollbox = HScrolledBox(scroll_policy=Gtk.PolicyType.NEVER) - scrollbox.set_viewport(self.toolbarBox) - scrollbox.modify_bg(Gtk.StateType.NORMAL, - style.Color(Config.PANEL_BCK_COLOR).get_gdk_color()) - self.mainVBox.pack_start(scrollbox, False, False, 0) + scrollbox = HScrolledBox(scroll_policy=Gtk.PolicyType.NEVER) + scrollbox.set_viewport(self.toolbarBox) + scrollbox.modify_bg(Gtk.StateType.NORMAL, + style.Color(Config.PANEL_BCK_COLOR).get_gdk_color()) + self.mainVBox.pack_start(scrollbox, False, False, 0) - self.firstTbBtn = None - self.loadStage[1] = 1 - if timeout >= 0 and time.time() > timeout: return False + self.firstTbBtn = None - for i in range(loadStage[1]-1, len(Config.CATEGORIES)): + for i in range(len(Config.CATEGORIES)): category = Config.CATEGORIES[i] - if loadStage[2] == 0: - self.loadData["btnBox"] = RoundVBox(fillcolor = Config.CATEGORY_BCK_COLOR, bordercolor = Config.PANEL_BCK_COLOR, radius = Config.PANEL_RADIUS) - self.loadData["btnBox"].set_border_width(Config.PANEL_SPACING) - loadStage[2] = 1 - if timeout >= 0 and time.time() > timeout: return False - - if loadStage[2] == 1: - self.loadData["btn"] = ImageRadioButton(self.firstTbBtn, - category + '.png', category + 'sel.png', - category + 'sel.png') - loadStage[2] = 2 - if timeout >= 0 and time.time() > timeout: return False - if self.firstTbBtn == None: - self.firstTbBtn = self.loadData["btn"] - self.loadData["btn"].connect('clicked',self.handleToolbarBtnPress,category) - self.loadData["btn"].set_tooltip_text(str(category)) - self.loadData["btnBox"].add(self.loadData["btn"]) - self.toolbarBox.pack_start(self.loadData["btnBox"], True, True, 0) - - loadStage[2] = 0 - loadStage[1] += 1 - if timeout >= 0 and time.time() > timeout: return False - - self.loadData.pop("btn") - self.loadData.pop("btnBox") - loadStage[1] = 0 - return True + btn = ImageRadioButton(self.firstTbBtn, + category + '.png', category + 'sel.png', + category + 'sel.png') - def loadInstDic( self, instDic, timeout = -1, loadStage = [0,0,0] ): - - if loadStage[1] == 0: - self.firstInstButton = None - self.loadData["len"] = len(self.instrumentList['all']) - loadStage[1] = 1 - if timeout >= 0 and time.time() > timeout: return False - - - for i in range( loadStage[1]-1, self.loadData["len"] ): - instrument = self.instrumentList["all"][i] - if loadStage[2] == 0: - self.loadData["instBox"] = RoundVBox(fillcolor = Config.INST_BCK_COLOR, bordercolor = Config.INSTRUMENT_GRID_COLOR, radius = Config.PANEL_RADIUS) - self.loadData["instBox"].set_border_width(Config.PANEL_SPACING) - loadStage[2] = 1 - if timeout >= 0 and time.time() > timeout: return False - - if loadStage[2] == 1: - try: - self.loadData['instButton'] = ImageRadioButton( - self.firstInstButton, instrument + '.png', - instrument + 'sel.png', instrument + 'sel.png') - except: - self.loadData["instButton"] = ImageRadioButton( - self.firstInstButton, 'generic.png', - 'genericsel.png', 'genericsel.png') - loadStage[2] = 2 - if timeout >= 0 and time.time() > timeout: return False - - if loadStage[2] == 2: - self.loadData["instButton"].clickedHandler = self.loadData["instButton"].connect('clicked',self.handleInstrumentButtonClick, instrument) - self.loadData["instButton"].connect('enter',self.handleInstrumentButtonEnter, instrument) - self.loadData["instButton"].connect('focus-in-event', self.handleInstrumentButtonFocus, instrument) - loadStage[2] = 3 - if timeout >= 0 and time.time() > timeout: return False - - self.loadData["instBox"].set_tooltip_text(str(self.instrumentDB.instNamed[instrument].nameTooltip)) - - self.loadData["instBox"].pack_start(self.loadData["instButton"], - False, False, 0) - instDic[instrument] = self.loadData["instBox"] + if self.firstTbBtn == None: + self.firstTbBtn = btn + btn.connect('clicked',self.handleToolbarBtnPress,category) + btn.set_tooltip_text(str(category)) + self.toolbarBox.pack_start(btn, False, False, 0) + + def loadInstDic( self, instDic): + + self.firstInstButton = None + + for instrument in self.instrumentList['all']: + try: + btn = ImageRadioButton( + self.firstInstButton, instrument + '.png', + instrument + 'sel.png', instrument + 'sel.png') + except: + btn = ImageRadioButton( + self.firstInstButton, 'generic.png', + 'genericsel.png', 'genericsel.png') + + btn.clickedHandler = btn.connect('clicked',self.handleInstrumentButtonClick, instrument) + btn.connect('enter',self.handleInstrumentButtonEnter, instrument) + btn.connect('focus-in-event', self.handleInstrumentButtonFocus, instrument) + + btn.set_tooltip_text(str(self.instrumentDB.instNamed[instrument].nameTooltip)) + instDic[instrument] = btn if self.firstInstButton == None: - self.firstInstButton = self.loadData["instButton"] - loadStage[2] = 0 - if timeout >= 0 and time.time() > timeout: return False - - loadStage[1] += 1 - - self.loadData.pop("instBox") - self.loadData.pop("instButton") - self.loadData.pop("len") - loadStage[1] = 0 - return True + self.firstInstButton = btn def loadInstrumentViewport( self ): self.instBox = Gtk.Alignment.new(0.5, 0, 0, 1) @@ -271,6 +171,7 @@ class InstrumentPanel( Gtk.EventBox ): scrollwin = Gtk.ScrolledWindow() scrollwin.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scrollwin.add_with_viewport(box) + box.get_parent().set_shadow_type(Gtk.ShadowType.NONE) self.mainVBox.pack_end(scrollwin, True, True, 0) @@ -284,7 +185,7 @@ class InstrumentPanel( Gtk.EventBox ): elif category == "percussions": category = "percussions.enterMode" if self.instTable != None: - for child in self.instTable.get_children()[:]: + for child in self.instTable.get_children(): self.instTable.remove(child) self.instBox.remove(self.instTable) self.instTable.destroy() @@ -313,7 +214,6 @@ class InstrumentPanel( Gtk.EventBox ): self.instTable.attach(self.instDic[inst], col, col + 1, row, row + 1, Gtk.AttachOptions.SHRINK, Gtk.AttachOptions.SHRINK, 0, 0) - self.instBox.add(self.instTable) self.instTable.show_all() @@ -327,7 +227,7 @@ class InstrumentPanel( Gtk.EventBox ): def handleInstrumentButtonClick(self,widget,instrument): if widget.get_active() is True and self.recstate == False: if self.setInstrument: - widget.event( Gdk.Event( Gdk.LEAVE_NOTIFY ) ) # fake the leave event + #widget.event( Gdk.Event( Gdk.LEAVE_NOTIFY ) ) # fake the leave event self.setInstrument(instrument) time.sleep(0.05) if self.playInstrument: self.playInstrument(instrument) @@ -340,12 +240,12 @@ class InstrumentPanel( Gtk.EventBox ): def handleInstrumentButtonFocus(self, widget, event, instrument): if self._scrolled_window is None: - parent = widget.parent + parent = widget.get_parent() while parent is not None: if isinstance(parent, Gtk.ScrolledWindow): self._scrolled_window = parent break - parent = parent.parent + parent = parent.get_parent() else: return top = self._scrolled_window @@ -399,8 +299,7 @@ class DrumPanel( Gtk.EventBox ): btnBox.set_border_width(Config.PANEL_SPACING) self.drums = {} for drumkit in self.instrumentList: - instBox = RoundVBox(fillcolor = Config.INST_BCK_COLOR, bordercolor = Config.PANEL_COLOR, radius = Config.PANEL_RADIUS) - instBox.set_border_width(Config.PANEL_SPACING) + instBox = Gtk.VBox() self.drums[drumkit] = ImageRadioButton(firstBtn, drumkit + '.png', drumkit + 'sel.png', drumkit + 'sel.png') self.drums[drumkit].clickedHandler = self.drums[drumkit].connect('clicked',self.setDrums,drumkit) @@ -423,11 +322,3 @@ class DrumPanel( Gtk.EventBox ): btn.handler_block(btn.clickedHandler) btn.set_active(state) btn.handler_unblock(btn.clickedHandler) - -if __name__ == "__main__": - win = Gtk.Window() - wc = DrumPanel(None) - win.add(wc) - win.show() - #start the Gtk event loop - Gtk.main() diff --git a/Mini/miniTamTamMain.py b/Mini/miniTamTamMain.py index 2bfec3d..cf50cae 100644 --- a/Mini/miniTamTamMain.py +++ b/Mini/miniTamTamMain.py @@ -1,7 +1,6 @@ from gi.repository import Gtk from gi.repository import GObject import os -import random import time import xdrlib import commands @@ -41,17 +40,14 @@ from gettext import gettext as _ Tooltips = Config.Tooltips -class miniTamTamMain(Gtk.EventBox): +class miniTamTamMain(Gtk.HBox): def __init__(self, activity): - Gtk.EventBox.__init__(self) + Gtk.HBox.__init__(self) self.instrumentPanel = None self.activity = activity - #self.set_border_width(Config.MAIN_WINDOW_PADDING) - #self.set_border_width(0) - self.instrumentDB = InstrumentDB.getRef() self.firstTime = False self.playing = False @@ -88,12 +84,11 @@ class miniTamTamMain(Gtk.EventBox): self.sequencer.beat = self.beat self.loop.beat = self.beat - self.mainWindowBox = Gtk.HBox() self.leftBox = Gtk.VBox() self.rightBox = Gtk.VBox() - self.mainWindowBox.pack_start(self.rightBox, False, True, 0) - self.mainWindowBox.pack_start(self.leftBox, True, True, 0) - self.add(self.mainWindowBox) + # TODO: right is at left, and left is at right? + self.pack_start(self.rightBox, False, False, 0) + self.pack_start(self.leftBox, False, False, 0) self.enableKeyboard() self.setInstrument(self.instrument) @@ -177,7 +172,6 @@ class miniTamTamMain(Gtk.EventBox): self.activity.connect( "shared", self.shared ) if os.path.isfile("FORCE_SHARE"): # HOST - r = random.random() #print "::::: Sharing as TTDBG%f :::::" % r #self.activity.set_title(_("TTDBG%f" % r)) print "::::: Sharing as TamTam :::::" @@ -192,9 +186,7 @@ class miniTamTamMain(Gtk.EventBox): def drawGeneration( self ): - slidersBox = RoundVBox(fillcolor = Config.PANEL_COLOR, bordercolor = Config.PANEL_BCK_COLOR, radius = Config.PANEL_RADIUS) - slidersBox.set_border_width(Config.PANEL_SPACING) - + slidersBox = Gtk.VBox() geneSliderBox = Gtk.VBox() self.geneSliderBoxImgTop = Gtk.Image() self.geneSliderBoxImgTop.set_from_file(imagefile('complex6.png')) @@ -259,20 +251,12 @@ class miniTamTamMain(Gtk.EventBox): slidersBoxSub.pack_start(volumeSliderBox, True, True, 0) slidersBox.pack_start(slidersBoxSub, True, True, 0) - generateBtnSub = RoundHBox( - fillcolor=Config.PANEL_COLOR, - bordercolor=Config.PANEL_BCK_COLOR, - radius=Config.PANEL_RADIUS) - generateBtnSub.set_border_width(Config.PANEL_SPACING) + generateBtnSub = Gtk.HBox() - #playImg = Gtk.Image() - #playImg.set_from_icon_name('media-playback-start', Gtk.ICON_SIZE_LARGE_TOOLBAR) self.playButton = ImageToggleButton('miniplay.png', 'stop.png') - #self.playButton.set_relief(Gtk.RELIEF_NONE) - #self.playButton.set_image(playImg) self.playButton.connect('clicked',self.handlePlayButton) generateBtnSub.pack_start(self.playButton, True, True, 0) - #self.playButton.set_tooltip(_('Play / Stop')) + self.playButton.set_tooltip_text(_('Play / Stop')) generateBtn = ImageButton('dice.png', clickImg_path='diceblur.png') generateBtn.connect('button-press-event', self.handleGenerateBtn) @@ -281,10 +265,7 @@ class miniTamTamMain(Gtk.EventBox): # drums - drum_box = RoundVBox( - fillcolor=Config.PANEL_COLOR, - bordercolor=Config.PANEL_BCK_COLOR, - radius=Config.PANEL_RADIUS) + drum_box = Gtk.VBox() drum_scroll = VScrolledBox(scroll_policy=Gtk.PolicyType.NEVER) drum_scroll.set_viewport(drum_box) @@ -346,13 +327,13 @@ class miniTamTamMain(Gtk.EventBox): def updateInstrumentPanel(self): if self.instrumentPanel is None: self.instrumentPanel = InstrumentPanel() - self.leftBox.pack_start(self.instrumentPanel, True, True, 0) width = Gdk.Screen.width() - self.rightBox.get_size_request()[0] self.instrumentPanel.configure(self.setInstrument, self.playInstrumentNote, False, self.micRec, width=width) self.instrumentPanel.load() + self.leftBox.pack_start(self.instrumentPanel, True, True, 0) def micRec(self, widget, mic): self.csnd.inputMessage("i5600 0 4") @@ -413,12 +394,12 @@ class miniTamTamMain(Gtk.EventBox): self.activity.close() def handleGenerationSlider(self, adj): - img = int(adj.value * 7)+1 + img = int(adj.get_value() * 7)+1 self.geneSliderBoxImgTop.set_from_file( imagefile('complex' + str(img) + '.png')) def handleGenerationSliderRelease(self, widget, event): - self.regularity = widget.get_adjustment().value + self.regularity = widget.get_adjustment().get_value() self.beatPickup = False self.regenerate() self.beatPickup = True @@ -441,7 +422,7 @@ class miniTamTamMain(Gtk.EventBox): self.drumFillin.setBeats( self.beat ) def handleBeatSlider(self, adj): - img = self.scale(int(adj.value),2,12,1,11) + img = self.scale(int(adj.get_value()),2,12,1,11) self.beatSliderBoxImgTop.set_from_file( imagefile('beat' + str(img) + '.png')) self.sequencer.beat = self.beat @@ -449,7 +430,7 @@ class miniTamTamMain(Gtk.EventBox): self.drumFillin.setBeats( self.beat ) def handleBeatSliderRelease(self, widget, event): - self.beat = int(widget.get_adjustment().value) + self.beat = int(widget.get_adjustment().get_value()) self.sequencer.beat = self.beat self.loop.beat = self.beat self.drumFillin.setBeats( self.beat ) @@ -473,9 +454,9 @@ class miniTamTamMain(Gtk.EventBox): def handleTempoSliderChange(self,adj): if self.network.isPeer(): - self.requestTempoChange(int(adj.value)) + self.requestTempoChange(int(adj.get_value())) else: - self._updateTempo( int(adj.value) ) + self._updateTempo(int(adj.get_value())) def _updateTempo( self, val ): @@ -502,7 +483,7 @@ class miniTamTamMain(Gtk.EventBox): imagefile('tempo' + str(img) + '.png')) def handleBalanceSlider(self, adj): - self.instVolume = int(adj.value) + self.instVolume = int(adj.get_value()) self.drumVolume = sqrt( (100-self.instVolume)*0.01 ) self.adjustDrumVolume() self.drumFillin.setVolume(self.drumVolume) @@ -517,7 +498,7 @@ class miniTamTamMain(Gtk.EventBox): imagefile('instr' + str(img2) + '.png')) def handleReverbSlider(self, adj): - self.reverb = adj.value + self.reverb = adj.get_value() self.drumFillin.setReverb( self.reverb ) img = int(self.scale(self.reverb,0,1,0,4)) self._playToolbar.reverbSliderImgRight.set_from_file( @@ -525,7 +506,7 @@ class miniTamTamMain(Gtk.EventBox): self.keyboardStandAlone.setReverb(self.reverb) def handleVolumeSlider(self, adj): - self.volume = adj.value + self.volume = adj.get_value() self.csnd.setMasterVolume(self.volume) img = int(self.scale(self.volume,0,200,0,3.9)) self.volumeSliderBoxImgTop.set_from_file( -- cgit v0.9.1