SlideShare a Scribd company logo
KIVY
NUI Applications with Python
Python Meetup Innsbruck | 25. April 2017
Robert Niederreiter
CROSS PLATFORM
kivy
ARCHITECTURE
Widget Kv Language
Cache Clock Gesture Event Loop Properties
Core Providers
Window
Text
Image
Video
Audio
Graphics
Vertex Buffer
Frame Buffer
Texture
Shader
Instructions
Inputs
Motion Event
Post Processing
(double tab,
Dejitter, …)
Pygame PIL Gstreamer
FFMpeg SDL Cairo
GLES API GLEW
MouseTUIO WM_Touch
Mac TouchMTDev HIDInput
App brought to foreground
After process is killed (Android/iOS)
Kivy bootstrap for Android/iOS
Python start, run()
build()
on_start()
Apps functionson_resume()
Extenal App/OS or internal
function pauses App
on_pause()
Save your work here.
Resume is not guaranteed.
on_stop()
Kivy window destroyed
Python stop
on_pause()
Resume?
return True
return False
NoYes
LIFECYCLE
EVENT LOOP
Clock Events Loop
Filesystem
Network
Process
Other
Motion Events
Post Processing
(double tab, swipe, ...)
Input Processing
Event
Dispatcher
Dispatch Input Events
Custom Events
Property Events
Window Events
GUI
Touch
Mouse
Keyboard
Joystick
Other
Input Kivy Main Thread
Non GUI
Operations
(may run in
dedicated thread)
Main
Loop
EventDispatcher
App
Widget
Widgets are self-contained
and organized as tree
Animation
Clock
MotionEvent
Layout
Controls size and
position of it's children
FloatLayout
BoxLayout
GridLayout
ButtonBehavior
CoverBehavior
DragBehavior
behaviors
...
Button
Switch
Slider
Popup
...
uix
graphics
Widget representation is done using canvas, graphics
instructions are applied to it
ContextInstruction VertexInstruction
Color
Rotate
Scale
...
Triangle
Rectangle
Ellipse
...
Kv Language
The KV language (sometimes called kvlang, or kivy language),
allows you to create your widget tree in a declarative way
and to bind widget properties to each other or to callbacks in a
natural manner.
...
OBJECTS
Mixin Classes for Widgets
APPLICATION
import kivy
# replace with your current kivy version
kivy.require('1.9.1')
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
# MyApp inherits from App object
def build(self):
# build returns the root widget
return Label(text='Hello world')
if __name__ == '__main__':
MyApp().run()
REPETITIVE EVENTS
from kivy.clock import Clock
def my_callback(dt):
# ``dt`` is delta time
print('My callback is called'.format(dt))
# call ``my_callback`` X times per second
event = Clock.schedule_interval(my_callback, 1 / 30.)
# unscedule can be done by either using
event.cancel()
# or
Clock.unschedule(event)
def my_callback(dt):
# if repetitive callback returns False, it gets unscheduled as well
if some_condition:
return False
# regular processing
Clock.schedule_interval(my_callback, 1 / 30.)
ONE-TIME EVENTS
from kivy.clock import Clock
def my_callback(dt):
print('My callback is called'.format(dt))
# call ``my_callback`` once in one second
Clock.schedule_once(my_callback, 1)
The second argument is the amount of time to wait before calling the function,
in seconds. However, you can achieve some other results with special values
for the second argument:
● If X is greater than 0, the callback will be called in X seconds
● If X is 0, the callback will be called after the next frame
● If X is -1, the callback will be called before the next frame
INPUT AND PROPERTY EVENTS
from kivy.uix.widget import Widget
from kivy.properties import ListProperty
class CustomBtn(Widget):
# it's possible to bind to kivy property changes
pressed = ListProperty([0, 0])
def on_touch_down(self, touch):
# event handler for regular touch events
if self.collide_point(*touch.pos):
# setting pressed property triggers property event
self.pressed = touch.pos
# return True to indicate event consumed
return True
# delegate touch event to super class
return super(CustomBtn, self).on_touch_down(touch)
def on_pressed(self, instance, pos):
# event handler triggered if ``pressed`` property changed
print('pressed at {pos}'.format(pos=pos))
CUSTOM EVENTS
from kivy.event import EventDispatcher
class MyEventDispatcher(EventDispatcher):
def __init__(self, **kw):
# register custom event
self.register_event_type('on_test')
super(MyEventDispatcher, self).__init__(**kw)
def do_something(self, value):
# when do_something is called, the 'on_test' event will be
# dispatched with the value
self.dispatch('on_test', value)
def on_test(self, *args):
# default event handler
print('I am dispatched'.format(args))
def my_callback(value, *args):
print('Hello, I got an event!'.format(args))
ev = MyEventDispatcher() # instanciate ``MyEventDispatcher``
ev.bind(on_test=my_callback) # bind ``my_callback`` to ``on_test``
ev.do_something('test') # ``do_something`` dispatches ``on_test``
WIDGET TREE
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
# create widget and add children
layout = BoxLayout(padding=10)
button = Button(text='My first button')
layout.add_widget(button)
# remove child from widget
layout.remove_widget(button)
# clear children
layout.clear_widgets()
# traversing the tree, iterate widget children
for child in layout.children:
print(child)
# traversing the tree, access parent widget
child = layout.children[0]
Layout = child.parent
# setting a z-index for a child widget
layout.add_widget(widget, index)
KV LANGUAGE
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
Builder.load_string('''
<CustomLayout>
Button:
text: 'Hello World!!'
size_hint: .5, .5
pos_hint: {'center_x': .5, 'center_y': .5}
''')
class CustomLayout(FloatLayout):
pass
As your application grow more complex, it’s common that the construction of widget
trees and explicit declaration of bindings, becomes verbose and hard to maintain.
The KV Language is a attempt to overcome these short-comings.
In the example above KV code is defined inside python module as docstring passed
to Builder.load_string. KV code can also be contained in a separate
file which can be loaded by using Builder.load_file('path/to/file.kv')
GRAPHICS
class MyWidget(Widget):
def __init__(self, **kw):
super(MyWidget, self).__init__(**kw)
with self.canvas:
# add your instruction for main canvas here
Color(1, 0, .4, mode='rgb')
Line(points=(x1, y1, x2, y2, x3, y3))
with self.canvas.before:
# you can use this to add instructions rendered before
with self.canvas.after:
# you can use this to add instructions rendered after
MyWidget:
canvas:
Color:
rgba: 1, .3, .8, .5
Line:
points: zip(self.data.x, self.data.y)
Graphics instructions in Python
Graphics instructions in KV language
Thank You!
References:
https://kivy.org/docs/guide/basic.html
Credits:
Photos by:
https://www.flickr.com/photos/photos_by_chrystal
https://www.flickr.com/photos/steffireichert
https://creativecommons.org/licenses/by-nc-nd/2.0

More Related Content

What's hot

Using eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in CiliumUsing eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in Cilium
ScyllaDB
 
U boot-boot-flow
U boot-boot-flowU boot-boot-flow
Linux systems - Getting started with setting up and embedded platform
Linux systems - Getting started with setting up and embedded platformLinux systems - Getting started with setting up and embedded platform
Linux systems - Getting started with setting up and embedded platform
Emertxe Information Technologies Pvt Ltd
 
A practical guide to buildroot
A practical guide to buildrootA practical guide to buildroot
A practical guide to buildroot
Emertxe Information Technologies Pvt Ltd
 
BPF Hardware Offload Deep Dive
BPF Hardware Offload Deep DiveBPF Hardware Offload Deep Dive
BPF Hardware Offload Deep Dive
Netronome
 
Yocto - Embedded Linux Distribution Maker
Yocto - Embedded Linux Distribution MakerYocto - Embedded Linux Distribution Maker
Yocto - Embedded Linux Distribution Maker
Sherif Mousa
 
Accelerating Envoy and Istio with Cilium and the Linux Kernel
Accelerating Envoy and Istio with Cilium and the Linux KernelAccelerating Envoy and Istio with Cilium and the Linux Kernel
Accelerating Envoy and Istio with Cilium and the Linux Kernel
Thomas Graf
 
Qemu Introduction
Qemu IntroductionQemu Introduction
Qemu Introduction
Chiawei Wang
 
How VXLAN works on Linux
How VXLAN works on LinuxHow VXLAN works on Linux
How VXLAN works on Linux
Etsuji Nakai
 
Platform Drivers
Platform DriversPlatform Drivers
Qt5 (minimal) on beaglebone, with Yocto
Qt5 (minimal) on beaglebone, with YoctoQt5 (minimal) on beaglebone, with Yocto
Qt5 (minimal) on beaglebone, with Yocto
Prabindh Sundareson
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequence
Houcheng Lin
 
YOW2021 Computing Performance
YOW2021 Computing PerformanceYOW2021 Computing Performance
YOW2021 Computing Performance
Brendan Gregg
 
Meet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracingMeet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracing
Viller Hsiao
 
Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCC
Kernel TLV
 
X / DRM (Direct Rendering Manager) Architectural Overview
X / DRM (Direct Rendering Manager) Architectural OverviewX / DRM (Direct Rendering Manager) Architectural Overview
X / DRM (Direct Rendering Manager) Architectural Overview
Moriyoshi Koizumi
 
BusyBox for Embedded Linux
BusyBox for Embedded LinuxBusyBox for Embedded Linux
BusyBox for Embedded Linux
Emertxe Information Technologies Pvt Ltd
 
P4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC OffloadP4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC Offload
Open-NFP
 
Linux Linux Traffic Control
Linux Linux Traffic ControlLinux Linux Traffic Control
Linux Linux Traffic Control
SUSE Labs Taipei
 
Kubernetes extensibility: CRDs & Operators
Kubernetes extensibility: CRDs & OperatorsKubernetes extensibility: CRDs & Operators
Kubernetes extensibility: CRDs & Operators
SIGHUP
 

What's hot (20)

Using eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in CiliumUsing eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in Cilium
 
U boot-boot-flow
U boot-boot-flowU boot-boot-flow
U boot-boot-flow
 
Linux systems - Getting started with setting up and embedded platform
Linux systems - Getting started with setting up and embedded platformLinux systems - Getting started with setting up and embedded platform
Linux systems - Getting started with setting up and embedded platform
 
A practical guide to buildroot
A practical guide to buildrootA practical guide to buildroot
A practical guide to buildroot
 
BPF Hardware Offload Deep Dive
BPF Hardware Offload Deep DiveBPF Hardware Offload Deep Dive
BPF Hardware Offload Deep Dive
 
Yocto - Embedded Linux Distribution Maker
Yocto - Embedded Linux Distribution MakerYocto - Embedded Linux Distribution Maker
Yocto - Embedded Linux Distribution Maker
 
Accelerating Envoy and Istio with Cilium and the Linux Kernel
Accelerating Envoy and Istio with Cilium and the Linux KernelAccelerating Envoy and Istio with Cilium and the Linux Kernel
Accelerating Envoy and Istio with Cilium and the Linux Kernel
 
Qemu Introduction
Qemu IntroductionQemu Introduction
Qemu Introduction
 
How VXLAN works on Linux
How VXLAN works on LinuxHow VXLAN works on Linux
How VXLAN works on Linux
 
Platform Drivers
Platform DriversPlatform Drivers
Platform Drivers
 
Qt5 (minimal) on beaglebone, with Yocto
Qt5 (minimal) on beaglebone, with YoctoQt5 (minimal) on beaglebone, with Yocto
Qt5 (minimal) on beaglebone, with Yocto
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequence
 
YOW2021 Computing Performance
YOW2021 Computing PerformanceYOW2021 Computing Performance
YOW2021 Computing Performance
 
Meet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracingMeet cute-between-ebpf-and-tracing
Meet cute-between-ebpf-and-tracing
 
Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCC
 
X / DRM (Direct Rendering Manager) Architectural Overview
X / DRM (Direct Rendering Manager) Architectural OverviewX / DRM (Direct Rendering Manager) Architectural Overview
X / DRM (Direct Rendering Manager) Architectural Overview
 
BusyBox for Embedded Linux
BusyBox for Embedded LinuxBusyBox for Embedded Linux
BusyBox for Embedded Linux
 
P4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC OffloadP4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC Offload
 
Linux Linux Traffic Control
Linux Linux Traffic ControlLinux Linux Traffic Control
Linux Linux Traffic Control
 
Kubernetes extensibility: CRDs & Operators
Kubernetes extensibility: CRDs & OperatorsKubernetes extensibility: CRDs & Operators
Kubernetes extensibility: CRDs & Operators
 

Similar to Kivy Talk Python Meetup Innsbruck 2017.04.25

GWT MVP Case Study
GWT MVP Case StudyGWT MVP Case Study
GWT MVP Case Study
David Chandler
 
The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180 The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180
Mahmoud Samir Fayed
 
2011 py con
2011 py con2011 py con
2011 py con
Eing Ong
 
Programming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidProgramming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for Android
Emanuele Di Saverio
 
The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210
Mahmoud Samir Fayed
 
09events
09events09events
09events
Waheed Warraich
 
Day 5
Day 5Day 5
Building a js widget
Building a js widgetBuilding a js widget
Building a js widget
Tudor Barbu
 
Titanium Appcelerator - Beginners
Titanium Appcelerator - BeginnersTitanium Appcelerator - Beginners
Titanium Appcelerator - Beginners
Ambarish Hazarnis
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony application
Samuel ROZE
 
How to dispatch redux action with timeout
How to dispatch redux action with timeoutHow to dispatch redux action with timeout
How to dispatch redux action with timeout
BOSC Tech Labs
 
Gevent be or not to be
Gevent be or not to beGevent be or not to be
Gevent be or not to be
Aleksandr Mokrov
 
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
it-people
 
Asynchronous JS in Odoo
Asynchronous JS in OdooAsynchronous JS in Odoo
Asynchronous JS in Odoo
Odoo
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
Rodolfo Carvalho
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
shanmuga rajan
 
Writing videogames with titanium appcelerator
Writing videogames with titanium appceleratorWriting videogames with titanium appcelerator
Writing videogames with titanium appcelerator
Alessio Ricco
 
NestJS
NestJSNestJS
NestJS
Wilson Su
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app development
anistar sung
 
mobl
moblmobl
mobl
zefhemel
 

Similar to Kivy Talk Python Meetup Innsbruck 2017.04.25 (20)

GWT MVP Case Study
GWT MVP Case StudyGWT MVP Case Study
GWT MVP Case Study
 
The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180 The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180
 
2011 py con
2011 py con2011 py con
2011 py con
 
Programming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidProgramming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for Android
 
The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210
 
09events
09events09events
09events
 
Day 5
Day 5Day 5
Day 5
 
Building a js widget
Building a js widgetBuilding a js widget
Building a js widget
 
Titanium Appcelerator - Beginners
Titanium Appcelerator - BeginnersTitanium Appcelerator - Beginners
Titanium Appcelerator - Beginners
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony application
 
How to dispatch redux action with timeout
How to dispatch redux action with timeoutHow to dispatch redux action with timeout
How to dispatch redux action with timeout
 
Gevent be or not to be
Gevent be or not to beGevent be or not to be
Gevent be or not to be
 
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
 
Asynchronous JS in Odoo
Asynchronous JS in OdooAsynchronous JS in Odoo
Asynchronous JS in Odoo
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Writing videogames with titanium appcelerator
Writing videogames with titanium appceleratorWriting videogames with titanium appcelerator
Writing videogames with titanium appcelerator
 
NestJS
NestJSNestJS
NestJS
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app development
 
mobl
moblmobl
mobl
 

Recently uploaded

E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
kalichargn70th171
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 

Recently uploaded (20)

E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 

Kivy Talk Python Meetup Innsbruck 2017.04.25

  • 1. KIVY NUI Applications with Python Python Meetup Innsbruck | 25. April 2017 Robert Niederreiter
  • 3. ARCHITECTURE Widget Kv Language Cache Clock Gesture Event Loop Properties Core Providers Window Text Image Video Audio Graphics Vertex Buffer Frame Buffer Texture Shader Instructions Inputs Motion Event Post Processing (double tab, Dejitter, …) Pygame PIL Gstreamer FFMpeg SDL Cairo GLES API GLEW MouseTUIO WM_Touch Mac TouchMTDev HIDInput
  • 4. App brought to foreground After process is killed (Android/iOS) Kivy bootstrap for Android/iOS Python start, run() build() on_start() Apps functionson_resume() Extenal App/OS or internal function pauses App on_pause() Save your work here. Resume is not guaranteed. on_stop() Kivy window destroyed Python stop on_pause() Resume? return True return False NoYes LIFECYCLE
  • 5. EVENT LOOP Clock Events Loop Filesystem Network Process Other Motion Events Post Processing (double tab, swipe, ...) Input Processing Event Dispatcher Dispatch Input Events Custom Events Property Events Window Events GUI Touch Mouse Keyboard Joystick Other Input Kivy Main Thread Non GUI Operations (may run in dedicated thread) Main Loop
  • 6. EventDispatcher App Widget Widgets are self-contained and organized as tree Animation Clock MotionEvent Layout Controls size and position of it's children FloatLayout BoxLayout GridLayout ButtonBehavior CoverBehavior DragBehavior behaviors ... Button Switch Slider Popup ... uix graphics Widget representation is done using canvas, graphics instructions are applied to it ContextInstruction VertexInstruction Color Rotate Scale ... Triangle Rectangle Ellipse ... Kv Language The KV language (sometimes called kvlang, or kivy language), allows you to create your widget tree in a declarative way and to bind widget properties to each other or to callbacks in a natural manner. ... OBJECTS Mixin Classes for Widgets
  • 7. APPLICATION import kivy # replace with your current kivy version kivy.require('1.9.1') from kivy.app import App from kivy.uix.label import Label class MyApp(App): # MyApp inherits from App object def build(self): # build returns the root widget return Label(text='Hello world') if __name__ == '__main__': MyApp().run()
  • 8. REPETITIVE EVENTS from kivy.clock import Clock def my_callback(dt): # ``dt`` is delta time print('My callback is called'.format(dt)) # call ``my_callback`` X times per second event = Clock.schedule_interval(my_callback, 1 / 30.) # unscedule can be done by either using event.cancel() # or Clock.unschedule(event) def my_callback(dt): # if repetitive callback returns False, it gets unscheduled as well if some_condition: return False # regular processing Clock.schedule_interval(my_callback, 1 / 30.)
  • 9. ONE-TIME EVENTS from kivy.clock import Clock def my_callback(dt): print('My callback is called'.format(dt)) # call ``my_callback`` once in one second Clock.schedule_once(my_callback, 1) The second argument is the amount of time to wait before calling the function, in seconds. However, you can achieve some other results with special values for the second argument: ● If X is greater than 0, the callback will be called in X seconds ● If X is 0, the callback will be called after the next frame ● If X is -1, the callback will be called before the next frame
  • 10. INPUT AND PROPERTY EVENTS from kivy.uix.widget import Widget from kivy.properties import ListProperty class CustomBtn(Widget): # it's possible to bind to kivy property changes pressed = ListProperty([0, 0]) def on_touch_down(self, touch): # event handler for regular touch events if self.collide_point(*touch.pos): # setting pressed property triggers property event self.pressed = touch.pos # return True to indicate event consumed return True # delegate touch event to super class return super(CustomBtn, self).on_touch_down(touch) def on_pressed(self, instance, pos): # event handler triggered if ``pressed`` property changed print('pressed at {pos}'.format(pos=pos))
  • 11. CUSTOM EVENTS from kivy.event import EventDispatcher class MyEventDispatcher(EventDispatcher): def __init__(self, **kw): # register custom event self.register_event_type('on_test') super(MyEventDispatcher, self).__init__(**kw) def do_something(self, value): # when do_something is called, the 'on_test' event will be # dispatched with the value self.dispatch('on_test', value) def on_test(self, *args): # default event handler print('I am dispatched'.format(args)) def my_callback(value, *args): print('Hello, I got an event!'.format(args)) ev = MyEventDispatcher() # instanciate ``MyEventDispatcher`` ev.bind(on_test=my_callback) # bind ``my_callback`` to ``on_test`` ev.do_something('test') # ``do_something`` dispatches ``on_test``
  • 12. WIDGET TREE from kivy.uix.boxlayout import BoxLayout from kivy.uix.button import Button # create widget and add children layout = BoxLayout(padding=10) button = Button(text='My first button') layout.add_widget(button) # remove child from widget layout.remove_widget(button) # clear children layout.clear_widgets() # traversing the tree, iterate widget children for child in layout.children: print(child) # traversing the tree, access parent widget child = layout.children[0] Layout = child.parent # setting a z-index for a child widget layout.add_widget(widget, index)
  • 13. KV LANGUAGE from kivy.uix.floatlayout import FloatLayout from kivy.lang import Builder Builder.load_string(''' <CustomLayout> Button: text: 'Hello World!!' size_hint: .5, .5 pos_hint: {'center_x': .5, 'center_y': .5} ''') class CustomLayout(FloatLayout): pass As your application grow more complex, it’s common that the construction of widget trees and explicit declaration of bindings, becomes verbose and hard to maintain. The KV Language is a attempt to overcome these short-comings. In the example above KV code is defined inside python module as docstring passed to Builder.load_string. KV code can also be contained in a separate file which can be loaded by using Builder.load_file('path/to/file.kv')
  • 14. GRAPHICS class MyWidget(Widget): def __init__(self, **kw): super(MyWidget, self).__init__(**kw) with self.canvas: # add your instruction for main canvas here Color(1, 0, .4, mode='rgb') Line(points=(x1, y1, x2, y2, x3, y3)) with self.canvas.before: # you can use this to add instructions rendered before with self.canvas.after: # you can use this to add instructions rendered after MyWidget: canvas: Color: rgba: 1, .3, .8, .5 Line: points: zip(self.data.x, self.data.y) Graphics instructions in Python Graphics instructions in KV language