first commit
This commit is contained in:
commit
417e54da96
5696 changed files with 900003 additions and 0 deletions
11
kivy_venv/share/kivy-examples/demo/showcase/README.txt
Normal file
11
kivy_venv/share/kivy-examples/demo/showcase/README.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
Showcase
|
||||
========
|
||||
|
||||
Demonstrate all the possibilities of Kivy toolkit.
|
||||
|
||||
Android
|
||||
-------
|
||||
|
||||
You can copy/paste this directory into /sdcard/kivy/showcase in your
|
||||
android device.
|
||||
|
Binary file not shown.
3
kivy_venv/share/kivy-examples/demo/showcase/android.txt
Normal file
3
kivy_venv/share/kivy-examples/demo/showcase/android.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
title=Showcase
|
||||
author=Kivy team
|
||||
orientation=landscape
|
BIN
kivy_venv/share/kivy-examples/demo/showcase/data/background.png
Normal file
BIN
kivy_venv/share/kivy-examples/demo/showcase/data/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
Binary file not shown.
After Width: | Height: | Size: 220 KiB |
|
@ -0,0 +1,4 @@
|
|||
Icons adapted from the Open Iconic set of icons, which are licensed under MIT.
|
||||
|
||||
https://useiconic.com/
|
||||
https://github.com/iconic/open-iconic
|
BIN
kivy_venv/share/kivy-examples/demo/showcase/data/icons/bug.png
Normal file
BIN
kivy_venv/share/kivy-examples/demo/showcase/data/icons/bug.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 587 B |
Binary file not shown.
After Width: | Height: | Size: 584 B |
|
@ -0,0 +1,39 @@
|
|||
ShowcaseScreen:
|
||||
name: 'Accordions'
|
||||
|
||||
fullscreen: True
|
||||
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
ToggleButton:
|
||||
id: tbh
|
||||
text: 'Horizontal'
|
||||
group: 'accordion'
|
||||
state: 'down'
|
||||
|
||||
ToggleButton:
|
||||
text: 'Vertical'
|
||||
group: 'accordion'
|
||||
|
||||
Accordion:
|
||||
|
||||
orientation: 'horizontal' if tbh.state == 'down' else 'vertical'
|
||||
|
||||
AccordionItem:
|
||||
title: 'Panel 1'
|
||||
Label:
|
||||
text: 'This is a label fit to the content view'
|
||||
text_size: self.width, None
|
||||
|
||||
AccordionItem:
|
||||
title: 'Panel 2'
|
||||
Button:
|
||||
text: 'A button, what else?'
|
||||
|
||||
AccordionItem:
|
||||
title: 'Panel 3'
|
||||
Label:
|
||||
text: 'This is a label fit to the content view'
|
||||
text_size: self.width, None
|
|
@ -0,0 +1,33 @@
|
|||
ShowcaseScreen:
|
||||
name: 'Bubbles'
|
||||
|
||||
Bubble:
|
||||
size_hint_y: None
|
||||
height: self.content_height + self.arrow_margin_y
|
||||
|
||||
BubbleContent:
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
|
||||
BubbleButton:
|
||||
text: 'Cut'
|
||||
BubbleButton:
|
||||
text: 'Copy'
|
||||
BubbleButton:
|
||||
text: 'Paste'
|
||||
|
||||
Widget:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
Label:
|
||||
text: 'Hello'
|
||||
|
||||
Bubble:
|
||||
arrow_pos: 'left_mid'
|
||||
BubbleContent:
|
||||
Label:
|
||||
text: 'World'
|
|
@ -0,0 +1,26 @@
|
|||
ShowcaseScreen:
|
||||
name: 'Buttons'
|
||||
|
||||
Button:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
text: 'Button normal'
|
||||
|
||||
Button:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
text: 'Button down'
|
||||
state: 'down'
|
||||
|
||||
Button:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
text: 'Button disabled'
|
||||
disabled: True
|
||||
|
||||
Button:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
text: 'Button down disabled'
|
||||
state: 'down'
|
||||
disabled: True
|
|
@ -0,0 +1,51 @@
|
|||
<ColoredLabel@Label>:
|
||||
font_size: '48sp'
|
||||
color: (.6, .6, .6, 1)
|
||||
canvas.before:
|
||||
Color:
|
||||
rgb: (.9, .9, .9)
|
||||
Rectangle:
|
||||
pos: self.x + sp(2), self.y + sp(2)
|
||||
size: self.width - sp(4), self.height - sp(4)
|
||||
|
||||
ShowcaseScreen:
|
||||
name: 'Carousel'
|
||||
fullscreen: True
|
||||
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
ToggleButton:
|
||||
text: 'Loop'
|
||||
id: btnloop
|
||||
|
||||
Label:
|
||||
size_hint_x: None
|
||||
width: self.height
|
||||
text: '{}'.format(carousel.index)
|
||||
|
||||
Button:
|
||||
size_hint_x: None
|
||||
width: self.height
|
||||
text: 'Prev'
|
||||
on_release: carousel.load_previous()
|
||||
|
||||
Button:
|
||||
size_hint_x: None
|
||||
width: self.height
|
||||
text: 'Next'
|
||||
on_release: carousel.load_next()
|
||||
|
||||
Carousel:
|
||||
id: carousel
|
||||
loop: btnloop.state == 'down'
|
||||
|
||||
ColoredLabel:
|
||||
text: 'Slide 0'
|
||||
|
||||
ColoredLabel:
|
||||
text: 'Slide 1'
|
||||
|
||||
ColoredLabel:
|
||||
text: 'Slide 2'
|
|
@ -0,0 +1,33 @@
|
|||
ShowcaseScreen:
|
||||
name: 'CheckBoxes'
|
||||
|
||||
GridLayout:
|
||||
|
||||
cols: 3
|
||||
spacing: '8dp'
|
||||
size_hint: .5, None
|
||||
height: self.minimum_height
|
||||
|
||||
Label:
|
||||
text: 'Checkbox'
|
||||
|
||||
CheckBox:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
CheckBox:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
Label:
|
||||
text: 'CheckBox with group'
|
||||
|
||||
CheckBox:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
group: 'g2'
|
||||
|
||||
CheckBox:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
group: 'g2'
|
|
@ -0,0 +1,9 @@
|
|||
ShowcaseScreen:
|
||||
|
||||
fullscreen: True
|
||||
name: 'CodeInput'
|
||||
|
||||
CodeInput:
|
||||
padding: '4dp'
|
||||
text: 'class Hello(object):\n\tpass\n\nprint("Hello world")'
|
||||
focus: True if root.parent else False
|
|
@ -0,0 +1,40 @@
|
|||
ShowcaseScreen:
|
||||
fullscreen: True
|
||||
name: 'DropDown'
|
||||
|
||||
# trick to not lost the Dropdown instance
|
||||
# Dropdown itself is not really made to be used in kv.
|
||||
__safe_id: [dropdown.__self__]
|
||||
|
||||
Button:
|
||||
id: btn
|
||||
text: '-'
|
||||
on_release: dropdown.open(self)
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
Widget:
|
||||
on_parent: dropdown.dismiss()
|
||||
|
||||
DropDown:
|
||||
|
||||
id: dropdown
|
||||
on_select: btn.text = 'Selected value: {}'.format(args[1])
|
||||
|
||||
Button:
|
||||
text: 'Value A'
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
on_release: dropdown.select('A')
|
||||
|
||||
Button:
|
||||
text: 'Value B'
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
on_release: dropdown.select('B')
|
||||
|
||||
Button:
|
||||
text: 'Value C'
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
on_release: dropdown.select('C')
|
|
@ -0,0 +1,24 @@
|
|||
ShowcaseScreen:
|
||||
name: 'FileChoosers'
|
||||
fullscreen: True
|
||||
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
ToggleButton:
|
||||
text: 'Icon'
|
||||
state: 'down'
|
||||
group: 'filechooser'
|
||||
on_release: filechooser.view_mode = 'icon'
|
||||
|
||||
ToggleButton:
|
||||
text: 'List'
|
||||
group: 'filechooser'
|
||||
on_release: filechooser.view_mode = 'list'
|
||||
|
||||
FileChooser:
|
||||
id: filechooser
|
||||
|
||||
FileChooserIconLayout
|
||||
FileChooserListLayout
|
|
@ -0,0 +1,17 @@
|
|||
ShowcaseScreen:
|
||||
popup: popup.__self__
|
||||
fullscreen: True
|
||||
name: 'Popups'
|
||||
BoxLayout:
|
||||
id: bl
|
||||
Popup:
|
||||
id: popup
|
||||
title: "Hello World"
|
||||
on_parent:
|
||||
if self.parent == bl: self.parent.remove_widget(self)
|
||||
Button:
|
||||
text: 'press to dismiss'
|
||||
on_release: popup.dismiss()
|
||||
Button:
|
||||
text: 'press to show Popup'
|
||||
on_release: root.popup.open()
|
|
@ -0,0 +1,15 @@
|
|||
ShowcaseScreen:
|
||||
name: 'ProgressBar'
|
||||
|
||||
Label:
|
||||
text: 'Progression: {}%'.format(int(pb.value))
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
ProgressBar:
|
||||
id: pb
|
||||
size_hint_x: .5
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
value: (app.time * 20) % 100.
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
ShowcaseScreen:
|
||||
name: 'RstDocument'
|
||||
fullscreen: True
|
||||
on_parent: if not args[1]: textinput.focus = False
|
||||
|
||||
GridLayout:
|
||||
cols: 2 if root.width > root.height else 1
|
||||
spacing: '8dp'
|
||||
|
||||
TextInput:
|
||||
id: textinput
|
||||
text:
|
||||
('.. _top:\n'
|
||||
'\n'
|
||||
'Hello world\n'
|
||||
'===========\n'
|
||||
'\n'
|
||||
'This is an **emphased text**, *italic text*, ``interpreted text``.\n'
|
||||
'And this is a reference to top_::\n'
|
||||
'\n'
|
||||
' $ print("Hello world")\n')
|
||||
|
||||
RstDocument:
|
||||
text: textinput.text
|
|
@ -0,0 +1,14 @@
|
|||
ShowcaseScreen:
|
||||
name: 'Scatter'
|
||||
|
||||
Widget:
|
||||
|
||||
Scatter:
|
||||
id: scatter
|
||||
size_hint: None, None
|
||||
size: image.size
|
||||
|
||||
Image:
|
||||
id: image
|
||||
source: 'data/faust_github.jpg'
|
||||
size: self.texture_size
|
|
@ -0,0 +1,46 @@
|
|||
#:import Factory kivy.factory.Factory
|
||||
|
||||
ShowcaseScreen:
|
||||
name: 'ScreenManager'
|
||||
fullscreen: True
|
||||
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
Spinner:
|
||||
text: 'Default transition'
|
||||
values: ('SlideTransition', 'SwapTransition', 'FadeTransition', 'WipeTransition')
|
||||
on_text: sm.transition = Factory.get(self.text)()
|
||||
|
||||
ScreenManager:
|
||||
id: sm
|
||||
|
||||
Screen:
|
||||
name: 'screen1'
|
||||
canvas.before:
|
||||
Color:
|
||||
rgb: .8, .2, .2
|
||||
Rectangle:
|
||||
size: self.size
|
||||
|
||||
AnchorLayout:
|
||||
Button:
|
||||
size_hint: None, None
|
||||
size: '150dp', '48dp'
|
||||
text: 'Go to screen 2'
|
||||
on_release: sm.current = 'screen2'
|
||||
|
||||
Screen:
|
||||
name: 'screen2'
|
||||
canvas.before:
|
||||
Color:
|
||||
rgb: .2, .8, .2
|
||||
Rectangle:
|
||||
size: self.size
|
||||
AnchorLayout:
|
||||
Button:
|
||||
size_hint: None, None
|
||||
size: '150dp', '48dp'
|
||||
text: 'Go to screen 1'
|
||||
on_release: sm.current = 'screen1'
|
|
@ -0,0 +1,55 @@
|
|||
ShowcaseScreen:
|
||||
name: 'Sliders'
|
||||
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
Label:
|
||||
text: 'Default'
|
||||
|
||||
Slider:
|
||||
id: s1
|
||||
|
||||
Label:
|
||||
text: '{}'.format(s1.value)
|
||||
|
||||
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
Label:
|
||||
text: 'Stepped'
|
||||
|
||||
Slider:
|
||||
id: s2
|
||||
step: 20
|
||||
|
||||
Label:
|
||||
text: '{}'.format(s2.value)
|
||||
|
||||
AnchorLayout:
|
||||
size_hint_y: None
|
||||
height: '100dp'
|
||||
|
||||
GridLayout:
|
||||
cols: 2
|
||||
spacing: '8dp'
|
||||
size_hint_x: None
|
||||
width: self.minimum_width
|
||||
|
||||
Slider:
|
||||
size_hint_x: None
|
||||
width: '48dp'
|
||||
orientation: 'vertical'
|
||||
value: s1.value
|
||||
on_value: s1.value = self.value
|
||||
|
||||
Slider:
|
||||
size_hint_x: None
|
||||
width: '48dp'
|
||||
orientation: 'vertical'
|
||||
step: 20
|
||||
value: s2.value
|
||||
on_value: s2.value = self.value
|
|
@ -0,0 +1,11 @@
|
|||
ShowcaseScreen:
|
||||
name: 'Spinner'
|
||||
fullscreen: True
|
||||
|
||||
Spinner:
|
||||
text: 'Home'
|
||||
values: ('Home', 'Work', 'Other', 'Not defined')
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
Widget
|
|
@ -0,0 +1,13 @@
|
|||
ShowcaseScreen:
|
||||
name: 'Splitter'
|
||||
fullscreen: True
|
||||
|
||||
RelativeLayout:
|
||||
id: rl
|
||||
|
||||
Splitter:
|
||||
sizable_from: 'right'
|
||||
min_size: 10
|
||||
max_size: rl.width
|
||||
Button:
|
||||
text: 'Panel'
|
|
@ -0,0 +1,39 @@
|
|||
ShowcaseScreen:
|
||||
name: 'Switches'
|
||||
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
Label:
|
||||
text: 'Switch normal'
|
||||
Switch:
|
||||
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
Label:
|
||||
text: 'Switch active'
|
||||
Switch:
|
||||
active: True
|
||||
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
Label:
|
||||
text: 'Switch off & disabled'
|
||||
Switch:
|
||||
disabled: True
|
||||
active: False
|
||||
|
||||
BoxLayout:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
|
||||
Label:
|
||||
text: 'Switch on & disabled'
|
||||
Switch:
|
||||
disabled: True
|
||||
active: True
|
|
@ -0,0 +1,69 @@
|
|||
#:import random random.random
|
||||
|
||||
ShowcaseScreen:
|
||||
name: 'TabbedPanel + Layouts'
|
||||
fullscreen: True
|
||||
on_parent: if args[1] and tp.current_tab == tab_fl: app.showcase_floatlayout(fl)
|
||||
|
||||
TabbedPanel:
|
||||
id: tp
|
||||
do_default_tab: False
|
||||
|
||||
TabbedPanelItem:
|
||||
id: tab_fl
|
||||
text: 'FloatLayout'
|
||||
on_release: app.showcase_floatlayout(fl)
|
||||
FloatLayout:
|
||||
CFloatLayout:
|
||||
id: fl
|
||||
TabbedPanelItem:
|
||||
text: 'BoxLayout'
|
||||
on_release: app.showcase_boxlayout(box)
|
||||
FloatLayout
|
||||
CBoxLayout:
|
||||
id: box
|
||||
TabbedPanelItem:
|
||||
text: 'GridLayout'
|
||||
on_release: app.showcase_gridlayout(grid)
|
||||
FloatLayout
|
||||
CGridLayout:
|
||||
id: grid
|
||||
rows: 3
|
||||
TabbedPanelItem:
|
||||
on_release: app.showcase_stacklayout(stack)
|
||||
text: 'StackLayout'
|
||||
FloatLayout
|
||||
CStackLayout:
|
||||
id: stack
|
||||
TabbedPanelItem:
|
||||
text: 'AnchorLayout'
|
||||
on_release: app.showcase_anchorlayout(anchor)
|
||||
FloatLayout
|
||||
CAnchorLayout:
|
||||
id: anchor
|
||||
BoxLayout:
|
||||
orientation: 'vertical'
|
||||
size_hint: .4, .5
|
||||
Button
|
||||
Button
|
||||
text: 'anchor_x: {}'.format(anchor.anchor_x)
|
||||
Button
|
||||
text: 'anchor_y: {}'.format(anchor.anchor_y)
|
||||
Button
|
||||
|
||||
<CFloatLayout@FloatLayout+BackgroundColor>
|
||||
<CBoxLayout@BoxLayout+BackgroundColor>
|
||||
<CGridLayout@GridLayout+BackgroundColor>
|
||||
<CStackLayout@StackLayout+BackgroundColor>
|
||||
<CAnchorLayout@AnchorLayout+BackgroundColor>
|
||||
|
||||
|
||||
<BackgroundColor@Widget>
|
||||
pos_hint: {'center_x': .5, 'center_y': .5}
|
||||
size_hint: .9, .9
|
||||
canvas.before:
|
||||
Color:
|
||||
rgba: .2, .3, .4, 1
|
||||
Rectangle:
|
||||
size: self.size
|
||||
pos: self.pos
|
|
@ -0,0 +1,48 @@
|
|||
ShowcaseScreen:
|
||||
name: 'TextInputs'
|
||||
focused: ti_default
|
||||
on_parent:
|
||||
if not args[1] and self.focused: self.focused.focus = False
|
||||
if args[1]: ti_default.focus = True
|
||||
|
||||
CTextInput
|
||||
size_hint_y: None
|
||||
height: '32dp'
|
||||
multiline: False
|
||||
text: 'Monoline textinput'
|
||||
|
||||
CTextInput:
|
||||
id: ti_default
|
||||
size_hint_y: None
|
||||
height: '32dp'
|
||||
text: 'Focused textinput'
|
||||
focus: True
|
||||
|
||||
CTextInput:
|
||||
size_hint_y: None
|
||||
height: '32dp'
|
||||
text: 'Password'
|
||||
password: True
|
||||
|
||||
CTextInput:
|
||||
size_hint_y: None
|
||||
height: '32dp'
|
||||
text: 'Readonly textinput'
|
||||
readonly: True
|
||||
|
||||
CTextInput:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
text: 'Multiline textinput\nSecond line'
|
||||
multiline: True
|
||||
|
||||
CTextInput:
|
||||
size_hint_y: None
|
||||
height: '32dp'
|
||||
disabled: True
|
||||
text: 'Disabled textinput'
|
||||
|
||||
<CTextInput@TextInput>
|
||||
on_focus:
|
||||
screen = self.parent.parent.parent.parent
|
||||
if screen.parent: screen.focused = self
|
|
@ -0,0 +1,39 @@
|
|||
ShowcaseScreen:
|
||||
name: 'ToggleButton'
|
||||
|
||||
GridLayout:
|
||||
|
||||
cols: 3
|
||||
spacing: '8dp'
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
|
||||
Label:
|
||||
text: 'Choice 1'
|
||||
|
||||
ToggleButton:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
text: 'A'
|
||||
group: 'g1'
|
||||
|
||||
ToggleButton:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
text: 'B'
|
||||
group: 'g1'
|
||||
|
||||
Label:
|
||||
text: 'Choice 2'
|
||||
|
||||
ToggleButton:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
text: 'A'
|
||||
group: 'g2'
|
||||
|
||||
ToggleButton:
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
text: 'B'
|
||||
group: 'g2'
|
243
kivy_venv/share/kivy-examples/demo/showcase/main.py
Normal file
243
kivy_venv/share/kivy-examples/demo/showcase/main.py
Normal file
|
@ -0,0 +1,243 @@
|
|||
'''
|
||||
Showcase of Kivy Features
|
||||
=========================
|
||||
|
||||
This showcases many features of Kivy. You should see a
|
||||
menu bar across the top with a demonstration area below. The
|
||||
first demonstration is the accordion layout. You can see, but not
|
||||
edit, the kv language code for any screen by pressing the bug or
|
||||
'show source' icon. Scroll through the demonstrations using the
|
||||
left and right icons in the top right or selecting from the menu
|
||||
bar.
|
||||
|
||||
The file showcase.kv describes the main container, while each demonstration
|
||||
pane is described in a separate .kv file in the data/screens directory.
|
||||
The image data/background.png provides the gradient background while the
|
||||
icons in data/icon directory are used in the control bar. The file
|
||||
data/faust_github.jpg is used in the Scatter pane. The icons are
|
||||
from `http://www.gentleface.com/free_icon_set.html` and licensed as
|
||||
Creative Commons - Attribution and Non-commercial Use Only; they
|
||||
sell a commercial license.
|
||||
|
||||
The file android.txt is used to package the application for use with the
|
||||
Kivy Launcher Android application. For Android devices, you can
|
||||
copy/paste this directory into /sdcard/kivy/showcase on your Android device.
|
||||
|
||||
'''
|
||||
|
||||
from time import time
|
||||
from kivy.app import App
|
||||
from os.path import dirname, join
|
||||
from kivy.lang import Builder
|
||||
from kivy.properties import (
|
||||
NumericProperty,
|
||||
StringProperty,
|
||||
BooleanProperty,
|
||||
ListProperty,
|
||||
)
|
||||
from kivy.clock import Clock
|
||||
from kivy.animation import Animation
|
||||
from kivy.uix.screenmanager import Screen
|
||||
|
||||
|
||||
class ShowcaseScreen(Screen):
|
||||
fullscreen = BooleanProperty(False)
|
||||
|
||||
def add_widget(self, *args, **kwargs):
|
||||
if 'content' in self.ids:
|
||||
return self.ids.content.add_widget(*args, **kwargs)
|
||||
return super(ShowcaseScreen, self).add_widget(*args, **kwargs)
|
||||
|
||||
|
||||
class ShowcaseApp(App):
|
||||
|
||||
index = NumericProperty(-1)
|
||||
current_title = StringProperty()
|
||||
time = NumericProperty(0)
|
||||
show_sourcecode = BooleanProperty(False)
|
||||
sourcecode = StringProperty()
|
||||
screen_names = ListProperty([])
|
||||
hierarchy = ListProperty([])
|
||||
|
||||
def build(self):
|
||||
self.title = 'hello world'
|
||||
Clock.schedule_interval(self._update_clock, 1 / 60.)
|
||||
self.screens = {}
|
||||
self.available_screens = sorted([
|
||||
'Buttons', 'ToggleButton', 'Sliders', 'ProgressBar', 'Switches',
|
||||
'CheckBoxes', 'TextInputs', 'Accordions', 'FileChoosers',
|
||||
'Carousel', 'Bubbles', 'CodeInput', 'DropDown', 'Spinner',
|
||||
'Scatter', 'Splitter', 'TabbedPanel + Layouts', 'RstDocument',
|
||||
'Popups', 'ScreenManager'])
|
||||
self.screen_names = self.available_screens
|
||||
curdir = dirname(__file__)
|
||||
self.available_screens = [join(curdir, 'data', 'screens',
|
||||
'{}.kv'.format(fn).lower()) for fn in self.available_screens]
|
||||
self.go_next_screen()
|
||||
|
||||
def on_pause(self):
|
||||
return True
|
||||
|
||||
def on_resume(self):
|
||||
pass
|
||||
|
||||
def on_current_title(self, instance, value):
|
||||
self.root.ids.spnr.text = value
|
||||
|
||||
def go_previous_screen(self):
|
||||
self.index = (self.index - 1) % len(self.available_screens)
|
||||
screen = self.load_screen(self.index)
|
||||
sm = self.root.ids.sm
|
||||
sm.switch_to(screen, direction='right')
|
||||
self.current_title = screen.name
|
||||
self.update_sourcecode()
|
||||
|
||||
def go_next_screen(self):
|
||||
self.index = (self.index + 1) % len(self.available_screens)
|
||||
screen = self.load_screen(self.index)
|
||||
sm = self.root.ids.sm
|
||||
sm.switch_to(screen, direction='left')
|
||||
self.current_title = screen.name
|
||||
self.update_sourcecode()
|
||||
|
||||
def go_screen(self, idx):
|
||||
self.index = idx
|
||||
self.root.ids.sm.switch_to(self.load_screen(idx), direction='left')
|
||||
self.update_sourcecode()
|
||||
|
||||
def go_hierarchy_previous(self):
|
||||
ahr = self.hierarchy
|
||||
if len(ahr) == 1:
|
||||
return
|
||||
if ahr:
|
||||
ahr.pop()
|
||||
if ahr:
|
||||
idx = ahr.pop()
|
||||
self.go_screen(idx)
|
||||
|
||||
def load_screen(self, index):
|
||||
if index in self.screens:
|
||||
return self.screens[index]
|
||||
screen = Builder.load_file(self.available_screens[index])
|
||||
self.screens[index] = screen
|
||||
return screen
|
||||
|
||||
def read_sourcecode(self):
|
||||
fn = self.available_screens[self.index]
|
||||
with open(fn) as fd:
|
||||
return fd.read()
|
||||
|
||||
def toggle_source_code(self):
|
||||
self.show_sourcecode = not self.show_sourcecode
|
||||
if self.show_sourcecode:
|
||||
height = self.root.height * .3
|
||||
else:
|
||||
height = 0
|
||||
|
||||
Animation(height=height, d=.3, t='out_quart').start(
|
||||
self.root.ids.sv)
|
||||
|
||||
self.update_sourcecode()
|
||||
|
||||
def update_sourcecode(self):
|
||||
if not self.show_sourcecode:
|
||||
self.root.ids.sourcecode.focus = False
|
||||
return
|
||||
self.root.ids.sourcecode.text = self.read_sourcecode()
|
||||
self.root.ids.sv.scroll_y = 1
|
||||
|
||||
def showcase_floatlayout(self, layout):
|
||||
|
||||
def add_button(*t):
|
||||
if not layout.get_parent_window():
|
||||
return
|
||||
if len(layout.children) > 5:
|
||||
layout.clear_widgets()
|
||||
layout.add_widget(Builder.load_string('''
|
||||
#:import random random.random
|
||||
Button:
|
||||
size_hint: random(), random()
|
||||
pos_hint: {'x': random(), 'y': random()}
|
||||
text:
|
||||
'size_hint x: {} y: {}\\n pos_hint x: {} y: {}'.format(\
|
||||
self.size_hint_x, self.size_hint_y, self.pos_hint['x'],\
|
||||
self.pos_hint['y'])
|
||||
'''))
|
||||
Clock.schedule_once(add_button, 1)
|
||||
Clock.schedule_once(add_button)
|
||||
|
||||
def showcase_boxlayout(self, layout):
|
||||
|
||||
def add_button(*t):
|
||||
if not layout.get_parent_window():
|
||||
return
|
||||
if len(layout.children) > 5:
|
||||
layout.orientation = 'vertical'\
|
||||
if layout.orientation == 'horizontal' else 'horizontal'
|
||||
layout.clear_widgets()
|
||||
layout.add_widget(Builder.load_string('''
|
||||
Button:
|
||||
text: self.parent.orientation if self.parent else ''
|
||||
'''))
|
||||
Clock.schedule_once(add_button, 1)
|
||||
Clock.schedule_once(add_button)
|
||||
|
||||
def showcase_gridlayout(self, layout):
|
||||
|
||||
def add_button(*t):
|
||||
if not layout.get_parent_window():
|
||||
return
|
||||
if len(layout.children) > 15:
|
||||
layout.rows = 3 if layout.rows is None else None
|
||||
layout.cols = None if layout.rows == 3 else 3
|
||||
layout.clear_widgets()
|
||||
layout.add_widget(Builder.load_string('''
|
||||
Button:
|
||||
text:
|
||||
'rows: {}\\ncols: {}'.format(self.parent.rows, self.parent.cols)\
|
||||
if self.parent else ''
|
||||
'''))
|
||||
Clock.schedule_once(add_button, 1)
|
||||
Clock.schedule_once(add_button)
|
||||
|
||||
def showcase_stacklayout(self, layout):
|
||||
orientations = ('lr-tb', 'tb-lr',
|
||||
'rl-tb', 'tb-rl',
|
||||
'lr-bt', 'bt-lr',
|
||||
'rl-bt', 'bt-rl')
|
||||
|
||||
def add_button(*t):
|
||||
if not layout.get_parent_window():
|
||||
return
|
||||
if len(layout.children) > 11:
|
||||
layout.clear_widgets()
|
||||
cur_orientation = orientations.index(layout.orientation)
|
||||
layout.orientation = orientations[cur_orientation - 1]
|
||||
layout.add_widget(Builder.load_string('''
|
||||
Button:
|
||||
text: self.parent.orientation if self.parent else ''
|
||||
size_hint: .2, .2
|
||||
'''))
|
||||
Clock.schedule_once(add_button, 1)
|
||||
Clock.schedule_once(add_button)
|
||||
|
||||
def showcase_anchorlayout(self, layout):
|
||||
|
||||
def change_anchor(self, *l):
|
||||
if not layout.get_parent_window():
|
||||
return
|
||||
anchor_x = ('left', 'center', 'right')
|
||||
anchor_y = ('top', 'center', 'bottom')
|
||||
if layout.anchor_x == 'left':
|
||||
layout.anchor_y = anchor_y[anchor_y.index(layout.anchor_y) - 1]
|
||||
layout.anchor_x = anchor_x[anchor_x.index(layout.anchor_x) - 1]
|
||||
|
||||
Clock.schedule_once(change_anchor, 1)
|
||||
Clock.schedule_once(change_anchor, 1)
|
||||
|
||||
def _update_clock(self, dt):
|
||||
self.time = time()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ShowcaseApp().run()
|
100
kivy_venv/share/kivy-examples/demo/showcase/showcase.kv
Normal file
100
kivy_venv/share/kivy-examples/demo/showcase/showcase.kv
Normal file
|
@ -0,0 +1,100 @@
|
|||
#:kivy 1.8.0
|
||||
#:import KivyLexer kivy.extras.highlight.KivyLexer
|
||||
#:import Factory kivy.factory.Factory
|
||||
|
||||
<ActionSpinnerOptions@SpinnerOption>
|
||||
background_color: .4, .4, .4, 1
|
||||
|
||||
<ActionSpinner@Spinner+ActionItem>
|
||||
canvas.before:
|
||||
Color:
|
||||
rgba: 0.128, 0.128, 0.128, 1
|
||||
Rectangle:
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
border: 27, 20, 12, 12
|
||||
background_normal: 'atlas://data/images/defaulttheme/action_group'
|
||||
option_cls: Factory.ActionSpinnerOptions
|
||||
|
||||
<ActionDropdown>:
|
||||
on_size: self.width = '220dp'
|
||||
|
||||
<ShowcaseScreen>:
|
||||
ScrollView:
|
||||
do_scroll_x: False
|
||||
do_scroll_y: False if root.fullscreen else (content.height > root.height - dp(16))
|
||||
AnchorLayout:
|
||||
size_hint_y: None
|
||||
height: root.height if root.fullscreen else max(root.height, content.height)
|
||||
GridLayout:
|
||||
id: content
|
||||
cols: 1
|
||||
spacing: '8dp'
|
||||
padding: '8dp'
|
||||
size_hint: (1, 1) if root.fullscreen else (.8, None)
|
||||
height: self.height if root.fullscreen else self.minimum_height
|
||||
|
||||
|
||||
BoxLayout:
|
||||
orientation: 'vertical'
|
||||
|
||||
canvas.before:
|
||||
Color:
|
||||
rgb: .6, .6, .6
|
||||
Rectangle:
|
||||
size: self.size
|
||||
source: 'data/background.png'
|
||||
|
||||
ActionBar:
|
||||
|
||||
ActionView:
|
||||
id: av
|
||||
ActionPrevious:
|
||||
with_previous: (False if sm.current_screen.name == 'button' else True) if sm.current_screen else False
|
||||
title: 'Showcase' + ('' if not app.current_title else ' - {}'.format(app.current_title))
|
||||
on_release: app.go_hierarchy_previous()
|
||||
|
||||
ActionSpinner:
|
||||
id: spnr
|
||||
important: True
|
||||
text: 'Jump to Screen'
|
||||
values: app.screen_names
|
||||
on_text:
|
||||
if sm.current != args[1]:\
|
||||
idx = app.screen_names.index(args[1]);\
|
||||
app.go_screen(idx)
|
||||
ActionToggleButton:
|
||||
text: 'Toggle sourcecode'
|
||||
icon: 'data/icons/bug.png'
|
||||
on_release: app.toggle_source_code()
|
||||
ActionButton:
|
||||
text: 'Previous screen'
|
||||
icon: 'data/icons/chevron-left.png'
|
||||
on_release: app.go_previous_screen()
|
||||
|
||||
ActionButton:
|
||||
text: 'Next screen'
|
||||
icon: 'data/icons/chevron-right.png'
|
||||
on_release: app.go_next_screen()
|
||||
important: True
|
||||
|
||||
ScrollView:
|
||||
id: sv
|
||||
size_hint_y: None
|
||||
height: 0
|
||||
|
||||
CodeInput:
|
||||
id: sourcecode
|
||||
lexer: KivyLexer()
|
||||
text: app.sourcecode
|
||||
readonly: True
|
||||
size_hint_y: None
|
||||
font_size: '12sp'
|
||||
height: self.minimum_height
|
||||
|
||||
ScreenManager:
|
||||
id: sm
|
||||
on_current_screen:
|
||||
spnr.text = args[1].name
|
||||
idx = app.screen_names.index(args[1].name)
|
||||
if idx > -1: app.hierarchy.append(idx)
|
Loading…
Add table
Add a link
Reference in a new issue