Advertisement
here2share

# kivy_generic.py

Jan 28th, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # kivy_generic.py
  4.  
  5. import kivy
  6. kivy.require('1.9.0')
  7. from kivy.app import App
  8. from kivy.uix.screenmanager import ScreenManager, Screen
  9. from kivy.uix.scatter import ScatterPlane
  10. from kivy.uix.scatter import Scatter
  11. from kivy.uix.label import Label
  12. from kivy.lang import Builder
  13.  
  14.  
  15. class MyScatter(Scatter):
  16.     pass
  17.  
  18. class MyScatterPlane(ScatterPlane):
  19.     def __init__(self, **kwargs):
  20.         super(MyScatterPlane, self).__init__(**kwargs)
  21.         self.keys_down = []
  22.         self.keyboard = Window.request_keyboard(None, self)
  23.         self.keyboard.bind(on_key_down=self.on_keyboard_down)
  24.         self.keyboard.bind(on_key_up=self.on_keyboard_up)
  25.  
  26.     def on_keyboard_down(self, keyboard, keycode, text, modifiers):
  27.         return self.keys_down.append(keycode[1])
  28.  
  29.     def on_keyboard_up(self, window, keycode):
  30.         try:
  31.             self.keys_down.remove(keycode[1])
  32.         except KeyError as err:
  33.             print(err)
  34.         return True
  35.  
  36.     def on_touch_down(self, touch):
  37.         if(touch.button == 'left'):
  38.             return super(Scatter, self).on_touch_down(touch)          #works
  39.         elif('shift' in self.keys_down and touch.button == 'right'):
  40.             return super(MyScatterPlane, self).on_touch_down(touch)
  41.         else:
  42.             return False
  43.  
  44.     def on_touch_up(self, touch):
  45.         return super(MyScatterPlane, self).on_touch_up(touch)
  46.  
  47. ui = Builder.load_string("""
  48. ScreenManager:
  49.    MainScreen:
  50.  
  51. <MainScreen@Screen>:
  52.    MyScatterPlane:
  53.        Label:
  54.            pos: 100, 100
  55.            text: 'Test'
  56.        MyScatter:
  57.            canvas:
  58.                Color:
  59.                    rgb: 0.5, 0.1, 0.1
  60.                Rectangle:
  61.                    size: self.size
  62.            pos: 0, 0
  63.            size_hint: None, None
  64.            size: 100, 100
  65. """)
  66.  
  67.  
  68. class TestApp(App):
  69.     def build(self):
  70.         return ui
  71.  
  72. if __name__ == '__main__':
  73.     TestApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement