first commit

This commit is contained in:
Yura 2024-09-15 15:12:16 +03:00
commit 417e54da96
5696 changed files with 900003 additions and 0 deletions

View file

@ -0,0 +1,9 @@
#:kivy 1.0
Widget:
Button:
text: "Hello World"
Button:
text: "I'm another label"
pos: (200, 200)

View file

@ -0,0 +1,25 @@
Camera:
canvas:
Color:
rgb: (1, 1, 1)
Rectangle:
texture: self.texture
size: (320, 240)
Color:
rgb: (0.5, 0, 1)
Rectangle:
texture: self.texture
pos: (320, 0)
size: (320, 240)
Color:
rgb: (0, 1, 0)
Rectangle:
texture: self.texture
pos: (320, 240)
size: (320, 240)
Color:
rgb: (1, 0, 0)
Rectangle:
texture: self.texture
pos: (0, 240)
size: (320, 240)

View file

@ -0,0 +1,11 @@
#:kivy 1.0
Widget:
canvas:
Fbo:
size: (200, 200)
Color:
rgba: (0.7, 0.3, 0.5, 0.7)
Rectangle:
size: (200, 200)
pos: (200, 200)

View file

@ -0,0 +1,23 @@
BoxLayout:
Button:
id: bswitch
BoxLayout:
orientation: 'vertical' if bswitch.state == 'down' else 'horizontal'
Button:
id: btn1
text: 'Button 1'
Button:
text: btn1.state
Button:
text: 'Button 3'
Button:
text: 'Button 4'
Button:
text: 'Button 5'

View file

@ -0,0 +1,36 @@
Widget:
Video:
id: myvideo
source: '../widgets/cityCC0.mpg'
play: mybutton.state == 'down'
canvas:
Color:
rgb: (1, 1, 1)
BorderImage:
texture: self.texture
size: self.texture_size
Image:
source: 'kivy.jpg'
canvas:
PushMatrix:
Rotate:
angle: 1
BorderImage:
border: 250, 250, 250, 250
texture: self.texture
size: self.texture_size
PopMatrix:
Button:
id: mybutton
text: 'Push me'
pos: 100, 100
Slider:
width: myvideo.width
height: 25
min: 0
max: myvideo.duration
value: myvideo.position
pos: myvideo.pos

View file

@ -0,0 +1,6 @@
Widget:
Scatter:
size: image.texture_size
Image:
id: image
source: 'kivy.jpg'

View file

@ -0,0 +1,27 @@
Widget:
canvas:
StencilPush
# create a rectangle mask, from pos 100, 100, with a 100, 100 size.
Rectangle:
pos: 100, 100
size: 100, 100
StencilUse
# we want to show a big green rectangle, however, the previous stencil
# mask will crop us :)
Color:
rgb: 0, 1, 0
Rectangle:
size: 900, 900
StencilUnUse
# Remove the mask previously set
Rectangle:
pos: 100, 100
size: 100, 100
StencilPop

View file

@ -0,0 +1,42 @@
BoxLayout:
orientation: 'vertical'
spacing: 5
padding: 5
Video:
id: myvideo
source: '../widgets/cityCC0.mpg'
fit_mode: "contain"
on_eos: self.play = True; print('woot we are looping!')
BoxLayout:
size_hint_y: None
height: 30
Label:
id: mylabel
text: str(myvideo.position)
Slider:
value: myvideo.position
max: myvideo.duration
on_value: print(args[1])
BoxLayout:
size_hint_y: None
height: 50
spacing: 5
ToggleButton:
group: 'video'
text: 'Play'
state: 'down' if myvideo.play else 'normal'
on_press: myvideo.play = True
ToggleButton:
group: 'video'
text: 'Stop'
state: 'down' if not myvideo.play else 'normal'
on_press: myvideo.play = False

View file

@ -0,0 +1,28 @@
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
Builder.load_string('''
[BlehItem@BoxLayout]:
orientation: 'vertical'
Label:
text: str(ctx.idx)
Button:
text: ctx.word
''')
class BlehApp(App):
def build(self):
root = BoxLayout()
for idx, word in enumerate(('Hello', 'World')):
wid = Builder.template('BlehItem', **{
'idx': idx, 'word': word,
})
root.add_widget(wid)
return root
if __name__ == '__main__':
BlehApp().run()

View file

@ -0,0 +1,20 @@
'''
The use of id in KV
===================
This small example shows how to refer from one widget
to another within KV.
'''
import kivy
kivy.require('1.8.0')
from kivy.app import App
class TestApp(App):
pass
if __name__ == '__main__':
TestApp().run()

View file

@ -0,0 +1,11 @@
#:kivy 1.8.0
BoxLayout:
orientation: 'vertical'
TextInput:
# setting the id of the widget
id: my_id
text: 'The text of the label is set within kivy'
Label:
# showing the text of the textinput by referring on the id
text: my_id.text

View file

@ -0,0 +1,34 @@
'''
Referring on ids from Python
=============================
This example shows how to refer to an id from a Python file.
'''
import kivy
kivy.require('1.8.0')
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
class RootWidget(BoxLayout):
def first_function(self, status):
# print out the given parameter
print(status)
# check the status of the switch by referring on the id
if self.ids.my_switch.active is True:
# set the text of the label by referring on the id
self.ids.my_label.text = 'Switch is ON'
else:
# set the text of the label by referring on the id
self.ids.my_label.text = 'Switch is OFF'
class TestApp(App):
pass
if __name__ == '__main__':
TestApp().run()

View file

@ -0,0 +1,11 @@
#:kivy 1.8.0
RootWidget:
BoxLayout:
orientation: 'vertical'
Switch:
id: my_switch
on_active: root.first_function(self.active)
Label:
id: my_label
text: 'This text will be changed by the python file'

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

View file

@ -0,0 +1,38 @@
from kivy.app import App
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.core.window import Window
class KvApp(App):
def __init__(self, filename, **kwargs):
self.filename = filename
super(KvApp, self).__init__(**kwargs)
def _print_fps(self, *largs):
print('FPS: %2.4f (real draw: %d)' % (
Clock.get_fps(), Clock.get_rfps()))
def _reload_keypress(self, instance, code, *largs):
if code != 286:
return
for child in Window.children[:]:
Window.remove_widget(child)
root = Builder.load_file(self.filename)
Window.add_widget(root)
def build(self):
Clock.schedule_interval(self._print_fps, 1)
Window.bind(on_keyboard=self._reload_keypress)
return Builder.load_file(self.filename)
if __name__ == '__main__':
import sys
import os
if len(sys.argv) < 2:
print('Usage: %s filename.kv' % os.path.basename(sys.argv[0]))
sys.exit(1)
KvApp(filename=sys.argv[1]).run()