-
Notifications
You must be signed in to change notification settings - Fork 0
/
hajiztest.py
117 lines (98 loc) · 3.04 KB
/
hajiztest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import kivy
kivy.require('1.0.6')
from random import random, randint
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.scatter import Scatter
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.slider import Slider
from kivy.uix.image import Image
from kivy.uix.scrollview import ScrollView
from kivy.animation import Animation
from kivy.properties import StringProperty
from kivy.graphics import Line, Ellipse, Color
class MyWidget(Widget):
def __init__(self):
Widget.__init__(self)
with self.canvas:
Color (1,1,1)
Line(points=(100,100,2000,2000))
clrbtn = Button(text='Reset')
def reset_canvas(obj):
children = self.children[:]
self.canvas.clear()
with self.canvas:
Color (1,1,1)
Line(points=(100,100,2000,2000))
for child in children:
self.add_widget(child)
clrbtn.bind(on_release=reset_canvas)
self.add_widget(clrbtn)
def on_touch_down(self, touch):
with self.canvas:
Color (1,0,0)
Ellipse(pos=(touch.x-5, touch.y-5), size=(10, 10))
Color (*(random(),random(),random()))
touch.ud['whatever'] = Line(points=(touch.x, touch.y, touch.y, touch.x))
for child in self.children[:]:
child.dispatch('on_touch_down', touch)
def on_touch_move(self, touch):
if 'whatever' in touch.ud:
touch.ud['whatever'].points += [touch.x, touch.y, touch.y, touch.x]
def on_touch_up(self, touch):
if 'whatever' in touch.ud:
with self.canvas:
Color (0,0,1)
Ellipse(pos=(touch.x-5, touch.y-5), size=(10, 10))
class Window(Scatter):
def __init__(self):
Scatter.__init__(self, pos=(200,200), size=(300,300))
layout = BoxLayout(pos=(50, 50), size=(200,200))
btn1 = Button(text='Hello')
btn2 = Button(text='World')
layout.add_widget(btn1)
layout.add_widget(btn2)
self.add_widget(Image(source='img/background.jpg', size=(300,300)))
self.add_widget(layout)
class Workspace(ScrollView):
initial_y = None
def __init__(self):
ScrollView.__init__(self, size_hint=(None, None), size=(1000, 1000), pos=(0, 0))
layout = GridLayout(cols=1, spacing=0, size_hint_y=None)
for i in range(30):
btn = Button(text=str(i), size_hint_y=None, height=200)
layout.add_widget(btn)
self.add_widget(layout)
def on_touch_down(self, touch):
ScrollView.on_touch_down (self, touch)
self.initial_y = self.scroll_y
def on_touch_up(self, touch):
ScrollView.on_touch_up (self, touch)
if self.initial_y == None:
return
scroll_y = self.scroll_y
level_y = int(scroll_y*10)
level_y = level_y / 10.
if scroll_y <= self.initial_y:
if level_y < 0:
level_y = 0
else:
level_y = level_y + 0.1
if level_y > 1:
level_y = 1
adjust = Animation(scroll_y = level_y, duration=0.3)
adjust.start(self)
self.initial_y = None
return True
class TouchtracerApp(App):
def build(self):
root = Widget()
# trying workspace idea
workspace = Workspace()
root.add_widget(workspace)
return root
if __name__ in ('__main__', '__android__'):
TouchtracerApp().run()