From efe75bcce5a94fa0f2c8accb05d48333103d4290 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Tue, 15 Jan 2013 12:49:16 +0000 Subject: Porting TamTamEdit to Gtk3 Signed-off-by: Aaron Gordon --- (limited to 'Edit') diff --git a/Edit/EditToolbars.py b/Edit/EditToolbars.py index e2b41e4..70cd0b7 100644 --- a/Edit/EditToolbars.py +++ b/Edit/EditToolbars.py @@ -1,16 +1,15 @@ -import gtk +from gi.repository import Gtk, Gdk, GObject import common.Config as Config -from sugar.graphics.toolbutton import ToolButton -from sugar.graphics.toggletoolbutton import ToggleToolButton -from sugar.graphics.radiotoolbutton import RadioToolButton -from sugar.graphics.palette import Palette -from sugar.graphics.icon import Icon +from sugar3.graphics.toolbutton import ToolButton +from sugar3.graphics.toggletoolbutton import ToggleToolButton +from sugar3.graphics.radiotoolbutton import RadioToolButton +from sugar3.graphics.palette import Palette +from sugar3.graphics.icon import Icon from common.Util.ThemeWidgets import * from gettext import gettext as _ # Generation palette -import gobject from common.Generation.Generator import GenerationParameters # Generation palette and Properties palette from common.Generation.GenerationConstants import GenerationConstants @@ -46,18 +45,18 @@ def common_buttons(toolbar, edit): toolbar.stopButton.set_tooltip(_('Stop')) # Play button Image - toolbar.playButtonImg = gtk.Image() + toolbar.playButtonImg = Gtk.Image() toolbar.playButtonImg.set_from_icon_name( - 'media-playback-start', gtk.ICON_SIZE_LARGE_TOOLBAR) + 'media-playback-start', Gtk.IconSize.LARGE_TOOLBAR) toolbar.playButtonImg.show() # Pause button Image - toolbar.pauseButtonImg = gtk.Image() + toolbar.pauseButtonImg = Gtk.Image() toolbar.pauseButtonImg.set_from_icon_name( - 'media-playback-pause', gtk.ICON_SIZE_LARGE_TOOLBAR) + 'media-playback-pause', Gtk.IconSize.LARGE_TOOLBAR) toolbar.pauseButtonImg.show() - toolbar.separator = gtk.SeparatorToolItem() + toolbar.separator = Gtk.SeparatorToolItem() toolbar.separator.set_expand(False) toolbar.separator.set_draw(True) toolbar.insert(toolbar.separator,-1) @@ -112,24 +111,24 @@ def common_buttons(toolbar, edit): toolbar.duplicateButton.set_tooltip(_('Duplicate')) -class mainToolbar(gtk.Toolbar): +class mainToolbar(Gtk.Toolbar): def __init__(self, edit): - gtk.Toolbar.__init__(self) + Gtk.Toolbar.__init__(self) self.edit = edit - self.tooltips = gtk.Tooltips() + #self.tooltips = gtk.Tooltips() common_buttons(self, self.edit) -class generateToolbar(gtk.Toolbar): +class generateToolbar(Gtk.Toolbar): def __init__(self, edit): - gtk.Toolbar.__init__(self) + Gtk.Toolbar.__init__(self) self.edit = edit - self.tooltips = gtk.Tooltips() + #self.tooltips = gtk.Tooltips() # BigGeneration button self.bigGenerationButton = ToolButton('diceB') @@ -147,13 +146,13 @@ class generateToolbar(gtk.Toolbar): self.generationButton.show() -class recordToolbar(gtk.Toolbar): +class recordToolbar(Gtk.Toolbar): def __init__(self, edit): - gtk.Toolbar.__init__(self) + Gtk.Toolbar.__init__(self) self.edit = edit - self.tooltips = gtk.Tooltips() + #self.tooltips = gtk.Tooltips() # Record button self.recordButton = ToggleToolButton('recordK') @@ -171,13 +170,13 @@ class recordToolbar(gtk.Toolbar): self.recordOggButton.show() self.recordOggButton.set_tooltip(_('Record to ogg')) -class toolsToolbar(gtk.Toolbar): +class toolsToolbar(Gtk.Toolbar): def __init__(self, edit): - gtk.Toolbar.__init__(self) + Gtk.Toolbar.__init__(self) self.edit = edit - self.tooltips = gtk.Tooltips() + #self.tooltips = gtk.Tooltips() # Volume / Tempo button self._volumeTempoPalette = volumeTempoPalette(_('Volume / Tempo'), self.edit) @@ -200,10 +199,10 @@ class pointerPalette(Palette): self.edit = edit - self.pointerBox = gtk.VBox() + self.pointerBox = Gtk.VBox() - self.snapGridHBox = gtk.HBox() - self.snapGridImage = gtk.Image() + self.snapGridHBox = Gtk.HBox() + self.snapGridImage = Gtk.Image() self.snapGridImage.set_from_file(Config.TAM_TAM_ROOT + '/icons/grid.svg') self.snapGridBox = BigComboBox() self.snapGridBox.connect('changed', self.handleSnapGrid) @@ -234,10 +233,10 @@ class drawPalette(Palette): self.edit = edit - self.drawBox = gtk.VBox() + self.drawBox = Gtk.VBox() - self.snapGridHBox = gtk.HBox() - self.snapGridImage = gtk.Image() + self.snapGridHBox = Gtk.HBox() + self.snapGridImage = Gtk.Image() self.snapGridImage.set_from_file(Config.TAM_TAM_ROOT + '/icons/grid.svg') self.snapGridBox = BigComboBox() self.snapGridBox.connect('changed', self.handleSnapGrid) @@ -268,10 +267,10 @@ class paintPalette(Palette): self.edit = edit - self.paintBox = gtk.VBox() + self.paintBox = Gtk.VBox() - self.noteDurHBox = gtk.HBox() - self.noteDurImage = gtk.Image() + self.noteDurHBox = Gtk.HBox() + self.noteDurImage = Gtk.Image() self.noteDurImage.set_from_file(Config.TAM_TAM_ROOT + '/icons/notedur.svg') self.noteDurBox = BigComboBox() self.noteDurBox.connect('changed', self.handleNoteDur) @@ -283,8 +282,8 @@ class paintPalette(Palette): self.noteDurHBox.pack_start(self.noteDurImage, False, False, padding = 5) self.noteDurHBox.pack_start(self.noteDurBox, False, False, padding = 5) - self.snapGridHBox = gtk.HBox() - self.snapGridImage = gtk.Image() + self.snapGridHBox = Gtk.HBox() + self.snapGridImage = Gtk.Image() self.snapGridImage.set_from_file(Config.TAM_TAM_ROOT + '/icons/grid.svg') self.snapGridBox = BigComboBox() self.snapGridBox.connect('changed', self.handleSnapGrid) @@ -330,24 +329,24 @@ class volumeTempoPalette(Palette): self.edit = edit - self.volumeTempoBox = gtk.VBox() + self.volumeTempoBox = Gtk.VBox() - self.volumeSliderBox = gtk.HBox() - self.volumeSliderLabel = gtk.Label(_('Volume')) - self.volumeSliderAdj = gtk.Adjustment(Config.DEFAULT_VOLUME, 0, 100, 1, 1, 0) + self.volumeSliderBox = Gtk.HBox() + self.volumeSliderLabel = Gtk.Label(_('Volume')) + self.volumeSliderAdj = Gtk.Adjustment(Config.DEFAULT_VOLUME, 0, 100, 1, 1, 0) self.volumeSliderAdj.connect('value-changed', self.edit.handleVolume) - self.volumeSlider = gtk.HScale(adjustment = self.volumeSliderAdj) + self.volumeSlider = Gtk.HScale(adjustment = self.volumeSliderAdj) self.volumeSlider.set_size_request(250,-1) self.volumeSlider.set_inverted(False) self.volumeSlider.set_draw_value(False) self.volumeSliderBox.pack_start(self.volumeSliderLabel, False, False, padding = 5) self.volumeSliderBox.pack_end(self.volumeSlider, False, False, padding = 5) - self.tempoSliderBox = gtk.HBox() - self.tempoSliderLabel = gtk.Label(_('Tempo')) - self.tempoSliderAdj = gtk.Adjustment(Config.PLAYER_TEMPO, 40, 240, 1, 1, 0) + self.tempoSliderBox = Gtk.HBox() + self.tempoSliderLabel = Gtk.Label(_('Tempo')) + self.tempoSliderAdj = Gtk.Adjustment(Config.PLAYER_TEMPO, 40, 240, 1, 1, 0) self.tempoSliderAdj.connect('value-changed', self.edit.handleTempo) - self.tempoSlider = gtk.HScale(adjustment = self.tempoSliderAdj) + self.tempoSlider = Gtk.HScale(adjustment = self.tempoSliderAdj) self.tempoSlider.set_size_request(250,-1) self.tempoSlider.set_inverted(False) self.tempoSlider.set_draw_value(False) @@ -377,27 +376,27 @@ class generationPalette(Palette): self.pattern = GenerationConstants.DEFAULT_PATTERN self.scale = GenerationConstants.DEFAULT_SCALE - self.mainBox = gtk.VBox() - self.slidersBox = gtk.HBox() - self.scaleModeBox = gtk.VBox() - self.decisionBox = gtk.HBox() + self.mainBox = Gtk.VBox() + self.slidersBox = Gtk.HBox() + self.scaleModeBox = Gtk.VBox() + self.decisionBox = Gtk.HBox() - self.XYSlider1MainBox = gtk.VBox() - self.XYSlider1TopLabel = gtk.Label(_('Rhythm')) - self.XSlider1BottomLabelBox = gtk.HBox() - self.XSlider1Img = gtk.Image() + self.XYSlider1MainBox = Gtk.VBox() + self.XYSlider1TopLabel = Gtk.Label(_('Rhythm')) + self.XSlider1BottomLabelBox = Gtk.HBox() + self.XSlider1Img = Gtk.Image() self.XSlider1Img.set_from_file(Config.TAM_TAM_ROOT + '/icons/sideR.svg') - self.XSlider1BottomLabel = gtk.Label(_('Density')) - self.YSlider1BottomLabelBox = gtk.HBox() - self.YSlider1Img = gtk.Image() + self.XSlider1BottomLabel = Gtk.Label(_('Density')) + self.YSlider1BottomLabelBox = Gtk.HBox() + self.YSlider1Img = Gtk.Image() self.YSlider1Img.set_from_file(Config.TAM_TAM_ROOT + '/icons/updownR.svg') - self.YSlider1BottomLabel = gtk.Label(_('Regularity')) + self.YSlider1BottomLabel = Gtk.Label(_('Regularity')) self.XYSliderBox1 = RoundFixed(fillcolor = '#CCCCCC', bordercolor = '#000000') self.XYSliderBox1.set_size_request(200,200) self.XYButton1 = ImageToggleButton( Config.TAM_TAM_ROOT + '/icons/XYBut.svg', Config.TAM_TAM_ROOT + '/icons/XYButDown.svg') - self.XAdjustment1 = gtk.Adjustment(self.rythmDensity[0] * 100, 0, 100, 1, 1, 1) + self.XAdjustment1 = Gtk.Adjustment(self.rythmDensity[0] * 100, 0, 100, 1, 1, 1) self.XAdjustment1.connect("value-changed", self.handleXAdjustment1) - self.YAdjustment1 = gtk.Adjustment(self.rythmRegularity[0] * 100, 0, 100, 1, 1, 1) + self.YAdjustment1 = Gtk.Adjustment(self.rythmRegularity[0] * 100, 0, 100, 1, 1, 1) self.YAdjustment1.connect("value-changed", self.handleYAdjustment1) self.XYSlider1 = XYSlider( self.XYSliderBox1, self.XYButton1, self.XAdjustment1, self.YAdjustment1, False, True ) self.XSlider1BottomLabelBox.pack_start(self.XSlider1Img, False, False, padding = 5) @@ -409,22 +408,22 @@ class generationPalette(Palette): self.XYSlider1MainBox.pack_start(self.XSlider1BottomLabelBox, False, False, padding = 2) self.XYSlider1MainBox.pack_start(self.YSlider1BottomLabelBox, False, False, padding = 2) - self.XYSlider2MainBox = gtk.VBox() - self.XYSlider2TopLabel = gtk.Label(_('Pitch')) - self.XSlider2BottomLabelBox = gtk.HBox() - self.XSlider2Img = gtk.Image() + self.XYSlider2MainBox = Gtk.VBox() + self.XYSlider2TopLabel = Gtk.Label(_('Pitch')) + self.XSlider2BottomLabelBox = Gtk.HBox() + self.XSlider2Img = Gtk.Image() self.XSlider2Img.set_from_file(Config.TAM_TAM_ROOT + '/icons/sideR.svg') - self.XSlider2BottomLabel = gtk.Label(_('Regularity')) - self.YSlider2BottomLabelBox = gtk.HBox() - self.YSlider2Img = gtk.Image() + self.XSlider2BottomLabel = Gtk.Label(_('Regularity')) + self.YSlider2BottomLabelBox = Gtk.HBox() + self.YSlider2Img = Gtk.Image() self.YSlider2Img.set_from_file(Config.TAM_TAM_ROOT + '/icons/updownR.svg') - self.YSlider2BottomLabel = gtk.Label(_('Maximum step')) + self.YSlider2BottomLabel = Gtk.Label(_('Maximum step')) self.XYSliderBox2 = RoundFixed(fillcolor = '#CCCCCC', bordercolor = '#000000') self.XYSliderBox2.set_size_request(200,200) self.XYButton2 = ImageToggleButton( Config.TAM_TAM_ROOT + '/icons/XYBut.svg', Config.TAM_TAM_ROOT + '/icons/XYButDown.svg') - self.XAdjustment2 = gtk.Adjustment(self.pitchRegularity[0] * 100, 0, 100, 1, 1, 1) + self.XAdjustment2 = Gtk.Adjustment(self.pitchRegularity[0] * 100, 0, 100, 1, 1, 1) self.XAdjustment2.connect("value-changed", self.handleXAdjustment2) - self.YAdjustment2 = gtk.Adjustment(self.pitchStep[0] * 100, 0, 100, 1, 1, 1) + self.YAdjustment2 = Gtk.Adjustment(self.pitchStep[0] * 100, 0, 100, 1, 1, 1) self.YAdjustment2.connect("value-changed", self.handleYAdjustment2) self.XYSlider2 = XYSlider( self.XYSliderBox2, self.XYButton2, self.XAdjustment2, self.YAdjustment2, False, True ) self.XSlider2BottomLabelBox.pack_start(self.XSlider2Img, False, False, padding = 5) @@ -436,22 +435,22 @@ class generationPalette(Palette): self.XYSlider2MainBox.pack_start(self.XSlider2BottomLabelBox, False, False, padding = 2) self.XYSlider2MainBox.pack_start(self.YSlider2BottomLabelBox, False, False, padding = 2) - self.XYSlider3MainBox = gtk.VBox() - self.XYSlider3TopLabel = gtk.Label(_('Duration')) - self.XSlider3BottomLabelBox = gtk.HBox() - self.XSlider3Img = gtk.Image() + self.XYSlider3MainBox = Gtk.VBox() + self.XYSlider3TopLabel = Gtk.Label(_('Duration')) + self.XSlider3BottomLabelBox = Gtk.HBox() + self.XSlider3Img = Gtk.Image() self.XSlider3Img.set_from_file(Config.TAM_TAM_ROOT + '/icons/sideR.svg') - self.XSlider3BottomLabel = gtk.Label(_('Note duration')) - self.YSlider3BottomLabelBox = gtk.HBox() - self.YSlider3Img = gtk.Image() + self.XSlider3BottomLabel = Gtk.Label(_('Note duration')) + self.YSlider3BottomLabelBox = Gtk.HBox() + self.YSlider3Img = Gtk.Image() self.YSlider3Img.set_from_file(Config.TAM_TAM_ROOT + '/icons/updownR.svg') - self.YSlider3BottomLabel = gtk.Label(_('Silence density')) + self.YSlider3BottomLabel = Gtk.Label(_('Silence density')) self.XYSliderBox3 = RoundFixed(fillcolor = '#CCCCCC', bordercolor = '#000000') self.XYSliderBox3.set_size_request(200,200) self.XYButton3 = ImageToggleButton( Config.TAM_TAM_ROOT + '/icons/XYBut.svg', Config.TAM_TAM_ROOT + '/icons/XYButDown.svg') - self.XAdjustment3 = gtk.Adjustment(self.duration[0] * 100, 0, 100, 1, 1, 1) + self.XAdjustment3 = Gtk.Adjustment(self.duration[0] * 100, 0, 100, 1, 1, 1) self.XAdjustment3.connect("value-changed", self.handleXAdjustment3) - self.YAdjustment3 = gtk.Adjustment(self.silence[0] * 100, 0, 100, 1, 1, 1) + self.YAdjustment3 = Gtk.Adjustment(self.silence[0] * 100, 0, 100, 1, 1, 1) self.YAdjustment3.connect("value-changed", self.handleYAdjustment3) self.XYSlider3 = XYSlider( self.XYSliderBox3, self.XYButton3, self.XAdjustment3, self.YAdjustment3, False, True ) self.XSlider3BottomLabelBox.pack_start(self.XSlider3Img, False, False, padding = 5) @@ -467,15 +466,15 @@ class generationPalette(Palette): self.slidersBox.pack_start(self.XYSlider2MainBox, False, False, padding = 5) self.slidersBox.pack_start(self.XYSlider3MainBox, False, False, padding = 5) - self.previewBox = gtk.HBox() - self.previewDA = gtk.DrawingArea() + self.previewBox = Gtk.HBox() + self.previewDA = Gtk.DrawingArea() self.previewDA.set_size_request( -1, 100 ) self.previewDA.connect( "size-allocate", self.handlePreviewAlloc ) - self.previewDA.connect( "expose-event", self.handlePreviewExpose ) + self.previewDA.connect( "draw", self.handlePreviewExpose ) self.previewBox.pack_start( self.previewDA, True, True, padding = 5 ) - self.scaleBoxHBox = gtk.HBox() - self.scaleBoxLabel = gtk.Label(_('Scale: ')) + self.scaleBoxHBox = Gtk.HBox() + self.scaleBoxLabel = Gtk.Label(_('Scale: ')) self.scaleBox = BigComboBox() scales = [Tooltips.ALGO['majorKey'], Tooltips.ALGO['minorHarmKey'], Tooltips.ALGO['minorKey'], Tooltips.ALGO['phrygienKey'], @@ -486,8 +485,8 @@ class generationPalette(Palette): self.scaleBox.append_item(scales.index(scale), scale) self.scaleBox.connect('changed', self.handleScale) - self.modeBoxHBox = gtk.HBox() - self.modeBoxLabel = gtk.Label(_('Mode: ')) + self.modeBoxHBox = Gtk.HBox() + self.modeBoxLabel = Gtk.Label(_('Mode: ')) self.modeBox = BigComboBox() modes = [_('Drunk'), _('Drone and Jump'), _('Repeater'), _('Loop segments')] for mode in modes: @@ -516,44 +515,45 @@ class generationPalette(Palette): self.set_content(self.mainBox) + # Has to be converted to cairo drawing # -- Preview drawing ----------------------------------- - win = gtk.gdk.get_default_root_window() - self.gc = gtk.gdk.GC( win ) - self.parametersDirty = False - self.drawingPreview = False - self.predrawTarget = 0 - self.predrawIdleAbort = False - self.predrawBuffer = False + #win = Gdk.get_default_root_window() + #self.gc = gtk.gdk.GC( win ) + #self.parametersDirty = False + #self.drawingPreview = False + #self.predrawTarget = 0 + #self.predrawIdleAbort = False + #self.predrawBuffer = False # self.predrawBuffer is initialized in handlePreviewAlloc - pix = gtk.gdk.pixbuf_new_from_file(imagefile('sampleBG.png')) - self.sampleBg = gtk.gdk.Pixmap( win, pix.get_width(), pix.get_height() ) - self.sampleBg.draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE ) - self.sampleBg.endOffset = pix.get_width()-5 - self.sampleNoteHeight = 7 - if True: # load clipmask - pix = gtk.gdk.pixbuf_new_from_file(imagefile('sampleNoteMask.png')) - pixels = pix.get_pixels() - stride = pix.get_rowstride() - channels = pix.get_n_channels() - bitmap = "" - byte = 0 - shift = 0 - for j in range(pix.get_height()): - offset = stride*j - for i in range(pix.get_width()): - r = pixels[i*channels+offset] - if r != "\0": byte += 1 << shift - shift += 1 - if shift > 7: - bitmap += "%c" % byte - byte = 0 - shift = 0 - if shift > 0: - bitmap += "%c" % byte - byte = 0 - shift = 0 - self.sampleNoteMask = gtk.gdk.bitmap_create_from_data( None, bitmap, pix.get_width(), pix.get_height() ) - self.sampleNoteMask.endOffset = pix.get_width()-3 + #pix = gtk.gdk.pixbuf_new_from_file(imagefile('sampleBG.png')) + # self.sampleBg = gtk.gdk.Pixmap( win, pix.get_width(), pix.get_height() ) + # self.sampleBg.draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE ) + #self.sampleBg.endOffset = pix.get_width()-5 + #self.sampleNoteHeight = 7 + #if True: # load clipmask + # pix = gtk.gdk.pixbuf_new_from_file(imagefile('sampleNoteMask.png')) + # pixels = pix.get_pixels() + # stride = pix.get_rowstride() + # channels = pix.get_n_channels() + # bitmap = "" + # byte = 0 + # shift = 0 + # for j in range(pix.get_height()): + # offset = stride*j + # for i in range(pix.get_width()): + # r = pixels[i*channels+offset] + # if r != "\0": byte += 1 << shift + # shift += 1 + # if shift > 7: + # bitmap += "%c" % byte + # byte = 0 + # shift = 0 + # if shift > 0: + # bitmap += "%c" % byte + # byte = 0 + # shift = 0 + # self.sampleNoteMask = gtk.gdk.bitmap_create_from_data( None, bitmap, pix.get_width(), pix.get_##height() ) + # self.sampleNoteMask.endOffset = pix.get_width()-3 colormap = self.previewDA.get_colormap() self.colors = { "Beat_Line": colormap.alloc_color( "#959595", True, True ), @@ -755,7 +755,7 @@ class generationPalette(Palette): return True def handlePreviewAlloc( self, widget, allocation ): - win = gtk.gdk.get_default_root_window() + win = Gdk.get_default_root_window() self.previewDA.width = allocation.width self.previewDA.height = allocation.height self.predrawBuffer = [ gtk.gdk.Pixmap( win, allocation.width, allocation.height ), @@ -813,21 +813,21 @@ class propertiesPalette(Palette): self.pageIds = [] self.context = "page" - self.mainBox = gtk.VBox() + self.mainBox = Gtk.VBox() - self.gridDivisionBox = gtk.HBox() - self.gridDivisionLabel = gtk.Label(_('Grid division: ')) - self.gridDivisionSliderAdj = gtk.Adjustment(4, 2, 12, 1, 1, 0) - self.gridDivisionSlider = gtk.HScale(adjustment = self.gridDivisionSliderAdj) + self.gridDivisionBox = Gtk.HBox() + self.gridDivisionLabel = Gtk.Label(_('Grid division: ')) + self.gridDivisionSliderAdj = Gtk.Adjustment(4, 2, 12, 1, 1, 0) + self.gridDivisionSlider = Gtk.HScale(adjustment = self.gridDivisionSliderAdj) self.gridDivisionSlider.set_digits(0) self.gridDivisionSlider.connect('button-release-event', self.handleBeat) self.gridDivisionSlider.set_size_request(200,-1) - self.gridDivisionSlider.set_value_pos(gtk.POS_RIGHT) + self.gridDivisionSlider.set_value_pos(Gtk.POS_RIGHT) self.gridDivisionBox.pack_start(self.gridDivisionLabel, False, False, padding = 5) self.gridDivisionBox.pack_end(self.gridDivisionSlider, False, False, padding = 52) - self.pageColorBox = gtk.HBox() - self.pageColorLabel = gtk.Label(_('Page color: ')) + self.pageColorBox = Gtk.HBox() + self.pageColorLabel = Gtk.Label(_('Page color: ')) self.pageColorComboBox = BigComboBox() for color in (0,1,2,3): self.pageColorComboBox.append_item(color, text=None, @@ -839,16 +839,16 @@ class propertiesPalette(Palette): self.pageColorBox.pack_start(self.pageColorLabel, False, False, padding = 5) self.pageColorBox.pack_end(self.pageColorComboBox, False, False, padding = 55) - self.pageSeparator = gtk.HSeparator() + self.pageSeparator = Gtk.HSeparator() self.pageSeparator.set_size_request(20, -1) - self.transposeBox = gtk.HBox() - self.transposeLabel = gtk.Label(_('Transposition: ')) + self.transposeBox = Gtk.HBox() + self.transposeLabel = Gtk.Label(_('Transposition: ')) self.transposeDownButton = ImageButton(Config.TAM_TAM_ROOT + '/icons/arrow-down.svg') self.transposeDownButton.connect('clicked', self.stepPitch, -1) self.transposeUpButton = ImageButton(Config.TAM_TAM_ROOT + '/icons/arrow-up.svg') self.transposeUpButton.connect('clicked', self.stepPitch, 1) - self.transposeCheckButton = gtk.CheckButton() + self.transposeCheckButton = Gtk.CheckButton() self.transposeCheckButton.connect('toggled', self.handleGeneCheckButton) self.geneCheckButtonDic['transpose'] = self.transposeCheckButton self.transposeBox.pack_start(self.transposeLabel, False, False, padding = 5) @@ -856,13 +856,13 @@ class propertiesPalette(Palette): self.transposeBox.pack_end(self.transposeUpButton, False, False, padding = 50) self.transposeBox.pack_end(self.transposeDownButton, False, False, padding = 5) - self.volumeBox = gtk.HBox() - self.volumeLabel = gtk.Label(_('Volume') + ': ') + self.volumeBox = Gtk.HBox() + self.volumeLabel = Gtk.Label(_('Volume') + ': ') self.volumeDownButton = ImageButton(Config.TAM_TAM_ROOT + '/icons/arrow-down.svg') self.volumeDownButton.connect('clicked', self.stepVolume, -0.1) self.volumeUpButton = ImageButton(Config.TAM_TAM_ROOT + '/icons/arrow-up.svg') self.volumeUpButton.connect('clicked', self.stepVolume, 0.1) - self.volumeCheckButton = gtk.CheckButton() + self.volumeCheckButton = Gtk.CheckButton() self.volumeCheckButton.connect('toggled', self.handleGeneCheckButton) self.geneCheckButtonDic['volume'] = self.volumeCheckButton self.volumeBox.pack_start(self.volumeLabel, False, False, padding = 5) @@ -870,147 +870,147 @@ class propertiesPalette(Palette): self.volumeBox.pack_end(self.volumeUpButton, False, False, padding = 50) self.volumeBox.pack_end(self.volumeDownButton, False, False, padding = 5) - self.panBox = gtk.HBox() - self.panLabel = gtk.Label(_('Pan: ')) - self.panSliderAdj = gtk.Adjustment(0.5, 0, 1, .1, .1, 0) + self.panBox = Gtk.HBox() + self.panLabel = Gtk.Label(_('Pan: ')) + self.panSliderAdj = Gtk.Adjustment(0.5, 0, 1, .1, .1, 0) self.panSliderAdj.connect('value-changed', self.handlePan) - self.panSlider = gtk.HScale(adjustment = self.panSliderAdj) + self.panSlider = Gtk.HScale(adjustment = self.panSliderAdj) self.panSlider.set_size_request(200,-1) - self.panSlider.set_value_pos(gtk.POS_RIGHT) + #self.panSlider.set_value_pos(Gtk.POS_RIGHT) self.panSlider.set_digits(2) - self.panSlider.set_update_policy(gtk.UPDATE_DISCONTINUOUS) - self.panCheckButton = gtk.CheckButton() + #self.panSlider.set_update_policy(Gtk.UPDATE_DISCONTINUOUS) + self.panCheckButton = Gtk.CheckButton() self.panCheckButton.connect('toggled', self.handleGeneCheckButton) self.geneCheckButtonDic['pan'] = self.panCheckButton self.panBox.pack_start(self.panLabel, False, False, padding = 5) self.panBox.pack_end(self.panCheckButton, False, False, padding = 5) self.panBox.pack_end(self.panSlider, False, False, padding = 5) - self.reverbBox = gtk.HBox() - self.reverbLabel = gtk.Label(_('Reverb') + ': ') - self.reverbSliderAdj = gtk.Adjustment(0.1, 0, 1, 0.1, 0.1, 0) + self.reverbBox = Gtk.HBox() + self.reverbLabel = Gtk.Label(_('Reverb') + ': ') + self.reverbSliderAdj = Gtk.Adjustment(0.1, 0, 1, 0.1, 0.1, 0) self.reverbSliderAdj.connect("value-changed", self.handleReverb) - self.reverbSlider = gtk.HScale(adjustment = self.reverbSliderAdj) + self.reverbSlider = Gtk.HScale(adjustment = self.reverbSliderAdj) self.reverbSlider.set_size_request(200,-1) - self.reverbSlider.set_value_pos(gtk.POS_RIGHT) + #self.reverbSlider.set_value_pos(Gtk.POS_RIGHT) self.reverbSlider.set_digits(2) - self.reverbSlider.set_update_policy(gtk.UPDATE_DISCONTINUOUS) - self.reverbCheckButton = gtk.CheckButton() + #self.reverbSlider.set_update_policy(Gtk.UPDATE_DISCONTINUOUS) + self.reverbCheckButton = Gtk.CheckButton() self.reverbCheckButton.connect('toggled', self.handleGeneCheckButton) self.geneCheckButtonDic['reverb'] = self.reverbCheckButton self.reverbBox.pack_start(self.reverbLabel, False, False, padding = 5) self.reverbBox.pack_end(self.reverbCheckButton, False, False, padding = 5) self.reverbBox.pack_end(self.reverbSlider, False, False, padding = 5) - self.attackDurBox = gtk.HBox() - self.attackDurLabel = gtk.Label(_('Attack duration') + ': ') - self.attackDurSliderAdj = gtk.Adjustment(0.04, 0.03, 1, .01, .01, 0) + self.attackDurBox = Gtk.HBox() + self.attackDurLabel = Gtk.Label(_('Attack duration') + ': ') + self.attackDurSliderAdj = Gtk.Adjustment(0.04, 0.03, 1, .01, .01, 0) self.attackDurSliderAdj.connect('value-changed', self.handleAttack) - self.attackDurSlider = gtk.HScale(adjustment = self.attackDurSliderAdj) + self.attackDurSlider = Gtk.HScale(adjustment = self.attackDurSliderAdj) self.attackDurSlider.set_size_request(200,-1) - self.attackDurSlider.set_value_pos(gtk.POS_RIGHT) + #self.attackDurSlider.set_value_pos(gtk.POS_RIGHT) self.attackDurSlider.set_digits(2) - self.attackDurSlider.set_update_policy(gtk.UPDATE_DISCONTINUOUS) - self.attackDurCheckButton = gtk.CheckButton() + #self.attackDurSlider.set_update_policy(gtk.UPDATE_DISCONTINUOUS) + self.attackDurCheckButton = Gtk.CheckButton() self.attackDurCheckButton.connect('toggled', self.handleGeneCheckButton) self.geneCheckButtonDic['attack'] = self.attackDurCheckButton self.attackDurBox.pack_start(self.attackDurLabel, False, False, padding = 5) self.attackDurBox.pack_end(self.attackDurCheckButton, False, False, padding = 5) self.attackDurBox.pack_end(self.attackDurSlider, False, False, padding = 5) - self.decayDurBox = gtk.HBox() - self.decayDurLabel = gtk.Label(_('Decay duration') + ': ') - self.decayDurSliderAdj = gtk.Adjustment(0.31, 0.03, 1, .01, .01, 0) + self.decayDurBox = Gtk.HBox() + self.decayDurLabel = Gtk.Label(_('Decay duration') + ': ') + self.decayDurSliderAdj = Gtk.Adjustment(0.31, 0.03, 1, .01, .01, 0) self.decayDurSliderAdj.connect('value-changed', self.handleDecay) - self.decayDurSlider = gtk.HScale(adjustment = self.decayDurSliderAdj) + self.decayDurSlider = Gtk.HScale(adjustment = self.decayDurSliderAdj) self.decayDurSlider.set_size_request(200,-1) - self.decayDurSlider.set_value_pos(gtk.POS_RIGHT) + #self.decayDurSlider.set_value_pos(gtk.POS_RIGHT) self.decayDurSlider.set_digits(2) - self.decayDurSlider.set_update_policy(gtk.UPDATE_DISCONTINUOUS) - self.decayDurCheckButton = gtk.CheckButton() + #self.decayDurSlider.set_update_policy(gtk.UPDATE_DISCONTINUOUS) + self.decayDurCheckButton = Gtk.CheckButton() self.decayDurCheckButton.connect('toggled', self.handleGeneCheckButton) self.geneCheckButtonDic['decay'] = self.decayDurCheckButton self.decayDurBox.pack_start(self.decayDurLabel, False, False, padding = 5) self.decayDurBox.pack_end(self.decayDurCheckButton, False, False, padding = 5) self.decayDurBox.pack_end(self.decayDurSlider, False, False, padding = 5) - self.filterTypeBox = gtk.HBox() - self.filterTypeLabel = gtk.Label(_('Filter Type: ')) - self.filterTypeComboBox = BigComboBox() - for filtertype in self.filterTypes: - self.filterTypeComboBox.append_item(self.filterTypes.index(filtertype), filtertype) - self.filterTypeComboBox.connect('changed', self.handleFilterTypes) - self.filterTypeBox.pack_start(self.filterTypeLabel, False, False, padding = 5) - self.filterTypeBox.pack_end(self.filterTypeComboBox, False, False, padding = 55) + self.filterTypeBox = Gtk.HBox() + self.filterTypeLabel = Gtk.Label(_('Filter Type: ')) + #self.filterTypeComboBox = BigComboBox() + #for filtertype in self.filterTypes: + # self.filterTypeComboBox.append_item(self.filterTypes.index(filtertype), filtertype) + # self.filterTypeComboBox.connect('changed', self.handleFilterTypes) + #self.filterTypeBox.pack_start(self.filterTypeLabel, False, False, padding = 5) + #self.filterTypeBox.pack_end(self.filterTypeComboBox, False, False, padding = 55) - self.filterCutoffBox = gtk.HBox() + self.filterCutoffBox = Gtk.HBox() self.filterCutoffLabel = \ - gtk.Label(Tooltips.PROP['cutoffSlider'] + ': ') - self.filterCutoffSliderAdj = gtk.Adjustment(1000, 100, 7000, 100, 100, 0) + Gtk.Label(Tooltips.PROP['cutoffSlider'] + ': ') + self.filterCutoffSliderAdj = Gtk.Adjustment(1000, 100, 7000, 100, 100, 0) self.filterCutoffSliderAdj.connect('value-changed', self.handleFilter) - self.filterCutoffSlider = gtk.HScale(adjustment = self.filterCutoffSliderAdj) + self.filterCutoffSlider = Gtk.HScale(adjustment = self.filterCutoffSliderAdj) self.filterCutoffSlider.set_size_request(200,-1) - self.filterCutoffSlider.set_value_pos(gtk.POS_RIGHT) + s#elf.filterCutoffSlider.set_value_pos(gtk.POS_RIGHT) self.filterCutoffSlider.set_digits(0) - self.filterCutoffSlider.set_update_policy(gtk.UPDATE_DISCONTINUOUS) - self.filterCutoffCheckButton = gtk.CheckButton() + #self.filterCutoffSlider.set_update_policy(gtk.UPDATE_DISCONTINUOUS) + self.filterCutoffCheckButton = Gtk.CheckButton() self.filterCutoffCheckButton.connect('toggled', self.handleGeneCheckButton) self.geneCheckButtonDic['filter'] = self.filterCutoffCheckButton self.filterCutoffBox.pack_start(self.filterCutoffLabel, False, False, padding = 5) self.filterCutoffBox.pack_end(self.filterCutoffCheckButton, False, False, padding = 5) self.filterCutoffBox.pack_end(self.filterCutoffSlider, False, False, padding = 5) - self.generationMainBox = gtk.VBox() - self.generationSeparator = gtk.HSeparator() - self.generationLabel = gtk.Label(_('Generation')) - - self.generationTypeBox = gtk.HBox() - self.generationTypeLabel = gtk.Label(_('Type') + ': ') - self.generationTypeComboBox = BigComboBox() - for genetype in self.geneTypes: - self.generationTypeComboBox.append_item(self.geneTypes.index(genetype), genetype) - self.generationTypeComboBox.connect('changed', self.handleGeneTypes) - self.generationTypeComboBox.set_active(0) - self.generationTypeBox.pack_start(self.generationTypeLabel, False, False, padding = 5) - self.generationTypeBox.pack_end(self.generationTypeComboBox, False, False, padding = 55) - - self.minimumBox = gtk.HBox() - self.minimumLabel = gtk.Label(_('Minimum') + ': ') - self.minimumSliderAdj = gtk.Adjustment(0, 0, 100, 1, 1, 0) + self.generationMainBox = Gtk.VBox() + self.generationSeparator = Gtk.HSeparator() + self.generationLabel = Gtk.Label(_('Generation')) + + self.generationTypeBox = Gtk.HBox() + self.generationTypeLabel = Gtk.Label(_('Type') + ': ') + #self.generationTypeComboBox = BigComboBox() + #for genetype in self.geneTypes: + # self.generationTypeComboBox.append_item(self.geneTypes.index(genetype), genetype) + #self.generationTypeComboBox.connect('changed', self.handleGeneTypes) + #self.generationTypeComboBox.set_active(0) + #self.generationTypeBox.pack_start(self.generationTypeLabel, False, False, padding = 5) + #self.generationTypeBox.pack_end(self.generationTypeComboBox, False, False, padding = 55) + + self.minimumBox = Gtk.HBox() + self.minimumLabel = Gtk.Label(_('Minimum') + ': ') + self.minimumSliderAdj = Gtk.Adjustment(0, 0, 100, 1, 1, 0) self.minimumSliderAdj.connect('value-changed', self.handleMinimum) - self.minimumSlider = gtk.HScale(adjustment = self.minimumSliderAdj) + self.minimumSlider = Gtk.HScale(adjustment = self.minimumSliderAdj) self.minimumSlider.set_size_request(200,-1) - self.minimumSlider.set_update_policy(gtk.UPDATE_DISCONTINUOUS) - self.minimumSlider.set_value_pos(gtk.POS_RIGHT) + #self.minimumSlider.set_update_policy(gtk.UPDATE_DISCONTINUOUS) + #self.minimumSlider.set_value_pos(gtk.POS_RIGHT) self.minimumSlider.set_digits(0) self.minimumBox.pack_start(self.minimumLabel, False, False, padding = 5) self.minimumBox.pack_end(self.minimumSlider, False, False, padding = 52) - self.maximumBox = gtk.HBox() - self.maximumLabel = gtk.Label(_('Maximum') + ': ') - self.maximumSliderAdj = gtk.Adjustment(100, 0, 100, 1, 1, 0) + self.maximumBox = Gtk.HBox() + self.maximumLabel = Gtk.Label(_('Maximum') + ': ') + self.maximumSliderAdj = Gtk.Adjustment(100, 0, 100, 1, 1, 0) self.maximumSliderAdj.connect('value-changed', self.handleMaximum) - self.maximumSlider = gtk.HScale(adjustment = self.maximumSliderAdj) + self.maximumSlider = Gtk.HScale(adjustment = self.maximumSliderAdj) self.maximumSlider.set_size_request(200,-1) - self.maximumSlider.set_update_policy(gtk.UPDATE_DISCONTINUOUS) - self.maximumSlider.set_value_pos(gtk.POS_RIGHT) + #self.maximumSlider.set_update_policy(gtk.UPDATE_DISCONTINUOUS) + #self.maximumSlider.set_value_pos(gtk.POS_RIGHT) self.maximumSlider.set_digits(0) self.maximumBox.pack_start(self.maximumLabel, False, False, padding = 5) self.maximumBox.pack_end(self.maximumSlider, False, False, padding = 52) - self.randomBox = gtk.HBox() - self.randomLabel = gtk.Label(_('Random') + ': ') - self.randomSliderAdj = gtk.Adjustment(20, 0, 100, 1, 1, 0) + self.randomBox = Gtk.HBox() + self.randomLabel = Gtk.Label(_('Random') + ': ') + self.randomSliderAdj = Gtk.Adjustment(20, 0, 100, 1, 1, 0) self.randomSliderAdj.connect('value-changed', self.handleRandom) - self.randomSlider = gtk.HScale(adjustment = self.randomSliderAdj) + self.randomSlider = Gtk.HScale(adjustment = self.randomSliderAdj) self.randomSlider.set_size_request(200,-1) - self.randomSlider.set_update_policy(gtk.UPDATE_DISCONTINUOUS) - self.randomSlider.set_value_pos(gtk.POS_RIGHT) + #self.randomSlider.set_update_policy(gtk.UPDATE_DISCONTINUOUS) + #self.randomSlider.set_value_pos(gtk.POS_RIGHT) self.randomSlider.set_digits(0) self.randomBox.pack_start(self.randomLabel, False, False, padding = 5) self.randomBox.pack_end(self.randomSlider, False, False, padding = 52) - self.decisionBox = gtk.HBox() + self.decisionBox = Gtk.HBox() self.acceptButton = ImageButton(Config.TAM_TAM_ROOT + '/icons/accept.svg') self.acceptButton.connect('clicked', self.acceptGeneration) self.cancelButton = ImageButton(Config.TAM_TAM_ROOT + '/icons/cancel.svg') diff --git a/Edit/HitInterface.py b/Edit/HitInterface.py index 049c2b0..2c3572d 100644 --- a/Edit/HitInterface.py +++ b/Edit/HitInterface.py @@ -1,11 +1,13 @@ -import pygtk -pygtk.require( '2.0' ) -import gtk +from gi.repository import Gtk, Gdk +import cairo from common.Util.NoteDB import PARAMETER from Edit.NoteInterface import NoteInterface import common.Config as Config +def gdk_color_to_cairo(color): + return (color.red/65536.0, color.green/65536.0, color.blue/65536.0) + class HitInterface( NoteInterface ): def __init__( self, noteDB, owner, note ): @@ -92,7 +94,7 @@ class HitInterface( NoteInterface ): playSample = False - if event.type == gtk.gdk._2BUTTON_PRESS: # select bar + if event.type == Gdk.EventType._2BUTTON_PRESS: # select bar self.potentialDeselect = False start = 0 check = self.note.cs.onset - Config.TICKS_PER_BEAT @@ -180,16 +182,19 @@ class HitInterface( NoteInterface ): #======================================================= # Draw - def draw( self, win, gc, startX, stopX ): + def draw( self, surface, gc, startX, stopX ): if stopX < self.imgX: return False # we don't need to draw and no one after us will draw if startX > self.imgX + self.imgWidth: return True # we don't need to draw, but maybe a later note does - - gc.foreground = self.color - win.draw_rectangle( gc, True, self.x+2, self.y+2, self.width-4, self.height-4 ) + cxt = cairo.Context(surface) + cxt.set_source_rgb(*gdk_color_to_cairo(self.color)) + cxt.rectangle(self.x+2, self.y+2, self.width-4, self.height-4) + cxt.fill() if self.selected: img = self.imageSelected else: img = self.image - win.draw_pixbuf( gc, img, 0, 0, self.imgX, self.imgY, self.imgWidth, self.imgHeight, gtk.gdk.RGB_DITHER_NONE ) + cxt.set_source_surface(img, 0, 0) + cxt.paint() + #win.draw_pixbuf( gc, img, 0, 0, self.imgX, self.imgY, self.imgWidth, self.imgHeight, gtk.gdk.RGB_DITHER_NONE ) return True # we drew something diff --git a/Edit/MainWindow.py b/Edit/MainWindow.py index bcdf59e..7f15e09 100644 --- a/Edit/MainWindow.py +++ b/Edit/MainWindow.py @@ -1,34 +1,36 @@ -import pygtk -pygtk.require('2.0') -import gtk - -import gobject +from gi.repository import Gtk, Gdk, GdkPixbuf, GObject +import cairo import common.Util.Instruments import common.Util.InstrumentDB as InstrumentDB -from common.Util.ThemeWidgets import * +from common.Util.ThemeWidgets import RoundHBox, BigComboBox, ImageToggleButton from common.Util.Profiler import TP from common.Util import NoteDB from common.Util.NoteDB import PARAMETER from common.Util import ControlStream from common.Util.CSoundClient import new_csound_client from common.Util.CSoundNote import CSoundNote -from EditToolbars import common_buttons -from EditToolbars import mainToolbar -from EditToolbars import recordToolbar -from EditToolbars import generateToolbar -from EditToolbars import toolsToolbar +from common.Config import imagefile +#from EditToolbars import common_buttons +#from EditToolbars import mainToolbar +#from EditToolbars import recordToolbar +#from EditToolbars import generateToolbar +#from EditToolbars import toolsToolbar from gettext import gettext as _ from subprocess import Popen -from sugar.graphics.palette import Palette, Invoker -from sugar.datastore import datastore +from sugar3.graphics.palette import Palette, Invoker +from sugar3.datastore import datastore import time import os import commands import random from common.Util import OS from common.port.scrolledbox import HScrolledBox -from sugar.graphics import style +from sugar3.graphics import style +from sugar3.graphics.toolbarbox import ToolbarButton + +def gdk_color_to_cairo(color): + return (color.red/65536.0, color.green/65536.0, color.blue/65536.0) class CONTEXT: PAGE = 0 @@ -38,7 +40,7 @@ class CONTEXT: import common.Config as Config from common.Generation.GenerationConstants import GenerationConstants -from Edit.Properties import Properties +#from Edit.Properties import Properties from Edit.TrackInterface import TrackInterface, TrackInterfaceParasite from Edit.TuneInterface import TuneInterface, TuneInterfaceParasite @@ -55,13 +57,13 @@ DRUM_TRACK_SIZE = Config.scale(165) #----------------------------------- # The main TamTam window #----------------------------------- -class MainWindow(gtk.EventBox): +class MainWindow(Gtk.EventBox): def __init__( self, activity ): - gtk.EventBox.__init__(self) + Gtk.EventBox.__init__(self) self.instrumentDB = InstrumentDB.getRef() self.csnd = new_csound_client() - self.tooltips = gtk.Tooltips() + #self.tooltips = Gtk.Tooltips() self.activity = activity for i in [6,7,8,9,10]: @@ -130,7 +132,7 @@ class MainWindow(gtk.EventBox): def init_GUI(): self.GUI = {} - self.GUI["2main"] = gtk.VBox() + self.GUI["2main"] = Gtk.VBox() self.GUI["2instrumentPalette"] = instrumentPalette(_('Track 1 Volume'), self) def draw_inst_icons(): @@ -138,10 +140,9 @@ class MainWindow(gtk.EventBox): self.GUI["2instrumentIcons"] = {} for i in instruments: try: - pixbuf = gtk.gdk.pixbuf_new_from_file(i.img) + pixbuf = cairo.ImageSurface.create_from_png(i.img) except: - pixbuf = gtk.gdk.pixbuf_new_from_file( - imagefile('generic.png')) + pixbuf = cairo.ImageSurface.create_from_png(imagefile('generic.png')) self.GUI['2instrumentIcons'][i.name] = pixbuf TP.ProfileBegin("init_GUI::instrument icons") draw_inst_icons() @@ -150,22 +151,22 @@ class MainWindow(gtk.EventBox): #------------------------------------------------------------------------ # page - self.GUI["2page"] = gtk.HBox() - self.scrollWin = gtk.ScrolledWindow() - self.scrollWin.set_policy(gtk.POLICY_NEVER,gtk.POLICY_AUTOMATIC) + self.GUI["2page"] = Gtk.HBox() + self.scrollWin = Gtk.ScrolledWindow() + self.scrollWin.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self.scrollWin.add_with_viewport(self.GUI["2page"]) - self.GUI["2main"].pack_start( self.scrollWin, True ) + self.GUI["2main"].pack_start( self.scrollWin, True , True, 0) if 1: # + instrument panel - self.GUI["2instrumentPanel"] = gtk.VBox() - self.GUI["2page"].pack_start( self.GUI["2instrumentPanel"], True ) + self.GUI["2instrumentPanel"] = Gtk.VBox() + self.GUI["2page"].pack_start( self.GUI["2instrumentPanel"], True, True, 0 ) # + + instrument 1 box self.GUI["2instrument1Box"] = formatRoundBox( RoundHBox(), Config.BG_COLOR ) self.GUI["2instrument1Box"].set_size_request(-1, TRACK_SIZE) - self.GUI["2instrument1volBox"] = gtk.VBox() - #self.GUI["2instrument1volumeAdjustment"] = gtk.Adjustment( self._data["track_volume"][1], 0, 100, 1, 1, 0 ) + self.GUI["2instrument1volBox"] = Gtk.VBox() + #self.GUI["2instrument1volumeAdjustment"] = Gtk.Adjustment( self._data["track_volume"][1], 0, 100, 1, 1, 0 ) #self.GUI["2instrument1volumeAdjustment"].connect( "value_changed", self.onTrackVolumeChanged, 0 ) - #self.GUI["2instrument1volumeSlider"] = gtk.VScale(self.GUI["2instrument1volumeAdjustment"]) + #self.GUI["2instrument1volumeSlider"] = Gtk.VScale(self.GUI["2instrument1volumeAdjustment"]) #self.GUI["2instrument1volumeSlider"].set_draw_value(False) #self.GUI["2instrument1volumeSlider"].set_inverted(True) #self.GUI["2instrument1volumeSlider"].set_size_request( 30, -1 ) @@ -181,15 +182,15 @@ class MainWindow(gtk.EventBox): self.GUI["2instrument1Button"] = InstrumentButton( self, 0, Config.BG_COLOR ) self.GUI["2instrument1Button"].connect('button-release-event',self.GUI["2instrumentPalette"].setBlock, 0) self.GUI["2instrument1Button"].setPrimary( self.GUI["2instrumentIcons"][self.trackInstrument[0].name] ) - self.GUI["2instrument1Box"].pack_start( self.GUI["2instrument1Button"], padding = 3 ) - self.GUI["2instrumentPanel"].pack_start( self.GUI["2instrument1Box"] ) + self.GUI["2instrument1Box"].pack_start( self.GUI["2instrument1Button"], expand=True, fill=True, padding = 3 ) + self.GUI["2instrumentPanel"].add( self.GUI["2instrument1Box"] ) # + + instrument 2 box self.GUI["2instrument2Box"] = formatRoundBox( RoundHBox(), Config.BG_COLOR ) self.GUI["2instrument2Box"].set_size_request(-1, TRACK_SIZE) - self.GUI["2instrument2volBox"] = gtk.VBox() - #self.GUI["2instrument2volumeAdjustment"] = gtk.Adjustment( self._data["track_volume"][1], 0, 100, 1, 1, 0 ) + self.GUI["2instrument2volBox"] = Gtk.VBox() + #self.GUI["2instrument2volumeAdjustment"] = Gtk.Adjustment( self._data["track_volume"][1], 0, 100, 1, 1, 0 ) #self.GUI["2instrument2volumeAdjustment"].connect( "value_changed", self.onTrackVolumeChanged, 1 ) - #self.GUI["2instrument2volumeSlider"] = gtk.VScale(self.GUI["2instrument2volumeAdjustment"]) + #self.GUI["2instrument2volumeSlider"] = Gtk.VScale(self.GUI["2instrument2volumeAdjustment"]) #self.GUI["2instrument2volumeSlider"].set_draw_value(False) #self.GUI["2instrument2volumeSlider"].set_inverted(True) #self.GUI["2instrument2volumeSlider"].set_size_request( 30, -1 ) @@ -205,15 +206,15 @@ class MainWindow(gtk.EventBox): self.GUI["2instrument2Button"] = InstrumentButton( self, 1, Config.BG_COLOR ) self.GUI["2instrument2Button"].connect('button-release-event',self.GUI["2instrumentPalette"].setBlock, 1) self.GUI["2instrument2Button"].setPrimary( self.GUI["2instrumentIcons"][self.trackInstrument[1].name] ) - self.GUI["2instrument2Box"].pack_start( self.GUI["2instrument2Button"], padding = 3 ) - self.GUI["2instrumentPanel"].pack_start( self.GUI["2instrument2Box"] ) + self.GUI["2instrument2Box"].pack_start( self.GUI["2instrument2Button"], expand=True,fill=True, padding =3 ) + self.GUI["2instrumentPanel"].add( self.GUI["2instrument2Box"] ) # + + instrument 3 box self.GUI["2instrument3Box"] = formatRoundBox( RoundHBox(), Config.BG_COLOR ) self.GUI["2instrument3Box"].set_size_request(-1, TRACK_SIZE) - self.GUI["2instrument3volBox"] = gtk.VBox() - #self.GUI["2instrument3volumeAdjustment"] = gtk.Adjustment( self._data["track_volume"][2], 0, 100, 1, 1, 0 ) + self.GUI["2instrument3volBox"] = Gtk.VBox() + #self.GUI["2instrument3volumeAdjustment"] = Gtk.Adjustment( self._data["track_volume"][2], 0, 100, 1, 1, 0 ) #self.GUI["2instrument3volumeAdjustment"].connect( "value_changed", self.onTrackVolumeChanged, 2 ) - #self.GUI["2instrument3volumeSlider"] = gtk.VScale(self.GUI["2instrument3volumeAdjustment"]) + #self.GUI["2instrument3volumeSlider"] = Gtk.VScale(self.GUI["2instrument3volumeAdjustment"]) #self.GUI["2instrument3volumeSlider"].set_draw_value(False) #self.GUI["2instrument3volumeSlider"].set_inverted(True) #elf.GUI["2instrument3volumeSlider"].set_size_request( 30, -1 ) @@ -229,15 +230,15 @@ class MainWindow(gtk.EventBox): self.GUI["2instrument3Button"] = InstrumentButton( self, 2, Config.BG_COLOR ) self.GUI["2instrument3Button"].connect('button-release-event',self.GUI["2instrumentPalette"].setBlock, 2) self.GUI["2instrument3Button"].setPrimary( self.GUI["2instrumentIcons"][self.trackInstrument[2].name] ) - self.GUI["2instrument3Box"].pack_start( self.GUI["2instrument3Button"], padding = 3 ) - self.GUI["2instrumentPanel"].pack_start( self.GUI["2instrument3Box"] ) + self.GUI["2instrument3Box"].pack_start( self.GUI["2instrument3Button"], expand=True,fill=True, padding = 3 ) + self.GUI["2instrumentPanel"].add( self.GUI["2instrument3Box"] ) # + + instrument 4 box self.GUI["2instrument4Box"] = formatRoundBox( RoundHBox(), Config.BG_COLOR ) self.GUI["2instrument4Box"].set_size_request(-1, TRACK_SIZE) - self.GUI["2instrument4volBox"] = gtk.VBox() - #self.GUI["2instrument4volumeAdjustment"] = gtk.Adjustment( self._data["track_volume"][3], 0, 100, 1, 1, 0 ) + self.GUI["2instrument4volBox"] = Gtk.VBox() + #self.GUI["2instrument4volumeAdjustment"] = Gtk.Adjustment( self._data["track_volume"][3], 0, 100, 1, 1, 0 ) #self.GUI["2instrument4volumeAdjustment"].connect( "value_changed", self.onTrackVolumeChanged, 3 ) - #self.GUI["2instrument4volumeSlider"] = gtk.VScale(self.GUI["2instrument4volumeAdjustment"]) + #self.GUI["2instrument4volumeSlider"] = Gtk.VScale(self.GUI["2instrument4volumeAdjustment"]) #self.GUI["2instrument4volumeSlider"].set_draw_value(False) #self.GUI["2instrument4volumeSlider"].set_inverted(True) #self.GUI["2instrument4volumeSlider"].set_size_request( 30, -1 ) @@ -253,15 +254,15 @@ class MainWindow(gtk.EventBox): self.GUI["2instrument4Button"] = InstrumentButton( self, 3, Config.BG_COLOR ) self.GUI["2instrument4Button"].connect('button-release-event',self.GUI["2instrumentPalette"].setBlock, 3) self.GUI["2instrument4Button"].setPrimary( self.GUI["2instrumentIcons"][self.trackInstrument[3].name] ) - self.GUI["2instrument4Box"].pack_start( self.GUI["2instrument4Button"], padding = 3 ) - self.GUI["2instrumentPanel"].pack_start( self.GUI["2instrument4Box"] ) + self.GUI["2instrument4Box"].pack_start( self.GUI["2instrument4Button"], expand=True,fill=True, padding = 3 ) + self.GUI["2instrumentPanel"].add( self.GUI["2instrument4Box"] ) # + + drum box self.GUI["2drumBox"] = formatRoundBox( RoundHBox(), Config.BG_COLOR ) self.GUI["2drumBox"].set_size_request(-1, DRUM_TRACK_SIZE) - self.GUI["2drumVolBox"] = gtk.VBox() - self.GUI["2drumvolumeAdjustment"] = gtk.Adjustment( self._data["track_volume"][4], 0, 100, 1, 1, 0 ) + self.GUI["2drumVolBox"] = Gtk.VBox() + self.GUI["2drumvolumeAdjustment"] = Gtk.Adjustment( self._data["track_volume"][4], 0, 100, 1, 1, 0 ) self.GUI["2drumvolumeAdjustment"].connect( "value_changed", self.onTrackVolumeChanged, 4 ) - #self.GUI["2drumvolumeSlider"] = gtk.VScale(self.GUI["2drumvolumeAdjustment"]) + #self.GUI["2drumvolumeSlider"] = Gtk.VScale(self.GUI["2drumvolumeAdjustment"]) #self.GUI["2drumvolumeSlider"].set_draw_value(False) #self.GUI["2drumvolumeSlider"].set_inverted(True) #self.GUI["2drumvolumeSlider"].set_size_request( 30, -1 ) @@ -280,35 +281,37 @@ class MainWindow(gtk.EventBox): self.GUI["2drumPalette"] = drumPalette(_('Track 5 Properties'), self, 4) self.GUI["2drumButton"].connect("toggled", self.pickDrum) self.GUI["2drumButton"].connect('button-release-event',self.GUI["2drumPalette"].setBlock) - self.GUI["2drumBox"].pack_start( self.GUI["2drumButton"] ) - self.GUI["2instrumentPanel"].pack_start( self.GUI["2drumBox"] ) - self.GUI["2page"].pack_start( self.GUI["2instrumentPanel"], True ) + self.GUI["2drumBox"].add( self.GUI["2drumButton"] ) + self.GUI["2instrumentPanel"].add( self.GUI["2drumBox"] ) + self.GUI["2page"].add( self.GUI["2instrumentPanel"]) # + track interface - tracks_width = gtk.gdk.screen_width() - int(TRACK_SIZE * 1.25) + tracks_width = Gdk.Screen.width() - int(TRACK_SIZE * 1.25) self.trackInterface = TrackInterface( self.noteDB, self, self.getScale, tracks_width) self.noteDB.addListener( self.trackInterface, TrackInterfaceParasite, True ) self.trackInterface.set_size_request(tracks_width, -1) - self.GUI["2page"].pack_start( self.trackInterface, False ) + self.GUI["2page"].pack_start( self.trackInterface, False, True, 0) #------------------------------------------------------------------------ # tune interface + # Commented out by Aaron if 1: # + tune interface self.GUI["2tuneScrolledWindow"] = HScrolledBox() self.tuneInterface = TuneInterface( self.noteDB, self, self.GUI["2tuneScrolledWindow"].get_adjustment() ) self.noteDB.addListener( self.tuneInterface, TuneInterfaceParasite, True ) self.GUI["2tuneScrolledWindow"].set_viewport( self.tuneInterface ) - self.tuneInterface.get_parent().set_shadow_type( gtk.SHADOW_NONE ) + self.tuneInterface.get_parent().set_shadow_type( Gtk.ShadowType.NONE ) self.GUI["2tuneScrolledWindow"].set_size_request(-1, Config.PAGE_THUMBNAIL_HEIGHT + style.DEFAULT_PADDING * 2) - self.GUI["2tuneScrolledWindow"].modify_bg(gtk.STATE_NORMAL, + self.GUI["2tuneScrolledWindow"].modify_bg(Gtk.StateType.NORMAL, style.Color(Config.TOOLBAR_BCK_COLOR).get_gdk_color()) - self.GUI["2main"].pack_start( self.GUI["2tuneScrolledWindow"], False, True ) + self.GUI["2main"].pack_start( self.GUI["2tuneScrolledWindow"], False, True, 0 ) # set tooltips for key in self.GUI: if Tooltips.Edit.has_key(key): - self.tooltips.set_tip(self.GUI[key],Tooltips.Edit[key]) + pass + #self.tooltips.set_tip(self.GUI[key],Tooltips.Edit[key]) self.add( self.GUI["2main"] ) @@ -336,21 +339,21 @@ class MainWindow(gtk.EventBox): #TP.ProfileEnd("init_GUI::propertiesPanel") #self.GUI["9propertiesPopup"].add( self.propertiesPanel ) # + playback scope - self.GUI["9loopPopup"] = gtk.Window(gtk.WINDOW_POPUP) + self.GUI["9loopPopup"] = Gtk.Window(Gtk.WindowType.POPUP) self.GUI["9loopPopup"].move( 100, 100 ) self.GUI["9loopPopup"].resize( 300, 100 ) self.GUI["9loopPopup"].set_modal(True) - self.GUI["9loopPopup"].add_events( gtk.gdk.BUTTON_PRESS_MASK ) + #self.GUI["9loopPopup"].add_events( gtk.gdk.BUTTON_PRESS_MASK ) self.GUI["9loopPopup"].connect("button-release-event", lambda w,e:self.GUI["2loopButton"].set_active(False) ) self.GUI["9loopBox"] = formatRoundBox( RoundHBox(), Config.BG_COLOR ) - self.GUI["9loopAllOnce"] = gtk.Button("AO") - self.GUI["9loopBox"].pack_start( self.GUI["9loopAllOnce"] ) - self.GUI["9loopAllRepeat"] = gtk.Button("AR") - self.GUI["9loopBox"].pack_start( self.GUI["9loopAllRepeat"] ) - self.GUI["9loopSelectedOnce"] = gtk.Button("SO") - self.GUI["9loopBox"].pack_start( self.GUI["9loopSelectedOnce"] ) - self.GUI["9loopSelectedRepeat"] = gtk.Button("SR") - self.GUI["9loopBox"].pack_start( self.GUI["9loopSelectedRepeat"] ) + self.GUI["9loopAllOnce"] = Gtk.Button("AO") + self.GUI["9loopBox"].add( self.GUI["9loopAllOnce"] ) + self.GUI["9loopAllRepeat"] = Gtk.Button("AR") + self.GUI["9loopBox"].add( self.GUI["9loopAllRepeat"] ) + self.GUI["9loopSelectedOnce"] = Gtk.Button("SO") + self.GUI["9loopBox"].add( self.GUI["9loopSelectedOnce"] ) + self.GUI["9loopSelectedRepeat"] = Gtk.Button("SR") + self.GUI["9loopBox"].add( self.GUI["9loopSelectedRepeat"] ) self.GUI["9loopPopup"].add(self.GUI["9loopBox"]) TP.ProfileEnd("init_GUI::popups") @@ -404,62 +407,64 @@ class MainWindow(gtk.EventBox): # Toolbar if Config.HAVE_TOOLBOX: - from sugar.graphics.toolbarbox import ToolbarButton - - common_buttons(self.activity.toolbox.toolbar, self) - self._activity_toolbar = self.activity.toolbox.toolbar - self._play_button = self.activity.toolbox.toolbar.playButton - self._stop_button = self.activity.toolbox.toolbar.stopButton - - separator = gtk.SeparatorToolItem() - separator.props.draw = True - separator.set_expand(False) - self.activity.toolbox.toolbar.insert(separator, -1) - - self._generateToolbar = generateToolbar(self) - self._generateToolbar.show() - generate_toolbar_button = ToolbarButton(label=_('Generate'), - page=self._generateToolbar, - icon_name='diceB') - generate_toolbar_button.show() - self.activity.toolbox.toolbar.insert(generate_toolbar_button, -1) - - self._recordToolbar = recordToolbar(self) - self._recordToolbar.show() - record_toolbar_button = ToolbarButton(label=_('Record'), - page=self._recordToolbar, - icon_name='media-record') - record_toolbar_button.show() - self.activity.toolbox.toolbar.insert(record_toolbar_button, -1) - self._record_button = self._recordToolbar.recordButton - - self._toolsToolbar = toolsToolbar(self) - self._toolsToolbar.show() - tools_toolbar_button = ToolbarButton(label=_('Tools'), - page=self._toolsToolbar, - icon_name='preferences-system') - tools_toolbar_button.show() - self.activity.toolbox.toolbar.insert(tools_toolbar_button, -1) - - separator = gtk.SeparatorToolItem() - separator.props.draw = False - separator.set_expand(True) - self.activity.toolbox.toolbar.insert(separator, -1) + pass + #from sugar.graphics.toolbarbox import ToolbarButton + + #common_buttons(self.activity.toolbox.toolbar, self) + #self._activity_toolbar = self.activity.toolbox.toolbar + #self._play_button = self.activity.toolbox.toolbar.playButton + #self._stop_button = self.activity.toolbox.toolbar.stopButton + + #separator = Gtk.SeparatorToolItem() + #separator.props.draw = True + #separator.set_expand(False) + #self.activity.toolbox.toolbar.insert(separator, -1) + + #self._generateToolbar = generateToolbar(self) + #self._generateToolbar.show() + #generate_toolbar_button = ToolbarButton(label=_('Generate'), + # page=self._generateToolbar, + # icon_name='diceB') + #generate_toolbar_button.show() + #self.activity.toolbox.toolbar.insert(generate_toolbar_button, -1) + + #self._recordToolbar = recordToolbar(self) + #self._recordToolbar.show() + #record_toolbar_button = ToolbarButton(label=_('Record'), + # page=self._recordToolbar, + # icon_name='media-record') + #record_toolbar_button.show() + #self.activity.toolbox.toolbar.insert(record_toolbar_button, -1) + #self._record_button = self._recordToolbar.recordButton + + #self._toolsToolbar = toolsToolbar(self) + #self._toolsToolbar.show() + #tools_toolbar_button = ToolbarButton(label=_('Tools'), + # page=self._toolsToolbar, + # icon_name='preferences-system') + #tools_toolbar_button.show() + #self.activity.toolbox.toolbar.insert(tools_toolbar_button, -1) + + #separator = Gtk.SeparatorToolItem() + #separator.props.draw = False + #separator.set_expand(True) + #self.activity.toolbox.toolbar.insert(separator, -1) else: - self._mainToolbar = mainToolbar(self) - self._mainToolbar.show() - self.activity.toolbox.add_toolbar(_('Compose'), self._mainToolbar) - self._activity_toolbar = self._mainToolbar - self._play_button = self._mainToolbar.playButton - self._stop_button = self._mainToolbar.stopButton - - self._toolsToolbar = toolsToolbar(self) - self._toolsToolbar.show() - self.activity.toolbox.add_toolbar(_('Tools'), - self._toolsToolbar) - self._record_button = self._toolsToolbar.recordButton - - self.activity.toolbox.set_current_toolbar(1) + pass + #self._mainToolbar = mainToolbar(self) + #self._mainToolbar.show() + #self.activity.toolbox.add_toolbar(_('Compose'), self._mainToolbar) + #self._activity_toolbar = self._mainToolbar + #self._play_button = self._mainToolbar.playButton + #self._stop_button = self._mainToolbar.stopButton + + #self._toolsToolbar = toolsToolbar(self) + #self._toolsToolbar.show() + #self.activity.toolbox.add_toolbar(_('Tools'), + # self._toolsToolbar) + #self._record_button = self._toolsToolbar.recordButton + + #self.activity.toolbox.set_current_toolbar(1) self.show_all() #gtk command @@ -668,7 +673,8 @@ class MainWindow(gtk.EventBox): def handlePlay(self, widget = None): if widget: - widget.event(gtk.gdk.Event(gtk.gdk.LEAVE_NOTIFY)) # fake the leave event + pass + #widget.event(gtk.gdk.Event(gtk.gdk.LEAVE_NOTIFY)) # fake the leave event if self.audioRecordWidget: filename = Config.TMP_DIR + "/perf.wav" @@ -770,7 +776,8 @@ class MainWindow(gtk.EventBox): def handleStop(self, widget = None, rewind = True): if widget: - widget.event(gtk.gdk.Event(gtk.gdk.LEAVE_NOTIFY)) # fake the leave event + pass + #widget.event(gtk.gdk.Event(gtk.gdk.LEAVE_NOTIFY)) # fake the leave event if self.audioRecordWidget: filename = Config.TMP_DIR + "/perf.wav" @@ -1469,11 +1476,11 @@ class MainWindow(gtk.EventBox): def handleSave(self, widget = None): - chooser = gtk.FileChooserDialog( + chooser = Gtk.FileChooserDialog( title='Save Tune', - action=gtk.FILE_CHOOSER_ACTION_SAVE, - buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_SAVE,gtk.RESPONSE_OK)) - filter = gtk.FileFilter() + action=Gtk.FileChooserAction.SAVE, + buttons=(Gtk.STOCK_CANCEL,Gtk.ResponeType.CANCEL,Gtk.STOCK_SAVE,Gtk.ResponseType.OK)) + filter = Gtk.FileFilter() filter.add_pattern('*.tam') chooser.set_filter(filter) chooser.set_current_folder(Config.DATA_DIR) @@ -1481,7 +1488,7 @@ class MainWindow(gtk.EventBox): for f in chooser.list_shortcut_folder_uris(): chooser.remove_shortcut_folder_uri(f) - if chooser.run() == gtk.RESPONSE_OK: + if chooser.run() == Gtk.ResponseType.OK: ofilename = chooser.get_filename() if ofilename[-4:] != '.tam': ofilename += '.tam' @@ -1539,12 +1546,12 @@ class MainWindow(gtk.EventBox): print 'ERROR: failed to open file %s for reading\n' % ofilename def handleLoad(self, widget): - chooser = gtk.FileChooserDialog( + chooser = Gtk.FileChooserDialog( title='Load Tune', - action=gtk.FILE_CHOOSER_ACTION_OPEN, - buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) + action=Gtk.FileChooserAction.OPEN, + buttons=(Gtk.STOCK_CANCEL,Gtk.ResponseType.CANCEL,Gtk.STOCK_OPEN,Gtk.ResponseType.OK)) - filter = gtk.FileFilter() + filter = Gtk.FileFilter() filter.add_pattern('*.tam') chooser.set_filter(filter) chooser.set_current_folder(Config.DATA_DIR) @@ -1552,7 +1559,7 @@ class MainWindow(gtk.EventBox): for f in chooser.list_shortcut_folder_uris(): chooser.remove_shortcut_folder_uri(f) - if chooser.run() == gtk.RESPONSE_OK: + if chooser.run() == Gtk.ResponseType.OK: print 'DEBUG: loading file: ', chooser.get_filename() self._loadFile( chooser.get_filename() ) @@ -1883,10 +1890,10 @@ class MainWindow(gtk.EventBox): self.context = context - if self.context == CONTEXT.NOTE: - self._generateToolbar.generationButton.set_sensitive(False) - else: - self._generateToolbar.generationButton.set_sensitive(True) + #if self.context == CONTEXT.NOTE: + # self._generateToolbar.generationButton.set_sensitive(False) + #else: + # self._generateToolbar.generationButton.set_sensitive(True) def getContext(self): return self.context @@ -1924,24 +1931,20 @@ class MainWindow(gtk.EventBox): return "Tam-Tam [Volume %i, Tempo %i, Beats/Page %i]" % (self.getVolume(), self.getTempo(), self.getBeatsPerPage()) -class InstrumentButton(gtk.DrawingArea): +class InstrumentButton(Gtk.DrawingArea): def __init__(self, owner, index, backgroundFill): - gtk.DrawingArea.__init__(self) + Gtk.DrawingArea.__init__(self) self.index = index self.owner = owner - self.win = gtk.gdk.get_default_root_window() - self.gc = gtk.gdk.GC( self.win ) - - colormap = self.get_colormap() - self.color = { "background": colormap.alloc_color( backgroundFill, True, True ), - "divider": colormap.alloc_color( "#000", True, True ), - "+/-": colormap.alloc_color( Config.FG_COLOR, True, True ), - "+/-Highlight": colormap.alloc_color( "#FFF", True, True ) } + self.color = { "background": Gdk.Color.parse(backgroundFill)[1], + "divider": Gdk.Color.parse("#000")[1], + "+/-": Gdk.Color.parse('#818286')[1], + "+/-Highlight": Gdk.Color.parse("#FFF")[1] } - self.pixmap = None + self.surface = None self.primary = None self.primaryWidth = self.primaryHeight = 1 self.secondary = None @@ -1950,22 +1953,22 @@ class InstrumentButton(gtk.DrawingArea): self.clicked = None self.hover = None - self.add_events( gtk.gdk.BUTTON_PRESS_MASK - | gtk.gdk.BUTTON_RELEASE_MASK - | gtk.gdk.POINTER_MOTION_MASK - | gtk.gdk.POINTER_MOTION_HINT_MASK - | gtk.gdk.LEAVE_NOTIFY_MASK - | gtk.gdk.ENTER_NOTIFY_MASK ) + self.add_events( Gdk.EventMask.BUTTON_PRESS_MASK + | Gdk.EventMask.BUTTON_RELEASE_MASK + | Gdk.EventMask.POINTER_MOTION_MASK + | Gdk.EventMask.POINTER_MOTION_HINT_MASK + | Gdk.EventMask.LEAVE_NOTIFY_MASK + | Gdk.EventMask.ENTER_NOTIFY_MASK ) self.connect( "size-allocate", self.size_allocate ) self.connect( "button-press-event", self.button_press ) self.connect( "button-release-event", self.button_release ) self.connect( "motion-notify-event", self.motion_notify ) self.connect( "leave-notify-event", self.leave_notify ) - self.connect( "expose-event", self.expose ) + self.connect( "draw", self.expose ) def size_allocate(self, widget, allocation): self.alloc = allocation - self.pixmap = gtk.gdk.Pixmap(self.win, allocation.width, allocation.height) + self.surface = cairo.ImageSurface(cairo.FORMAT_RGB24, allocation.width, allocation.height) self.primaryX = (self.alloc.width - self.primaryWidth) // 2 self.primaryY = (self.alloc.height - self.primaryHeight) // 2 self.secondaryX = (self.alloc.width - self.secondaryWidth) // 2 @@ -1980,21 +1983,21 @@ class InstrumentButton(gtk.DrawingArea): self._updatePixmap() def button_press(self, widget, event): - self.clicked = "PRIMARY" self.hover = None + x, y = widget.get_pointer() - if event.x >= self.hotspots[0][0] and event.x <= self.hotspots[0][2] \ - and event.y >= self.hotspots[0][1] and event.y <= self.hotspots[0][3]: + if x >= self.hotspots[0][0] and x <= self.hotspots[0][2] \ + and y >= self.hotspots[0][1] and y <= self.hotspots[0][3]: self.clicked = "HOTSPOT_0" elif self.secondary != None: - if event.x >= self.hotspots[1][0] and event.x <= self.hotspots[1][2] \ - and event.y >= self.hotspots[1][1] and event.y <= self.hotspots[1][3]: + if x >= self.hotspots[1][0] and x <= self.hotspots[1][2] \ + and y >= self.hotspots[1][1] and y <= self.hotspots[1][3]: self.clicked = "HOTSPOT_1" - elif event.y > self.alloc.height//2: + elif y > self.alloc.height//2: self.clicked = "SECONDARY" def button_release(self, widget, event): @@ -2017,22 +2020,24 @@ class InstrumentButton(gtk.DrawingArea): if self.clicked != None: return - if event.is_hint: - x, y, state = widget.window.get_pointer() - event.x = float(x) - event.y = float(y) - event.state = state + x, y = widget.get_pointer() + + #if event.is_hint: + # x, y, state = widget.window.get_pointer() + # event.x = float(x) + # event.y = float(y) + # event.state = state - if event.x >= self.hotspots[0][0] and event.x <= self.hotspots[0][2] \ - and event.y >= self.hotspots[0][1] and event.y <= self.hotspots[0][3]: + if x >= self.hotspots[0][0] and x <= self.hotspots[0][2] \ + and y >= self.hotspots[0][1] and y <= self.hotspots[0][3]: if self.hover != "HOTSPOT_0": self.hover = "HOTSPOT_0" self.queue_draw() elif self.secondary != None \ - and event.x >= self.hotspots[1][0] and event.x <= self.hotspots[1][2] \ - and event.y >= self.hotspots[1][1] and event.y <= self.hotspots[1][3]: + and x >= self.hotspots[1][0] and x <= self.hotspots[1][2] \ + and y >= self.hotspots[1][1] and y <= self.hotspots[1][3]: if self.hover != "HOTSPOT_1": self.hover = "HOTSPOT_1" self.queue_draw() @@ -2042,7 +2047,7 @@ class InstrumentButton(gtk.DrawingArea): self.queue_draw() def leave_notify( self, widget, event ): - if event.mode != gtk.gdk.CROSSING_NORMAL: + if event.mode != Gdk.CrossingMode.NORMAL: return if self.hover != None: self.hover = None @@ -2051,10 +2056,11 @@ class InstrumentButton(gtk.DrawingArea): def setPrimary(self, img): + # img is a cairo.ImageSurface self.primary = img self.primaryWidth = img.get_width() self.primaryHeight = img.get_height() - if self.pixmap: + if self.surface: self.primaryX = (self.alloc.width - self.primaryWidth) // 2 self.primaryY = (self.alloc.height - self.primaryHeight) // 2 self._updatePixmap() @@ -2065,46 +2071,59 @@ class InstrumentButton(gtk.DrawingArea): self.secondaryWidth = img.get_width() self.secondaryHeight = img.get_height() self.secondaryOffset = self.secondaryHeight//2 - if self.pixmap: + if self.surface: self.secondaryX = (self.alloc.width - self.secondaryWidth) // 2 self.secondaryY = self.alloc.height//2 - if self.pixmap: + if self.surface: self._updatePixmap() def _updatePixmap(self): - self.gc.foreground = self.color["background"] - self.pixmap.draw_rectangle(self.gc, True, 0, 0, self.alloc.width, self.alloc.height) + cxt = cairo.Context(self.surface) + cxt.set_source_rgb(*gdk_color_to_cairo(self.color["background"])) + cxt.rectangle(0, 0, self.alloc.width, self.alloc.height) + cxt.fill() if self.secondary != None: - self.pixmap.draw_pixbuf(self.gc, self.primary, 0, 0, self.primaryX, self.primaryY, self.primaryWidth, self.primaryHeight//2, gtk.gdk.RGB_DITHER_NONE) - self.pixmap.draw_pixbuf(self.gc, self.secondary, 0, self.secondaryOffset, self.secondaryX, self.secondaryY, self.secondaryWidth, self.secondaryHeight//2, gtk.gdk.RGB_DITHER_NONE) - self.gc.foreground = self.color["divider"] - self.gc.set_line_attributes(2, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER) - self.pixmap.draw_line(self.gc, 2, self.alloc.height//2, self.alloc.width-4, self.alloc.height//2) + cxt.set_source_surface(self.primary, 0, 0) + cxt.set_source_surface(self.secondary, 0, self.secondaryOffset) + cxt.paint() + cxt.set_source_rgb(*gdk_color_to_cairo(self.color["divider"])) + #self.gc.set_line_attributes(2, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER) + cxt.move_to(2, self.alloc.height//2) + cxt.line_to(self.alloc.width-4, self.alloc.height//2) + cxt.stroke() else: - self.pixmap.draw_pixbuf(self.gc, self.primary, 0, 0, self.primaryX, self.primaryY, self.primaryWidth, self.primaryHeight, gtk.gdk.RGB_DITHER_NONE) + cxt.set_source_surface(self.primary, 0, 0) + cxt.paint() self.queue_draw() - def expose(self, widget, event): - self.window.draw_drawable(self.gc, self.pixmap, 0, 0, 0, 0, self.alloc.width, self.alloc.height) - self.gc.set_line_attributes(4, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_MITER) + def expose(self, widget, cr): + cr.set_source_surface(self.surface, 0, 0) + cr.paint() + cr.set_line_width(4) + #self.gc.set_line_attributes(4, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_MITER) if self.secondary != None: if self.clicked == "HOTSPOT_0" or (self.clicked == None and self.hover == "HOTSPOT_0" ): - self.gc.foreground = self.color["+/-Highlight"] + cr.set_source_rgb(*gdk_color_to_cairo(self.color["+/-Highlight"])) else: - self.gc.foreground = self.color["+/-"] - self.window.draw_line( self.gc, self.hotspots[0][0], self.hotspots[0][5], self.hotspots[0][2], self.hotspots[0][5] ) + cr.set_source_rgb(*gdk_color_to_cairo(self.color["+/-"])) + cr.move_to(self.hotspots[0][0], self.hotspots[0][5]) + cr.line_to(self.hotspots[0][2], self.hotspots[0][5]) if self.clicked == "HOTSPOT_1" or (self.clicked == None and self.hover == "HOTSPOT_1" ): - self.gc.foreground = self.color["+/-Highlight"] + cr.set_source_rgb(*gdk_color_to_cairo(self.color["+/-Highlight"])) else: - self.gc.foreground = self.color["+/-"] - self.window.draw_line( self.gc, self.hotspots[1][0], self.hotspots[1][5], self.hotspots[1][2], self.hotspots[1][5] ) + cr.set_source_rgb(*gdk_color_to_cairo(self.color["+/-"])) + cr.move_to(self.hotspots[1][0], self.hotspots[1][5]) + cr.line_to(self.hotspots[1][2], self.hotspots[1][5]) else: if self.clicked == "HOTSPOT_0" or self.hover == "HOTSPOT_0": - self.gc.foreground = self.color["+/-Highlight"] + cr.set_source_rgb(*gdk_color_to_cairo(self.color["+/-Highlight"])) else: - self.gc.foreground = self.color["+/-"] - self.window.draw_line(self.gc, self.hotspots[0][0], self.hotspots[0][5], self.hotspots[0][2], self.hotspots[0][5]) - self.window.draw_line(self.gc, self.hotspots[0][4], self.hotspots[0][1], self.hotspots[0][4], self.hotspots[0][3]) + cr.set_source_rgb(*gdk_color_to_cairo(self.color["+/-"])) + cr.move_to(self.hotspots[0][0], self.hotspots[0][5]) + cr.line_to(self.hotspots[0][2], self.hotspots[0][5]) + cr.move_to(self.hotspots[0][4], self.hotspots[0][1]) + cr.line_to(self.hotspots[0][4], self.hotspots[0][3]) + cr.stroke() def set_palette(self, palette): pass @@ -2117,7 +2136,7 @@ class NoneInvoker(Invoker): self._position_hint = Invoker.AT_CURSOR def get_rect(self): - return gtk.gdk.Rectangle(0, 0, 0, 0) + return Gdk.Rectangle() def get_toplevel(self): return None @@ -2134,8 +2153,8 @@ class Popup(Palette): self.props.invoker = NoneInvoker() self.set_group_id( "TamTamPopup" ) - self.connect( "key-press-event", self.on_key_press ) - self.connect( "key-release-event", self.on_key_release ) + self.connect( "activate", self.on_key_press ) + self.connect( "activate", self.on_key_release ) #self.connect( "focus_out_event", self.closePopup ) @@ -2189,28 +2208,28 @@ class instrumentPalette(Popup): self.skipVolAdj = False self.lastClickedTrack = None - self.tooltips = gtk.Tooltips() + #self.tooltips = gtk.Tooltips() - self.mainBox = gtk.VBox() - self.volumeBox = gtk.HBox() - self.instrumentMainBox = gtk.HBox() + self.mainBox = Gtk.VBox() + self.volumeBox = Gtk.HBox() + self.instrumentMainBox = Gtk.HBox() - self.muteButtonLabel = gtk.Label(_('M')) - self.muteButton = gtk.CheckButton() + self.muteButtonLabel = Gtk.Label(_('M')) + self.muteButton = Gtk.CheckButton() self.muteButton.connect("toggled",self.handlemuteButton) self.muteButton.set_active(True) - self.tooltips.set_tip(self.muteButton, _('Mute track')) + #self.tooltips.set_tip(self.muteButton, _('Mute track')) - self.soloButtonLabel = gtk.Label(_('S')) - self.soloButton = gtk.CheckButton() + self.soloButtonLabel = Gtk.Label(_('S')) + self.soloButton = Gtk.CheckButton() self.soloButton.connect("toggled",self.handlesoloButton) self.soloButton.set_active(True) - self.tooltips.set_tip(self.soloButton, _('Solo track')) + #self.tooltips.set_tip(self.soloButton, _('Solo track')) - self.volumeSliderAdj = gtk.Adjustment( self.edit._data["track_volume"][0], 0, 100, 1, 1, 0 ) + self.volumeSliderAdj = Gtk.Adjustment( self.edit._data["track_volume"][0], 0, 100, 1, 1, 0 ) self.volumeSliderAdj.connect( "value-changed", self.handleTrackVolume) - self.volumeSlider = gtk.HScale(adjustment = self.volumeSliderAdj) + self.volumeSlider = Gtk.HScale(adjustment = self.volumeSliderAdj) self.volumeSlider.set_size_request(250, -1) self.volumeSlider.set_inverted(False) self.volumeSlider.set_draw_value(False) @@ -2221,15 +2240,15 @@ class instrumentPalette(Popup): image = imagefile(category.lower() + '.png') if not os.path.isfile(image): image = imagefile('generic.png') - self.categoryBox.append_item(category, category.capitalize(), - icon_name = image, size = instrumentPalette.ICON_SIZE) + #self.categoryBox.append_item(category, category.capitalize(), + # icon_name = image, size = instrumentPalette.ICON_SIZE) self.categoryBox.connect('changed', self.handleCategoryChange) self.icons = [] for i in self.instrumentDB.inst: if not i.kit and not i.kitStage: - self.icons.append([i, gtk.gdk.pixbuf_new_from_file_at_size( + self.icons.append([i, GdkPixbuf.Pixbuf.new_from_file_at_size( i.img, instrumentPalette.ICON_SIZE[0], instrumentPalette.ICON_SIZE[1])]) @@ -2237,15 +2256,15 @@ class instrumentPalette(Popup): self.instrumentBox1 = BigComboBox() self.instrumentBox1.connect('changed', self.handleInstrumentChange) - self.volumeBox.pack_start(self.muteButtonLabel, padding = 5) - self.volumeBox.pack_start(self.muteButton, padding = 5) + self.volumeBox.pack_start(self.muteButtonLabel, expand=True, fill=True, padding = 5) + self.volumeBox.pack_start(self.muteButton, expand=True, fill=True, padding = 5) #self.volumeBox.pack_start(self.soloButtonLabel, padding = 5) #self.volumeBox.pack_start(self.soloButton, padding = 5) - self.volumeBox.pack_start(self.volumeSlider, padding = 5) - self.mainBox.pack_start(self.volumeBox, padding = 5) - self.instrumentMainBox.pack_start(self.categoryBox, padding = 5) - self.instrumentMainBox.pack_start(self.instrumentBox1, padding = 5) - self.mainBox.pack_start(self.instrumentMainBox, padding = 5) + self.volumeBox.pack_start(self.volumeSlider, expand=True, fill=True, padding=5) + self.mainBox.pack_start(self.volumeBox, expand=True, fill=True, padding=5) + self.instrumentMainBox.pack_start(self.categoryBox, expand=True, fill=True, padding=5) + self.instrumentMainBox.pack_start(self.instrumentBox1, expand=True, fill=True, padding=5) + self.mainBox.pack_start(self.instrumentMainBox, expand=True, fill=True, padding=5) self.mainBox.show_all() self.set_content(self.mainBox) @@ -2280,7 +2299,7 @@ class instrumentPalette(Popup): for i in self.icons: if category == 'all' or i[0].category == category: - self.instrumentBox1.append_item(i[0].name, None, pixbuf = i[1]) + #self.instrumentBox1.append_item(i[0].name, None, pixbuf = i[1]) self.instruments.append(i[0].name) if not self.skip: @@ -2318,24 +2337,24 @@ class drumPalette(Popup): self.skip = False - self.tooltips = gtk.Tooltips() + #self.tooltips = gtk.Tooltips() - self.mainBox = gtk.VBox() - self.volumeBox = gtk.HBox() - self.instrumentMainBox = gtk.HBox() + self.mainBox = Gtk.VBox() + self.volumeBox = Gtk.HBox() + self.instrumentMainBox = Gtk.HBox() - self.muteButton = gtk.CheckButton() + self.muteButton = Gtk.CheckButton() self.muteButton.connect("toggled",self.edit.handlemuteButton, self.trackID) self.muteButton.connect("button-press-event",self.edit.handlemuteButtonRightClick, self.trackID) self.muteButton.set_active(True) - self.tooltips.set_tip(self.muteButton, _('Left click to mute, right click to solo')) + #self.tooltips.set_tip(self.muteButton, _('Left click to mute, right click to solo')) if self.trackID < 4: exec "self.volumeSliderAdj = self.edit.GUI['2instrument%svolumeAdjustment']" % str(self.trackID+1) else: self.volumeSliderAdj = self.edit.GUI["2drumvolumeAdjustment"] self.volumeSliderAdj.connect( "value-changed", self.edit.handleTrackVolume, self.trackID) - self.volumeSlider = gtk.HScale(adjustment = self.volumeSliderAdj) + self.volumeSlider = Gtk.HScale(adjustment = self.volumeSliderAdj) self.volumeSlider.set_size_request(250, -1) self.volumeSlider.set_inverted(False) self.volumeSlider.set_draw_value(False) @@ -2346,11 +2365,11 @@ class drumPalette(Popup): self.loadDrumMenu(self.getDrums()) self.drumBox.connect('changed', self.handleInstrumentChange) - self.volumeBox.pack_start(self.muteButton, padding = 5) - self.volumeBox.pack_start(self.volumeSlider, padding = 5) - self.mainBox.pack_start(self.volumeBox, padding = 5) + self.volumeBox.pack_start(self.muteButton, expand=True, fill=True, padding = 5) + self.volumeBox.pack_start(self.volumeSlider, expand=True, fill=True, padding = 5) + self.mainBox.pack_start(self.volumeBox, expand=True, fill=True, padding = 5) self.instrumentMainBox.pack_start(self.drumBox, False, False, padding = 5) - self.mainBox.pack_start(self.instrumentMainBox, padding = 5) + self.mainBox.pack_start(self.instrumentMainBox, expand=True, fill=True, padding = 5) self.mainBox.show_all() self.set_content(self.mainBox) @@ -2369,12 +2388,12 @@ class drumPalette(Popup): self.skip = False def loadDrumMenu(self, instruments): - self.drumBox.remove_all() + self.drumBox.clear() for instrument in instruments: image = imagefile(instrument + '.png') if not os.path.isfile(image): image = imagefile('generic.png') - self.drumBox.append_item(instrument, text = None, icon_name = image, size = instrumentPalette.ICON_SIZE) + #self.drumBox.append_item(instrument, text = None, icon_name = image, size = instrumentPalette.ICON_SIZE) def getDrums(self): return sorted([instrument for instrument in self.instrumentDB.instNamed.keys() if self.instrumentDB.instNamed[instrument].kit]) diff --git a/Edit/NoteInterface.py b/Edit/NoteInterface.py index 9dc4247..2547176 100644 --- a/Edit/NoteInterface.py +++ b/Edit/NoteInterface.py @@ -1,19 +1,20 @@ -import pygtk -pygtk.require( '2.0' ) -import gtk +from gi.repository import Gtk, Gdk, GObject +import cairo import common.Config as Config from common.Util.NoteDB import PARAMETER from common.Util.CSoundClient import new_csound_client +def gdk_color_to_cairo(color): + return (color.red/65536.0, color.green/65536.0, color.blue/65536.0) + class NoteInterface: def __init__( self, noteDB, owner, note ): self.noteDB = noteDB self.owner = owner self.note = note - self.origin = self.owner.getTrackOrigin( note.track ) self.firstTransform = True self.x = 0 @@ -37,7 +38,7 @@ class NoteInterface: self.lastDragP = 0 self.lastDragD = 0 - self.image, self.imageSelected, self.colormap, self.baseColors = self.owner.getDrawingPackage( note.track ) + self.image, self.imageSelected, self.baseColors = self.owner.getDrawingPackage( note.track ) self.updateParameter( None, None ) @@ -54,7 +55,9 @@ class NoteInterface: r = self.baseColors[0][0] + int(self.baseColors[1][0]*self.note.cs.amplitude) g = self.baseColors[0][1] + int(self.baseColors[1][1]*self.note.cs.amplitude) b = self.baseColors[0][2] + int(self.baseColors[1][2]*self.note.cs.amplitude) - self.color = self.colormap.alloc_color( r, g, b, True, True ) # TODO potential memory leak? + #self.color = self.colormap.alloc_color( r, g, b, True, True ) # TODO potential memory leak? + print r, g, b + self.color = Gdk.Color(r, g, b) self.oldAmplitude = self.note.cs.amplitude self.updateTransform() @@ -329,17 +332,22 @@ class NoteInterface: #======================================================= # Draw - def draw( self, win, gc, startX, stopX ): + def draw(self, surface, gc, startX, stopX ): if stopX < self.imgX: return False # we don't need to draw and no one after us will draw if startX > self.imgX + self.imgWidth: return True # we don't need to draw, but maybe a later note does - - gc.foreground = self.color - win.draw_rectangle( gc, True, self.x+1, self.y+1, self.width-2, self.height-2 ) + cxt = cairo.Context(surface) + cxt.set_source_rgb(*gdk_color_to_cairo(self.color)) + cxt.rectangle(self.x+1, self.y+1, self.width-2, self.height-2 ) + cxt.fill() if self.selected: img = self.imageSelected else: img = self.image - win.draw_pixbuf( gc, img, 0, 0, self.imgX, self.imgY, self.imgWidth-Config.NOTE_IMAGE_ENDLENGTH, self.imgHeight, gtk.gdk.RGB_DITHER_NONE ) - win.draw_pixbuf( gc, img, Config.NOTE_IMAGE_TAIL, 0, self.imgX+self.imgWidth-Config.NOTE_IMAGE_ENDLENGTH, self.imgY, Config.NOTE_IMAGE_ENDLENGTH, self.imgHeight, gtk.gdk.RGB_DITHER_NONE ) + #win.draw_pixbuf( gc, img, 0, 0, self.imgX, self.imgY, self.imgWidth-Config.NOTE_IMAGE_ENDLENGTH, self.imgHeight, gtk.gdk.RGB_DITHER_NONE ) + cxt.set_source_surface(img, 0, 0) + cxt.paint() + cxt.set_source_surface(img, Config.NOTE_IMAGE_TAIL, 0) + cxt.paint() + #win.draw_pixbuf( gc, img, Config.NOTE_IMAGE_TAIL, 0, self.imgX+self.imgWidth-Config.NOTE_IMAGE_ENDLENGTH, self.imgY, Config.NOTE_IMAGE_ENDLENGTH, self.imgHeight, gtk.gdk.RGB_DITHER_NONE ) return True # we drew something diff --git a/Edit/TrackInterface.py b/Edit/TrackInterface.py index 73f70df..2e6e9b3 100644 --- a/Edit/TrackInterface.py +++ b/Edit/TrackInterface.py @@ -1,8 +1,5 @@ -import pygtk -pygtk.require( '2.0' ) -import gtk - -import gobject +from gi.repository import Gtk, Gdk, GObject +import cairo from math import floor import time @@ -18,6 +15,17 @@ from common.Util.CSoundNote import CSoundNote from common.Generation.GenerationConstants import GenerationConstants from common.Util.Profiler import TP +def gdk_color_to_cairo(color): + return (color.red/65536.0, color.green/65536.0, color.blue/65536.0) + +def gdk_rect(x, y, width, height): + r = Gdk.Rectangle() + r.x = x + r.y = y + r.width = width + r.height = height + return r + class SELECTNOTES: ALL = -1 NONE = 0 @@ -43,19 +51,19 @@ class TrackInterfaceParasite: def attach( self ): return self.parasite -class TrackInterface( gtk.EventBox ): +class TrackInterface( Gtk.EventBox ): def __init__( self, noteDB, owner, getScaleFunction, width ): - gtk.EventBox.__init__( self ) + Gtk.EventBox.__init__( self ) self.noteDB = noteDB self.owner = owner self.getScale = getScaleFunction - self.drawingArea = gtk.DrawingArea() + self.drawingArea = Gtk.DrawingArea() self.drawingAreaDirty = False # are we waiting to draw? self.add( self.drawingArea ) - self.dirtyRectToAdd = gtk.gdk.Rectangle() # used by the invalidate_rect function + self.dirtyRectToAdd = Gdk.Rectangle() # used by the invalidate_rect function self.fullWidth = 1 # store the maximum allowed width self.width = 1 @@ -93,19 +101,19 @@ class TrackInterface( gtk.EventBox ): self.cursor = { \ "default": None, \ - "drag-onset": gtk.gdk.Cursor(gtk.gdk.SB_RIGHT_ARROW), \ - "drag-pitch": gtk.gdk.Cursor(gtk.gdk.BOTTOM_SIDE), \ - "drag-duration": gtk.gdk.Cursor(gtk.gdk.RIGHT_SIDE), \ - "drag-playhead": gtk.gdk.Cursor(gtk.gdk.SB_H_DOUBLE_ARROW), \ - "pencil": gtk.gdk.Cursor(gtk.gdk.PENCIL), \ - "paste": gtk.gdk.Cursor(gtk.gdk.CENTER_PTR), \ + "drag-onset": Gdk.Cursor(Gdk.CursorType.SB_RIGHT_ARROW), \ + "drag-pitch": Gdk.Cursor(Gdk.CursorType.BOTTOM_SIDE), \ + "drag-duration": Gdk.Cursor(Gdk.CursorType.RIGHT_SIDE), \ + "drag-playhead": Gdk.Cursor(Gdk.CursorType.SB_H_DOUBLE_ARROW), \ + "pencil": Gdk.Cursor(Gdk.CursorType.PENCIL), \ + "paste": Gdk.Cursor(Gdk.CursorType.CENTER_PTR), \ "error": None } - self.add_events(gtk.gdk.POINTER_MOTION_MASK|gtk.gdk.POINTER_MOTION_HINT_MASK) + self.add_events(Gdk.EventMask.POINTER_MOTION_MASK|Gdk.EventMask.POINTER_MOTION_HINT_MASK) self.connect( "size-allocate", self.size_allocate ) - self.drawingArea.connect( "expose-event", self.expose ) + self.drawingArea.connect( "draw", self.expose ) self.connect( "button-press-event", self.handleButtonPress ) self.connect( "button-release-event", self.handleButtonRelease ) self.connect( "motion-notify-event", self.handleMotion ) @@ -119,23 +127,26 @@ class TrackInterface( gtk.EventBox ): delta = ( high[0]-low[0], high[1]-low[1], high[2]-low[2] ) self.trackColors.append( (low, delta) ) - colormap = self.drawingArea.get_colormap() - self.beatColor = colormap.alloc_color( Config.BEAT_COLOR, True, True ) - self.playheadColor = colormap.alloc_color( Config.PLAYHEAD_COLOR, True, True ) - self.marqueeColor = colormap.alloc_color( Config.MARQUEE_COLOR, True, True ) + #colormap = self.drawingArea.get_colormap() + self.beatColor = Gdk.Color.parse(Config.BEAT_COLOR)[1] + self.playheadColor = Gdk.Color.parse(Config.PLAYHEAD_COLOR)[1] + self.marqueeColor = Gdk.Color.parse(Config.MARQUEE_COLOR)[1] self.image = {} - win = gtk.gdk.get_default_root_window() - self.gc = gtk.gdk.GC( win ) def prepareDrawable( name, width = -1 ): - pix = gtk.gdk.pixbuf_new_from_file(imagefile(name + '.png')) - if width != -1: - pix = pix.scale_simple(width, pix.get_height(), gtk.gdk.INTERP_BILINEAR) - self.image[name] = gtk.gdk.Pixmap( win, pix.get_width(), pix.get_height() ) - self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE ) + #pix = cairo.ImageSurface.create_from_png(imagefile(name + '.png')) + path = "common/Resources/Images/" + pix = cairo.ImageSurface.create_from_png(path + name + '.png') + self.image[name] = pix + #if width != -1: + # pix = pix.scale_simple(width, pix.get_height(), gtk.gdk.INTERP_BILINEAR) + #self.image[name] = gtk.gdk.Pixmap( win, pix.get_width(), pix.get_height() ) + #self.image[name].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE ) + def preparePixbuf( name ): - self.image[name] = gtk.gdk.pixbuf_new_from_file(imagefile(name + '.png')) + path = "common/Resources/Images/" + self.image[name] = cairo.ImageSurface.create_from_png(path + name + '.png') prepareDrawable( "trackBG", width ) prepareDrawable( "trackBGSelected", width ) @@ -149,9 +160,9 @@ class TrackInterface( gtk.EventBox ): # define dimensions self.width = self.trackFullWidth = width self.trackWidth = self.width - Config.TRACK_SPACING - self.trackFullHeight = self.image["trackBG"].get_size()[1] + self.trackFullHeight = self.image["trackBG"].get_height() self.trackHeight = self.trackFullHeight - Config.TRACK_SPACING - self.trackFullHeightDrum = self.image["trackBGDrum"].get_size()[1] + self.trackFullHeightDrum = self.image["trackBGDrum"].get_height() self.trackHeightDrum = self.trackFullHeightDrum - Config.TRACK_SPACING self.height = self.trackHeight*(Config.NUMBER_OF_TRACKS-1) + self.trackHeightDrum + Config.TRACK_SPACING*Config.NUMBER_OF_TRACKS self.trackLimits = [] @@ -160,9 +171,9 @@ class TrackInterface( gtk.EventBox ): for i in range(self.drumIndex): start = i*(self.trackFullHeight) self.trackLimits.append( (start,start+self.trackFullHeight) ) - self.trackRect.append( gtk.gdk.Rectangle(Config.TRACK_SPACING_DIV2,start+Config.TRACK_SPACING_DIV2, self.trackWidth, self.trackHeight ) ) + self.trackRect.append( gdk_rect(Config.TRACK_SPACING_DIV2,start+Config.TRACK_SPACING_DIV2, self.trackWidth, self.trackHeight ) ) self.trackLimits.append( ( self.height - self.trackFullHeightDrum, self.height ) ) - self.trackRect.append( gtk.gdk.Rectangle( Config.TRACK_SPACING_DIV2, self.height - self.trackFullHeightDrum + Config.TRACK_SPACING_DIV2, self.trackWidth, self.trackHeightDrum ) ) + self.trackRect.append( gdk_rect( Config.TRACK_SPACING_DIV2, self.height - self.trackFullHeightDrum + Config.TRACK_SPACING_DIV2, self.trackWidth, self.trackHeightDrum ) ) self.pitchPerPixel = float(Config.NUMBER_OF_POSSIBLE_PITCHES-1) / (self.trackHeight - Config.NOTE_HEIGHT) self.pixelsPerPitch = float(self.trackHeight-Config.NOTE_HEIGHT)/(Config.MAXIMUM_PITCH - Config.MINIMUM_PITCH) @@ -178,11 +189,11 @@ class TrackInterface( gtk.EventBox ): self.beatSpacing.append( [ self.ticksToPixels( i, Config.TICKS_PER_BEAT*j ) for j in range(i) ] ) # screen buffers - self.screenBuf = [ gtk.gdk.Pixmap( win, self.width, self.height ), \ - gtk.gdk.Pixmap( win, self.width, self.height ) ] + self.screenBuf = [ cairo.ImageSurface(cairo.FORMAT_RGB24, self.width, self.height), \ + cairo.ImageSurface(cairo.FORMAT_RGB24, self.width, self.height) ] self.screenBufPage = [ -1, -1 ] self.screenBufBeats = [ -1, -1 ] - self.screenBufDirtyRect = [ gtk.gdk.Rectangle(), gtk.gdk.Rectangle() ] + self.screenBufDirtyRect = [ Gdk.Rectangle(), Gdk.Rectangle() ] self.screenBufDirty = [ False, False ] self.screenBufResume = [ [0,0], [0,0] ] # allows for stopping and restarting in the middle of a draw self.curScreen = 0 @@ -239,9 +250,9 @@ class TrackInterface( gtk.EventBox ): def getDrawingPackage( self, track ): if track == self.drumIndex: - return ( self.image["hit"], self.image["hitSelected"], self.drawingArea.get_colormap(), self.trackColors[track] ) + return ( self.image["hit"], self.image["hitSelected"], self.trackColors[track] ) else: - return ( self.image["note"], self.image["noteSelected"], self.drawingArea.get_colormap(), self.trackColors[track] ) + return ( self.image["note"], self.image["noteSelected"], self.trackColors[track] ) def getActivePages( self ): return self.screenBufPage @@ -257,11 +268,11 @@ class TrackInterface( gtk.EventBox ): def predrawPage( self ): if self.screenBufPage[self.preScreen] == -1: return True # no page to predraw if not self.predrawTimeout: - self.predrawTimeout = gobject.timeout_add( 50, self._predrawTimeout ) + self.predrawTimeout = GObject.timeout_add( 50, self._predrawTimeout ) def abortPredrawPage( self ): if self.predrawTimeout: - gobject.source_remove( self.predrawTimeout ) + GObject.source_remove( self.predrawTimeout ) self.predrawTimeout = False def _predrawTimeout( self ): @@ -354,8 +365,8 @@ class TrackInterface( gtk.EventBox ): self.drawingArea.set_size_request( width, height ) - if self.window != None: - self.invalidate_rect( 0, 0, width, height, self.curPage, False ) + #if self.window != None: + # self.invalidate_rect( 0, 0, width, height, self.curPage, False ) def setPointerGrid(self, value): self.pointerGrid = value @@ -375,11 +386,11 @@ class TrackInterface( gtk.EventBox ): self.clickButton = event.button - if event.type == gtk.gdk._2BUTTON_PRESS: self.buttonPressCount = 2 - elif event.type == gtk.gdk._3BUTTON_PRESS: self.buttonPressCount = 3 + if event.type == Gdk.EventType._2BUTTON_PRESS: self.buttonPressCount = 2 + elif event.type == Gdk.EventType._3BUTTON_PRESS: self.buttonPressCount = 3 else: self.buttonPressCount = 1 - self.clickLoc = [ int(event.x), int(event.y) ] + self.clickLoc = [ int(widget.get_pointer()[0] ), int(widget.get_pointer()[1] ) ] if self.curAction == "paste": @@ -404,21 +415,21 @@ class TrackInterface( gtk.EventBox ): if self.trackLimits[i][1] < event.y: continue handled = 0 - notes = self.noteDB.getNotesByTrack( self.curPage, i, self ) - last = len(notes)-1 - for n in range(last+1): - if i == self.drumIndex and n < last: # check to see if the next hit overlaps this one - if notes[n].getStartTick() == notes[n+1].getStartTick() and notes[n].getPitch() == notes[n+1].getPitch(): - continue - handled = notes[n].handleButtonPress( self, event ) - if handled == 0: - continue - elif handled == 1: - if not self.curAction: self.curAction = True # it was handled but no action was declared, set curAction to True anyway - TP.ProfileEnd( "TI::handleButtonPress" ) - return - else: # all other options mean we can stop looking - break + #notes = self.noteDB.getNotesByTrack( self.curPage, i, self ) + #last = len(notes)-1 + #for n in range(last+1): + # if i == self.drumIndex and n < last: # check to see if the next hit overlaps this one + # if notes[n].getStartTick() == notes[n+1].getStartTick() and notes[n].getPitch() == notes[n+1].getPitch(): + # continue + # handled = notes[n].handleButtonPress( self, event ) + # if handled == 0: + # continue + # elif handled == 1: + # if not self.curAction: self.curAction = True # it was handled but no action was declared, set curAction to True anyway + # TP.ProfileEnd( "TI::handleButtonPress" ) + # return + # else: # all other options mean we can stop looking + # break if self.interfaceMode == INTERFACEMODE.DRAW: if not handled or handled == -1: # event didn't overlap any notes, so we can draw @@ -439,10 +450,10 @@ class TrackInterface( gtk.EventBox ): self.selectNotes( { i:[n] }, True ) n.playSampleNote( False ) - noteS = self.noteDB.getNotesByTrack(self.curPage, i) - for note in noteS: - if note.cs.onset < snapOnset and (note.cs.onset + note.cs.duration) > snapOnset: - self.noteDB.updateNote(self.curPage, i, note.id, PARAMETER.DURATION, snapOnset - note.cs.onset) + #noteS = self.noteDB.getNotesByTrack(self.curPage, i) + #for note in noteS: + # if note.cs.onset < snapOnset and (note.cs.onset + note.cs.duration) > snapOnset: + # self.noteDB.updateNote(self.curPage, i, note.id, PARAMETER.DURATION, snapOnset - note.cs.onset) if i != self.drumIndex: # switch to drag duration self.updateDragLimits() @@ -562,15 +573,16 @@ class TrackInterface( gtk.EventBox ): def handleMotion( self, widget, event ): TP.ProfileBegin( "TI::handleMotion::Common" ) - if event.is_hint: - x, y, state = self.window.get_pointer() + #if event.is_hint: + if True: + x, y = widget.get_pointer() event.x = float(x) event.y = float(y) - event.state = state + #event.state = state if self.painting: i = self.paintTrack - curPos = self.pixelsToTicksFloor(self.curBeats, event.x - self.trackRect[i].x) + curPos = self.pixelsToTicksFloor(self.curBeats, x - self.trackRect[i].x) gridPos = self.paintGrid * int(curPos / self.paintGrid + 0.5) if gridPos >= self.curBeats * Config.TICKS_PER_BEAT: return @@ -1145,13 +1157,13 @@ class TrackInterface( gtk.EventBox ): if self.trackLimits[i][0] > event.y: break if self.trackLimits[i][1] < event.y: continue - notes = self.noteDB.getNotesByTrack( self.curPage, i, self ) - handled = 0 - for n in range(len(notes)): - handled = notes[n].updateTooltip( self, event ) - if handled == 0: continue - elif handled == 1: return # event was handled - else: break + #notes = self.noteDB.getNotesByTrack( self.curPage, i, self ) + #handled = 0 + #for n in range(len(notes)): + # handled = notes[n].updateTooltip( self, event ) + # if handled == 0: continue + # elif handled == 1: return # event was handled + # else: break # note wasn't handled, could potentially draw a note if self.interfaceMode == INTERFACEMODE.DRAW: @@ -1167,13 +1179,16 @@ class TrackInterface( gtk.EventBox ): self.setCursor("default") def setCursor( self, cursor ): - self.window.set_cursor(self.cursor[cursor]) + #self.window.set_cursor(self.cursor[cursor]) + w = self.get_window() + w.set_cursor(self.cursor[cursor]) #======================================================= # Drawing def draw( self, buf, noescape = True, timeout = 0 ): - if not self.screenBufDirty[buf]: return True + print "Buf = " , buf + #if not self.screenBufDirty[buf]: return True TP.ProfileBegin( "TrackInterface::draw" ) @@ -1186,12 +1201,16 @@ class TrackInterface( gtk.EventBox ): beats = self.screenBufBeats[buf] pixmap = self.screenBuf[buf] - + print "pixmap = ", pixmap + cxt = cairo.Context(pixmap) resume = self.screenBufResume[buf] - self.gc.set_clip_rectangle( self.screenBufDirtyRect[buf] ) + #self.gc.set_clip_rectangle( self.screenBufDirtyRect[buf] ) - self.gc.set_line_attributes( Config.BEAT_LINE_SIZE, gtk.gdk.LINE_ON_OFF_DASH, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER ) + cxt.set_line_width(Config.BEAT_LINE_SIZE) + cxt.set_line_join(cairo.LINE_JOIN_MITER) + cxt.set_line_cap(cairo.LINE_CAP_BUTT) + #self.gc.set_line_attributes( Config.BEAT_LINE_SIZE, gtk.gdk.LINE_ON_OFF_DASH, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER ) # regular tracks for i in range( resume[0], self.drumIndex ): if resume[1] == 0: @@ -1200,35 +1219,41 @@ class TrackInterface( gtk.EventBox ): # draw background if self.owner.getTrackSelected( i ): - pixmap.draw_drawable( self.gc, self.image["trackBGSelected"], 0, 0, 0, self.trackLimits[i][0], self.trackFullWidth, self.trackFullHeight ) + cxt.set_source_surface(self.image["trackBGSelected"], 0, 0) + cxt.paint() + #pixmap.draw_drawable( self.gc, self.image["trackBGSelected"], 0, 0, 0, self.trackLimits[i][0], self.trackFullWidth, self.trackFullHeight ) else: - pixmap.draw_drawable( self.gc, self.image["trackBG"], 0, 0, 0, self.trackLimits[i][0], self.trackFullWidth, self.trackFullHeight ) + cxt.set_source_surface(self.image["trackBG"], 0, 0) + cxt.paint() + #pixmap.draw_drawable( self.gc, self.image["trackBG"], 0, 0, 0, self.trackLimits[i][0], self.trackFullWidth, self.trackFullHeight ) # draw beat lines - self.gc.foreground = self.beatColor + cxt.set_source_rgb(*gdk_color_to_cairo(self.beatColor)) for j in range(1,self.screenBufBeats[buf]): x = beatStart + self.beatSpacing[beats][j] - pixmap.draw_line( self.gc, x, self.trackRect[i].y, x, self.trackRect[i].y+self.trackRect[i].height ) + cxt.move_to(x, self.trackRect[i].y) + cxt.line_to(x, self.trackRect[i].y+self.trackRect[i].height ) + cxt.stroke() resume[1] = 1 # background drawn # draw notes - TP.ProfileBegin("TI::draw notes") - notes = self.noteDB.getNotesByTrack( self.screenBufPage[buf], i, self ) - for n in range( resume[2], len(notes) ): - # check escape - if not noescape and time.time() > timeout: - resume[0] = i - resume[2] = n - TP.ProfilePause( "TrackInterface::draw" ) - return False - - if not notes[n].draw( pixmap, self.gc, startX, stopX ): break - TP.ProfileEnd("TI::draw notes") + #TP.ProfileBegin("TI::draw notes") + #notes = self.noteDB.getNotesByTrack( self.screenBufPage[buf], i, self ) + #for n in range( resume[2], len(notes) ): + # # check escape + # if not noescape and time.time() > timeout: + # resume[0] = i + # resume[2] = n + # TP.ProfilePause( "TrackInterface::draw" ) + # return False + # + # if not notes[n].draw( pixmap, self.gc, startX, stopX ): break + # TP.ProfileEnd("TI::draw notes") # finished a track, reset the resume values for the next one - resume[1] = 0 - resume[2] = 0 + #resume[1] = 0 + #resume[2] = 0 # drum track if stopY > self.trackLimits[self.drumIndex][0]: @@ -1236,15 +1261,20 @@ class TrackInterface( gtk.EventBox ): if resume[1] == 0: # draw background if self.owner.getTrackSelected( self.drumIndex ): - pixmap.draw_drawable( self.gc, self.image["trackBGDrumSelected"], 0, 0, 0, self.trackLimits[self.drumIndex][0], self.trackFullWidth, self.trackFullHeightDrum ) + cxt.set_source_surface(self.image["trackBGDrumSelected"], 0, 0) + cxt.paint() + #pixmap.draw_drawable( self.gc, self.image["trackBGDrumSelected"], 0, 0, 0, self.trackLimits[self.drumIndex][0], self.trackFullWidth, self.trackFullHeightDrum ) else: - pixmap.draw_drawable( self.gc, self.image["trackBGDrum"], 0, 0, 0, self.trackLimits[self.drumIndex][0], self.trackFullWidth, self.trackFullHeightDrum ) + cxt.set_source_surface(self.image["trackBGDrum"], 0, 0) + cxt.paint() + #pixmap.draw_drawable( self.gc, self.image["trackBGDrum"], 0, 0, 0, self.trackLimits[self.drumIndex][0], self.trackFullWidth, self.trackFullHeightDrum ) # draw beat lines - self.gc.foreground = self.beatColor + cxt.set_source_rgb(*gdk_color_to_cairo(self.beatColor)) for j in range(1,self.screenBufBeats[buf]): x = beatStart + self.beatSpacing[beats][j] - pixmap.draw_line( self.gc, x, self.trackRect[self.drumIndex].y, x, self.trackRect[self.drumIndex].y+self.trackRect[self.drumIndex].height ) + cxt.move_to(x, self.trackRect[self.drumIndex].y) + cxt.line_to(x, self.trackRect[self.drumIndex].y+self.trackRect[self.drumIndex].height ) resume[1] = 1 # background drawn @@ -1257,7 +1287,7 @@ class TrackInterface( gtk.EventBox ): resume[2] = n TP.ProfilePause( "TrackInterface::draw" ) return False - if not notes[n].draw( pixmap, self.gc, startX, stopX ): break + #if not notes[n].draw( pixmap, self.gc, startX, stopX ): break self.screenBufDirty[buf] = False @@ -1265,34 +1295,44 @@ class TrackInterface( gtk.EventBox ): return True - def expose( self, DA, event ): - - if self.screenBufDirty[self.curScreen]: - self.draw( self.curScreen ) + def expose( self, widget, cr ): + self.draw(self.curScreen) + #if self.screenBufDirty[self.curScreen]: + # self.draw( self.curScreen ) TP.ProfileBegin( "TrackInterface::expose" ) - startX = event.area.x - startY = event.area.y - stopX = event.area.x + event.area.width - stopY = event.area.y + event.area.height + alloc = widget.get_allocation() + startX = alloc.x + startY = alloc.y + stopX = alloc.x + alloc.width + stopY = alloc.y + alloc.height #print "%d %d %d %d" % (startX,startY,stopX,stopY) - self.gc.set_clip_rectangle( event.area ) + #self.gc.set_clip_rectangle( event.area ) # draw base - DA.window.draw_drawable( self.gc, self.screenBuf[self.curScreen], startX, startY, startX, startY, event.area.width, event.area.height ) + cr.set_source_surface(self.screenBuf[self.curScreen], 0, 0) + cr.paint() + #DA.window.draw_drawable( self.gc, self.screenBuf[self.curScreen], startX, startY, startX, startY, event.area.width, event.area.height ) # draw playhead - self.gc.set_line_attributes( Config.PLAYHEAD_SIZE, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER ) - self.gc.foreground = self.playheadColor - DA.window.draw_line( self.gc, self.playheadX, startY, self.playheadX, stopY ) + cr.set_line_width(Config.PLAYHEAD_SIZE) + cr.set_line_join(cairo.LINE_CAP_BUTT) + cr.set_line_join(cairo.LINE_JOIN_MITER) + #self.gc.set_line_attributes( Config.PLAYHEAD_SIZE, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER ) + cr.set_source_rgb(*gdk_color_to_cairo(self.playheadColor)) + cr.move_to(self.playheadX, startY) + cr.line_to(self.playheadX, stopY) + cr.stroke() if self.marqueeLoc: # draw the selection rect - self.gc.set_line_attributes( Config.MARQUEE_SIZE, gtk.gdk.LINE_ON_OFF_DASH, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER ) - self.gc.foreground = self.marqueeColor - DA.window.draw_rectangle( self.gc, False, self.marqueeRect[0][0], self.marqueeRect[0][1], self.marqueeRect[1][0], self.marqueeRect[1][1] ) + + #self.gc.set_line_attributes( Config.MARQUEE_SIZE, gtk.gdk.LINE_ON_OFF_DASH, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER ) + cr.set_source_rgb(*gdk_color_to_cairo(self.marqueeColor)) + cr.rectangle(self.marqueeRect[0][0], self.marqueeRect[0][1], self.marqueeRect[1][0], self.marqueeRect[1][1]) + cr.stroke() if self.pasteRect: # draw the paste highlight self.gc.set_function( gtk.gdk.INVERT ) @@ -1326,11 +1366,14 @@ class TrackInterface( gtk.EventBox ): self.screenBufDirtyRect[self.curScreen].width = width self.screenBufDirtyRect[self.curScreen].height = height else: - self.screenBufDirtyRect[self.curScreen] = self.screenBufDirtyRect[self.curScreen].union( self.dirtyRectToAdd ) + pass + #self.screenBufDirtyRect[self.curScreen] = self.screenBufDirtyRect[self.curScreen].join( self.dirtyRectToAdd ) self.screenBufResume[self.curScreen] = [0,0,0] self.screenBufDirty[self.curScreen] = True - if self.drawingArea.window != None: - self.drawingArea.window.invalidate_rect( self.dirtyRectToAdd, True ) + #if self.drawingArea.window != None: + if True: + r = self.dirtyRectToAdd + self.drawingArea.queue_draw_area(r.x, r.y, r.width, r.height) self.drawingAreaDirty = True if page == self.screenBufPage[self.preScreen] or page == -1: @@ -1340,11 +1383,12 @@ class TrackInterface( gtk.EventBox ): self.screenBufDirtyRect[self.preScreen].width = width self.screenBufDirtyRect[self.preScreen].height = height else: - self.screenBufDirtyRect[self.preScreen] = self.screenBufDirtyRect[self.preScreen].union( self.dirtyRectToAdd ) + pass + #self.screenBufDirtyRect[self.preScreen] = self.screenBufDirtyRect[self.preScreen].union( self.dirtyRectToAdd ) self.screenBufResume[self.preScreen] = [0,0,0] self.screenBufDirty[self.preScreen] = True - #self.queue_draw() + self.queue_draw() def getTrackOrigin( self, track ): return ( self.trackRect[track].x, self.trackRect[track].y ) diff --git a/Edit/TuneInterface.py b/Edit/TuneInterface.py index 2090855..ecd46f8 100644 --- a/Edit/TuneInterface.py +++ b/Edit/TuneInterface.py @@ -1,6 +1,5 @@ -import pygtk -pygtk.require( '2.0' ) -import gtk +from gi.repository import Gtk, Gdk +import cairo import common.Config as Config from common.Config import imagefile @@ -9,6 +8,17 @@ from Edit.MainWindow import CONTEXT from common.Util.NoteDB import PARAMETER +def gdk_color_to_cairo(color): + return (color.red/65536.0, color.green/65536.0, color.blue/65536.0) + +def gdk_rect(x, y, width, height): + r = Gdk.Rectangle() + r.x = x + r.y = y + r.width = width + r.height = height + return r + class TuneInterfaceParasite: def __init__( self, noteDB, owner, note ): @@ -75,7 +85,7 @@ class TuneInterfaceParasite: return True # we drew something -class TuneInterface( gtk.EventBox ): +class TuneInterface( Gtk.EventBox ): DRAG_BLOCK = -1 # block other drag events DRAG_SELECT = 1 @@ -83,18 +93,17 @@ class TuneInterface( gtk.EventBox ): DRAG_MOVE = 3 def __init__( self, noteDB, owner, adjustment ): - gtk.EventBox.__init__( self ) - + Gtk.EventBox.__init__( self ) self.noteDB = noteDB self.owner = owner self.adjustment = adjustment #adjustment.connect( "changed", self.adjustmentChanged ) adjustment.connect( "value-changed", self.adjustmentValue ) - self.drawingArea = gtk.DrawingArea() + self.drawingArea = Gtk.DrawingArea() self.drawingAreaDirty = False # is the drawingArea waiting to draw? self.add( self.drawingArea ) - self.dirtyRectToAdd = gtk.gdk.Rectangle() # used by the invalidate_rect function + self.dirtyRectToAdd = Gdk.Rectangle() # used by the invalidate_rect function self.selectedIds = [] self.displayedPage = -1 @@ -105,29 +114,33 @@ class TuneInterface( gtk.EventBox ): self.thumbnail = {} self.thumbnailDirty = {} self.thumbnailDirtyRect = {} - self.defaultwin = gtk.gdk.get_default_root_window() # used when creating pixmaps - self.gc = gtk.gdk.GC( self.defaultwin ) - colormap = self.drawingArea.get_colormap() - self.bgColor = colormap.alloc_color( Config.TOOLBAR_BCK_COLOR, True, True ) - self.lineColor = colormap.alloc_color( Config.THUMBNAIL_DRAG_COLOR, True, True ) - self.displayedColor = colormap.alloc_color( Config.THUMBNAIL_DISPLAYED_COLOR, True, True ) - self.selectedColor = colormap.alloc_color( Config.THUMBNAIL_SELECTED_COLOR, True, True ) + + self.bgColor = Gdk.Color.parse(Config.TOOLBAR_BCK_COLOR) [1] + self.lineColor = Gdk.Color.parse(Config.THUMBNAIL_DRAG_COLOR) [1] + self.displayedColor = Gdk.Color.parse(Config.THUMBNAIL_DISPLAYED_COLOR) [1] + self.selectedColor = Gdk.Color.parse(Config.THUMBNAIL_SELECTED_COLOR) [1] # prepare thumbnail self.thumbnailBG = [] - self.gc.foreground = self.bgColor + #self.gc.foreground = self.bgColor for i in range(4): - pix = gtk.gdk.pixbuf_new_from_file( - imagefile('pageThumbnailBG%d.png' % i)) - self.thumbnailBG.append( gtk.gdk.Pixmap( self.defaultwin, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT ) ) - self.thumbnailBG[i].draw_rectangle( self.gc, True, 0, 0, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT ) - self.thumbnailBG[i].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT, gtk.gdk.RGB_DITHER_NONE ) + pix = cairo.ImageSurface.create_from_png("common/Resources/Images/" + 'pageThumbnailBG%d.png' % i) + #pix = gtk.gdk.pixbuf_new_from_file(imagefile('pageThumbnailBG%d.png' % i)) + self.thumbnailBG.append(cairo.ImageSurface(cairo.FORMAT_RGB24, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT)) + cxt = cairo.Context(self.thumbnailBG[i]) + cxt.set_source_rgb(*gdk_color_to_cairo(self.bgColor)) + cxt.rectangle(0, 0, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT) + cxt.fill() + cxt.set_source_surface(pix, 0, 0) + cxt.paint() # load clipmask - pix = gtk.gdk.pixbuf_new_from_file(imagefile('pageThumbnailMask.png')) - pixels = pix.get_pixels() - stride = pix.get_rowstride() - channels = pix.get_n_channels() + #pix = gtk.gdk.pixbuf_new_from_file(imagefile('pageThumbnailMask.png')) + pix = cairo.ImageSurface.create_from_png("common/Resources/Images/"+ "pageThumbnailMask.png") + pixels = pix.get_data() + stride = pix.get_stride() + #channels = pix.get_n_channels() + channels = 4 bitmap = "" byte = 0 shift = 0 @@ -145,8 +158,13 @@ class TuneInterface( gtk.EventBox ): bitmap += "%c" % byte byte = 0 shift = 0 - self.clipMask = gtk.gdk.bitmap_create_from_data( None, bitmap, pix.get_width(), pix.get_height() ) - self.clearMask = gtk.gdk.Rectangle( 0, 0, 1200, 800 ) + + #self.clipMask = cairo.ImageSurface.create_for_data(bytearray(bitmap), cairo.FORMAT_ARGB32, pix.get_width(), pix.get_height()) + self.clearMask = Gdk.Rectangle() + self.clearMask.x = 0 + self.clearMask.y = 0 + self.clearMask.width = 1200 + self.clearMask.height = 800 self.pageOffset = 5 # offset the first page by this self.dropWidth = 5 # line thickness of the drop head @@ -175,10 +193,10 @@ class TuneInterface( gtk.EventBox ): self.visibleX = 0 self.visibleEndX = 0 - self.add_events(gtk.gdk.POINTER_MOTION_MASK|gtk.gdk.POINTER_MOTION_HINT_MASK) + self.add_events(Gdk.EventMask.POINTER_MOTION_MASK|Gdk.EventMask.POINTER_MOTION_HINT_MASK) self.connect( "size-allocate", self.size_allocated ) - self.drawingArea.connect( "expose-event", self.draw ) + self.drawingArea.connect( "draw", self.draw ) self.connect( "button-press-event", self.handleButtonPress ) self.connect( "button-release-event", self.handleButtonRelease ) self.connect( "motion-notify-event", self.handleMotion ) @@ -241,10 +259,10 @@ class TuneInterface( gtk.EventBox ): id = self.noteDB.getPageByIndex( ind ) - if event.type == gtk.gdk._3BUTTON_PRESS: # triple click -> select all + if event.type == Gdk.EventType._3BUTTON_PRESS: # triple click -> select all self.owner.displayPage( id ) self.selectAll() - elif event.type == gtk.gdk._2BUTTON_PRESS: # double click -> exclusive select + elif event.type == Gdk.EventType._2BUTTON_PRESS: # double click -> exclusive select self.owner.displayPage( id ) self.selectPage( id ) else: @@ -289,22 +307,23 @@ class TuneInterface( gtk.EventBox ): def handleMotion( self, widget, event ): - if event.is_hint: - x, y, state = self.window.get_pointer() - event.x = float(x) - event.y = float(y) - event.state = state + #if event.is_hint: + # x, y, state = self.window.get_pointer() + # event.x = float(x) + # event.y = float(y) + # event.state = state + x, y = widget.get_pointer() if self.button1Down: # clicking if Config.ModKeys.ctrlDown and (self.dragMode == None or self.dragMode == self.DRAG_MOVE): self.dropAt = -1 self.dragMode = self.DRAG_SELECT - if event.x >= self.pageOffset: ind = int(event.x-self.pageOffset)//Config.PAGE_THUMBNAIL_WIDTH + if x >= self.pageOffset: ind = int(event.x-self.pageOffset)//Config.PAGE_THUMBNAIL_WIDTH else: ind = 0 self.dragLastInd = ind if self.dragMode == self.DRAG_SELECT: # select on drag - if event.x > self.pageOffset: ind = int(event.x-self.pageOffset)//Config.PAGE_THUMBNAIL_WIDTH + if x > self.pageOffset: ind = int(event.x-self.pageOffset)//Config.PAGE_THUMBNAIL_WIDTH else: ind = 0 pageCount = self.noteDB.getPageCount() if ind >= pageCount: ind = pageCount-1 @@ -312,7 +331,7 @@ class TuneInterface( gtk.EventBox ): self.selectPage( self.noteDB.getPageByIndex(i), False ) self.dragLastInd = ind elif self.dragMode == self.DRAG_DESELECT: # deselect on drag - if event.x > self.pageOffset: ind = int(event.x-self.pageOffset)//Config.PAGE_THUMBNAIL_WIDTH + if x > self.pageOffset: ind = int(x-self.pageOffset)//Config.PAGE_THUMBNAIL_WIDTH else: ind = 0 pageCount = self.noteDB.getPageCount() if ind >= pageCount: ind = pageCount-1 @@ -342,7 +361,7 @@ class TuneInterface( gtk.EventBox ): self.invalidate_rect( self.dropAtX-self.dropWidthDIV2, 0, self.dropWidth, self.height ) else: # hovering - ind = int(event.x-self.pageOffset)//Config.PAGE_THUMBNAIL_WIDTH + ind = int(x-self.pageOffset)//Config.PAGE_THUMBNAIL_WIDTH if ind != self.lastPredrawInd and 0 <= ind < self.noteDB.getPageCount(): id = self.noteDB.getPageByIndex(ind) if id != self.displayedPage: @@ -380,11 +399,11 @@ class TuneInterface( gtk.EventBox ): startX = self.pageOffset + ind*Config.PAGE_THUMBNAIL_WIDTH stopX = startX + Config.PAGE_THUMBNAIL_WIDTH - if self.adjustment.value > startX: + if self.adjustment.get_value > startX: scroll = startX + Config.PAGE_THUMBNAIL_WIDTH + Config.PAGE_THUMBNAIL_WIDTH_DIV2 - self.baseWidth if scroll < 0: scroll = 0 self.adjustment.set_value( scroll ) - elif self.adjustment.value + self.baseWidth < stopX: + elif self.adjustment.get_value() + self.baseWidth < stopX: scroll = startX - Config.PAGE_THUMBNAIL_WIDTH_DIV2 if scroll + self.baseWidth > self.width: if self.waitingForAlloc: @@ -474,8 +493,9 @@ class TuneInterface( gtk.EventBox ): def notifyPageAdd( self, id, at ): if not self.thumbnail.has_key(id): - self.thumbnail[id] = gtk.gdk.Pixmap( self.defaultwin, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT ) - self.thumbnailDirtyRect[id] = gtk.gdk.Rectangle( 0, 0, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT ) + #self.thumbnail[id] = gtk.gdk.Pixmap( self.defaultwin, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT ) + self.thumbnail[id] = cairo.ImageSurface(cairo.FORMAT_RGB24, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT) + self.thumbnailDirtyRect[id] = gdk_rect(0, 0, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT ) self.thumbnailDirty[id] = True self.selectPage( id ) self.updateSize() @@ -498,8 +518,9 @@ class TuneInterface( gtk.EventBox ): def notifyPageDuplicate( self, new, at ): for id in new: - self.thumbnail[new[id]] = gtk.gdk.Pixmap( self.defaultwin, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT ) - self.thumbnailDirtyRect[new[id]] = gtk.gdk.Rectangle( 0, 0, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT ) + #self.thumbnail[new[id]] = gtk.gdk.Pixmap( self.defaultwin, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT ) + self.thumbnail[new[id]] = cairo.ImageSurface(cairo.FORMAT_RGB24, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT) + self.thumbnailDirtyRect[new[id]] = gdk_rect( 0, 0, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT ) self.thumbnailDirty[new[id]] = True self.updateSize() @@ -525,6 +546,7 @@ class TuneInterface( gtk.EventBox ): stopY = rect.y + rect.height # draw background + print self.thumbnailBG[self.noteDB.getPage(id).color] pixmap.draw_drawable( self.gc, self.thumbnailBG[self.noteDB.getPage(id).color], startX, startY, startX, startY, rect.width, rect.height+1 ) # draw regular tracks @@ -548,26 +570,29 @@ class TuneInterface( gtk.EventBox ): self.thumbnailDirty[id] = False - def draw( self, drawingArea, event ): + def draw( self, drawingArea, cr): - startX = event.area.x - startY = event.area.y - stopX = event.area.x + event.area.width - stopY = event.area.y + event.area.height + alloc = drawingArea.get_allocation() + startX = alloc.x + startY = alloc.y + stopX = alloc.x + alloc.width + stopY = alloc.y + alloc.height - self.gc.set_clip_rectangle( self.clearMask ) + #self.gc.set_clip_rectangle( self.clearMask ) # draw background - self.gc.foreground = self.bgColor - drawingArea.window.draw_rectangle( self.gc, True, startX, startY, event.area.width, event.area.height ) + cr.set_source_rgb(*gdk_color_to_cairo(self.bgColor)) + cr.rectangle(startX, startY, alloc.width, alloc.height) + cr.fill() tracks = [ self.owner.getTrackSelected(i) for i in range(Config.NUMBER_OF_TRACKS) ] # draw pages - self.gc.set_clip_mask( self.clipMask ) + #self.gc.set_clip_mask( self.clipMask ) x = self.pageOffset endx = x + Config.PAGE_THUMBNAIL_WIDTH + print self.noteDB.getTune() for pageId in self.noteDB.getTune(): if endx < startX: x = endx @@ -621,8 +646,11 @@ class TuneInterface( gtk.EventBox ): self.dirtyRectToAdd.y = y self.dirtyRectToAdd.width = width self.dirtyRectToAdd.height = height - if self.drawingArea.window: - self.drawingArea.window.invalidate_rect( self.dirtyRectToAdd, True ) + + #if self.drawingArea.window: + if True: + r = self.dirtyRectToAdd + self.drawingArea.queue_draw_area(r.x, r.y, r.width, r.height) self.drawingAreaDirty = True def invalidate_thumbnail( self, id, x, y, width, height ): @@ -637,7 +665,7 @@ class TuneInterface( gtk.EventBox ): self.dirtyRectToAdd.y = y self.dirtyRectToAdd.width = width self.dirtyRectToAdd.height = height - self.thumbnailDirtyRect[id] = self.thumbnailDirtyRect[id].union( self.dirtyRectToAdd ) + #self.thumbnailDirtyRect[id] = self.thumbnailDirtyRect[id].union( self.dirtyRectToAdd ) ind = self.noteDB.getPageIndex( id ) self.invalidate_rect( self.pageOffset + ind*Config.PAGE_THUMBNAIL_WIDTH, 0, Config.PAGE_THUMBNAIL_WIDTH, self.height ) -- cgit v0.9.1