Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # kivy_generic.py
- import kivy
- kivy.require('1.9.0')
- from kivy.app import App
- from kivy.uix.screenmanager import ScreenManager, Screen
- from kivy.uix.scatter import ScatterPlane
- from kivy.uix.scatter import Scatter
- from kivy.uix.label import Label
- from kivy.lang import Builder
- class MyScatter(Scatter):
- pass
- class MyScatterPlane(ScatterPlane):
- def __init__(self, **kwargs):
- super(MyScatterPlane, self).__init__(**kwargs)
- self.keys_down = []
- self.keyboard = Window.request_keyboard(None, self)
- self.keyboard.bind(on_key_down=self.on_keyboard_down)
- self.keyboard.bind(on_key_up=self.on_keyboard_up)
- def on_keyboard_down(self, keyboard, keycode, text, modifiers):
- return self.keys_down.append(keycode[1])
- def on_keyboard_up(self, window, keycode):
- try:
- self.keys_down.remove(keycode[1])
- except KeyError as err:
- print(err)
- return True
- def on_touch_down(self, touch):
- if(touch.button == 'left'):
- return super(Scatter, self).on_touch_down(touch) #works
- elif('shift' in self.keys_down and touch.button == 'right'):
- return super(MyScatterPlane, self).on_touch_down(touch)
- else:
- return False
- def on_touch_up(self, touch):
- return super(MyScatterPlane, self).on_touch_up(touch)
- ui = Builder.load_string("""
- ScreenManager:
- MainScreen:
- <MainScreen@Screen>:
- MyScatterPlane:
- Label:
- pos: 100, 100
- text: 'Test'
- MyScatter:
- canvas:
- Color:
- rgb: 0.5, 0.1, 0.1
- Rectangle:
- size: self.size
- pos: 0, 0
- size_hint: None, None
- size: 100, 100
- """)
- class TestApp(App):
- def build(self):
- return ui
- if __name__ == '__main__':
- TestApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement