Skip to content

Instantly share code, notes, and snippets.

@onslauth
Created March 22, 2017 19:26
Show Gist options
  • Save onslauth/99a4fbc9a9e3a71e98ffa383fc694629 to your computer and use it in GitHub Desktop.
Save onslauth/99a4fbc9a9e3a71e98ffa383fc694629 to your computer and use it in GitHub Desktop.
# Class definition of ChannelImageButton
class ChannelImageButton( ButtonBehavior, Image ):
pass
# Code that is adding the ChannelImageButtons to the GridLayout in the ScrollView.
# Get a list of images
channels = project.get_image_channels( btn.__image_id__ )
# Clear any widgets in the GridLayout in the ScrollView
self.channel_scroll_view.button_list.clear_widgets( )
# Create ChannelImageButtons, and set their texture to the image
# Try to draw a rectangle on the buttons canvas
for i in channels:
image = CoreImage( io.BytesIO( i[ 1 ] ), ext = "jpg" )
losses = project.get_channel_loss( i[ 0 ] )
gains = project.get_channel_gain( i[ 0 ] )
btn = ChannelImageButton( size_hint = ( None, None ), size = ( image.texture.width, image.texture.height ) )
btn.__channel_id__ = i[ 0 ]
btn.texture = image.texture
height = image.texture.height
print( "height: %d" % height )
for i in losses:
print( "i.start_x: %d" % i[ 0 ] )
print( "i.end_x: %d" % i[ 1 ] )
with btn.canvas:
Color( 1, 0, 0, 0.25 )
d = 30
Rectangle( pos = ( i[ 0 ], 0 ),
size = ( i[ 1 ] - i[ 0 ], height ) )
for i in gains:
with btn.canvas:
Color( 0, 1, 0, 0.25 )
d = 30
Rectangle( pos = ( i[ 0 ], 0 ),
size = ( i[ 1 ] - i[ 0 ], height ) )
btn.canvas.ask_update( )
self.channel_scroll_view.button_list.add_widget( btn )
self.channel_scroll_view.button_list.width = image.texture.width
kv file:
<ChannelScrollView>:
button_list: button_list
canvas.before:
Color:
rgba: hex( "#646668" )
Rectangle:
pos: self.pos
size: self.size
GridLayout:
canvas.before:
Color:
rgba: ( 1, 1, 1, 1 )
Rectangle:
pos: self.pos
size: self.size
id: button_list
size_hint_y: None
size_hint_x: None
spacing: 50
cols: 1
height: sum( x.height for x in self.children )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment