Last active
December 11, 2016 14:04
-
-
Save SynedraAcus/c8ddb8fe6b57e3a733b051e028b51b97 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
#! /usr/bin/python3 | |
from kivy.app import App | |
from kivy.uix.image import Image | |
from kivy.uix.widget import Widget | |
from kivy.uix.relativelayout import RelativeLayout | |
from kivy.core.window import Window | |
from kivy.graphics.context_instructions import Scale, PushMatrix, PopMatrix | |
class ActorWidget(Widget): | |
""" | |
The actor widget that contains an actor image | |
""" | |
def __init__(self, source='Chassis.png', **kwargs): | |
super(ActorWidget, self).__init__(**kwargs) | |
self.img = Image(source=source, size=(32, 32), allow_stretch=True) | |
self.add_widget(self.img) | |
self.bind(pos=self.update_img) | |
self.bind(size=self.update_img) | |
def update_img(self, a, b): | |
self.img.pos = self.pos | |
self.img.size = self.size | |
class DemoWidget(RelativeLayout): | |
def __init__(self, wid, *args, **kwargs): | |
super(DemoWidget, self).__init__(*args, **kwargs) | |
self.wid = wid | |
self.add_widget(self.wid) | |
self._keyboard = Window.request_keyboard(self._keyboard_closed, self) | |
self._keyboard.bind(on_key_down=self._on_key_down) | |
def _keyboard_closed(self): | |
self._keyboard.unbind(on_key_down=self.on_key_down) | |
self._keyboard=None | |
def _on_key_down(self, *args, **kwargs): | |
print('Key accepted') # To see that it's not some keyboard issue | |
self.wid.canvas.before.add(PushMatrix()) | |
self.wid.canvas.before.add(Scale(y=10.0)) | |
self.wid.canvas.after.add(PopMatrix()) | |
self.wid.canvas.ask_update | |
class TestApp(App): | |
def __init__(self): | |
super(TestApp,self).__init__() | |
def build(self): | |
root = DemoWidget(wid=ActorWidget(), size=(32,32), size_hint=(None, None)) | |
Window.size=(100, 100) | |
return root | |
app = TestApp() | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment