Python embedding question.

T

Thomas Troeger

Hi,

Sorry I've posted a similar question some weeks ago, but I got no
answers. I want to embed a Python application on a device with limited
resources, esp. storage limitations. Is there a way to reduce the Python
interpreter to a set of modules that's urgently needed? Or is there a
method to have gzipped modules that are unzipped on the fly into memory
when they're accessed? That would be even better.

Additionally, is there a Python module that contains all the stuff
needed for an embedded application like graphics, sound etc. or do I
have to use the various bindings to libraries like cairo, Qt or similar?
Is there a site that helps with those decisions?

I've really looked at a lot of places but haven't found a suitable
solutions yet, so I'm asking here in hope that someone has experience
with that topic.

Regards,
Thomas.
 
K

Kay Schluehr

I've really looked at a lot of places but haven't found a suitable
solutions yet, so I'm asking here in hope that someone has experience
with that topic.

Which solutions did you rule out?
 
T

Thomas Troeger

Kay said:
Which solutions did you rule out?

- Python + Qt, because it's definitely overkill for my plans. I only
need simple graphics and some sound, no widgets. Basically I'm looking
for something really lightweight that has methods for drawing graphic
primitives and renders fonts -- no complicated widgets, windows,
scrollbars and the like. And, for example, the Qt library is a real
heavyweight with approx. 10 MB for qt-3.3.8 alone.

- The same holds for cairo/pango, I've written a test program (in C, I
must say) that has dynamic links to 10 libraries that are all like 250kb
in size. That's a lot for a small embedded device.

I'd like a solution that's not over 10MB altogether, and the interpreter
comes at a 60 MB if all modules are included. I can't imagine noone has
had this problem before... and I'm trying to not invent the wheel again :^)
 
U

Uwe Schmitt

- Python + Qt, because it's definitely overkill for my plans. I only
need simple graphics and some sound, no widgets. Basically I'm looking
for something really lightweight that has methods for drawing graphic
primitives and renders fonts -- no complicated widgets, windows,
scrollbars and the like. And, for example, the Qt library is a real
heavyweight with approx. 10 MB for qt-3.3.8 alone.

- The same holds for cairo/pango, I've written a test program (in C, I
must say) that has dynamic links to 10 libraries that are all like 250kb
in size. That's a lot for a small embedded device.
Did you try pygame ? I think it has a small footprint.

Greetings, Uwe
 
D

David Lyon

Thomas said:
I want to embed a Python application on a device with limited
resources, esp. storage limitations. Is there a way to reduce the
Python interpreter to a set of modules that's urgently needed?
Of course there is. What is the target platform ?

What can be done is to go through the python source code and comment out
everything that *you* find unneccessary. I can't tell you what this
would be - because I don't know exactly what you are after. But to your
question - the answer is yes.. of course.
Or is there a method to have gzipped modules that are unzipped on the
fly into memory when they're accessed? That would be even better. Yes - also possible.

Additionally, is there a Python module that contains all the stuff
needed for an embedded application like graphics, sound etc.
No. Because that depends on what hardware platform you want to run on.
or do I have to use the various bindings to libraries like cairo, Qt
or similar? Is there a site that helps with those decisions?
I doubt it. These are decisions for you to make according to the
limitations of your hardware.
I've really looked at a lot of places but haven't found a suitable
solutions yet, so I'm asking here in hope that someone has experience
with that topic.
:)

Regards

David
 
T

Troeger, Thomas (ext)

Hi,
Of course there is. What is the target platform ?

Thanks for your answer. The plattform is x86, so basically it's a PC
with a compact flash drive. The problem is that the compact flash is
rather limited in speed and size (there is other stuff on it too).
Yes - also possible.

That sounds promising, is there a link you can give? Or do I have to
modify the module loading code for this, i.e. the interpreter? I think
that wouldn't be too much of a problem if I understand where Python
loads modules; I haven't checked the Python source yet for that one, and
searching for Python and zip or similar always yields tons of links that
use the Python zip or tar module :)
Regards
David

Cheers,
Thomas.
 
J

Jan Claeys

Op Tue, 15 Jul 2008 11:51:47 +0200, schreef Thomas Troeger:
I want to embed a Python application on a device with limited
resources, esp. storage limitations. Is there a way to reduce the Python
interpreter to a set of modules that's urgently needed?

You might want to have a look at how the OpenWRT people do it.

In general: have a look at embeded linux projects, several of them have
python packages... ;-)

Additionally, is there a Python module that contains all the stuff
needed for an embedded application like graphics, sound etc. or do I
have to use the various bindings to libraries like cairo, Qt or similar?

I'd say that PyGame could be a solution.

Or otherwise you could do your own audio/graphics programming (you don't
tell us which OS you use, but there exist python modules that allow you
to do barebones graphics & sound programming on linux...).
 
T

Thomas Troeger

Jan said:
I'd say that PyGame could be a solution.

Or otherwise you could do your own audio/graphics programming (you don't
tell us which OS you use, but there exist python modules that allow you
to do barebones graphics & sound programming on linux...).

Yes, I'm using a very small Linux system with busybox, running from a
compact flash drive. I'll investigate PyGame, it sounds as if it is a
good candidate :p

Thanks so far,
Thomas.
 
T

Thomas Troeger

I'd say that PyGame could be a solution.
Or otherwise you could do your own audio/graphics programming (you don't
tell us which OS you use, but there exist python modules that allow you
to do barebones graphics & sound programming on linux...).

After some more reading I've stumbled over pyglet. Any experiences with
it? It seems it does a lot of cool things, if anyone has used it more
intensely I'd be happy to hear if the following things can be done:

- Linux framebuffer (16, 24 bpp) display of 2d graphics with overlays
(i.e. menues, contextual areas that pop up etc.). I don't have X on the
embedded device, just the regular framebuffer.
- alpha blending of several layers.
- rendering of TTF fonts and unicode, for example display of arabic text
(which renders from right to left) and mixed text support like in the
unicode bidirectional algorithm.
- hardware caching of bitmaps for faster graphics operations (needed for
tool tips or similar tasks).

I'll try to find that out myself (I'm pretty excited about the thing
already ^^), but I'd be happy to hear of people who have used it already.

Cheers,
Thomas.
 
C

Carl Banks

After some more reading I've stumbled over pyglet. Any experiences with
it? It seems it does a lot of cool things, if anyone has used it more
intensely I'd be happy to hear if the following things can be done:

- Linux framebuffer (16, 24 bpp) display of 2d graphics with overlays
(i.e. menues, contextual areas that pop up etc.). I don't have X on the
embedded device, just the regular framebuffer.
- alpha blending of several layers.
- rendering of TTF fonts and unicode, for example display of arabic text
(which renders from right to left) and mixed text support like in the
unicode bidirectional algorithm.
- hardware caching of bitmaps for faster graphics operations (needed for
tool tips or similar tasks).

I'll try to find that out myself (I'm pretty excited about the thing
already ^^), but I'd be happy to hear of people who have used it already.

Pyglet runs on top of OpenGL, which might have performance problems on
an embedded device, if OpenGL or Mesa is even supported. If it's
supported, I suspect performance will be adequate for 2D drawing. It
almost certainly is the lightest solution you can find.


Carl Banks
 
T

Thomas Troeger

Carl said:
Pyglet runs on top of OpenGL, which might have performance problems on
an embedded device, if OpenGL or Mesa is even supported. If it's
supported, I suspect performance will be adequate for 2D drawing. It
almost certainly is the lightest solution you can find.


Carl Banks

I've managed to put together a small pyGame program, it runs smoothly
and seems to be exactly what I wanted. It's fast! Even with 100 moving
objects it still runs so fast that I can consider using Python/pyGame
for the whole project.

There are still some questions left which I haven't found out by myself,
so maybe someone here can answer them:

- I can't see how to create more sophisticated text output, it seems the
built in font render facilities are limited to simple strings. Is that
true? I'd need a way to at least render multiline text with paragraphs
and bidirectionality, like pango does it. Is there a way to integrate
pango support into pyGame? I'd prefer marked up text display with text
properties ...
- Is there some way to reserve screen areas so they are excluded from a
blit, or do I have to manage stuff like this myself? I am thinking about
several graphic layers where each layer is painted on top of the next
layer, for example to draw a gui in front of a background image.
- There seems to be support for video overlay, i.e. is it possible to
have an external program paint an image from a camera into a portion of
the screen while pyGame is running?

Maybe this is the wrong list to ask, so please forgive the question but
direct me to somewhere better.

Cheers,
Thomas.
 
U

Uwe Schmitt

I've managed to put together a small pyGame program, it runs smoothly
and seems to be exactly what I wanted. It's fast! Even with 100 moving
objects it still runs so fast that I can consider using Python/pyGame
for the whole project.

There are still some questions left which I haven't found out by myself,
so maybe someone here can answer them:

- I can't see how to create more sophisticated text output, it seems the
built in font render facilities are limited to simple strings. Is that
true? I'd need a way to at least render multiline text with paragraphs
and bidirectionality, like pango does it. Is there a way to integrate
pango support into pyGame? I'd prefer marked up text display with text
properties ...
- Is there some way to reserve screen areas so they are excluded from a
blit, or do I have to manage stuff like this myself? I am thinking about
several graphic layers where each layer is painted on top of the next
layer, for example to draw a gui in front of a background image.
- There seems to be support for video overlay, i.e. is it possible to
have an external program paint an image from a camera into a portion of
the screen while pyGame is running?

Maybe this is the wrong list to ask, so please forgive the question but
direct me to somewhere better.

Cheers,
Thomas.

Maybe http://sourceforge.net/projects/pygameui/ helps you,
at least the source code.

Greetings, Uwe
 
P

Pierre-Alain Dorange

Thomas Troeger said:
I've managed to put together a small pyGame program, it runs smoothly
and seems to be exactly what I wanted. It's fast! Even with 100 moving
objects it still runs so fast that I can consider using Python/pyGame
for the whole project.

There are still some questions left which I haven't found out by myself,
so maybe someone here can answer them:

- I can't see how to create more sophisticated text output, it seems the
built in font render facilities are limited to simple strings. Is that
true?

Yes, for my part i start to make a (small) library myself for my little
game in development (simple).
Supporting bidirectionnal in such a case is not a big deal, but markups
will be not trivial (but python has tools to parse text, this can help).

Also have a look at somme gui library for pygame :
<http://www.pygame.org/tags/gui>
<http://www.pygame.org/wiki/gui>

It seems PGU is one of the most used.
said:
- Is there some way to reserve screen areas so they are excluded from a
blit, or do I have to manage stuff like this myself?

You can blit any rectangle it's trivial. for example group.draw render
the sprites in it, into the surface given, this surface can be the
screen or any other "virtual surface". You just have to render this
"virtual" on screen whn done.

You can also used the more sophisticate "dirty rect"
(group.RenderUdates) or even better group.LayeredUpdates.
I start with but a can not make all things work properly at that time.
I am thinking about
several graphic layers where each layer is painted on top of the next
layer, for example to draw a gui in front of a background image.

For this is simply create sprite groups (one per layer) and than call
group render (group.draw) in the order i need. Easy and efficient.
- There seems to be support for video overlay, i.e. is it possible to
have an external program paint an image from a camera into a portion of
the screen while pyGame is running?

Don't know...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top