saltykiam
saltykiam

Reputation: 57

Combining python Curses with Asciimatics

I've made a curses programme with Python and was wondering if I could add asciimatics animations in it? I aimed to add the animations effects in one of my curses windows, but it seems like I can't change or resize the Screen which asciimatics effects are added to.

Is this possible to resize the asciimatics screen to add it to my curses window?

Upvotes: 1

Views: 346

Answers (1)

Peter Brittain
Peter Brittain

Reputation: 13619

[ EDIT: Added option to use existing curses handle. ]

The short answer is probably not without some changes to your app or asciimatics.

The easiest option is just to allow asciimatics to take over while running the animation. For example, if this is for a title page, just run that before you initialize ncurses for your app.

If you actually want to embed it inside the same screen, you have a lot more work...

First let's clear up details on the environment... Asciimatics uses ncurses on systems where it is natively available (e.g. Linux, mac) and win32 on Windows, so if you are using something like PDcurses on Windows, this is incompatible. Sorry - no real options.

However, if you are only using a native curses system like Linux, you have a couple of options...

  1. Convert your curses calls to equivalent Screen calls. There's an obvious one-to-one mapping for printing, using colours and getting character input. If you need multiple curses windows, you can uses Canvases (or possibly Frames if this is for a UI) to get the same effect in asciimatics.

  2. Consider working on https://github.com/peterbrittain/asciimatics/issues/46. This will allow you to start drawing directly on an existing screen, rather than the current implementation that assumes asciimatics can initialize ncurses and then take full control of the screen (including clearing the screen and controlling the refresh).

  3. Pass your curses screen handle to asciimatics and then ensure your updates cooperate with animations. As you can see here you can construct the curses screeb handler if you already have a screen handle.

Option 1 is likely to be safest as it uses a single consistent API. I can help you with 2 if you head over to the asciimatics gitter lobby (link on github homepage). Option 3 might work, but uses an internal API (and so may break in the future) and you'll need to sync your updates with asciimatics

Upvotes: 1

Related Questions