Created
November 28, 2013 00:43
-
-
Save clayote/7685603 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A graphical selector for "swatches," which may be colors, textures, | |
or standalone sprites.""" | |
from kivy.uix.gridlayout import GridLayout | |
from kivy.uix.togglebutton import ToggleButton | |
from kivy.properties import ( | |
NumericProperty, | |
StringProperty, | |
ObjectProperty) | |
kv = """ | |
<Swatch>: | |
BoxLayout: | |
orientation: 'vertical' | |
pos: root.pos | |
size: root.size | |
Image: | |
texture: root.display_texture | |
Label: | |
text: root.display_text | |
color: root.color | |
disabled_color: root.disabled_color | |
font_name: root.font_name | |
font_size: root.font_size | |
disabled: root.state == 'normal' | |
""" | |
class Swatch(ToggleButton): | |
display_text = StringProperty() | |
display_texture = ObjectProperty() | |
class SwatchBox(GridLayout): | |
texdict = ObjectProperty() | |
style = ObjectProperty() | |
finality = NumericProperty(0) | |
def on_texdict(self, i, v): | |
self.finality += 1 | |
def on_style(self, i, v): | |
self.finality += 1 | |
def on_parent(self, i, v): | |
self.finality += 1 | |
def on_finality(self, i, v): | |
if v == 3: | |
self.finalize() | |
def finalize(self): | |
for (key, val) in self.texdict.iteritems(): | |
self.add_widget(Swatch( | |
display_text=key, display_texture=val, | |
background_color=self.style.bg_active.rgba, | |
color=self.style.text_active.rgba, | |
disabled_color=self.style.text_inactive.rgba, | |
font_name=self.style.fontface, | |
font_size=self.style.fontsize)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment