Transition (submodule)¶
The asynckivy.transition submodule provides various transition effects that can be used to create smooth visual
transitions for Kivy widgets. All APIs in this module are designed to be used with async with statements:
from asynckivy import transition
async with transition.slide(widget):
...
You can imitate the ScreenManager by adding or removing widgets from the widget inside the with-block:
from kivy.factory import Factory as F
from asynckivy import transition
layout = F.RelativeLayout()
screen1 = F.Label(text='Screen 1')
screen2 = F.Label(text='Screen 2')
layout.add_widget(screen1)
...
async with transition.slide(layout, use_outer_canvas=True):
layout.remove_widget(screen1)
layout.add_widget(screen2)
API Reference¶
- fade(target: kivy.core.window.WindowBase | kivy.uix.widget.Widget | kivy.graphics.Canvas = kivy.core.window.Window.canvas, *, goal_opacity=0.0, duration=1.0, out_curve='linear', in_curve='linear')¶
Fades out the
target, executes the code inside the with-block, and then fades it back in.Added in version 0.9.0.
Changed in version 0.9.1: Now accepts Canvas as target.
- gl_transitions_dot_com(target: kivy.uix.widget.Widget, fs: str, *, duration=1.0, uniforms: Mapping = None)¶
A transition that uses a GLSL fragment shader from https://gl-transitions.com/.
cross_warp = """ // Author: Eke Péter <peterekepeter@gmail.com> // License: MIT vec4 transition(vec2 p) { float x = progress; x=smoothstep(.0,1.0,(x*2.0+p.x-1.0)); return mix(getFromColor((p-.5)*(1.-x)+.5), getToColor((p-.5)*x+.5), x); } """ async with gl_transitions_dot_com(widget, fs=cross_warp): ...
See
shader()for details.Added in version 0.9.3.
- iris(target: kivy.core.window.WindowBase = kivy.core.window.Window, *, duration=1, out_curve='in_cubic', in_curve='out_cubic', color: Sequence[float] = kivy.utils.colormap.white, circle_center: Sequence[float] = None, overlay: kivy.graphics.VertexInstruction = None)¶
縮む円によって
targetが見える範囲を絞っていき、完全に見えなくなったらwithブロック内を実行し、その後円を広げてtargetを再び見せる。Added in version 0.9.0.
- scale(target: kivy.core.window.WindowBase | kivy.uix.widget.Widget = kivy.core.window.Window, *, duration=1, out_curve='out_quad', in_curve='in_quad', use_outer_canvas=False)¶
Shrinks the
target, executes the code inside the with-block, and then restores it to its original size.Added in version 0.9.0.
- shader(target: kivy.uix.widget.Widget, fs: str, *, duration=1.0, uniforms: Mapping = None, progress_var: str = 'progress', out_texture_var: str = 'out_tex', in_texture_var: str = 'in_tex')¶
A transition that uses a GLSL fragment shader.
fade = """ /* Outputs from the vertex shader */ varying vec4 frag_color; varying vec2 tex_coord0; uniform float t; uniform sampler2D out_tex; uniform sampler2D in_tex; void main(void) { vec4 cout = texture2D(out_tex, tex_coord0); vec4 cin = texture2D(in_tex, tex_coord0); gl_FragColor = mix(cout, cin, t); } """ async with shader(widget, fs=fade, progress_var='t', out_texture_var='out_tex', in_texture_var='in_tex'): ...
- Parameters:
fs – The GLSL fragment shader code to use.
progress_var – Name of the uniform
floatvariable representing the normalized progress (elapsed time divided byduration).out_texture_var – Name of the uniform
sampler2Dvariable for the outgoing texture. This corresponds to the rendered content of the target before__aenter__.in_texture_var – Name of the uniform
sampler2Dvariable for the incoming texture. This corresponds to the rendered content of the target before__aexit__.uniforms – Additional uniform variables to be set on the shader.
Warning
Do not modify the target’s parent — such as adding or removing widgets or graphics instructions — while the transition is in progress. Modifying the target itself is fine.
Added in version 0.9.3.
- slide(target: kivy.core.window.WindowBase | kivy.uix.widget.Widget = kivy.core.window.Window, *, duration=1.0, out_curve='in_back', in_curve='out_back', x_direction: Literal['left', 'right', None] = 'left', y_direction: Literal['down', 'up', None] = None, use_outer_canvas=False)¶
Slides the
targetout, executes the code inside the with-block, and then slides it back in.Added in version 0.9.0.
Changed in version 0.9.2: The default value of
out_curvehas changed from'in_cubic'to'in_back'. The default value ofin_curvehas changed from'out_cubic'to'out_back'.