From bc664180643e2c666bee69e461356e37067d5ca0 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Sat, 29 Jan 2011 17:13:05 +0100 Subject: [PATCH] little canvas stress: 1. show that the compiler is not working very well on different branch 2. if we activate monitor module, every second, the screen look weird 3. deletion is soooooooo long ! --- examples/canvas_stress.py | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 examples/canvas_stress.py diff --git a/examples/canvas_stress.py b/examples/canvas_stress.py new file mode 100644 index 000000000..a44599675 --- /dev/null +++ b/examples/canvas_stress.py @@ -0,0 +1,52 @@ +from kivy.uix.button import Button +from kivy.uix.widget import Widget +from kivy.uix.label import Label +from kivy.uix.boxlayout import BoxLayout +from kivy.app import App +from kivy.graphics import Color, Rectangle +from random import random as r +from functools import partial + + +class StressCanvasApp(App): + + def add_rects(self, label, wid, count, *largs): + label.text = str(int(label.text) + count) + with wid.canvas: + for x in xrange(count): + Color(r(), 1, 1, mode='hsv') + Rectangle(pos=(r() * wid.width + wid.x, + r() * wid.height + wid.y), size=(20, 20)) + + def reset_rects(self, label, wid, *largs): + label.text = '0' + wid.canvas.clear() + + def build(self): + wid = Widget() + + label = Label(text='0') + + btn_add100 = Button(text='+ 100 rects') + btn_add100.bind(on_press=partial(self.add_rects, label, wid, 100)) + + btn_add500 = Button(text='+ 500 rects') + btn_add500.bind(on_press=partial(self.add_rects, label, wid, 500)) + + btn_reset = Button(text='Reset') + btn_reset.bind(on_press=partial(self.reset_rects, label, wid)) + + layout = BoxLayout(size_hint=(1, None), height=50) + layout.add_widget(btn_add100) + layout.add_widget(btn_add500) + layout.add_widget(btn_reset) + layout.add_widget(label) + + root = BoxLayout(orientation='vertical') + root.add_widget(wid) + root.add_widget(layout) + + return root + +if __name__ == '__main__': + StressCanvasApp().run()