Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Edit/HitInterface.py2
-rw-r--r--Edit/MainWindow.py26
-rw-r--r--Edit/NoteInterface.py7
-rw-r--r--Edit/TrackInterface.py5
-rw-r--r--Util/ThemeWidgets.py405
5 files changed, 271 insertions, 174 deletions
diff --git a/Edit/HitInterface.py b/Edit/HitInterface.py
index 1b12b1f..f121302 100644
--- a/Edit/HitInterface.py
+++ b/Edit/HitInterface.py
@@ -48,6 +48,8 @@ class HitInterface( NoteInterface ):
endy = max( self.imgY, oldY ) + self.imgHeight
self.owner.invalidate_rect( x, y, endx-x, endy-y, self.note.page )
+ self.firstTransform = False
+
def updateDragLimits( self, dragLimits, leftBound, rightBound, widthBound, maxRightBound ):
left = 0 - self.note.cs.onset
right = maxRightBound - self.note.cs.duration - self.note.cs.onset
diff --git a/Edit/MainWindow.py b/Edit/MainWindow.py
index 4514f3e..14de116 100644
--- a/Edit/MainWindow.py
+++ b/Edit/MainWindow.py
@@ -198,6 +198,13 @@ class MainWindow( gtk.EventBox ):
# right panel
self.GUI["2rightPanel"] = gtk.VBox()
if 1: # + track interface
+ #self.GUI["2XYSliderFixed"] = formatRoundBox( RoundFixed(), "#6C9790" )
+ #self.GUI["2XYSliderFixed"].set_size_request( -1, 713 )
+ #self.GUI["2XYSliderButton"] = ImageToggleButton( Config.IMAGE_ROOT+"pointer.png", Config.IMAGE_ROOT+"pointerDown.png" )
+ #self.GUI["2XYSliderXAdjustment"] = gtk.Adjustment( 650, 500, 1000, 1, 1, 1 )
+ #self.GUI["2XYSliderYAdjustment"] = gtk.Adjustment( 650, 500, 1000, 1, 1, 1 )
+ #self.GUI["2XYSlider"] = XYSlider( self.GUI["2XYSliderFixed"], self.GUI["2XYSliderButton"], self.GUI["2XYSliderXAdjustment"], self.GUI["2XYSliderYAdjustment"], True, True )
+ #self.GUI["2rightPanel"].pack_start( self.GUI["2XYSlider"], False, False, 0 )
self.trackInterface = TrackInterface( self.noteDB, self )
self.noteDB.addListener( self.trackInterface, TrackInterfaceParasite )
self.trackInterface.set_size_request( -1, 713 )
@@ -267,9 +274,6 @@ class MainWindow( gtk.EventBox ):
# + + + note box
self.GUI["2noteBox"] = gtk.HBox()
self.GUI["2noteBox"].set_size_request( contextWidth-50, -1 )
- self.GUI["2noteGenerateButton"] = gtk.Button("nGen")
- self.GUI["2noteGenerateButton"].connect( "clicked", lambda a1:self.noteGenerate() )
- self.GUI["2noteBox"].pack_start( self.GUI["2noteGenerateButton"] )
self.GUI["2notePropertiesButton"] = gtk.Button("nProp")
self.GUI["2notePropertiesButton"].connect( "clicked", lambda a1:self.noteProperties() )
self.GUI["2noteBox"].pack_start( self.GUI["2notePropertiesButton"] )
@@ -570,11 +574,7 @@ class MainWindow( gtk.EventBox ):
for p in range(Config.NUMBER_OF_PAGES):
dict[t][p] = []
- if self.generateMode == "note":
- # unsupported!?
- self.handleCloseGenerationParametersWindow( None, None )
- return
- elif self.generateMode == "track":
+ if self.generateMode == "track":
if self.trackSelected == [ 0 for i in range(Config.NUMBER_OF_TRACKS) ]:
newtracks = set(range(Config.NUMBER_OF_TRACKS))
else:
@@ -610,10 +610,7 @@ class MainWindow( gtk.EventBox ):
newnotes += dict[tid][pid]
# delete the notes and add the new
- if self.generateMode == "note":
- print "TODO generateMode == note"
- else: # track or page mode
- self.noteDB.deleteNotesByTrack( newpages, newtracks )
+ self.noteDB.deleteNotesByTrack( newpages, newtracks )
stream = []
for page in newpages:
@@ -654,11 +651,6 @@ class MainWindow( gtk.EventBox ):
#=======================================================
# Note Functions
- def noteGenerate( self ):
- self.generateMode = "note"
- self.generationParametersWindow.show_all()
- return
-
def noteProperties( self ):
# TODO
return
diff --git a/Edit/NoteInterface.py b/Edit/NoteInterface.py
index 25a160d..c923013 100644
--- a/Edit/NoteInterface.py
+++ b/Edit/NoteInterface.py
@@ -41,7 +41,6 @@ class NoteInterface:
def destroy( self ):
if self.selected:
- print "destroy", self.note.id
self.owner.deselectNotes( { self.note.track: [self] } )
else: # if we were deselected above the rect has already been invalidated
self.owner.invalidate_rect( self.imgX, self.imgY, self.imgWidth, self.imgHeight, self.note.page, True )
@@ -100,7 +99,6 @@ class NoteInterface:
if dirty:
if self.firstTransform:
self.owner.invalidate_rect( self.imgX, self.imgY, self.imgWidth, self.imgHeight, self.note.page, True )
- self.firstTransform = False
else:
x = min( self.imgX, oldX )
y = min( self.imgY, oldY )
@@ -108,6 +106,8 @@ class NoteInterface:
endy = max( self.imgY, oldY ) + self.imgHeight
self.owner.invalidate_rect( x, y, endx-x, endy-y, self.note.page, True )
+ self.firstTransform = False
+
def updateDragLimits( self, dragLimits, leftBound, rightBound, widthBound, maxRightBound ):
left = leftBound - self.note.cs.onset
right = rightBound - self.note.cs.duration - self.note.cs.onset
@@ -306,8 +306,7 @@ class NoteInterface:
def setSelected( self, state ):
if self.selected != state:
self.selected = state
- if self.note.page == self.owner.curPage:
- self.owner.invalidate_rect( self.imgX, self.imgY, self.imgWidth, self.imgHeight, self.note.page )
+ self.owner.invalidate_rect( self.imgX, self.imgY, self.imgWidth, self.imgHeight, self.note.page )
return True # state changed
return False # state is the same
diff --git a/Edit/TrackInterface.py b/Edit/TrackInterface.py
index a5b7593..ce3ad6e 100644
--- a/Edit/TrackInterface.py
+++ b/Edit/TrackInterface.py
@@ -204,6 +204,7 @@ class TrackInterface( gtk.EventBox ):
return False
def predrawPage( self, timeout ):
+ if self.screenBufPage[self.preScreen] == -1: return True # no page to predraw
return self.draw( self.preScreen, False, timeout )
def displayPage( self, page, predraw = -1 ):
@@ -235,8 +236,6 @@ class TrackInterface( gtk.EventBox ):
self.screenBufPage[self.preScreen] = predraw
self.screenBufBeats[self.preScreen] = self.noteDB.getPage(predraw).beats
self.invalidate_rect( 0, 0, self.width, self.height, predraw )
- elif self.screenBufPage[self.preScreen] == -1: # make sure predraw is assigned to a valid page at least
- self.screenBufPage[self.preScreen] = self.screenBufPage[self.curScreen]
if clearNotes: # clear the notes now that we've sorted out the screen buffers
self.clearSelectedNotes( oldPage )
@@ -482,7 +481,7 @@ class TrackInterface( gtk.EventBox ):
self.selectedNotes[trackN] = []
map( lambda note:self.selectedNotes[trackN].append(note), track )
elif mode == SELECTNOTES.NONE:
- track = self.noteDB.getNotesByTrack( page, trackN, self )
+ track = self.selectedNotes[trackN] #self.noteDB.getNotesByTrack( page, trackN, self )
map( lambda note:note.setSelected( False ), track )
self.selectedNotes[trackN] = []
elif mode == SELECTNOTES.ADD:
diff --git a/Util/ThemeWidgets.py b/Util/ThemeWidgets.py
index e8d9180..e4cdccd 100644
--- a/Util/ThemeWidgets.py
+++ b/Util/ThemeWidgets.py
@@ -1,6 +1,6 @@
import pygtk
pygtk.require( '2.0' )
-import gtk
+import gtk
class ITYPE:
@@ -10,13 +10,13 @@ class ITYPE:
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 )
-
+
if snap: self.snap = 1/snap
else: self.snap = False
-
+
colormap = self.get_colormap()
self.troughcolor = colormap.alloc_color( trough_color, True, True )
-
+
img = gtk.Image()
img.set_from_file( image_name )
self.sliderPixbuf = img.get_pixbuf()
@@ -27,31 +27,31 @@ class ImageHScale( gtk.HScale ):
img = gtk.Image()
img.set_from_file( insensitive_name )
self.insensitivePixbuf = img.get_pixbuf()
-
+
name = image_name + "ImageHScale"
- self.set_name(name)
-
+ self.set_name(name)
+
rc_str = """
style "scale_style" {
GtkRange::slider_width = %d
GtkScale::slider_length = %d
}
-widget "*%s*" style "scale_style"
+widget "*%s*" style "scale_style"
""" % ( self.sliderPixbuf.get_width(), self.sliderPixbuf.get_height(), name)
gtk.rc_parse_string( rc_str )
-
+
self.pixbufWidth = self.sliderPixbuf.get_width()
self.pixbufHeight = self.sliderPixbuf.get_height()
self.sliderBorder = slider_border
self.sliderBorderMUL2 = self.sliderBorder*2
-
+
self.set_draw_value(False)
-
+
self.connect( "expose-event", self.expose )
self.connect( "size-allocate", self.size_allocate )
self.connect( "button-release-event", self.button_release )
adjustment.connect( "value-changed", self.value_changed )
-
+
def size_allocate( self, widget, allocation ):
self.alloc = allocation
self.sliderY = self.alloc.height//2 - self.pixbufHeight//2
@@ -61,88 +61,88 @@ widget "*%s*" style "scale_style"
if snap: self.snap = 1/snap
else: self.snap = False
self.queue_draw()
-
+
def value_changed( self, adjustment ):
if self.snap:
val = round(self.snap*self.get_value())/self.snap
if val != self.get_value():
self.set_value( val )
-
+
def expose( self, widget, event ):
-
+
style = self.get_style()
gc = style.fg_gc[gtk.STATE_NORMAL]
-
+
gc.foreground = self.troughcolor
-
+
self.window.draw_rectangle( gc, True, self.alloc.x + self.sliderBorder, self.alloc.y + self.alloc.height//2 - 1, self.alloc.width - self.sliderBorderMUL2, 3 )
-
+
val = self.get_value()
if self.snap:
val = round(self.snap*val)/self.snap
adj = self.get_adjustment()
- if self.get_inverted():
+ if self.get_inverted():
sliderX = int((self.alloc.width - self.pixbufWidth)*(adj.upper-val)/(adj.upper - adj.lower))
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:
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 )
-
+
return True
-
+
def button_release( self, widget, event ):
-
+
if self.snap:
self.set_value( round(self.snap*self.get_value())/self.snap )
class ImageVScale( gtk.VScale ):
def __init__( self, image_name, adjustment = None, slider_border = 0, insensitive_name = None, trough_color = "#3D403A", snap = False ):
gtk.VScale.__init__( self, adjustment )
-
+
if snap: self.snap = 1/snap
else: self.snap = False
-
+
colormap = self.get_colormap()
self.troughcolor = colormap.alloc_color( trough_color, True, True )
-
+
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.set_from_file( insensitive_name )
self.insensitivePixbuf = img.get_pixbuf()
-
+
name = image_name + "ImageVScale"
- self.set_name(name)
-
+ self.set_name(name)
+
rc_str = """
style "scale_style" {
GtkRange::slider_width = %d
GtkScale::slider_length = %d
}
-widget "*%s*" style "scale_style"
+widget "*%s*" style "scale_style"
""" % ( self.sliderPixbuf.get_width(), self.sliderPixbuf.get_height(), name)
gtk.rc_parse_string( rc_str )
-
+
self.pixbufWidth = self.sliderPixbuf.get_width()
self.pixbufHeight = self.sliderPixbuf.get_height()
self.sliderBorder = slider_border
self.sliderBorderMUL2 = self.sliderBorder*2
-
+
self.set_draw_value(False)
-
+
self.connect( "expose-event", self.expose )
self.connect( "size-allocate", self.size_allocate )
self.connect( "button-release-event", self.button_release )
adjustment.connect( "value-changed", self.value_changed )
-
+
def size_allocate( self, widget, allocation ):
self.alloc = allocation
self.sliderX = self.alloc.width//2 - self.pixbufWidth//2
@@ -152,67 +152,172 @@ widget "*%s*" style "scale_style"
if snap: self.snap = 1/snap
else: self.snap = False
self.queue_draw()
-
+
def value_changed( self, adjustment ):
if self.snap:
val = round(self.snap*self.get_value())/self.snap
if val != self.get_value():
self.set_value( val )
-
+
def expose( self, widget, event ):
-
+
style = self.get_style()
gc = style.fg_gc[gtk.STATE_NORMAL]
-
+
gc.foreground = self.troughcolor
-
+
self.window.draw_rectangle( gc, True, self.alloc.x + self.alloc.width//2 - 1, self.alloc.y + self.sliderBorder, 3, self.alloc.height - self.sliderBorderMUL2 )
-
+
val = self.get_value()
if self.snap:
val = round(self.snap*val)/self.snap
adj = self.get_adjustment()
- if self.get_inverted():
+ if self.get_inverted():
sliderY = int((self.alloc.height - self.pixbufHeight)*(adj.upper-val)/(adj.upper - adj.lower))
else:
sliderY = int((self.alloc.height - self.pixbufHeight)*(val-adj.lower)/(adj.upper - adj.lower))
-
+
if self.insensitivePixbuf != None and self.state == gtk.STATE_INSENSITIVE:
self.window.draw_pixbuf( gc, self.insensitivePixbuf, 0, 0, self.alloc.x + self.sliderX, self.alloc.y + 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 + self.sliderX, self.alloc.y + sliderY, self.pixbufWidth, self.pixbufHeight, gtk.gdk.RGB_DITHER_NORMAL, 0, 0 )
-
+
return True
-
+
def button_release( self, widget, event ):
-
+
if self.snap:
self.set_value( round(self.snap*self.get_value())/self.snap )
+class XYSlider( gtk.EventBox ):
+ def __init__( self, fixed, button, xadjustment, yadjustment, flipX = False, flipY = False ):
+ gtk.EventBox.__init__( self )
+
+ self.fixed = fixed
+ self.button = button
+ self.xadjustment = xadjustment
+ self.yadjustment = yadjustment
+ self.flipX = flipX
+ self.flipY = flipY
+
+ if ( button.get_parent() == None ):
+ fixed.put( button, 0, 0 )
+
+ self.add(fixed)
+
+ self.fWidth = self.fHeight = 1
+ self.bWidth = self.bHeight = 1
+
+ self.add_events(gtk.gdk.POINTER_MOTION_HINT_MASK)
+ self.connect( "size-allocate", lambda w,a:self.updateAlloc() )
+ self.connect( "button-press-event", self.handlePress )
+ self.connect( "button-release-event", self.handleRelease )
+ self.connect( "motion-notify-event", self.handleMotion )
+ self.button.connect( "size-allocate", lambda w,a: self.updateButton() )
+ self.button.connect( "button-press-event", self.handleButtonPress )
+ self.button.connect( "button-release-event", self.handleButtonRelease )
+ self.button.add_events(gtk.gdk.BUTTON_MOTION_MASK|gtk.gdk.POINTER_MOTION_HINT_MASK)
+ self.button.connect( "motion-notify-event", self.handleMotion )
+ self.xadjustment.connect( "changed", lambda a1: self.updateAdjustemnt("x") )
+ self.xadjustment.connect( "value-changed", lambda a1: self.updateLoc() )
+ self.yadjustment.connect( "changed", lambda a1: self.updateAdjustment("y") )
+ self.yadjustment.connect( "value-changed", lambda a1: self.updateLoc() )
+
+ self.updateAdjustment("x")
+ self.updateAdjustment("y")
+ self.updateButton()
+
+ def updateAlloc( self ):
+ alloc = self.fixed.get_allocation()
+ if self.fWidth != alloc.width or self.fHeight != alloc.height:
+ self.fWidth = alloc.width
+ self.fHeight = alloc.height
+ self.width = self.fWidth - self.bWidth
+ self.height = self.fHeight - self.bHeight
+ self.updateLoc()
+
+ def updateButton( self ):
+ alloc = self.button.get_allocation()
+ if self.bWidth != alloc.width or self.bHeight != alloc.height:
+ self.bWidth = alloc.width
+ self.bHeight = alloc.height
+ self.bWidthDIV2 = alloc.width//2
+ self.bHeightDIV2 = alloc.height//2
+ self.width = self.fWidth - self.bWidth
+ self.height = self.fHeight - self.bHeight
+ self.updateLoc()
+
+ def updateAdjustment( self, which ):
+ if which == "x": self.xRange = int(self.xadjustment.upper - self.xadjustment.lower)
+ else: self.yRange = int(self.yadjustment.upper - self.yadjustment.lower)
+
+ def updateLoc( self ):
+ if self.flipX: self.x = (self.width*int(self.xadjustment.upper - self.xadjustment.value))//self.xRange
+ else: self.x = (self.width*int(self.xadjustment.value - self.xadjustment.lower))//self.xRange
+ if self.flipY: self.y = (self.height*int(self.yadjustment.upper - self.yadjustment.value))//self.yRange
+ else: self.y = (self.height*int(self.yadjustment.value - self.yadjustment.lower))//self.yRange
+
+ self.fixed.move( self.button, self.x, self.y )
+
+ def handlePress( self, w, event ):
+ self.clickOffset = (0,0)
+ self.updatePointer( int(event.x), int(event.y) )
+ self.button.set_active(True)
+
+ def handleRelease( self, w, event ):
+ self.button.set_active(False)
+
+ def handleButtonPress( self, w, event ):
+ self.clickOffset = ( event.x - self.bWidthDIV2, event.y - self.bHeightDIV2 )
+ self.button.set_active(True)
+
+ def handleButtonRelease( self, w, event ):
+ self.button.set_active(False)
+ return True # block event propagation
+
+ def handleMotion( self, w, event ):
+ x, y, state = self.window.get_pointer()
+ self.updatePointer( int(x - self.clickOffset[0]), int(y - self.clickOffset[1]) )
+ return True
+
+ def updatePointer( self, x, y ):
+ x -= self.bWidthDIV2
+ y -= self.bHeightDIV2
+ if x < 0: x = 0
+ elif x > self.width: x = self.width
+ if y < 0: y = 0
+ elif y > self.height: y = self.height
+ if self.flipX: xvalue = self.xadjustment.lower+(self.xRange*(self.width - x))//self.width
+ else: xvalue = self.xadjustment.lower+(self.xRange*x)//self.width
+ if xvalue != self.xadjustment.value: self.xadjustment.set_value(xvalue)
+ if self.flipY: yvalue = self.yadjustment.lower+(self.yRange*(self.height - y))//self.height
+ else: yvalue = self.yadjustment.lower+(self.yRange*y)//self.height
+ if yvalue != self.yadjustment.value: self.yadjustment.set_value(yvalue)
+
class RoundHBox( gtk.HBox ):
def __init__( self, radius = 5, fillcolor = "#000", bordercolor = "#FFF", homogeneous = False, spacing = 0 ):
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.connect( "expose-event", self.expose )
self.connect( "size-allocate", self.size_allocate )
-
+
def update_constants( self ):
-
+
if self.alloc == None: return
-
+
self.borderW = self.get_border_width()
self.borderWMUL2 = self.borderW*2
self.corner = self.radius + self.borderW
self.cornerMUL2 = self.corner*2
self.cornerMINborderW = self.corner - self.borderW
-
+
self.xPLUborderW = self.alloc.x + self.borderW
self.xPLUcorner = self.alloc.x + self.corner
self.xPLUwidthMINborderW = self.alloc.x + self.alloc.width - self.borderW
@@ -228,68 +333,68 @@ class RoundHBox( gtk.HBox ):
self.heightMINcorner = self.alloc.height - self.corner
self.heightMINborderWMUL2 = self.alloc.height - self.borderWMUL2
self.heightMINcornerMUL2 = self.alloc.height - self.cornerMUL2
-
+
self.roundX1 = self.alloc.x + self.borderW - 1
self.roundX2 = self.alloc.x + self.alloc.width - self.corner - self.radius - 1
self.roundY1 = self.alloc.y + self.borderW - 1
self.roundY2 = self.alloc.y + self.alloc.height - self.corner - self.radius - 1
self.roundD = self.radius*2 + 1
self.rightAngle = 90*64
-
+
def size_allocate( self, widget, allocation ):
self.alloc = allocation
self.update_constants()
return False
-
+
def set_border_width( self, width ):
gtk.HBox.set_border_width( self, width )
self.update_constants()
-
+
def set_radius( self, radius ):
self.radius = radius
self.update_constants()
-
+
def set_fill_color( self, color ):
colormap = self.get_colormap()
self.fillcolor = colormap.alloc_color(color,True,True)
-
+
def set_border_color( self, color ):
colormap = self.get_colormap()
self.bordercolor = colormap.alloc_color(color,True,True)
-
+
def expose( self, widget, event ):
-
+
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
-
+
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
if self.borderW:
if stopY > self.corner and startY < self.heightMINcorner:
- if startX < self.borderW: # draw left border
+ if startX < self.borderW: # draw left border
self.window.draw_rectangle( gc, True, self.alloc.x, self.yPLUcorner, self.borderW, self.heightMINcornerMUL2 )
- if stopX > self.widthMINborderW: # draw right border
+ if stopX > self.widthMINborderW: # draw right border
self.window.draw_rectangle( gc, True, 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 )
if stopY > self.heightMINborderW: # draw bottom border
self.window.draw_rectangle( gc, True, 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 )
@@ -303,16 +408,16 @@ class RoundHBox( gtk.HBox ):
gc.foreground = self.bordercolor
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 )
+ 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
if stopY > self.heightMINcorner: # draw bottom right corner
- self.window.draw_rectangle( gc, True, self.xPLUwidthMINcorner, self.yPLUheightMINcorner, self.corner, self.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
-
+
gc.foreground = self.fillcolor
if startX < self.widthMINcorner and stopX > self.corner:
if startY < self.heightMINborderW and stopY > self.borderW: # draw centre fill
@@ -323,38 +428,38 @@ class RoundHBox( gtk.HBox ):
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 )
-
+
gc.foreground = saveForeground
-
+
#TP.ProfileEnd( "Round*Box::expose" )
-
+
return False
-
-
+
+
class RoundVBox( gtk.VBox ):
def __init__( self, radius = 5, fillcolor = "#000", bordercolor = "#FFF", homogeneous = False, spacing = 0 ):
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)
-
+
self.connect( "expose-event",self.expose )
self.connect( "size-allocate", self.size_allocate )
-
+
def update_constants( self ):
-
+
if self.alloc == None: return
-
+
self.borderW = self.get_border_width()
self.borderWMUL2 = self.borderW*2
self.corner = self.radius + self.borderW
self.cornerMUL2 = self.corner*2
self.cornerMINborderW = self.corner - self.borderW
-
+
self.xPLUborderW = self.alloc.x + self.borderW
self.xPLUcorner = self.alloc.x + self.corner
self.xPLUwidthMINborderW = self.alloc.x + self.alloc.width - self.borderW
@@ -370,68 +475,68 @@ class RoundVBox( gtk.VBox ):
self.heightMINcorner = self.alloc.height - self.corner
self.heightMINborderWMUL2 = self.alloc.height - self.borderWMUL2
self.heightMINcornerMUL2 = self.alloc.height - self.cornerMUL2
-
+
self.roundX1 = self.alloc.x + self.borderW - 1
self.roundX2 = self.alloc.x + self.alloc.width - self.corner - self.radius - 1
self.roundY1 = self.alloc.y + self.borderW - 1
self.roundY2 = self.alloc.y + self.alloc.height - self.corner - self.radius - 1
self.roundD = self.radius*2 + 1
self.rightAngle = 90*64
-
+
def size_allocate( self, widget, allocation ):
self.alloc = allocation
self.update_constants()
return False
-
+
def set_border_width( self, width ):
gtk.VBox.set_border_width( self, width )
self.update_constants()
-
+
def set_radius( self, radius ):
self.radius = radius
self.update_constants()
-
+
def set_fill_color( self, color ):
colormap = self.get_colormap()
self.fillcolor = colormap.alloc_color(color,True,True)
-
+
def set_border_color( self, color ):
colormap = self.get_colormap()
self.bordercolor = colormap.alloc_color(color,True,True)
-
+
def expose( self, widget, event ):
-
+
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
-
+
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
if self.borderW:
if stopY > self.corner and startY < self.heightMINcorner:
- if startX < self.borderW: # draw left border
+ if startX < self.borderW: # draw left border
self.window.draw_rectangle( gc, True, self.alloc.x, self.yPLUcorner, self.borderW, self.heightMINcornerMUL2 )
- if stopX > self.widthMINborderW: # draw right border
+ if stopX > self.widthMINborderW: # draw right border
self.window.draw_rectangle( gc, True, 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 )
if stopY > self.heightMINborderW: # draw bottom border
self.window.draw_rectangle( gc, True, 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 )
@@ -445,16 +550,16 @@ class RoundVBox( gtk.VBox ):
gc.foreground = self.bordercolor
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 )
+ 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
if stopY > self.heightMINcorner: # draw bottom right corner
- self.window.draw_rectangle( gc, True, self.xPLUwidthMINcorner, self.yPLUheightMINcorner, self.corner, self.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
-
+
gc.foreground = self.fillcolor
if startX < self.widthMINcorner and stopX > self.corner:
if startY < self.heightMINborderW and stopY > self.borderW: # draw centre fill
@@ -465,13 +570,13 @@ class RoundVBox( gtk.VBox ):
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 )
-
+
gc.foreground = saveForeground
-
+
#TP.ProfileEnd( "Round*Box::expose" )
-
+
return False
-
+
class RoundFixed( gtk.Fixed ):
def __init__( self, radius = 5, fillcolor = "#000", bordercolor = "#FFF" ):
gtk.Fixed.__init__( self )
@@ -625,7 +730,7 @@ class ImageButton(gtk.Button):
self.iwidthDIV2 = {}
self.iheight = {}
self.iheightDIV2 = {}
-
+
def prepareImage( name, path ):
pix = gtk.gdk.pixbuf_new_from_file(path)
if pix.get_has_alpha():
@@ -647,18 +752,18 @@ class ImageButton(gtk.Button):
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:
- prepareImage( "enter", 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:
prepareImage( "click", clickImg_path )
self.connect('pressed',self.on_btn_press, None)
self.connect('released',self.on_btn_release, None)
- if enterImg_path == None:
+ if enterImg_path == None:
self.image["enter"] = self.image["main"]
self.itype["enter"] = self.itype["main"]
self.iwidth["enter"] = self.iwidth["main"]
@@ -667,27 +772,27 @@ class ImageButton(gtk.Button):
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 = "main"
self.down = False
-
+
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
-
+ self.drawY = allocation.y + allocation.height//2
+
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.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 = "click"
self.down = True
@@ -698,11 +803,11 @@ class ImageButton(gtk.Button):
if self.down: self.curImage = "click"
else: self.curImage = "enter"
self.queue_draw()
-
+
def on_btn_leave(self, widget, event):
self.curImage = self.upImage = "main"
self.queue_draw()
-
+
def on_btn_release(self, widget, event):
self.curImage = self.upImage
self.down = False
@@ -713,7 +818,7 @@ class ImageToggleButton(gtk.ToggleButton):
def __init__(self , mainImg_path, altImg_path, enterImg_path = None, backgroundFill = None ):
gtk.ToggleButton.__init__(self)
self.alloc = None
-
+
win = gtk.gdk.get_default_root_window()
self.gc = gtk.gdk.GC( win )
self.image = {}
@@ -722,7 +827,7 @@ class ImageToggleButton(gtk.ToggleButton):
self.iwidthDIV2 = {}
self.iheight = {}
self.iheightDIV2 = {}
-
+
def prepareImage( name, path ):
pix = gtk.gdk.pixbuf_new_from_file(path)
if pix.get_has_alpha():
@@ -744,35 +849,35 @@ class ImageToggleButton(gtk.ToggleButton):
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 )
-
+ prepareImage( "alt", altImg_path )
+
if enterImg_path != None:
- prepareImage( "enter", enterImg_path )
+ prepareImage( "enter", enterImg_path )
self.connect('enter',self.on_btn_enter, None)
self.connect('leave',self.on_btn_leave, None)
-
+
self.connect('toggled',self.toggleImage, None)
self.connect('expose-event', self.expose)
self.connect('size-allocate', self.size_allocate)
-
+
self.set_size_request(self.iwidth["main"],self.iheight["main"])
-
+
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):
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 toggleImage(self, widget, event):
if not self.get_active():
self.curImage = "main"
@@ -783,7 +888,7 @@ class ImageToggleButton(gtk.ToggleButton):
def on_btn_enter(self, widget, event):
self.curImage = "enter"
self.queue_draw()
-
+
def on_btn_leave(self, widget, event):
if not self.get_active():
self.curImage = "main"
@@ -795,7 +900,7 @@ class ImageRadioButton(gtk.RadioButton):
def __init__( self, group, mainImg_path, altImg_path, enterImg_path = None, backgroundFill = None ):
gtk.RadioButton.__init__(self, group)
self.alloc = None
-
+
win = gtk.gdk.get_default_root_window()
self.gc = gtk.gdk.GC( win )
self.image = {}
@@ -804,7 +909,7 @@ class ImageRadioButton(gtk.RadioButton):
self.iwidthDIV2 = {}
self.iheight = {}
self.iheightDIV2 = {}
-
+
def prepareImage( name, path ):
pix = gtk.gdk.pixbuf_new_from_file(path)
if pix.get_has_alpha():
@@ -826,35 +931,35 @@ class ImageRadioButton(gtk.RadioButton):
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 )
-
+ prepareImage( "alt", altImg_path )
+
if enterImg_path != None:
- prepareImage( "enter", enterImg_path )
+ prepareImage( "enter", enterImg_path )
self.connect('enter',self.on_btn_enter, None)
self.connect('leave',self.on_btn_leave, None)
-
+
self.connect("toggled", self.toggleImage, None )
self.connect('expose-event', self.expose)
self.connect('size-allocate', self.size_allocate)
-
+
self.set_size_request(self.iwidth["main"],self.iheight["main"])
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):
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)
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 toggleImage(self, widget, event):
if not self.get_active():
self.curImage = "main"
@@ -865,7 +970,7 @@ class ImageRadioButton(gtk.RadioButton):
def on_btn_enter(self, widget, event):
self.curImage = "enter"
self.queue_draw()
-
+
def on_btn_leave(self, widget, event):
if not self.get_active():
self.curImage = "main"