Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Scripter - Pythonista UI animation framework built on ui.View.update()
-
Note: The usage and API has changed a bit since this first post. Please check the README.md in the repository for latest docs.
Single-file, no-dependencies, no-surprises UI animation framework powered by ui.View.update, that enables writing intuitive animation scripts using generators:
@script def sample(self): self.move_to(50, 200) self.pulse('red') yield self.hide()
The above script, when called as a function, will at the same time move the view and pulse the background in red, then hide it after the previous actions are complete. Scripter supports an arbitrarily complex combination of sections separated by yields, and calling several sub-scripts to get the combo you need, all coded in an intuitive and reliable way.
Check the repository or download the scripter.py file and run it to see a demo featuring showing and hiding, movement, color changes, counting, rotation, controlling several views simultaneously, animation easing functions, interaction with custom ui.View.draw, as well as pausing or cancelling the animation.
Checking the demo script code is probably the best way to get started, as real documentation is still on the todo list.
Features:
- Inherits ui.View, so you can enable it by inheriting Scripter to use all effects easily as in the example above.
- Or use as an animation control center by creating a Scripter instance, then presenting it or placing it as a hidden subview somewhere. All effects support providing the target view as a parameter.
- Animation primitives:
set_value
(typically for arange
)slide_value
timer
- Animation effects:
hide
,show
move_to
slide_color
pulse
(a color)rotate
- ... more to come, feature requests welcome
- Cancel all animations or a specific script
- Pause and continue all animations
yield 'wait'
- shorthand for pausing for the default duration (0.5 seconds), often needed to make animations feel more naturalslide_value
accepts anease_func
parameter, for even more natural-feeling animations. Check the curves to pick the right function for the occasion.
Note: As of Sep 15, 2017, ui.View.update is only available in Pythonista 3 beta.
-
@mikael , both your links are pointing to the raw contents of scripter.py
-
@Phuket2, thanks, fixed.
-
Syntax error in line 343
f' not supported in my Pythonista -
@cvp, as said, this relies on new update method of ui.View, which is only available in beta, but should be part of the soon-to-be-released App Store version.
-
@mikael Sorry, I had not read it correctly 😰
-
@cvp, thanks for trying and hopefully it will work for everyone soon. Or check out if you could still get the beta - I have had no hassles with it.
-
Added fly_out effect with a direction option, see demo.
-
Syntax error in line 343
f' not supported in my Pythonistaf'strings' are a Python 3.6+ feature which is why they work in the Pythonista beta but not in the App Store version.
I saw a really cool module https://github.com/asottile/future-fstrings that allows all Pythons (even 2.7!!) to do f-strings just by adding:
# -*- coding: future_fstrings -*-
as the first or second line of the file. No import or anything. Not sure if it will work in Pythonista but pretty mindbending nevertheless. -
@ccc Thanks but I'll wait for next version...
-
With some more practical experience with this I decided to change the way effects are used, to remove the need to define any classes or functions just to use simple effects.
There’s also now some proper API docs.
From the Quick Start:
Quick start
In order to start using the animation effects, just import scripter and call the effects as functions:
from scripter import * hide(my_button)
Effects expect an active UI view as the first argument. This can well be
self
orsender
where applicable.If you want to create a more complex animation from the effects provided, combine them in a
script:@script def my_script(): move(my_button, 50, 200) pulse(my_button, 'red') yield hide(my_button)
Scripts control the order of execution with
yield
statements. Here movement and a red
pulsing highlight happen at the same time. After both actions are completed,my_button
fades
away.Run scripter.py in Pythonista to see a demo of most of the available effects.
-
And courtesy of iOS 11 screen recording, here’s a video of the demo.
-
Hmm...I must be doing something wrong. Tried to run scripter.py ( to see demo) but all I get is https://imgur.com/a/na0Nx
-
@ihf, I did not test on iPad, and
present
had a wrong argument.Either download the latest or change line 539 to:
v.present('full_screen')
-
@mikael Thanks that worked! (In the version I have, it was line 552).
-
@omz, is there a way to access the various timing options in
scene
Action
as a function of t? Would like to have the option of using those in Scripter. -
See https://github.com/controversial/ui2/blob/master/ui2/animate.py
The above is mainly for ui animation. You may look at scene_drawing.py code to see how various timing options are implemented.
-
@enceladus, thanks, your answer guided me on a hunt through UIKit and SceneKit docs. I could not find the easing functions conveniently exposed by Apple.
-
scene_drawing.py in modules/standard library 3.5/site-packages. You can use curve_sinodial, curve_ease_in like functions.
-
current_func = lambda s,t,d:s+curve_sinodial(t)*d should work (I am outside and I will post the proper working code later.)