Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tshirtman/ec17f13038973e05c52db7aebd520a4b to your computer and use it in GitHub Desktop.
Save tshirtman/ec17f13038973e05c52db7aebd520a4b to your computer and use it in GitHub Desktop.
# Class definition of ChannelImageButton
from kivy.graphics import Clear, Rectangle, Color
from kivy.properties import ListProperty
class ChannelImageButton( ButtonBehavior, Image ):
losses = ListProperty()
gains = ListProperty()
def __init__(self, **kwargs):
super(ChannelImageButton, self).__init__(**kwargs)
self.bind(pos=self.update_canvas, size=self.update_canvas, losses=update_canvas, gains=update_canvas)
def update_canvas(self, *args):
with self.canvas.after:
Clear()
for i in self.losses:
Color(1, 0, 0, .25)
Rectangle(pos=(i[0], 0 ),
size=(i[1] - i[0], self.height))
for i in self.gains:
Color(0, 1, 0, 0.25)
Rectangle(pos=(i[0], 0),
size=(i[1] - i[0], self.height))
# 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(losses=losses, gains=gains)
btn.__channel_id__ = i[0]
btn.texture = image.texture
self.channel_scroll_view.button_list.add_widget(btn)
kv file:
<ChannelImageButton>:
size_hint: None, None
size: self.texture_size
<ChannelScrollView>:
button_list: button_list
size_hint_x: None
width: self.minimum_width
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
size: self.minimum_size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment