Created
August 3, 2014 10:56
-
-
Save AshokEmrys/4bb76200e67944fa0170 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from kivy.uix.label import Label as K_Label | |
from kivy.properties import OptionProperty | |
from kivy.lang import Builder | |
from kivy.graphics import Rectangle, Color | |
class CLabel(K_Label): | |
orientation = OptionProperty('horizontal', options=( | |
'horizontal', 'vertical')) | |
def __init__(self, *args, **kwargs): | |
super(CLabel, self).__init__(*args, **kwargs) | |
kv_style_file = 'label.kv' | |
if kv_style_file not in Builder.files: | |
Builder.load_file('label.kv') | |
def draw_on_canvas(self): | |
print 'proper', self.size, self.pos | |
with self.canvas.before: | |
Color(0, 1, 0) | |
Rectangle(size=self.size, | |
pos=self.pos) | |
self.text = "Changed" | |
if __name__ == '__main__': | |
from kivy.app import App | |
kv = ''' | |
test: | |
<test@BoxLayout>: | |
orientation: 'horizontal' | |
BoxLayout: | |
orientation: 'vertical' | |
CLabel: | |
id: vert_1 | |
orientation: 'vertical' | |
text: 'Vertical Label' | |
Button: | |
text: "Change" | |
size_hint_y: None | |
height: "30dp" | |
on_release: vert_1.draw_on_canvas() | |
BoxLayout: | |
orientation: 'vertical' | |
CLabel: | |
orientation: 'horizontal' | |
text: 'Horizontal Label' | |
CLabel: | |
orientation: 'horizontal' | |
text: 'Horizontal Label' | |
''' | |
class TestLabel(App): | |
def build(self): | |
return Builder.load_string(kv) | |
TestLabel().run() |
This file contains hidden or 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
<CLabel>: | |
canvas.before: | |
PushMatrix | |
Translate: | |
xy: self.center_x, self.center_y | |
Rotate: | |
angle: 90 if self.orientation is 'vertical' else 0 | |
axis: 0, 0, 1 | |
Translate: | |
xy: -self.center_x, -self.center_y | |
canvas.after: | |
PopMatrix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment