diff options
-rw-r--r-- | Edit/MainWindow.py | 24 | ||||
-rw-r--r-- | Edit/TrackInterface.py | 10 | ||||
-rwxr-xr-x | Resources/Images/pencil.png | bin | 0 -> 1173 bytes | |||
-rwxr-xr-x | Resources/Images/pencilDown.png | bin | 0 -> 1859 bytes | |||
-rwxr-xr-x | Resources/Images/pointer.png | bin | 0 -> 1444 bytes | |||
-rwxr-xr-x | Resources/Images/pointerDown.png | bin | 0 -> 2208 bytes | |||
-rw-r--r-- | Util/ThemeWidgets.py | 253 |
7 files changed, 192 insertions, 95 deletions
diff --git a/Edit/MainWindow.py b/Edit/MainWindow.py index 9270fab..482b0f3 100644 --- a/Edit/MainWindow.py +++ b/Edit/MainWindow.py @@ -190,6 +190,19 @@ class MainWindow( gtk.EventBox ): # + tool panel self.GUI["2toolPanel"] = gtk.HBox() self.GUI["2toolPanel"].set_size_request( -1, 75 ) + # + + tool box + self.GUI["2toolBox"] = formatRoundBox( RoundHBox(), "#6C9790" ) + self.GUI["2toolBox"].set_size_request( 146, -1 ) + self.GUI["2toolPointerButton"] = ImageRadioButton( None, Config.IMAGE_ROOT+"pointer.png", Config.IMAGE_ROOT+"pointerDown.png" ) +# self.GUI["2toolPointerButton"].set_active( True ) + self.GUI["2toolPointerButton"].toggled() + self.GUI["2toolPointerButton"].connect( "clicked", self.handleToolClick , "Default" ) + self.GUI["2toolBox"].pack_start( self.GUI["2toolPointerButton"] ) + self.GUI["2toolPencilButton"] = ImageRadioButton( self.GUI["2toolPointerButton"], Config.IMAGE_ROOT+"pencil.png", Config.IMAGE_ROOT+"pencilDown.png" ) + self.GUI["2toolPencilButton"].connect( "clicked", self.handleToolClick , "Draw" ) + self.GUI["2toolBox"].pack_start( self.GUI["2toolPencilButton"] ) + self.GUI["2toolPanel"].pack_start( self.GUI["2toolBox"], False, False ) + self.GUI["2rightPanel"].pack_start( self.GUI["2toolPanel"], False ) # + + page box self.GUI["2pageBox"] = formatRoundBox( RoundHBox(), "#6C9790" ) self.GUI["2pageDeleteButton"] = gtk.Button("Delete") @@ -218,14 +231,6 @@ class MainWindow( gtk.EventBox ): self.GUI["2loopButton"] = gtk.Button("Loop") self.GUI["2transportBox"].pack_start( self.GUI["2loopButton"] ) self.GUI["2toolPanel"].pack_start( self.GUI["2transportBox"] ) - # + + tool box - self.GUI["2toolBox"] = formatRoundBox( RoundHBox(), "#6C9790" ) - self.GUI["2toolPencilButton"] = gtk.Button("Pencil") - self.GUI["2toolBox"].pack_start( self.GUI["2toolPencilButton"] ) - self.GUI["2toolPointerButton"] = gtk.Button("Pointer") - self.GUI["2toolBox"].pack_start( self.GUI["2toolPointerButton"] ) - self.GUI["2toolPanel"].pack_start( self.GUI["2toolBox"] ) - self.GUI["2rightPanel"].pack_start( self.GUI["2toolPanel"], False ) # + tune box self.GUI["2tuneBox"] = formatRoundBox( RoundVBox(), "#6C9790" ) self.GUI["2tuneScrolledWindow"] = gtk.ScrolledWindow() @@ -602,6 +607,9 @@ class MainWindow( gtk.EventBox ): img = min(7,int(8*(self._data["tempo"]-widget.lower)/(widget.upper-widget.lower)))+1# tempo 1-8 self.GUI["2tempoImage"].set_from_file( Config.IMAGE_ROOT+"tempo"+str(img)+".png" ) + + def handleToolClick( self, widget, mode ): + if widget.get_active(): self.trackInterface.setInterfaceMode( mode ) def onKeyboardButton( self, widget, data ): self.kb_active = widget.get_active() diff --git a/Edit/TrackInterface.py b/Edit/TrackInterface.py index 4abf75a..af4f836 100644 --- a/Edit/TrackInterface.py +++ b/Edit/TrackInterface.py @@ -38,7 +38,7 @@ class TrackInterface( gtk.EventBox ): self.width = 1 self.height = 1 - self.interfaceMode = INTERFACEMODE.DRAW + self.interfaceMode = INTERFACEMODE.DEFAULT self.note = {} # list of pages, tracks, and notes: self.note[pageId][trackId][noteId] self.pageBeatCount = {} # keep track of the beat count for each page @@ -307,6 +307,14 @@ class TrackInterface( gtk.EventBox ): if self.trackSelected[i]: r.append( i ) return r + def setInterfaceMode( self, mode ): + if mode == "Draw": + self.interfaceMode = INTERFACEMODE.DRAW + elif mode == "Paste": + self.interfaceMode = INTERFACEMODE.PASTE + else: + self.interfaceMode = INTERFACEMODE.DEFAULT + # private def updateNoteMap( self, page ): self.noteMap[page] = {} diff --git a/Resources/Images/pencil.png b/Resources/Images/pencil.png Binary files differnew file mode 100755 index 0000000..9daa8fd --- /dev/null +++ b/Resources/Images/pencil.png diff --git a/Resources/Images/pencilDown.png b/Resources/Images/pencilDown.png Binary files differnew file mode 100755 index 0000000..245d9ca --- /dev/null +++ b/Resources/Images/pencilDown.png diff --git a/Resources/Images/pointer.png b/Resources/Images/pointer.png Binary files differnew file mode 100755 index 0000000..68a6c6e --- /dev/null +++ b/Resources/Images/pointer.png diff --git a/Resources/Images/pointerDown.png b/Resources/Images/pointerDown.png Binary files differnew file mode 100755 index 0000000..bd37524 --- /dev/null +++ b/Resources/Images/pointerDown.png diff --git a/Util/ThemeWidgets.py b/Util/ThemeWidgets.py index 7b7d470..88dbb11 100644 --- a/Util/ThemeWidgets.py +++ b/Util/ThemeWidgets.py @@ -2,6 +2,11 @@ import pygtk pygtk.require( '2.0' ) import gtk + +class ITYPE: + PIXBUF = 0 + PIXMAP = 1 + 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 ) @@ -471,156 +476,232 @@ class ImageButton(gtk.Button): def __init__(self , mainImg_path, enterImg_path = None, clickImg_path = None): gtk.Button.__init__(self) self.alloc = None - - self.enterImg = None - self.clickImg = None + win = gtk.gdk.get_default_root_window() + self.gc = gtk.gdk.GC( win ) + self.image = {} + self.itype = {} + self.iwidth = {} + self.iwidthDIV2 = {} + self.iheight = {} + self.iheightDIV2 = {} + + def prepareImage( name, path ): + pix = gtk.gdk.pixbuf_new_from_file(path) + if pix.get_has_alpha(): + 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].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE ) + self.itype[name] = ITYPE.PIXMAP + 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 + + prepareImage( "main", mainImg_path ) if enterImg_path != None: - self.enterImg = gtk.gdk.pixbuf_new_from_file(enterImg_path) + prepareImage( "enter", enterImg_path ) self.connect('enter',self.on_btn_enter, None) self.connect('leave',self.on_btn_leave, None) - if clickImg_path != None: - self.clickImg = gtk.gdk.pixbuf_new_from_file(clickImg_path) + prepareImage( "click", clickImg_path ) self.connect('pressed',self.on_btn_press, None) self.connect('released',self.on_btn_release, None) - - self.mainImg = gtk.gdk.pixbuf_new_from_file(mainImg_path) - self.image = self.mainImg - self.set_size_request(self.image.get_width(),self.image.get_height()) - + if enterImg_path == None: + self.image["enter"] = self.image["main"] + self.itype["enter"] = self.itype["main"] + self.iwidth["enter"] = self.iwidth["main"] + self.iwidthDIV2["enter"] = self.iwidthDIV2["main"] + self.iheight["enter"] = self.iheight["main"] + self.iheightDIV2["enter"] = self.iheightDIV2["main"] + self.connect('enter',self.on_btn_enter, None) + self.connect('leave',self.on_btn_leave, None) + + self.curImage = self.upImage = self.stateImage = "main" + self.connect('expose-event', self.expose) self.connect('size-allocate', self.size_allocate) + self.set_size_request(self.iwidth["main"],self.iheight["main"]) + def size_allocate(self, widget, allocation): self.alloc = allocation + self.drawX = allocation.x + allocation.width//2 + self.drawY = allocation.y + allocation.height//2 def expose(self, widget, event): - style = self.get_style() - gc = style.fg_gc[gtk.STATE_NORMAL] - self.window.draw_pixbuf(gc, self.image, 0, 0, self.alloc.x + (self.alloc.width//2) - self.image.get_width() // 2 , self.alloc.y + (self.alloc.height//2) - (self.image.get_height() // 2), width=self.image.get_width() , height=self.image.get_height(), dither=gtk.gdk.RGB_DITHER_NORMAL, x_dither=0, y_dither=0) + if self.itype[self.curImage] == ITYPE.PIXBUF: + self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iwidthDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], gtk.gdk.RGB_DITHER_NONE) + else: + self.window.draw_drawable( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iwidthDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage] ) return True - + + def on_btn_press(self, widget, event): + self.curImage = self.stateImage = "click" + self.queue_draw() + def on_btn_enter(self, widget, event): - self.image = self.enterImg + self.upImage = "enter" + self.curImage = self.stateImage self.queue_draw() def on_btn_leave(self, widget, event): - self.image = self.mainImg - self.queue_draw() - - def on_btn_press(self, widget, event): - self.image = self.clickImg + self.curImage = self.upImage = "main" self.queue_draw() def on_btn_release(self, widget, event): - if self.enterImg != None: - self.image = self.enterImg - self.queue_draw() - else: - self.image = self.mainImg - self.queue_draw() + self.curImage = self.upImage + self.stateImage = "main" + self.queue_draw() class ImageToggleButton(gtk.ToggleButton): + def __init__(self , mainImg_path, altImg_path, enterImg_path = None): gtk.ToggleButton.__init__(self) self.alloc = None - self.mainImg = gtk.gdk.pixbuf_new_from_file(mainImg_path) - self.altImg = gtk.gdk.pixbuf_new_from_file(altImg_path) + win = gtk.gdk.get_default_root_window() + self.gc = gtk.gdk.GC( win ) + self.image = {} + self.itype = {} + self.iwidth = {} + self.iwidthDIV2 = {} + self.iheight = {} + self.iheightDIV2 = {} + + def prepareImage( name, path ): + pix = gtk.gdk.pixbuf_new_from_file(path) + if pix.get_has_alpha(): + 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].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE ) + self.itype[name] = ITYPE.PIXMAP + 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 + + prepareImage( "main", mainImg_path ) + prepareImage( "alt", altImg_path ) + if enterImg_path != None: - self.enterImg = gtk.gdk.pixbuf_new_from_file(enterImg_path) + prepareImage( "enter", enterImg_path ) self.connect('enter',self.on_btn_enter, None) self.connect('leave',self.on_btn_leave, None) - self.connect('clicked',self.on_btn_click, None) - - self.set_size_request(self.mainImg.get_width(),self.mainImg.get_height()) - + + self.connect('toggled',self.toggleImage, None) self.connect('expose-event', self.expose) self.connect('size-allocate', self.size_allocate) - self.switch() - def size_allocate(self, widget, allocation): - self.alloc = allocation + self.set_size_request(self.iwidth["main"],self.iheight["main"]) - def switch(self): - if not self.get_active(): - self.image = self.mainImg - self.queue_draw() - else: - self.image = self.altImg - self.queue_draw() + self.toggleImage( self, None ) + def size_allocate(self, widget, allocation): + self.alloc = allocation + self.drawX = allocation.x + allocation.width//2 + self.drawY = allocation.y + allocation.height//2 + def expose(self, widget, event): - style = self.get_style() - gc = style.fg_gc[gtk.STATE_NORMAL] - self.window.draw_pixbuf(gc, self.image, 0, 0, self.alloc.x + (self.alloc.width//2) - self.image.get_width() // 2 , self.alloc.y + (self.alloc.height//2) - (self.image.get_height() // 2), width=self.image.get_width() , height=self.image.get_height(), dither=gtk.gdk.RGB_DITHER_NORMAL, x_dither=0, y_dither=0) + if self.itype[self.curImage] == ITYPE.PIXBUF: + self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iwidthDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], gtk.gdk.RGB_DITHER_NONE) + else: + self.window.draw_drawable( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iwidthDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage] ) return True - def on_btn_click(self, widget, event): - self.switch() + def toggleImage(self, widget, event): + if not self.get_active(): + self.curImage = "main" + else: + self.curImage = "alt" + self.queue_draw() def on_btn_enter(self, widget, event): - self.image = self.enterImg + self.curImage = "enter" self.queue_draw() def on_btn_leave(self, widget, event): - if self.get_active() == True: - self.image = self.altImg - self.queue_draw() + if not self.get_active(): + self.curImage = "main" else: - self.image = self.mainImg - self.queue_draw() + self.curImage = "alt" + self.queue_draw() class ImageRadioButton(gtk.RadioButton): - def __init__(self , group, mainImg_path, altImg_path, enterImg_path = None): + def __init__( self, group, mainImg_path, altImg_path, enterImg_path = None): gtk.RadioButton.__init__(self, group) self.alloc = None - self.mainImg = gtk.gdk.pixbuf_new_from_file(mainImg_path) - self.altImg = gtk.gdk.pixbuf_new_from_file(altImg_path) + win = gtk.gdk.get_default_root_window() + self.gc = gtk.gdk.GC( win ) + self.image = {} + self.itype = {} + self.iwidth = {} + self.iwidthDIV2 = {} + self.iheight = {} + self.iheightDIV2 = {} + + def prepareImage( name, path ): + pix = gtk.gdk.pixbuf_new_from_file(path) + if pix.get_has_alpha(): + 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].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE ) + self.itype[name] = ITYPE.PIXMAP + 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 + + prepareImage( "main", mainImg_path ) + prepareImage( "alt", altImg_path ) + if enterImg_path != None: - self.enterImg = gtk.gdk.pixbuf_new_from_file(enterImg_path) + prepareImage( "enter", enterImg_path ) self.connect('enter',self.on_btn_enter, None) self.connect('leave',self.on_btn_leave, None) - self.connect('clicked',self.on_btn_click, None) - - self.set_size_request(self.mainImg.get_width(),self.mainImg.get_height()) - + + self.connect("toggled", self.toggleImage, None ) self.connect('expose-event', self.expose) self.connect('size-allocate', self.size_allocate) - self.switch() + + self.set_size_request(self.iwidth["main"],self.iheight["main"]) + + self.toggleImage( self, None ) def size_allocate(self, widget, allocation): self.alloc = allocation - - def switch(self): - if not self.get_active(): - self.image = self.mainImg - self.queue_draw() - else: - self.image = self.altImg - self.queue_draw() + self.drawX = allocation.x + allocation.width//2 + self.drawY = allocation.y + allocation.height//2 def expose(self, widget, event): - style = self.get_style() - gc = style.fg_gc[gtk.STATE_NORMAL] - self.window.draw_pixbuf(gc, self.image, 0, 0, self.alloc.x + (self.alloc.width//2) - self.image.get_width() // 2 , self.alloc.y + (self.alloc.height//2) - (self.image.get_height() // 2), width=self.image.get_width() , height=self.image.get_height(), dither=gtk.gdk.RGB_DITHER_NORMAL, x_dither=0, y_dither=0) + 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.alloc.y + (self.alloc.height//2) - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], gtk.gdk.RGB_DITHER_NONE) + self.window.draw_pixbuf( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage], gtk.gdk.RGB_DITHER_NONE) + else: + self.window.draw_drawable( self.gc, self.image[self.curImage], 0, 0, self.drawX - self.iwidthDIV2[self.curImage], self.drawY - self.iheightDIV2[self.curImage], self.iwidth[self.curImage], self.iheight[self.curImage] ) return True - def on_btn_click(self, widget, event): - self.switch() - + def toggleImage(self, widget, event): + if not self.get_active(): + self.curImage = "main" + else: + self.curImage = "alt" + self.queue_draw() + def on_btn_enter(self, widget, event): - self.image = self.enterImg + self.curImage = "enter" self.queue_draw() def on_btn_leave(self, widget, event): - if self.get_active() == True: - self.image = self.altImg - self.queue_draw() + if not self.get_active(): + self.curImage = "main" else: - self.image = self.mainImg - self.queue_draw() - - + self.curImage = "alt" + self.queue_draw() |