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,15 @@
#:kivy 1.4
AnchorLayout:
anchor_x: "right"
anchor_y: "bottom"
Button:
text: "Button 1"
size_hint: .2, .4
Button:
text: "Button 2"
size_hint: .4, .2
Button:
text: "Button 3"
size_hint: .2, .2

View file

@ -0,0 +1,14 @@
#:kivy 1.4
BoxLayout:
orientation: 'vertical'
padding: 20
spacing: 10
Button:
text: "Button 1"
size_hint: 1, None
Button:
text: "Button 2"
size_hint: 1, 0.5
Button:
text: "Button 3"

View file

@ -0,0 +1,27 @@
#:kivy 1.4
GridLayout:
cols: 2
Button:
text: "Button 1"
Button:
text: "Button 2"
font_size: 24
Button:
text: "Button 3"
background_color: .7, .7, 1, 1
Button:
text: "Button 4"
on_press: self.text = 'pressed'
on_release: self.text = 'Button 4'
ToggleButton:
text: "A toggle button"
ToggleButton:
text: "a toggle button in a group"
group: "money"
ToggleButton:
text: "A toggle in the down state"
state: "down"
ToggleButton:
text: "another toggle button in a group"
group: "money"

View file

@ -0,0 +1,28 @@
#:kivy 1.4
GridLayout:
cols: 2
CheckBox:
Label:
text: "A checkbox"
CheckBox:
active: True
Label:
text: "Another checkbox"
CheckBox:
group: "money"
Label:
text: "A radio in a group"
CheckBox:
group: "money"
active: True
Label:
text: "Another radio in same group"
Switch:
Label:
text: "A Switch"
Switch:
active: True
Label:
text: "An active switch"

View file

@ -0,0 +1,19 @@
#:kivy 1.4
BoxLayout:
# Double as a Tabbed Panel Demo!
TabbedPanel:
tab_pos: "top_right"
default_tab_text: "List View"
default_tab_content: list_view_tab
TabbedPanelHeader:
text: 'Icon View'
content: icon_view_tab
FileChooserListView:
id: list_view_tab
FileChooserIconView:
id: icon_view_tab
show_hidden: True

View file

@ -0,0 +1,16 @@
#:kivy 1.4
FloatLayout:
Button:
text: "Button 1"
pos: 100, 100
size_hint: .2, .4
Button:
text: "Button 2"
pos: 200, 200
size_hint: .4, .2
Button:
text: "Button 3"
pos_hint: {'x': .8, 'y': .6}
size_hint: .2, .2

View file

@ -0,0 +1,20 @@
#:kivy 1.4
GridLayout:
cols: 2
Button:
text: "Button 1"
size_hint_x: None
width: 100
Button:
text: "Button 2"
Button:
text: "Button 3"
size_hint_x: None
Button:
text: "Button 4"
Button:
text: "Button 5"
size_hint_x: None
Button:
text: "Button 6"

View file

@ -0,0 +1,62 @@
#:kivy 1.4
GridLayout:
cols: 1
Label:
text: "Label crowded by size hint"
size_hint_y: .2
Label:
text: 'Label with\nmultiple\nlines'
size_hint_y: .4
Label:
font_size: '48sp'
text: "Label [color=ff3333][sub]with[/sub][/color] [color=3333ff][b]mark[sup]up[/sup][/b][/color]"
markup: True
Button:
text: 'Labels in buttons'
GridLayout:
cols: 2
size_hint_y: 3
Button:
text: 'Left aligned at middle'
padding: 10, 10
halign: 'left'
valign: 'middle'
text_size: self.size
Button:
text: 'right aligned at top'
padding: 10, 10
halign: 'right'
valign: 'top'
text_size: self.size
Button:
text: 'Left aligned with no padding'
halign: 'left'
valign: 'middle'
text_size: self.size
Button:
text: 'Multiple\nbold italic centered\nlines'
halign: 'center'
valign: 'middle'
bold: True
italic: True
text_size: self.size
Button:
text: 'multiple\nspaced lines\ncentered'
padding: 10, 10
halign: 'center'
valign: 'middle'
line_height: 1.5
text_size: self.size
Button:
text: 'button without\npadding\nor align'
Label:
text: "Label with [ref=reference]reference[/ref]"
markup: True
on_ref_press: self.text = "ref clicked"
Label:
text: "different font"
bold: True
font_name: "data/fonts/RobotoMono-Regular.ttf"
font_size: 32
valign: 'bottom'

View file

@ -0,0 +1,9 @@
#:kivy 1.4
BoxLayout:
orientation: "vertical"
Image:
source: "../../widgets/cityCC0.png"
Video:
source: "../../widgets/cityCC0.mpg"
state: "play"

View file

@ -0,0 +1,4 @@
#:kivy 1.4
RstDocument:
text: "Welcome\n---------------\nThis Kivy Catalog is an interactive showcase of Kivy Widgets defined with the Kivy (.kv) language. You can edit the .kv language description in the left pane and see your changes affect the widgets in the right pane. Your changes will update the widget within a few seconds though the impatient could type 'Ctrl-S' or click 'Render Now'.\n\nYou can explore most Kivy widgets from the menu in the upper left corner. You can also use this playground to test your Kivy language code and adding a new .kv file to the interface is easy.\n\nSome Kivy widgets are omitted from this catalog or could have more complete .kv representation. This is beta software; pull requests are welcome."

View file

@ -0,0 +1,39 @@
#:kivy 1.4
BoxLayout:
id: bl
orientation: "vertical"
popup: popup.__self__
canvas:
Color:
rgba: .18, .18, .18, .91
Rectangle:
size: self.size
pos: self.pos
Bubble:
size_hint: (None, None)
size: (150, self.content_height + self.arrow_margin_y)
pos_hint: {'center_x': .5, 'y': .6}
arrow_pos: 'bottom_mid'
BubbleContent:
orientation: 'horizontal'
size_hint_y: None
height: self.minimum_height
BubbleButton:
text: 'This is'
BubbleButton:
text: 'a'
BubbleButton:
text: 'Bubble'
Button:
text: 'press to show popup'
on_release: root.popup.open()
Popup:
id: popup
on_parent: if self.parent == bl: bl.remove_widget(self)
title: "An example popup"
content: popupcontent
Button:
id: popupcontent
text: "press to dismiss"
on_release: popup.dismiss()

View file

@ -0,0 +1,17 @@
#:kivy 1.4
BoxLayout:
orientation: 'vertical'
padding: 50
ProgressBar:
id: bar
value: 140
max: 300
Slider:
id: slider
max: 200
value: 140
on_value: slider.value = self.value
Slider:
orientation: 'vertical'
on_value: slider.value = self.value

View file

@ -0,0 +1,5 @@
#:kivy 1.4
BoxLayout:
RstDocument:
text: ".. _top:\n\nHello world\n===========\n\nThis is an **emphased text**, some ``interpreted text``.\nAnd this is a reference to top_::\n\n $ print('Hello world')\n"

View file

@ -0,0 +1,16 @@
#:kivy 1.4
FloatLayout:
Scatter:
size_hint: None, None
size: 100, 100
pos: 100, 100
Image:
source: "../../widgets/cityCC0.png"
Scatter:
size_hint: None, None
size: 100, 100
pos: 100, 100
do_rotation: False
Label:
text: "something"

View file

@ -0,0 +1,10 @@
#:kivy 1.4
BoxLayout:
orientation: 'vertical'
Spinner:
text: "Work"
values: "Work", "Home", "Mobile", "Skype"
size_hint: (None, None)
size: (100, 44)
# Wanted to put DropDown here, too, but it seems not to be working too well when loaded from .kv

View file

@ -0,0 +1,25 @@
#:kivy 1.4
StackLayout:
orientation: 'tb-lr'
padding: 10
spacing: 5
Button:
text: "Button 1"
size_hint: .2, .4
width: 100
Button:
text: "Button 2"
size_hint: .2, .4
Button:
text: "Button 3"
size_hint: .2, .4
Button:
text: "Button 4"
size_hint: .2, .4
Button:
text: "Button 5"
size_hint: .2, .4
Button:
text: "Button 6"
size_hint: .2, .4

View file

@ -0,0 +1,20 @@
#:kivy 1.4
BoxLayout:
orientation: "vertical"
TextInput:
text: "Single Line Input"
multiline: False
TextInput:
text: "Text Input, start typing here\nmultiline\nsupport"
background_color: .8, .8, 0, 1
size_hint: 1, 3
TextInput:
password: True
text: "Password (but you can't see it)"
multiline: False
on_text: viewer.text = self.text
TextInput:
id: viewer
readonly: True
text: "edit the password to see it here"

View file

@ -0,0 +1,144 @@
#:kivy 1.4
#:import KivyLexer kivy.extras.highlight.KivyLexer
<Container>:
canvas.before:
Color:
rgb: 0, 0, 0
Rectangle:
pos: self.pos
size: self.size
<Catalog>:
language_box: language_box
screen_manager: screen_manager
auto_reload: chkbx.active
info_label: info_lbl
orientation: 'vertical'
BoxLayout:
padding: '2sp'
canvas:
Color:
rgba: 1, 1, 1, .6
Rectangle:
size: self.size
pos: self.pos
size_hint: 1, None
height: '45sp'
Spinner:
size_hint: None, 1
width: '108sp'
text: 'Welcome'
values: [screen.name for screen in screen_manager.screens]
on_text: root.show_kv(*args)
Widget:
BoxLayout:
size_hint: None, 1
width: '150sp'
Label:
text: "Auto Reload"
CheckBox:
id: chkbx
active: True
size_hint_x: 1
Button:
size_hint: None, 1
width: '108sp'
text: 'Render Now'
on_release: root.change_kv(*args)
BoxLayout:
id: reactive_layout
orientation: 'vertical' if self.width < self.height else 'horizontal'
Splitter:
id: editor_pane
max_size: (reactive_layout.height if self.vertical else reactive_layout.width) - self.strip_size
min_size: sp(30) + self.strip_size
vertical: 1 if reactive_layout.width < reactive_layout.height else 0
sizable_from: 'bottom' if self.vertical else 'right'
size_hint: (1, None) if self.vertical else (None, 1)
size: 400, 400
on_vertical:
mid_size = self.max_size/2
if args[1]: self.height = mid_size
if not args[1]: self.width = mid_size
ScrollView:
id: kr_scroll
KivyRenderTextInput:
catalog: root
id: language_box
auto_indent: True
lexer: KivyLexer()
size_hint: 1, None
height: max(kr_scroll.height, self.minimum_height)
valign: "top"
text: "This box will display the kivy language for whatever has been selected"
on_text: root.schedule_reload()
on_cursor: root.schedule_reload()
ScreenManager:
id: screen_manager
Screen:
name: "Welcome"
PlaygroundContainer:
Screen:
name: "Float Layout"
FloatLayoutContainer
Screen:
name: "Box Layout"
BoxLayoutContainer:
Screen:
name: "Anchor Layout"
AnchorLayoutContainer:
Screen:
name: "Grid Layout"
GridLayoutContainer:
Screen:
name: "Stack Layout"
StackLayoutContainer:
Screen:
name: "Buttons"
ButtonContainer:
Screen:
name: "Labels"
LabelContainer:
Screen:
name: "Booleans"
CheckBoxContainer:
Screen:
name: "Progress Bar"
ProgressBarContainer:
Screen:
name: "Media"
MediaContainer:
Screen:
name: "Text"
TextContainer:
Screen:
name: "Popups"
PopupContainer:
Screen:
name: "Selectors"
SelectorsContainer:
Screen:
name: "File Choosers"
FileChooserContainer:
Screen:
name: "Scatter"
ScatterContainer:
Screen:
name: "ReST"
RestContainer:
FloatLayout:
size_hint: 1, None
height: 0
TextInput:
id:info_lbl
readonly: True
font_size: '14sp'
background_color: (0, 0, 0, 1)
foreground_color: (1, 1, 1, 1)
opacity:0
size_hint: 1, None
text_size: self.size
height: '150pt'
top: 0

View file

@ -0,0 +1,192 @@
'''
Kivy Catalog
============
The Kivy Catalog viewer showcases widgets available in Kivy
and allows interactive editing of kivy language code to get immediate
feedback. You should see a two panel screen with a menu spinner button
(starting with 'Welcome') and other controls across the top.The left pane
contains kivy (.kv) code, and the right side is that code rendered. You can
edit the left pane, though changes will be lost when you use the menu
spinner button. The catalog will show you dozens of .kv examples controlling
different widgets and layouts.
The catalog's interface is set in the file kivycatalog.kv, while the
interfaces for each menu option are set in containers_kvs directory. To
add a new .kv file to the Kivy Catalog, add a .kv file into the container_kvs
directory and reference that file in the ScreenManager section of
kivycatalog.kv.
Known bugs include some issue with the drop
'''
import kivy
kivy.require('1.4.2')
import os
import sys
from kivy.app import App
from kivy.factory import Factory
from kivy.lang import Builder, Parser, ParserException
from kivy.properties import ObjectProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.codeinput import CodeInput
from kivy.animation import Animation
from kivy.clock import Clock
CATALOG_ROOT = os.path.dirname(__file__)
# Config.set('graphics', 'width', '1024')
# Config.set('graphics', 'height', '768')
'''List of classes that need to be instantiated in the factory from .kv files.
'''
CONTAINER_KVS = os.path.join(CATALOG_ROOT, 'container_kvs')
CONTAINER_CLASSES = [c[:-3] for c in os.listdir(CONTAINER_KVS)
if c.endswith('.kv')]
class Container(BoxLayout):
'''A container is essentially a class that loads its root from a known
.kv file.
The name of the .kv file is taken from the Container's class.
We can't just use kv rules because the class may be edited
in the interface and reloaded by the user.
See :meth: change_kv where this happens.
'''
def __init__(self, **kwargs):
super(Container, self).__init__(**kwargs)
self.previous_text = open(self.kv_file).read()
parser = Parser(content=self.previous_text)
widget = Factory.get(parser.root.name)()
Builder._apply_rule(widget, parser.root, parser.root)
self.add_widget(widget)
@property
def kv_file(self):
'''Get the name of the kv file, a lowercase version of the class
name.
'''
return os.path.join(CONTAINER_KVS, self.__class__.__name__ + '.kv')
for class_name in CONTAINER_CLASSES:
globals()[class_name] = type(class_name, (Container,), {})
class KivyRenderTextInput(CodeInput):
def keyboard_on_key_down(self, window, keycode, text, modifiers):
is_osx = sys.platform == 'darwin'
# Keycodes on OSX:
ctrl, cmd = 64, 1024
key, key_str = keycode
if text and key not in (list(self.interesting_keys.keys()) + [27]):
# This allows *either* ctrl *or* cmd, but not both.
if modifiers == ['ctrl'] or (is_osx and modifiers == ['meta']):
if key == ord('s'):
self.catalog.change_kv(True)
return
return super(KivyRenderTextInput, self).keyboard_on_key_down(
window, keycode, text, modifiers)
class Catalog(BoxLayout):
'''Catalog of widgets. This is the root widget of the app. It contains
a tabbed pain of widgets that can be displayed and a textbox where .kv
language files for widgets being demoed can be edited.
The entire interface for the Catalog is defined in kivycatalog.kv,
although individual containers are defined in the container_kvs
directory.
To add a container to the catalog,
first create the .kv file in container_kvs
The name of the file (sans .kv) will be the name of the widget available
inside the kivycatalog.kv
Finally modify kivycatalog.kv to add an AccordionItem
to hold the new widget.
Follow the examples in kivycatalog.kv to ensure the item
has an appropriate id and the class has been referenced.
You do not need to edit any python code, just .kv language files!
'''
language_box = ObjectProperty()
screen_manager = ObjectProperty()
_change_kv_ev = None
def __init__(self, **kwargs):
self._previously_parsed_text = ''
super(Catalog, self).__init__(**kwargs)
self.show_kv(None, 'Welcome')
self.carousel = None
def show_kv(self, instance, value):
'''Called when an a item is selected, we need to show the .kv language
file associated with the newly revealed container.'''
self.screen_manager.current = value
child = self.screen_manager.current_screen.children[0]
with open(child.kv_file, 'rb') as file:
self.language_box.text = file.read().decode('utf8')
if self._change_kv_ev is not None:
self._change_kv_ev.cancel()
self.change_kv()
# reset undo/redo history
self.language_box.reset_undo()
def schedule_reload(self):
if self.auto_reload:
txt = self.language_box.text
child = self.screen_manager.current_screen.children[0]
if txt == child.previous_text:
return
child.previous_text = txt
if self._change_kv_ev is not None:
self._change_kv_ev.cancel()
if self._change_kv_ev is None:
self._change_kv_ev = Clock.create_trigger(self.change_kv, 2)
self._change_kv_ev()
def change_kv(self, *largs):
'''Called when the update button is clicked. Needs to update the
interface for the currently active kv widget, if there is one based
on the kv file the user entered. If there is an error in their kv
syntax, show a nice popup.'''
txt = self.language_box.text
kv_container = self.screen_manager.current_screen.children[0]
try:
parser = Parser(content=txt)
kv_container.clear_widgets()
widget = Factory.get(parser.root.name)()
Builder._apply_rule(widget, parser.root, parser.root)
kv_container.add_widget(widget)
except (SyntaxError, ParserException) as e:
self.show_error(e)
except Exception as e:
self.show_error(e)
def show_error(self, e):
self.info_label.text = str(e).encode('utf-8')
self.anim = Animation(top=190.0, opacity=1, d=2, t='in_back') +\
Animation(top=190.0, d=3) +\
Animation(top=0, opacity=0, d=2)
self.anim.start(self.info_label)
class KivyCatalogApp(App):
'''The kivy App that runs the main root. All we do is build a catalog
widget into the root.'''
def build(self):
return Catalog()
def on_pause(self):
return True
if __name__ == "__main__":
KivyCatalogApp().run()