From e256881651711fb39323bdf8cde091ed926187fa Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Tue, 15 Jan 2013 13:07:03 +0000 Subject: Ported TamTamEdit toolbars to Gtk3. Fixed some bugs Signed-off-by: Aaron Gordon --- diff --git a/Edit/EditToolbars.py b/Edit/EditToolbars.py index 9d7eb46..8a5af14 100644 --- a/Edit/EditToolbars.py +++ b/Edit/EditToolbars.py @@ -313,15 +313,17 @@ class paintPalette(Palette): self.noteDurBox.set_active(len) def handleNoteDur(self, widget): - data = widget.props.value - noteDur = int(self.noteDurs[data]) - self.edit.trackInterface.setPaintNoteDur(noteDur) + pass + #data = widget.get_property("value") + #noteDur = int(self.noteDurs[data]) + #self.edit.trackInterface.setPaintNoteDur(noteDur) def handleSnapGrid(self, widget): - data = widget.props.value - grid = int(self.gridDurs[data]) - self.edit.trackInterface.setPaintGrid(grid) - self.resizeNoteDur() + pass + #data = widget.get_active_text() + #grid = int(self.gridDurs[data]) + #self.edit.trackInterface.setPaintGrid(grid) + #self.resizeNoteDur() class volumeTempoPalette(Palette): def __init__(self, label, edit): @@ -404,7 +406,7 @@ class generationPalette(Palette): self.YSlider1BottomLabelBox.pack_start(self.YSlider1Img, False, False, padding = 5) self.YSlider1BottomLabelBox.pack_start(self.YSlider1BottomLabel, False, False, padding = 5) self.XYSlider1MainBox.pack_start(self.XYSlider1TopLabel, False, False, padding = 5) - self.XYSlider1MainBox.pack_start(self.XYSlider1, False, False, padding = 2) + #self.XYSlider1MainBox.pack_start(self.XYSlider1, False, False, padding = 2) self.XYSlider1MainBox.pack_start(self.XSlider1BottomLabelBox, False, False, padding = 2) self.XYSlider1MainBox.pack_start(self.YSlider1BottomLabelBox, False, False, padding = 2) @@ -431,7 +433,7 @@ class generationPalette(Palette): self.YSlider2BottomLabelBox.pack_start(self.YSlider2Img, False, False, padding = 5) self.YSlider2BottomLabelBox.pack_start(self.YSlider2BottomLabel, False, False, padding = 5) self.XYSlider2MainBox.pack_start(self.XYSlider2TopLabel, False, False, padding = 5) - self.XYSlider2MainBox.pack_start(self.XYSlider2, False, False, padding = 2) + #self.XYSlider2MainBox.pack_start(self.XYSlider2, False, False, padding = 2) self.XYSlider2MainBox.pack_start(self.XSlider2BottomLabelBox, False, False, padding = 2) self.XYSlider2MainBox.pack_start(self.YSlider2BottomLabelBox, False, False, padding = 2) @@ -458,7 +460,7 @@ class generationPalette(Palette): self.YSlider3BottomLabelBox.pack_start(self.YSlider3Img, False, False, padding = 5) self.YSlider3BottomLabelBox.pack_start(self.YSlider3BottomLabel, False, False, padding = 5) self.XYSlider3MainBox.pack_start(self.XYSlider3TopLabel, False, False, padding = 5) - self.XYSlider3MainBox.pack_start(self.XYSlider3, False, False, padding = 2) + #self.XYSlider3MainBox.pack_start(self.XYSlider3, False, False, padding = 2) self.XYSlider3MainBox.pack_start(self.XSlider3BottomLabelBox, False, False, padding = 2) self.XYSlider3MainBox.pack_start(self.YSlider3BottomLabelBox, False, False, padding = 2) @@ -555,10 +557,10 @@ class generationPalette(Palette): # 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 ), - "Note_Border": colormap.alloc_color( Config.BG_COLOR, True, True ), - "Note_Fill": colormap.alloc_color( Config.FG_COLOR, True, True ) } + #colormap = self.previewDA.get_colormap() + #self.colors = { "Beat_Line": colormap.alloc_color( "#959595", True, True ), + # "Note_Border": colormap.alloc_color( Config.BG_COLOR, True, True ), + # "Note_Fill": colormap.alloc_color( Config.FG_COLOR, True, True ) } self.scaleBox.set_active(0) self.modeBox.set_active(0) @@ -1018,25 +1020,25 @@ class propertiesPalette(Palette): self.decisionBox.pack_start(self.cancelButton, False, False, padding = 5) self.decisionBox.pack_start(self.acceptButton, False, False, padding = 5) - self.mainBox.pack_start(self.gridDivisionBox, padding = 3) - self.mainBox.pack_start(self.pageColorBox, padding = 3) - self.mainBox.pack_start(self.pageSeparator, padding = 10) - self.mainBox.pack_start(self.transposeBox, padding = 3) - self.mainBox.pack_start(self.volumeBox, padding = 3) - self.mainBox.pack_start(self.panBox, padding = 3) - self.mainBox.pack_start(self.reverbBox, padding = 3) - self.mainBox.pack_start(self.attackDurBox, padding = 3) - self.mainBox.pack_start(self.decayDurBox, padding = 3) - self.mainBox.pack_start(self.filterTypeBox, padding = 3) - self.mainBox.pack_start(self.filterCutoffBox, padding = 3) - self.generationMainBox.pack_start(self.generationSeparator, padding = 5) - self.generationMainBox.pack_start(self.generationLabel, padding = 10) - self.generationMainBox.pack_start(self.generationTypeBox, padding = 3) - self.generationMainBox.pack_start(self.minimumBox, padding = 3) - self.generationMainBox.pack_start(self.maximumBox, padding = 3) - self.generationMainBox.pack_start(self.randomBox, padding = 3) - self.generationMainBox.pack_start(self.decisionBox, padding = 3) - self.mainBox.pack_start(self.generationMainBox, padding = 3) + self.mainBox.pack_start(self.gridDivisionBox, True, True, padding = 3) + self.mainBox.pack_start(self.pageColorBox, True, True, padding = 3) + self.mainBox.pack_start(self.pageSeparator, True, True, padding = 10) + self.mainBox.pack_start(self.transposeBox, True, True, padding = 3) + self.mainBox.pack_start(self.volumeBox, True, True, padding = 3) + self.mainBox.pack_start(self.panBox, True, True, padding = 3) + self.mainBox.pack_start(self.reverbBox, True, True, padding = 3) + self.mainBox.pack_start(self.attackDurBox, True, True, padding = 3) + self.mainBox.pack_start(self.decayDurBox, True, True, padding = 3) + self.mainBox.pack_start(self.filterTypeBox, True, True, padding = 3) + self.mainBox.pack_start(self.filterCutoffBox, True, True, padding = 3) + self.generationMainBox.pack_start(self.generationSeparator, True, True, padding = 5) + self.generationMainBox.pack_start(self.generationLabel, True, True, padding = 10) + self.generationMainBox.pack_start(self.generationTypeBox, True, True, padding = 3) + self.generationMainBox.pack_start(self.minimumBox, True, True, padding = 3) + self.generationMainBox.pack_start(self.maximumBox, True, True, padding = 3) + self.generationMainBox.pack_start(self.randomBox, True, True, padding = 3) + self.generationMainBox.pack_start(self.decisionBox, True, True, padding = 3) + self.mainBox.pack_start(self.generationMainBox, True, True, padding = 3) self.mainBox.show_all() self.generationMainBox.hide() diff --git a/Edit/HitInterface.py b/Edit/HitInterface.py index 84e0356..db8700f 100644 --- a/Edit/HitInterface.py +++ b/Edit/HitInterface.py @@ -192,8 +192,9 @@ class HitInterface( NoteInterface ): if self.selected: img = self.imageSelected else: img = self.image - cxt.set_source_surface(img, 0, 0) - cxt.paint() + cxt.set_source_surface(img, self.imgX, self.imgY) + cxt.rectangle(self.x+2, self.y+2, self.width-4, self.height-4) + cxt.fill() #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 9269a19..3ea2a19 100644 --- a/Edit/MainWindow.py +++ b/Edit/MainWindow.py @@ -418,13 +418,13 @@ class MainWindow(Gtk.EventBox): 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._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() @@ -435,13 +435,13 @@ class MainWindow(Gtk.EventBox): 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) + 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 @@ -946,7 +946,7 @@ class MainWindow(Gtk.EventBox): def handleTempo(self, widget): self._data['tempo'] = round(widget.get_value()) - img = min(7,int(8*(self._data["tempo"]-widget.lower)/(widget.upper-widget.lower)))+1 # tempo 1-8 + img = min(7,int(8*(self._data["tempo"] - widget.get_lower())/(widget.get_upper() - widget.get_lower())))+1 # tempo 1-8 #self.GUI["2tempoImage"].set_from_file(imagefile('tempo' + str(img) + '.png')) if self.playing: self.csnd.setTempo(self._data['tempo']) diff --git a/Edit/NoteInterface.py b/Edit/NoteInterface.py index 5e3da41..7ba04b8 100644 --- a/Edit/NoteInterface.py +++ b/Edit/NoteInterface.py @@ -176,7 +176,7 @@ class 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 @@ -185,7 +185,7 @@ class NoteInterface: check += self.note.cs.duration while stop < check: stop += Config.TICKS_PER_BEAT emitter.selectNotesByBar( self.note.track, start, stop ) - elif event.type == gtk.gdk._3BUTTON_PRESS: # select track + elif event.type == Gdk.EventType._3BUTTON_PRESS: # select track self.potentialDeselect = False emitter.selectNotesByTrack( self.note.track ) else: @@ -337,16 +337,19 @@ class NoteInterface: if startX > self.imgX + self.imgWidth: return True # we don't need to draw, but maybe a later note does 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.rectangle(self.x+1, self.y, 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 ) - cxt.set_source_surface(img, 0, 0) - cxt.paint() - cxt.set_source_surface(img, Config.NOTE_IMAGE_TAIL, 0) - cxt.paint() + cxt.set_source_surface(img, self.x+1, self.y) + cxt.rectangle(self.x+1, self.y, self.width-2, self.height-2) + cxt.fill() + + #cxt.set_source_surface(img, self.imgX+self.imgWidth-Config.NOTE_IMAGE_ENDLENGTH, self.imgY) + #cxt.rectangle(self.imgX+self.imgWidth-Config.NOTE_IMAGE_ENDLENGTH, self.imgY, self.imgWidth-Config.NOTE_IMAGE_ENDLENGTH, self.imgHeight) + #cxt.fill() #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 d7ee42b..ea50dab 100644 --- a/Edit/TrackInterface.py +++ b/Edit/TrackInterface.py @@ -148,8 +148,7 @@ class TrackInterface( Gtk.EventBox ): #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 ): - path = "common/Resources/Images/" - self.image[name] = cairo.ImageSurface.create_from_png(path + name + '.png') + self.image[name] = cairo.ImageSurface.create_from_png(imagefile(name + '.png')) prepareDrawable( "trackBG", width ) prepareDrawable( "trackBGSelected", width ) @@ -386,7 +385,7 @@ class TrackInterface( Gtk.EventBox ): def handleButtonPress( self, widget, event ): TP.ProfileBegin( "TI::handleButtonPress" ) - + print event.x, event.y self.clickButton = event.button if event.type == Gdk.EventType._2BUTTON_PRESS: self.buttonPressCount = 2 @@ -576,9 +575,8 @@ class TrackInterface( Gtk.EventBox ): def handleMotion( self, widget, event ): TP.ProfileBegin( "TI::handleMotion::Common" ) - #if event.is_hint: - if True: - x, y = widget.get_pointer() + if event.is_hint: + x, y = event.x, event.y event.x = float(x) event.y = float(y) #event.state = state @@ -652,7 +650,6 @@ class TrackInterface( Gtk.EventBox ): self.updateTooltip( event ) TP.ProfileEnd( "TI::handleMotion::Hover" ) return - if self.curAction == "paste": TP.ProfileBegin( "TI::handleMotion::Paste" ) top = Config.NUMBER_OF_TRACKS @@ -663,7 +660,8 @@ class TrackInterface( Gtk.EventBox ): break self.updatePaste( self.pixelsToTicksFloor( self.curBeats, event.x ), top ) TP.ProfileEnd( "TI::handleMotion::Paste" ) - elif event.state & gtk.gdk.BUTTON1_MASK: + + elif event.state & Gdk.EventMask.BUTTON1_MOTION_MASK: TP.ProfileBegin( "TI::handleMotion::Drag" ) if not self.curAction: # no action is in progress yet we're dragging, start a marquee diff --git a/Edit/TuneInterface.py b/Edit/TuneInterface.py index 7a94080..fb145c4 100644 --- a/Edit/TuneInterface.py +++ b/Edit/TuneInterface.py @@ -618,7 +618,6 @@ class TuneInterface( Gtk.EventBox ): #self.gc.set_clip_origin( 0, 0 ) self.drawThumbnail( pageId, self.thumbnail[pageId], self.thumbnailDirtyRect[pageId] ) #self.gc.set_clip_origin( x, self.pageY ) - print "Coordinates ", x, self.pageY cr.set_source_surface(self.thumbnail[pageId], x, self.pageY) cr.paint() diff --git a/common/Util/ThemeWidgets.py b/common/Util/ThemeWidgets.py index 8d7f5b5..98c1acb 100644 --- a/common/Util/ThemeWidgets.py +++ b/common/Util/ThemeWidgets.py @@ -752,14 +752,12 @@ class RoundFixed( Gtk.Fixed ): 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) + #mainImg_path = imagefile(mainImg_path) + #clickImg_path = imagefile(clickImg_path) + #enterImg_path = imagefile(enterImg_path) Gtk.Button.__init__(self) self.alloc = None - win = gtk.gdk.get_default_root_window() - self.gc = gtk.gdk.GC( win ) self.image = {} self.itype = {} self.iwidth = {} @@ -769,6 +767,16 @@ class ImageButton(Gtk.Button): self.backgroundFill = backgroundFill + def newPrepareImage(name, path): + if path.endswith(".svg"): + pix = GdkPixbuf.Pixbuf.new_from_file(path) + self.image[name] = pix + self.itype[name] = ITYPE.PIXBUF + self.iwidth[name] = pix.get_width() + self.iwidthDIV2[name] = self.iwidth[name]//2 + self.iheight[name] = pix.get_height() + self.iheightDIV2[name] = self.iheight[name]//2 + def prepareImage( name, path ): pix = gtk.gdk.pixbuf_new_from_file(path) if pix.get_has_alpha(): @@ -791,14 +799,14 @@ class ImageButton(Gtk.Button): self.iheight[name] = pix.get_height() self.iheightDIV2[name] = self.iheight[name]//2 - prepareImage( "main", mainImg_path ) + newPrepareImage( "main", mainImg_path ) if enterImg_path != None: - prepareImage( "enter", enterImg_path ) + newPrepareImage( "enter", enterImg_path ) self.connect('enter-notify-event',self.on_btn_enter) self.connect('leave-notify-event',self.on_btn_leave) if clickImg_path != None: - prepareImage( "click", clickImg_path ) + newPrepareImage( "click", clickImg_path ) self.connect('pressed',self.on_btn_press, None) self.connect('released',self.on_btn_release, None) if enterImg_path == None: @@ -814,7 +822,7 @@ class ImageButton(Gtk.Button): self.curImage = self.upImage = "main" self.down = False - self.connect('expose-event', self.expose) + self.connect('draw', self.draw) self.connect('size-allocate', self.size_allocate) self.set_size_request(self.iwidth["main"],self.iheight["main"]) @@ -824,6 +832,12 @@ class ImageButton(Gtk.Button): self.drawX = allocation.x + allocation.width//2 self.drawY = allocation.y + allocation.height//2 + def draw(self, widget, cr): + #Gdk.cairo_set_source_pixbuf(cr, self.image[self.curImage], 0, 0) + #cr.paint() + cr.rectangle(0, 0, 100, 100) + cr.fill() + def expose(self, widget, event): if self.itype[self.curImage] == ITYPE.PIXBUF: self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], gtk.gdk.RGB_DITHER_NONE) @@ -832,6 +846,7 @@ class ImageButton(Gtk.Button): return True def setImage(self, name, pix): + print "setImage ", name, pix if name == "main" and self.image["main"] == self.image["enter"]: updateEnter = True else: @@ -907,6 +922,7 @@ class ImageToggleButton(Gtk.ToggleButton): self.alloc = None self.within = False self.clicked = False + self.is_png = True self.image = {} self.itype = {} @@ -918,28 +934,16 @@ class ImageToggleButton(Gtk.ToggleButton): self.backgroundFill = backgroundFill def prepareImage( name, path ): - 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] = cairo.ImageSurface(cairo.FORMAT_RGB24, pix.get_width(), pix.get_height() ) - cxt = cairo.Context(self.image[name]) - colormap = self.get_colormap() - print backgroundFill - #self.gc.foreground = colormap.alloc_color( backgroundFill, True, True ) - cxt.rectangle(0, 0, pix.get_width(), pix.get_height() ) - cxt.fill() + if path.endswith(".png"): + pix = cairo.ImageSurface.create_from_png(path) + self.is_png = True - cxt.set_source_pixbuf(pix, 0, 0) - cxt.paint() - self.itype[name] = ITYPE.PIXMAP - else: - 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 + elif path.endswith(".svg"): + pix = GdkPixbuf.Pixbuf.new_from_file(path) + self.is_png = False + + self.image[name] = pix + self.itype[name] = ITYPE.PIXBUF self.iwidth[name] = pix.get_width() self.iwidthDIV2[name] = self.iwidth[name]//2 @@ -965,7 +969,7 @@ class ImageToggleButton(Gtk.ToggleButton): self.connect('toggled',self.toggleImage) self.connect('pressed',self.pressed ) self.connect('released',self.released ) - self.connect('draw', self.expose) + self.connect('draw', self.draw) self.connect('size-allocate', self.size_allocate) self.set_size_request(self.iwidth["main"],self.iheight["main"]) @@ -977,6 +981,15 @@ class ImageToggleButton(Gtk.ToggleButton): self.drawX = allocation.x + allocation.width//2 self.drawY = allocation.y + allocation.height//2 + def draw(self, widget, cr): + if self.is_png: + cr.set_source_surface(self.image[self.curImage], 0, 0) + cr.paint() + else: + Gdk.cairo_set_source_pixbuf(cr, self.image[self.curImage], 0, 0) + cr.paint() + return True + def expose(self, widget, cr): if self.itype[self.curImage] == ITYPE.PIXBUF: cr.set_source_surface(self.image[self.curImage], 0, 0) -- cgit v0.9.1