Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Gordon <aaronsgordon@yahoo.com>2012-12-31 17:25:52 (GMT)
committer Aaron Gordon <aaronsgordon@yahoo.com>2012-12-31 17:25:52 (GMT)
commit0a640f8a17558921f44fb56464a07866bec4e233 (patch)
tree3d59370d0456917d6011754233883349e5cca081
parentccc5153a79db9ab4fe05f7672e4f039fa14ef112 (diff)
Porting to Gtk3
-rw-r--r--Edit/EditToolbars.py428
-rw-r--r--Edit/HitInterface.py23
-rw-r--r--Edit/MainWindow.py497
-rw-r--r--Edit/NoteInterface.py32
-rw-r--r--Edit/TrackInterface.py292
-rw-r--r--Edit/TuneInterface.py144
-rw-r--r--TamTamEdit.py27
-rw-r--r--common/Config.py14
-rw-r--r--common/Util/Clooper/__init__.py5
-rw-r--r--common/Util/ThemeWidgets.py272
-rw-r--r--common/Util/Trackpad.py44
-rw-r--r--common/port/scrolledbox.py87
12 files changed, 998 insertions, 867 deletions
diff --git a/Edit/EditToolbars.py b/Edit/EditToolbars.py
index e2b41e4..de85625 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:
@@ -515,45 +514,46 @@ class generationPalette(Palette):
self.mainBox.show_all()
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..e839dcd 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..ad73f42 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..efe7e8c 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 )
diff --git a/TamTamEdit.py b/TamTamEdit.py
index 419e40e..512c5bf 100644
--- a/TamTamEdit.py
+++ b/TamTamEdit.py
@@ -25,28 +25,24 @@ import time
import sys
import os
import shutil
-import pygtk
-pygtk.require('2.0')
-import gtk
-import gobject
+from gi.repository import Gtk, GObject
+
+
import time
import common.Config as Config
from common.Util.CSoundClient import new_csound_client
from common.Util.Profiler import TP
-from common.Util.InstrumentPanel import InstrumentPanel
+#from common.Util.InstrumentPanel import InstrumentPanel
from Edit.MainWindow import MainWindow
from common.Util.Trackpad import Trackpad
from gettext import gettext as _
import commands
-from sugar.activity import activity
-
-if Config.HAVE_TOOLBOX:
- from sugar.graphics.toolbarbox import ToolbarBox
- from sugar.activity import widgets
-
+from sugar3.activity import activity
+from sugar3.graphics.toolbarbox import ToolbarBox
+from sugar3.activity import widgets
class TamTamEdit(activity.Activity):
def __init__(self, handle):
@@ -57,8 +53,8 @@ class TamTamEdit(activity.Activity):
# shutil.copyfile(Config.SOUNDS_DIR + '/' + snd , Config.DATA_DIR + '/' + snd)
# os.system('chmod 0777 ' + Config.DATA_DIR + '/' + snd + ' &')
- color = gtk.gdk.color_parse(Config.WS_BCK_COLOR)
- self.modify_bg(gtk.STATE_NORMAL, color)
+ #color = gtk.gdk.color_parse(Config.WS_BCK_COLOR)
+ #self.modify_bg(gtk.STATE_NORMAL, color)
self.set_resizable(False)
@@ -95,12 +91,13 @@ class TamTamEdit(activity.Activity):
self.edit.onActivate(arg=None)
if Config.HAVE_TOOLBOX:
- separator = gtk.SeparatorToolItem()
+ separator = Gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
self.toolbox.toolbar.insert(separator, -1)
self.toolbox.toolbar.insert(widgets.StopButton(self), -1)
self.toolbox.toolbar.show_all()
+ self.set_toolbar_box(self.toolbox)
else:
self.activity_toolbar.share.hide()
@@ -142,7 +139,7 @@ class TamTamEdit(activity.Activity):
if Config.DEBUG:
print 'DEBUG: TamTam::onDestroy()'
- self.edit.onDestroy()
+ #self.edit.onDestroy()
csnd = new_csound_client()
csnd.connect(False)
diff --git a/common/Config.py b/common/Config.py
index bbdaa66..b1c1318 100644
--- a/common/Config.py
+++ b/common/Config.py
@@ -6,13 +6,13 @@ import gettext
import logging
from os.path import join
-import gtk
+from gi.repository import Gdk
-from sugar.activity.activity import get_bundle_path, get_activity_root
-from sugar import env
+from sugar3.activity.activity import get_bundle_path, get_activity_root
+from sugar3 import env
-#QUICKLOAD = os.path.isfile("QUICKLOAD") # skip loading inessential comenents to speed things up
+QUICKLOAD = os.path.isfile("QUICKLOAD") # skip loading inessential comenents to speed things up
FEATURES_OGG = True
FEATURES_MIC = None
@@ -63,7 +63,7 @@ PLUGIN_PERIOD = 1024
PLUGIN_NPERIODS = 2
try:
- from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton
+ from sugar3.graphics.toolbarbox import ToolbarBox, ToolbarButton
HAVE_TOOLBOX = True
except ImportError:
HAVE_TOOLBOX = False
@@ -104,8 +104,8 @@ CSOUND_STOP_RECORD_PERF = 'i5401 4 1 "%s"'
## GUI CONSTANTS
#################
-if max(gtk.gdk.screen_width(), gtk.gdk.screen_height()) <= 800:
- # Images created using `convert $i -resize 73%` command
+if max(Gdk.Screen.width(), Gdk.Screen.height()) <= 800:
+# # Images created using `convert $i -resize 73%` command
IMAGE_ROOT_SCALED = join(IMAGE_ROOT, '73', '')
scale = lambda x: int(x * .73)
else:
diff --git a/common/Util/Clooper/__init__.py b/common/Util/Clooper/__init__.py
index 363fc88..ca8c93d 100644
--- a/common/Util/Clooper/__init__.py
+++ b/common/Util/Clooper/__init__.py
@@ -1,7 +1,6 @@
import os
import sys
import logging
-
_sys_path = sys.path
_root_path = os.path.dirname(__file__)
@@ -15,7 +14,7 @@ for i in os.listdir(_root_path):
_sys_path = None
break
except Exception, e:
- logging.debug('skip %s blobs: %s' % (path, e))
+ print 'skip %s blobs: %s' % (path, e)
if _sys_path:
- raise('cannot find proper binary blobs')
+ raise Exception('cannot find proper binary blobs')
diff --git a/common/Util/ThemeWidgets.py b/common/Util/ThemeWidgets.py
index 7503d57..a786761 100644
--- a/common/Util/ThemeWidgets.py
+++ b/common/Util/ThemeWidgets.py
@@ -1,21 +1,21 @@
-import pygtk
-pygtk.require( '2.0' )
-import gtk
+from gi.repository import Gtk, Gdk, GdkPixbuf
+import cairo
+
import logging
import common.Config as Config
from common.Config import imagefile
-from sugar.graphics.combobox import ComboBox
-from sugar.graphics.palette import Palette, WidgetInvoker
+from sugar3.graphics.combobox import ComboBox
+from sugar3.graphics.palette import Palette, WidgetInvoker
class ITYPE:
PIXBUF = 0
PIXMAP = 1
-class ImageHScale( gtk.HScale ):
+class ImageHScale( Gtk.HScale ):
def __init__( self, image_name, adjustment = None, slider_border = 0, insensitive_name = None, trough_color = "#3D403A", snap = False ):
- gtk.HScale.__init__( self, adjustment )
+ Gtk.HScale.__init__( self, adjustment )
if snap: self.snap = 1/snap
else: self.snap = False
@@ -23,14 +23,14 @@ class ImageHScale( gtk.HScale ):
colormap = self.get_colormap()
self.troughcolor = colormap.alloc_color( trough_color, True, True )
- img = gtk.Image()
+ img = Gtk.Image()
img.set_from_file( image_name )
self.sliderPixbuf = img.get_pixbuf()
if insensitive_name == None:
self.insensitivePixbuf = None
else:
- img = gtk.Image()
+ img = Gtk.Image()
img.set_from_file( insensitive_name )
self.insensitivePixbuf = img.get_pixbuf()
@@ -53,7 +53,7 @@ widget "*%s*" style "scale_style"
self.set_draw_value(False)
- self.connect( "expose-event", self.expose )
+ self.connect( "draw", self.expose )
self.connect( "size-allocate", self.size_allocate )
self.connect( "button-release-event", self.button_release )
adjustment.connect( "changed", self.value_changed )
@@ -79,7 +79,7 @@ widget "*%s*" style "scale_style"
def expose( self, widget, event ):
style = self.get_style()
- gc = style.fg_gc[gtk.STATE_NORMAL]
+ gc = style.fg_gc[Gtk.StateType.NORMAL]
gc.foreground = self.troughcolor
@@ -94,7 +94,7 @@ widget "*%s*" style "scale_style"
else:
sliderX = int((self.alloc.width - self.pixbufWidth)*(val-adj.lower)/(adj.upper - adj.lower))
- if self.insensitivePixbuf != None and self.state == gtk.STATE_INSENSITIVE:
+ if self.insensitivePixbuf != None and self.state == Gtk.StateType.INSENSITIVE:
self.window.draw_pixbuf( gc, self.insensitivePixbuf, 0, 0, self.alloc.x + sliderX, self.alloc.y + self.sliderY, self.pixbufWidth, self.pixbufHeight, gtk.gdk.RGB_DITHER_NORMAL, 0, 0 )
else:
self.window.draw_pixbuf( gc, self.sliderPixbuf, 0, 0, self.alloc.x + sliderX, self.alloc.y + self.sliderY, self.pixbufWidth, self.pixbufHeight, gtk.gdk.RGB_DITHER_NORMAL, 0, 0 )
@@ -106,12 +106,12 @@ widget "*%s*" style "scale_style"
if self.snap:
self.set_value( round(self.snap*self.get_value())/self.snap )
-class ImageVScale( gtk.VScale ):
+class ImageVScale( Gtk.VScale ):
def __init__(self, image_name, adjustment=None, slider_border=0,
insensitive_name=None, trough_color="#3D403A", snap=False):
image_name = imagefile(image_name)
- gtk.VScale.__init__( self, adjustment )
+ Gtk.VScale.__init__( self, adjustment )
if snap: self.snap = 1/snap
else: self.snap = False
@@ -119,14 +119,14 @@ class ImageVScale( gtk.VScale ):
colormap = self.get_colormap()
self.troughcolor = colormap.alloc_color( trough_color, True, True )
- img = gtk.Image()
+ img = Gtk.Image()
img.set_from_file( image_name )
self.sliderPixbuf = img.get_pixbuf()
if insensitive_name == None:
self.insensitivePixbuf = None
else:
- img = gtk.Image()
+ img = Gtk.Image()
img.set_from_file( insensitive_name )
self.insensitivePixbuf = img.get_pixbuf()
@@ -173,7 +173,7 @@ widget "*%s*" style "scale_style"
def expose( self, widget, event ):
style = self.get_style()
- gc = style.fg_gc[gtk.STATE_NORMAL]
+ gc = style.fg_gc[Gtk.StateType.NORMAL]
gc.foreground = self.troughcolor
@@ -200,9 +200,9 @@ widget "*%s*" style "scale_style"
if self.snap:
self.set_value( round(self.snap*self.get_value())/self.snap )
-class XYSlider( gtk.EventBox ):
+class XYSlider( Gtk.EventBox ):
def __init__( self, fixed, button, xadjustment, yadjustment, flipX = False, flipY = False ):
- gtk.EventBox.__init__( self )
+ Gtk.EventBox.__init__( self )
self.fixed = fixed
self.button = button
@@ -306,18 +306,17 @@ class XYSlider( gtk.EventBox ):
else: yvalue = self.yadjustment.lower+(self.yRange*y)//self.height
if yvalue != self.yadjustment.value: self.yadjustment.set_value(yvalue)
-class RoundHBox( gtk.HBox ):
+class RoundHBox( Gtk.HBox ):
def __init__( self, radius = 5, fillcolor = "#000", bordercolor = "#FFF", homogeneous = False, spacing = 0 ):
- gtk.HBox.__init__( self, homogeneous, spacing )
+ Gtk.HBox.__init__( self, homogeneous, spacing )
self.alloc = None
self.radius = radius
- colormap = self.get_colormap()
- self.fillcolor = colormap.alloc_color(fillcolor,True,True)
- self.bordercolor = colormap.alloc_color(bordercolor,True,True)
+ _, self.fillcolor = Gdk.Color.parse(fillcolor)
+ _, self.bordercolor = Gdk.Color.parse(bordercolor)
- self.connect( "expose-event", self.expose )
+ self.connect( "draw", self.expose )
self.connect( "size-allocate", self.size_allocate )
def update_constants( self ):
@@ -330,6 +329,7 @@ class RoundHBox( gtk.HBox ):
self.cornerMUL2 = self.corner*2
self.cornerMINborderW = self.corner - self.borderW
+ self.alloc = self.get_allocation()
self.xPLUborderW = self.alloc.x + self.borderW
self.xPLUcorner = self.alloc.x + self.corner
self.xPLUwidthMINborderW = self.alloc.x + self.alloc.width - self.borderW
@@ -359,7 +359,7 @@ class RoundHBox( gtk.HBox ):
return False
def set_border_width( self, width ):
- gtk.HBox.set_border_width( self, width )
+ Gtk.HBox.set_border_width( self, width )
self.update_constants()
def set_radius( self, radius ):
@@ -367,96 +367,116 @@ class RoundHBox( gtk.HBox ):
self.update_constants()
def set_fill_color( self, color ):
- colormap = self.get_colormap()
- self.fillcolor = colormap.alloc_color(color,True,True)
+ _, self.fillcolor = Gdk.Color.parse(color)
def set_border_color( self, color ):
- colormap = self.get_colormap()
- self.bordercolor = colormap.alloc_color(color,True,True)
-
- def expose( self, widget, event ):
+ _, self.bordercolor = Gdk.Color.parse(color)
+ def expose( self, widget, cr):
if self.alloc == None: return
#TP.ProfileBegin( "Round*Box::expose" )
style = self.get_style()
- gc = style.fg_gc[gtk.STATE_NORMAL]
- startX = event.area.x - self.alloc.x
- startY = event.area.y - self.alloc.y
- stopX = startX + event.area.width
- stopY = startY + event.area.height
+ event = widget.get_allocation()
+ startX = event.x - self.alloc.x
+ startY = event.y - self.alloc.y
+ stopX = startX + event.width
+ stopY = startY + event.height
- saveForeground = gc.foreground
# Note: could maybe do some optimization to fill only areas that are within the dirty rect, but drawing
# seems to be quite fast compared to python code, so just leave it at clipping by each geometry feature
- gc.foreground = self.bordercolor
+ b = self.bordercolor
+ cr.set_source_rgb(b.red / 65536.0, b.green / 65536.0, b.blue / 65536.0)
if self.borderW:
if stopY > self.corner and startY < self.heightMINcorner:
if startX < self.borderW: # draw left border
- self.window.draw_rectangle( gc, True, self.alloc.x, self.yPLUcorner, self.borderW, self.heightMINcornerMUL2 )
+ cr.rectangle(self.alloc.x, self.yPLUcorner, self.borderW, self.heightMINcornerMUL2 )
if stopX > self.widthMINborderW: # draw right border
- self.window.draw_rectangle( gc, True, self.xPLUwidthMINborderW, self.yPLUcorner, self.borderW, self.heightMINcornerMUL2 )
+ cr.rectangle(self.xPLUwidthMINborderW, self.yPLUcorner, self.borderW, self.heightMINcornerMUL2 )
if stopX > self.corner and startX < self.widthMINcorner:
if startY < self.borderW: # draw top border
- self.window.draw_rectangle( gc, True, self.xPLUcorner, self.alloc.y, self.widthMINcornerMUL2, self.borderW )
+ cr.rectangle(self.xPLUcorner, self.alloc.y, self.widthMINcornerMUL2, self.borderW )
if stopY > self.heightMINborderW: # draw bottom border
- self.window.draw_rectangle( gc, True, self.xPLUcorner, self.yPLUheightMINborderW, self.widthMINcornerMUL2, self.borderW )
+ cr.rectangle(self.xPLUcorner, self.yPLUheightMINborderW, self.widthMINcornerMUL2, self.borderW )
if startX < self.corner:
if startY < self.corner: # draw top left corner
- self.window.draw_rectangle( gc, True, self.alloc.x, self.alloc.y, self.corner, self.corner )
- gc.foreground = self.fillcolor
- self.window.draw_arc( gc, True, self.roundX1, self.roundY1, self.roundD, self.roundD, self.rightAngle, self.rightAngle )
- gc.foreground = self.bordercolor
+ cr.rectangle(self.alloc.x, self.alloc.y, self.corner, self.corner )
+ cr.fill()
+ f = self.fillcolor
+ cr.set_source_rgb(f.red / 65536.0, f.green / 65536.0, f.blue / 65536.0)
+ #cr.arc( self.roundX1, self.roundY1, self.roundD, self.roundD, self.rightAngle, self.rightAngle )
+ #cr.fill()
+ cr.set_source_rgb(b.red / 65536.0, b.green / 65536.0, b.blue / 65536.0)
+
if stopY > self.heightMINcorner: # draw bottom left corner
- self.window.draw_rectangle( gc, True, self.alloc.x, self.yPLUheightMINcorner, self.corner, self.corner )
- gc.foreground = self.fillcolor
- self.window.draw_arc( gc, True, self.roundX1, self.roundY2, self.roundD, self.roundD, -self.rightAngle, -self.rightAngle )
- gc.foreground = self.bordercolor
+ cr.rectangle(self.alloc.x, self.yPLUheightMINcorner, self.corner, self.corner)
+ cr.fill()
+ f = self.fillcolor
+ cr.set_source_rgb(f.red / 65536.0, f.green / 65536.0, f.blue / 65536.0)
+ #cr.arc(self.roundX1, self.roundY2, self.roundD, self.roundD, -self.rightAngle, -self.rightAngle )
+ #cr.fill()
+ b = self.bordercolor
+ cr.set_source_rgb(b.red / 65536.0, b.green / 65536.0, b.blue / 65536.0)
+
if stopX > self.widthMINcorner:
if startY < self.corner: # draw top right corner
- self.window.draw_rectangle( gc, True, self.xPLUwidthMINcorner, self.alloc.y, self.corner, self.corner )
- gc.foreground = self.fillcolor
- self.window.draw_arc( gc, True, self.roundX2, self.roundY1, self.roundD, self.roundD, 0, self.rightAngle )
- gc.foreground = self.bordercolor
+ cr.rectangle(self.xPLUwidthMINcorner, self.alloc.y, self.corner, self.corner)
+ cr.fill()
+ f = self.fillcolor
+ cr.set_source_rgb(f.red / 65536.0, f.green / 65536.0, f.blue / 65536.0)
+ #cr.arc(self.roundX2, self.roundY1, self.roundD, self.roundD, 0, self.rightAngle)
+ #cr.fill()
+ b = self.bordercolor
+ cr.set_source_rgb(b.red / 65536.0, b.green / 65536.0, b.blue / 65536.0)
+
if stopY > self.heightMINcorner: # draw bottom right corner
- self.window.draw_rectangle( gc, True, self.xPLUwidthMINcorner, self.yPLUheightMINcorner, self.corner, self.corner )
- gc.foreground = self.fillcolor
- self.window.draw_arc( gc, True, self.roundX2, self.roundY2, self.roundD, self.roundD, 0, -self.rightAngle )
- gc.foreground = self.bordercolor
+ cr.rectangle(self.xPLUwidthMINcorner, self.yPLUheightMINcorner, self.corner, self.corner)
+ cr.fill()
+ f = self.fillcolor
+ cr.set_source_rgb(f.red / 65536.0, f.green / 65536.0, f.blue / 65536.0)
+ #cr.arc(self.roundX2, self.roundY2, self.roundD, self.roundD, 0, -self.rightAngle)
+ #cr.fill()
+ b = self.bordercolor
+ cr.set_source_rgb(b.red / 65536.0, b.green / 65536.0, b.blue / 65536.0)
+
+ f = self.fillcolor
+ cr.set_source_rgb(f.red / 65536.0, f.green / 65536.0, f.blue / 65536.0)
- gc.foreground = self.fillcolor
if startX < self.widthMINcorner and stopX > self.corner:
if startY < self.heightMINborderW and stopY > self.borderW: # draw centre fill
- self.window.draw_rectangle( gc, True, self.xPLUcorner, self.yPLUborderW, self.widthMINcornerMUL2, self.heightMINborderWMUL2 )
+ cr.rectangle(self.xPLUcorner, self.yPLUborderW, self.widthMINcornerMUL2, self.heightMINborderWMUL2)
+ cr.fill()
if startX < self.corner and stopX > self.borderW:
if startY < self.heightMINcorner and stopY > self.corner: # draw left fill
- self.window.draw_rectangle( gc, True, self.xPLUborderW, self.yPLUcorner, self.cornerMINborderW, self.heightMINcornerMUL2 )
+ cr.rectangle(self.xPLUborderW, self.yPLUcorner, self.cornerMINborderW, self.heightMINcornerMUL2)
+ cr.fill()
if startX < self.widthMINborderW and stopX > self.widthMINcorner:
if startY < self.heightMINcorner and stopY > self.corner: # draw right fill
- self.window.draw_rectangle( gc, True, self.xPLUwidthMINcorner, self.yPLUcorner, self.cornerMINborderW, self.heightMINcornerMUL2 )
+ cr.rectangle(self.xPLUwidthMINcorner, self.yPLUcorner, self.cornerMINborderW, self.heightMINcornerMUL2)
+ cr.fill()
- gc.foreground = saveForeground
+ #gc.foreground = saveForeground
#TP.ProfileEnd( "Round*Box::expose" )
return False
-class RoundVBox( gtk.VBox ):
+class RoundVBox( Gtk.VBox ):
def __init__( self, radius = 5, fillcolor = "#000", bordercolor = "#FFF", homogeneous = False, spacing = 0 ):
- gtk.VBox.__init__( self, homogeneous, spacing )
+ Gtk.VBox.__init__( self, homogeneous, spacing )
self.alloc = None
self.radius = radius
- colormap = self.get_colormap()
- self.fillcolor = colormap.alloc_color(fillcolor,True,True)
- self.bordercolor = colormap.alloc_color(bordercolor,True,True)
+ #colormap = self.get_colormap()
+ #self.fillcolor = colormap.alloc_color(fillcolor,True,True)
+ #self.bordercolor = colormap.alloc_color(bordercolor,True,True)
self.connect( "expose-event",self.expose )
self.connect( "size-allocate", self.size_allocate )
@@ -500,7 +520,7 @@ class RoundVBox( gtk.VBox ):
return False
def set_border_width( self, width ):
- gtk.VBox.set_border_width( self, width )
+ Gtk.VBox.set_border_width( self, width )
self.update_constants()
def set_radius( self, radius ):
@@ -588,9 +608,9 @@ class RoundVBox( gtk.VBox ):
return False
-class RoundFixed( gtk.Fixed ):
+class RoundFixed( Gtk.Fixed ):
def __init__( self, radius = 5, fillcolor = "#000", bordercolor = "#FFF" ):
- gtk.Fixed.__init__( self )
+ Gtk.Fixed.__init__( self )
self.alloc = None
self.radius = radius
@@ -641,7 +661,7 @@ class RoundFixed( gtk.Fixed ):
return False
def set_border_width( self, width ):
- gtk.Fixed.set_border_width( self, width )
+ Gtk.Fixed.set_border_width( self, width )
self.update_constants()
def set_radius( self, radius ):
@@ -729,14 +749,14 @@ class RoundFixed( gtk.Fixed ):
return False
-class ImageButton(gtk.Button):
+class ImageButton(Gtk.Button):
def __init__(self, mainImg_path, clickImg_path=None, enterImg_path=None,
backgroundFill=None ):
mainImg_path = imagefile(mainImg_path)
clickImg_path = imagefile(clickImg_path)
enterImg_path = imagefile(enterImg_path)
- gtk.Button.__init__(self)
+ Gtk.Button.__init__(self)
self.alloc = None
win = gtk.gdk.get_default_root_window()
self.gc = gtk.gdk.GC( win )
@@ -876,21 +896,18 @@ class ImageButton(gtk.Button):
self._palette.props.invoker = WidgetInvoker(self)
self._palette.props.invoker._position_hint = WidgetInvoker.AT_CURSOR
-class ImageToggleButton(gtk.ToggleButton):
+class ImageToggleButton(Gtk.ToggleButton):
- def __init__(self , mainImg_path, altImg_path, enterImg_path=None,
- backgroundFill=None):
+ def __init__(self , mainImg_path, altImg_path, enterImg_path=None, backgroundFill=None):
mainImg_path = imagefile(mainImg_path)
altImg_path = imagefile(altImg_path)
enterImg_path = imagefile(enterImg_path)
- gtk.ToggleButton.__init__(self)
+ Gtk.ToggleButton.__init__(self)
self.alloc = None
self.within = False
self.clicked = False
- win = gtk.gdk.get_default_root_window()
- self.gc = gtk.gdk.GC( win )
self.image = {}
self.itype = {}
self.iwidth = {}
@@ -901,22 +918,29 @@ class ImageToggleButton(gtk.ToggleButton):
self.backgroundFill = backgroundFill
def prepareImage( name, path ):
- pix = gtk.gdk.pixbuf_new_from_file(path)
- if pix.get_has_alpha():
+ pix = cairo.ImageSurface.create_from_png(path)
+ if True:
if backgroundFill == None:
self.image[name] = pix
self.itype[name] = ITYPE.PIXBUF
else:
- self.image[name] = gtk.gdk.Pixmap( win, pix.get_width(), pix.get_height() )
+ self.image[name] = cairo.ImageSurface(cairo.FORMAT_RGB24, pix.get_width(), pix.get_height() )
+ cxt = cairo.Context(self.image[name])
colormap = self.get_colormap()
- self.gc.foreground = colormap.alloc_color( backgroundFill, True, True )
- self.image[name].draw_rectangle( self.gc, True, 0, 0, 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 )
+ print backgroundFill
+ #self.gc.foreground = colormap.alloc_color( backgroundFill, True, True )
+ cxt.rectangle(0, 0, pix.get_width(), pix.get_height() )
+ cxt.fill()
+
+ cxt.set_source_pixbuf(pix, 0, 0)
+ cxt.paint()
self.itype[name] = ITYPE.PIXMAP
else:
- 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 )
+ self.image[name] = cairo.ImageSurface(cairo.FORMAT_RGB24, pix.get_width(), pix.get_height() )
+ cxt = cairo.Context(self.image[name])
+ cxt.set_source_pixbuf(pix, 0, 0)
self.itype[name] = ITYPE.PIXMAP
+
self.iwidth[name] = pix.get_width()
self.iwidthDIV2[name] = self.iwidth[name]//2
self.iheight[name] = pix.get_height()
@@ -941,7 +965,7 @@ class ImageToggleButton(gtk.ToggleButton):
self.connect('toggled',self.toggleImage)
self.connect('pressed',self.pressed )
self.connect('released',self.released )
- self.connect('expose-event', self.expose)
+ self.connect('draw', self.expose)
self.connect('size-allocate', self.size_allocate)
self.set_size_request(self.iwidth["main"],self.iheight["main"])
@@ -953,11 +977,15 @@ class ImageToggleButton(gtk.ToggleButton):
self.drawX = allocation.x + allocation.width//2
self.drawY = allocation.y + allocation.height//2
- def expose(self, widget, event):
+ def expose(self, widget, cr):
if self.itype[self.curImage] == ITYPE.PIXBUF:
- self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], gtk.gdk.RGB_DITHER_NONE)
+ cr.set_source_surface(self.image[self.curImage], 0, 0)
+ cr.paint()
+ #self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], gtk.gdk.RGB_DITHER_NONE)
else:
- self.window.draw_drawable( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage] )
+ cr.set_source_surface(self.image[self.curImage], 0, 0)
+ cr.paint()
+ #self.window.draw_drawable( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage] )
return True
def setImage(self, name, pix):
@@ -966,20 +994,23 @@ class ImageToggleButton(gtk.ToggleButton):
else:
updateEnter = False
- if pix.get_has_alpha():
+ if True:
if self.backgroundFill == None:
self.image[name] = pix
self.itype[name] = ITYPE.PIXBUF
else:
- self.image[name] = gtk.gdk.Pixmap( win, pix.get_width(), pix.get_height() )
- colormap = self.get_colormap()
- self.gc.foreground = colormap.alloc_color( self.backgroundFill, True, True )
- self.image[name].draw_rectangle( self.gc, True, 0, 0, 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 )
+ self.image[name] = cairo.ImageSurface(cairo.FORMAT_RGB24, pix.get_width(), pix.get_height() )
+ cxt = cairo.Context(self.image[name])
+ #colormap = self.get_colormap()
+ #self.gc.foreground = colormap.alloc_color( self.backgroundFill, True, True )
+ cxt.rectangle(0, 0, pix.get_width(), pix.get_height() )
+ cxt.fill()
+ cxt.set_source_pixbuf(pix, 0, 0)
self.itype[name] = ITYPE.PIXMAP
else:
- 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 )
+ self.image[name] = cairo.ImageSurface(cairo.FORMAT_RGB24, pix.get_width(), pix.get_height() )
+ cxt = cairo.Context(self.image[name])
+ cxt.set_source_pixbuf( pix, 0, 0)
self.itype[name] = ITYPE.PIXMAP
self.iwidth[name] = pix.get_width()
self.iwidthDIV2[name] = self.iwidth[name]//2
@@ -1018,7 +1049,7 @@ class ImageToggleButton(gtk.ToggleButton):
self.toggleImage( self )
def on_btn_enter(self, widget, event ):
- if event.mode == gtk.gdk.CROSSING_NORMAL:
+ if event.mode == Gdk.CrossingMode.NORMAL:
self.within = True
if not self.get_active() and not self.clicked:
self.curImage = "enter"
@@ -1027,7 +1058,7 @@ class ImageToggleButton(gtk.ToggleButton):
self.queue_draw()
def on_btn_leave(self, widget, event ):
- if event.mode == gtk.gdk.CROSSING_NORMAL:
+ if event.mode == Gdk.CrossingMode.NORMAL:
self.within = False
if not self.get_active():
self.curImage = "main"
@@ -1040,7 +1071,7 @@ class ImageToggleButton(gtk.ToggleButton):
self._palette.props.invoker = WidgetInvoker(self)
self._palette.props.invoker._position_hint = WidgetInvoker.AT_CURSOR
-class ImageRadioButton(gtk.RadioButton):
+class ImageRadioButton(Gtk.RadioButton):
def __init__(self, group, mainImg_path, altImg_path, enterImg_path=None,
backgroundFill=None):
@@ -1048,7 +1079,7 @@ class ImageRadioButton(gtk.RadioButton):
altImg_path = imagefile(altImg_path)
enterImg_path = imagefile(enterImg_path)
- gtk.RadioButton.__init__(self, group)
+ Gtk.RadioButton.__init__(self, group)
self.alloc = None
self.within = False
self.clicked = False
@@ -1204,10 +1235,10 @@ class ImageRadioButton(gtk.RadioButton):
self._palette.props.invoker = WidgetInvoker(self)
self._palette.props.invoker._position_hint = WidgetInvoker.AT_CURSOR
-class keyButton(gtk.Button):
+class keyButton(Gtk.Button):
import cairo
def __init__(self, width, height, fillcolor, strokecolor):
- gtk.Button.__init__(self)
+ Gtk.Button.__init__(self)
self.alloc = None
win = gtk.gdk.get_default_root_window()
self.gc = gtk.gdk.GC(win)
@@ -1261,39 +1292,40 @@ class keyButton(gtk.Button):
self.strokecolor = [r,g,b]
self.queue_draw()
-class BigComboBox(ComboBox):
+class BigComboBox(Gtk.ComboBox):
def __init__(self):
- ComboBox.__init__(self)
+ Gtk.ComboBox.__init__(self)
+ self._model = Gtk.ListStore(int, str, GdkPixbuf.Pixbuf, bool)
+ self.set_model(self._model)
- def append_item(self, action_id, text, icon_name=None, size = None,
- pixbuf = None):
+ def append_item(self, action_id, text, icon_name=None, size=None, pixbuf=None):
- if not self._icon_renderer and (icon_name or pixbuf):
- self._icon_renderer = gtk.CellRendererPixbuf()
+ if (icon_name or pixbuf):
+ self._icon_renderer = Gtk.CellRendererPixbuf()
settings = self.get_settings()
- w, h = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU)
+ _, w, h = Gtk.icon_size_lookup_for_settings(settings, Gtk.IconSize.MENU)
self._icon_renderer.props.stock_size = w
self.pack_start(self._icon_renderer, False)
self.add_attribute(self._icon_renderer, 'pixbuf', 2)
- if not self._text_renderer and text:
- self._text_renderer = gtk.CellRendererText()
+ if text:
+ self._text_renderer = Gtk.CellRendererText()
self.pack_end(self._text_renderer, True)
self.add_attribute(self._text_renderer, 'text', 1)
if not pixbuf:
if icon_name:
if not size:
- size = gtk.ICON_SIZE_LARGE_TOOLBAR
- width, height = gtk.icon_size_lookup(size)
+ size = Gtk.IconSize.LARGE_TOOLBAR
+ width, height = Gtk.icon_size_lookup(size)
else:
width, height = size
if icon_name[0:6] == "theme:":
icon_name = self._get_real_name_from_theme(icon_name[6:], size)
- pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon_name, width, height)
+ pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icon_name, width, height)
else:
pixbuf = None
-
+
self._model.append([action_id, text, pixbuf, False])
diff --git a/common/Util/Trackpad.py b/common/Util/Trackpad.py
index 64f9a81..331df1e 100644
--- a/common/Util/Trackpad.py
+++ b/common/Util/Trackpad.py
@@ -1,7 +1,5 @@
-import pygtk
-pygtk.require( '2.0' )
-import gtk
-import gobject
+from gi.repository import Gtk, Gdk, GObject
+import cairo
from common.Util.CSoundClient import new_csound_client
import common.Config as Config
@@ -15,9 +13,9 @@ class Trackpad:
self.win = win
self.csnd = new_csound_client()
- win.add_events(gtk.gdk.POINTER_MOTION_MASK)
- win.add_events(gtk.gdk.BUTTON_PRESS_MASK)
- win.add_events(gtk.gdk.BUTTON_RELEASE_MASK)
+ win.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
+ win.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
+ win.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
win.connect('motion-notify-event',self.handle_motion)
win.connect('key-press-event',self.handle_keyPress)
win.connect('key-release-event',self.handle_keyRelease)
@@ -31,24 +29,24 @@ class Trackpad:
self.buttonPressed = False
- self.create_invisible_cursor()
+ #self.create_invisible_cursor()
self.display = self.win.get_display()
- self.screen = gtk.gdk.Display.get_default_screen(self.display)
+ self.screen = Gdk.Display.get_default_screen(self.display)
self.context = None
def setContext(self, context):
self.context = context
- def create_invisible_cursor(self):
- pix_data = """/* XPM */
- static char * invisible_xpm[] = {
- "1 1 1 1",
- " c None",
- " "};"""
- color = gtk.gdk.Color()
- pix = gtk.gdk.pixmap_create_from_data(None, pix_data, 1, 1, 1, color, color)
- self.invisible_cursor = gtk.gdk.Cursor(pix,pix,color,color,0,0)
+ #def create_invisible_cursor(self):
+ # pix_data = """/* XPM */
+ # static char * invisible_xpm[] = {
+ # "1 1 1 1",
+ # " c None",
+ # " "};"""
+ # color = gtk.gdk.Color()
+ # pix = cairo.ImageSurface(cairo.FORMAT_RGB24, 0, 0)
+ # self.invisible_cursor = gtk.gdk.Cursor(pix,pix,color,color,0,0)
def handle_motion(self,widget,event):
if self.context != 'edit':
@@ -76,20 +74,20 @@ class Trackpad:
def handle_keyPress(self,widget,event):
if KEY_MAP_PIANO.has_key(event.hardware_keycode) and self.buttonPressed == False:
- gtk.gdk.Display.warp_pointer(self.display, self.screen, self.screen.get_width() / 2, self.screen.get_height() / 2)
- gtk.gdk.pointer_grab(self.win.window, event_mask = gtk.gdk.POINTER_MOTION_MASK)#, cursor = self.invisible_cursor)
+ Gdk.Display.warp_pointer(self.display, self.screen, self.screen.get_width() / 2, self.screen.get_height() / 2)
+ Gdk.pointer_grab(self.win.window, event_mask=Gdk.EventType.POINTER_MOTION_MASK)#, cursor = self.invisible_cursor)
self.buttonPressed = True
self.first_x = self.screen.get_width() / 2
self.first_y = self.screen.get_height() / 2
def handle_keyRelease(self,widget,event):
if KEY_MAP_PIANO.has_key(event.hardware_keycode):
- gtk.gdk.pointer_ungrab(time = 0L)
+ Gdk.pointer_ungrab(time = 0L)
self.buttonPressed = False
- self.restoreDelay = gobject.timeout_add(120, self.restore)
+ self.restoreDelay = GObject.timeout_add(120, self.restore)
def restore( self ):
self.csnd.setTrackpadX(0)
self.csnd.setTrackpadY(0)
- gobject.source_remove( self.restoreDelay )
+ GObject.source_remove( self.restoreDelay )
diff --git a/common/port/scrolledbox.py b/common/port/scrolledbox.py
index 47145ae..4d7a6d9 100644
--- a/common/port/scrolledbox.py
+++ b/common/port/scrolledbox.py
@@ -11,31 +11,32 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# Converting to Gtk3 Done.
+from gi.repository import Gtk, Gdk
-import gtk
+from sugar3.graphics.icon import Icon
-from sugar.graphics.icon import Icon
-
-class ScrollButton(gtk.ToolButton):
+class ScrollButton(Gtk.ToolButton):
def __init__(self, icon_name):
- gtk.ToolButton.__init__(self)
+ Gtk.ToolButton.__init__(self)
icon = Icon(icon_name=icon_name,
- icon_size=gtk.ICON_SIZE_SMALL_TOOLBAR)
+ icon_size=Gtk.IconSize.SMALL_TOOLBAR)
# The alignment is a hack to work around gtk.ToolButton code
# that sets the icon_size when the icon_widget is a gtk.Image
- alignment = gtk.Alignment(0.5, 0.5)
+ alignment = Gtk.Alignment()
+ alignment.set(0.5, 0.5, 1.0, 1.0)
alignment.add(icon)
self.set_icon_widget(alignment)
-class ScrolledBox(gtk.EventBox):
+class ScrolledBox(Gtk.EventBox):
def __init__(self, orientation,
- arrows_policy=gtk.POLICY_AUTOMATIC,
- scroll_policy=gtk.POLICY_AUTOMATIC):
+ arrows_policy=Gtk.PolicyType.AUTOMATIC,
+ scroll_policy=Gtk.PolicyType.AUTOMATIC):
- gtk.EventBox.__init__(self)
+ Gtk.EventBox.__init__(self)
self.orientation = orientation
self._viewport = None
self._abox = None
@@ -46,53 +47,53 @@ class ScrolledBox(gtk.EventBox):
self._left = None
self._right = None
- if orientation == gtk.ORIENTATION_HORIZONTAL:
- box = gtk.HBox()
+ if orientation == Gtk.Orientation.HORIZONTAL:
+ box = Gtk.HBox()
else:
- box = gtk.VBox()
- if self._arrows_policy == gtk.POLICY_AUTOMATIC:
+ box = Gtk.VBox()
+ if self._arrows_policy == Gtk.PolicyType.AUTOMATIC:
box.connect("size-allocate", self._box_allocate_cb)
self.add(box)
- if self._arrows_policy != gtk.POLICY_NEVER:
- if orientation == gtk.ORIENTATION_HORIZONTAL:
+ if self._arrows_policy != Gtk.PolicyType.NEVER:
+ if orientation == Gtk.Orientation.HORIZONTAL:
self._left = ScrollButton('go-left')
else:
self._left = ScrollButton('go-up')
self._left.connect('clicked', self._scroll_cb,
- gtk.gdk.SCROLL_LEFT)
+ Gdk.ScrollDirection.LEFT)
box.pack_start(self._left, False, False, 0)
- self._scrolled = gtk.ScrolledWindow()
- if orientation == gtk.ORIENTATION_HORIZONTAL:
- self._scrolled.set_policy(scroll_policy, gtk.POLICY_NEVER)
+ self._scrolled = Gtk.ScrolledWindow()
+ if orientation == Gtk.Orientation.HORIZONTAL:
+ self._scrolled.set_policy(scroll_policy, Gtk.PolicyType.NEVER)
else:
- self._scrolled.set_policy(gtk.POLICY_NEVER, scroll_policy)
+ self._scrolled.set_policy(Gtk.PolicyType.NEVER, scroll_policy)
self._scrolled.connect('scroll-event', self._scroll_event_cb)
box.pack_start(self._scrolled, True, True, 0)
- if orientation == gtk.ORIENTATION_HORIZONTAL:
+ if orientation == Gtk.Orientation.HORIZONTAL:
self._adj = self._scrolled.get_hadjustment()
else:
self._adj = self._scrolled.get_vadjustment()
self._adj.connect('changed', self._scroll_changed_cb)
self._adj.connect('value-changed', self._scroll_changed_cb)
- if self._arrows_policy != gtk.POLICY_NEVER:
- if orientation == gtk.ORIENTATION_HORIZONTAL:
+ if self._arrows_policy != Gtk.PolicyType.NEVER:
+ if orientation == Gtk.Orientation.HORIZONTAL:
self._right = ScrollButton('go-right')
else:
self._right = ScrollButton('go-down')
self._right.connect('clicked', self._scroll_cb,
- gtk.gdk.SCROLL_RIGHT)
+ Gdk.ScrollDirection.RIGHT)
box.pack_start(self._right, False, False, 0)
def modify_fg(self, state, bg):
- gtk.EventBox.modify_fg(self, state, bg)
+ Gtk.EventBox.modify_fg(self, state, bg)
self._viewport.get_parent().modify_fg(state, bg)
def modify_bg(self, state, bg):
- gtk.EventBox.modify_bg(self, state, bg)
+ Gtk.EventBox.modify_bg(self, state, bg)
self._viewport.get_parent().modify_bg(state, bg)
def set_viewport(self, widget):
@@ -102,7 +103,7 @@ class ScrolledBox(gtk.EventBox):
self._viewport.disconnect(self._aviewport_sig)
self._viewport = widget
- if self._arrows_policy == gtk.POLICY_AUTOMATIC:
+ if self._arrows_policy == Gtk.PolicyType.AUTOMATIC:
self._aviewport_sig = self._viewport.connect('size-allocate',
self._viewport_allocate_cb)
@@ -128,7 +129,7 @@ class ScrolledBox(gtk.EventBox):
if not self._abox or not self._aviewport:
return
- if self.orientation == gtk.ORIENTATION_HORIZONTAL:
+ if self.orientation == Gtk.Orientation.HORIZONTAL:
show_flag = self._abox.width < self._aviewport.width
else:
show_flag = self._abox.height < self._aviewport.height
@@ -141,24 +142,24 @@ class ScrolledBox(gtk.EventBox):
self._right.hide()
def _scroll_event_cb(self, widget, event):
- if self.orientation == gtk.ORIENTATION_HORIZONTAL:
- if event.direction == gtk.gdk.SCROLL_UP:
- event.direction = gtk.gdk.SCROLL_LEFT
- if event.direction == gtk.gdk.SCROLL_DOWN:
- event.direction = gtk.gdk.SCROLL_RIGHT
+ if self.orientation == Gtk.Orientation.HORIZONTAL:
+ if event.direction == Gdk.ScrollDirection.UP:
+ event.direction = Gdk.ScrollDirection.LEFT
+ if event.direction == Gdk.ScrollDirection.DOWN:
+ event.direction = Gdk.ScrollDirection.RIGHT
else:
- if event.direction == gtk.gdk.SCROLL_LEFT:
- event.direction = gtk.gdk.SCROLL_UP
- if event.direction == gtk.gdk.SCROLL_RIGHT:
- event.direction = gtk.gdk.SCROLL_DOWN
+ if event.direction == Gdk.ScrollDirection.LEFT:
+ event.direction = Gdk.ScrollDirection.UP
+ if event.direction == Gdk.ScrollDirection.RIGHT:
+ event.direction = Gdk.ScrollDirection.DOWN
- if self._scroll_policy == gtk.POLICY_NEVER:
+ if self._scroll_policy == Gtk.PolicyType.NEVER:
self._scroll_cb(None, event.direction)
return False
def _scroll_cb(self, widget, direction):
- if direction in (gtk.gdk.SCROLL_LEFT, gtk.gdk.SCROLL_UP):
+ if direction in (Gdk.ScrollDirection.LEFT, Gdk.ScrollDirection.UP):
val = max(self._adj.get_property('lower'), self._adj.get_value()
- self._adj.get_property('page_increment'))
else:
@@ -187,9 +188,9 @@ class ScrolledBox(gtk.EventBox):
class HScrolledBox(ScrolledBox):
def __init__(self, **kwargs):
- ScrolledBox.__init__(self, gtk.ORIENTATION_HORIZONTAL, **kwargs)
+ ScrolledBox.__init__(self, Gtk.Orientation.HORIZONTAL, **kwargs)
class VScrolledBox(ScrolledBox):
def __init__(self, **kwargs):
- ScrolledBox.__init__(self, gtk.ORIENTATION_VERTICAL, **kwargs)
+ ScrolledBox.__init__(self, Gtk.Orientation.VERTICAL, **kwargs)