
At the beginning of this year, Pythonista 3.2 brought support for ui.View.update, and thus made Scripter available for everyone.
I have been using Scripter for UI animations in about every one of my projects for the past months, have been happy with its efficiency and stability, and thus wanted to just promote it a bit more.
Here are some recent updates to the tool:
- Scrolling banner view
- Scripter in scene animations
- Scripter for long-running tasks and polling
Scrolling banner view
c = ScrollingBannerLabel(
text='Happy Pythonista 3.2 *****',
text_color='green',
font=('Futura', 24),
initial_delay=0.5,
scrolling_speed=50)
Simple utility view, handy for news ticker type use cases, with an adjustable initial delay and scrolling speed:
Scripter for Scene Nodes
Turned out that it was very easy to enable Scripter in Scenes. Whereas on the UI side I would consider Scripter 'essential' (providing functionality that is not really there otherwise), for Scenes it is 'nice to have', or available if you want to use the same syntax in both UI and Scenes.
Here's an example:
from scripter import *
from scene import *
class MyScene (Scene):
@script # setup can be a script
def setup(self):
self.background_color = 'black'
s = self.ship = SpriteNode(
'spc:PlayerShip1Orange',
alpha=0, scale=2,
position=self.size/2,
parent=self)
yield 1.0
pulse(self, 'white')
s = self.ship
show(s, duration=2.0)
scale_to(s, 1, duration=2.0)
yield
wobble(s)
yield
move_by(s, 0, 100)
yield
fly_out(s, 'up')
yield
l = LabelNode(
text='Tap anywhere',
position=self.size/2,
parent=self)
reveal_text(l)
yield 2.0
hide(l)
@script # touch events can be scripts
def touch_began(self, touch):
target = Vector(touch.location)
vector = target - self.ship.position
rotate_to(self.ship, vector.degrees-90)
yield
move_to(self.ship, *target, duration=0.7, ease_func=sinusoidal)
run(MyScene())
Long-running task, polling etc.
This is not an update to Scripter, just an expansion of my understanding on what it can be useful for.
As Scripter has a lot parallels to things like asyncio, it can also be used to run long-running computations without freezing the UI and without threads, or to implement polling for some conditions.
These require that you can insert a yield statement somewhere in your computation or loop, so calling long-running third party functions is not really an option.