minimal pyglet window implementation

45 views
Skip to first unread message

infinite8s

unread,
Feb 21, 2008, 2:14:23 PM2/21/08
to pyglet-users
Hello,

What is the minimal pyglet window implementation required for a full
screen app with no keyboard (only mouse gestures)? Is it possible to
have pyglet sit ontop of GLUT? I've been looking at Cocoa code for the
UIKit on the iphone (particularly from the clutter UI library) and I
think it might be possible to port pyglet to the iphone by creating c
functions that call the Cocoa objective C code then creating callbacks
that tie into pyglet event handling.

Basically, what are the minimum functions/classes that I would need to
implement? Thanks.

NMA

Arne Babenhauserheide

unread,
Feb 21, 2008, 3:18:58 PM2/21/08
to pyglet...@googlegroups.com, infinite8s
Sorry, if that's a dumb question, but what is GLUT?

As far as I know, the minimal implementation for the window and a clickable
Thing is similar to the following:

# First we need PyGlet, window and image for the faces.
from pyglet import window, image

# And the pyglet events
from pyglet.window import event

# and the mouse events.
from pyglet.window import mouse

# And we want to be able to wait a bit (and save processor time).
from time import sleep

class Window(pyglet.Window):
def __init__(things=[], *args, **kwds):
super(Window, self).__init__(fullscreen=True)
self.things = things #: The list of things which appear on the screen

def action():
"""Do whatever the class should do in each loop"""
pass

def event_loop():
self.dispatch_events()
self.clear()
self.action()
self.flip()
# wait for 3ms which is quite unnoticeable but massively reduces CPU load
sleep(0.003)

def on_mouse_release(self, x, y, button, modifiers):
"""Check, if a mouse-click hit a card. If yes, perform the clicked()
action."""
for i in self.things:
if i.is_inside(x, y):
i.clicked()

class Thing(object):
def __init__(image_path, *args, **kwds):
# super is necessary here to make multiple inheritance possible for
subclasses.
super(Thing, self).__init__(*args, **kwds)
self.image = image.load(image_path) #: the image to show

def is_inside(area, x, y, width=0, height=0):
"""Check if the given coordinates (optionally: A part of the given area)
is inside.

If the given coordinates or some part of the object given by the coordinates
and width and height are in the area, return true."""
# Do so. For an example, please check the attached files.
pass

def clicked():
"""Perform whatever action should be done when the icon thing was
clicked."""
print i, "was clicked."

For the mouse gestures, you might also need some mouse-tracking code since
this code only covers clickable Things.

Best wishes,
Arne

> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group. To post to this group, send email to
> pyglet...@googlegroups.com To unsubscribe from this group, send email to
> pyglet-users...@googlegroups.com For more options, visit this
> group at http://groups.google.com/group/pyglet-users?hl=en
> -~----------~----~----~----~------~----~------~--~---

--
Unpolitisch sein
Heißt politisch sein
Ohne es zu merken.
- Arne Babenhauserheide ( http://draketo.de )
-- Weblog: http://blog.draketo.de

-- Mein öffentlicher Schlüssel (PGP/GnuPG):
http://draketo.de/inhalt/ich/pubkey.txt

babglet.py
gui_base.py
signature.asc

Richard Jones

unread,
Feb 21, 2008, 3:59:32 PM2/21/08
to pyglet...@googlegroups.com
On Fri, 22 Feb 2008, Arne Babenhauserheide wrote:
> Sorry, if that's a dumb question, but what is GLUT?

Google "GLUT"


> As far as I know, the minimal implementation for the window and a clickable
> Thing is similar to the following:

What you've outlined is a minimal *use* of an existing pyglet Window.


Richard

Richard Jones

unread,
Feb 21, 2008, 4:02:05 PM2/21/08
to pyglet...@googlegroups.com
On Fri, 22 Feb 2008, infinite8s wrote:
> Basically, what are the minimum functions/classes that I would need to
> implement? Thanks.

In short - and I'm a little hazy on this because it's been a long time since I
last had my hands in the window code - the core responsibility is to provide
an OpenGL context. Of course there's a lot that goes into that - capabilities
requested by the programmer, handling multiple screens, etc. You might find
it useful to examine the existing pyglet.window.carbon implementation since
it's one of the most straight-forward of the three.


Richard

Alex Holkner

unread,
Feb 21, 2008, 4:36:16 PM2/21/08
to pyglet...@googlegroups.com

Of course, since the OP is targetting the iPhone, there's probably no
need to support multiple screens or capabilities ;-) Porting any
minimal OpenGL Cocoa example to Python would be sufficient to get
started.

The story as of a week or so ago was that PyObjC hasn't yet been
ported to the iPhone CPU (ARM?) (which is your only possible interface
to Cocoa).

Alex.

Arne Babenhauserheide

unread,
Feb 22, 2008, 3:15:26 AM2/22/08
to pyglet...@googlegroups.com
El Thursday, 21 de February de 2008 21:59:32 Richard Jones escribió:
> On Fri, 22 Feb 2008, Arne Babenhauserheide wrote:
> > Sorry, if that's a dumb question, but what is GLUT?
>
> Google "GLUT"

I didn't think that could work, but it did!

(In german "Glut" is the word for "glow", so I was quite sure that googling
wouldn't give me useful results)

> What you've outlined is a minimal *use* of an existing pyglet Window.

I misunderstood you. Sorry.

Wishes,
Arne

signature.asc

infinite8s

unread,
Feb 22, 2008, 11:20:50 AM2/22/08
to pyglet-users

> Of course, since the OP is targetting the iPhone, there's probably no
> need to support multiple screens or capabilities ;-) Porting any
> minimal OpenGL Cocoa example to Python would be sufficient to get
> started.
>
> The story as of a week or so ago was that PyObjC hasn't yet been
> ported to the iPhone CPU (ARM?) (which is your only possible interface
> to Cocoa).


The iphone only has a single screen (and probably graphics context). I
was just wondering what the minimal set of interfaces I would need to
implement to be able to use pyglet. I figured the timer interface
(although since the iPhone is running a version of OS X it would
likely have libc) and a single graphics context, although I'm not sure
where to start. I was thinking of taking the Carbon interface and
slowly stripping away the parts that weren't necessary for a full
screen app with minimal event supoort, and then slot in the proper
system dependent calls. I thought I could get around using pyobjc, but
there doesn't seem to be any way to wrap Obj C code in C, which could
then be called from ctypes. I've noticed that recent svn versions of
PyObjC have a version of libffi targeted toward ARM processors, so
maybe pyobjc will support the iPhone in the near future (maybe they
are waiting for the official SDK).

Naveen

Jay Freeman (saurik)

unread,
Mar 8, 2008, 5:57:19 AM3/8/08
to pyglet-users
So, I just found this thread, and wanted to point out that I already
ported PyObjC to the iPhone a couple weeks ago, have been distributing
it to a rather large number of developers, and it seems to work ;P. If
you'd like more information, please go here:

http://www.saurik.com/id/5

I just wrote that article to provide more of a jumping point to "it's
already done". ;)

(Also, I'm not certain why they needed to add their own port of
libffi, as the original distribution of libffi supports ARM, and only
a few changes were needed to make to the assembler in order to support
it...)

Sincerely,
Jay Freeman (saurik)
sau...@saurik.com
http://www.saurik.com/

On Feb 22, 8:20 am, infinite8s <naveen.michaudagra...@gmail.com>
wrote:

infinite8s

unread,
Mar 8, 2008, 1:02:34 PM3/8/08
to pyglet-users

Oh, that's great! Now I just have to map a simple pyglet
implementation onto the UIKit through PyObjC (anybody still want to
clue me in on a minimal interface to support?). Imagine doing pyglet
games on an iphone.

Also, it would be great if there was a way to bundle your version of
the iphone's python+pyobjc into an application bundle so the user
could just install the app. Is there a way to get your python+pyobj
without going through the apt-get installer?

Naveen

On Mar 8, 5:57 am, "Jay Freeman (saurik)" <sau...@saurik.com> wrote:
> So, I just found this thread, and wanted to point out that I already
> ported PyObjC to the iPhone a couple weeks ago, have been distributing
> it to a rather large number of developers, and it seems to work ;P. If
> you'd like more information, please go here:
>
> http://www.saurik.com/id/5
>
> I just wrote that article to provide more of a jumping point to "it's
> already done". ;)
>
> (Also, I'm not certain why they needed to add their own port of
> libffi, as the original distribution of libffi supports ARM, and only
> a few changes were needed to make to the assembler in order to support
> it...)
>
> Sincerely,
> Jay Freeman (saurik)
> sau...@saurik.comhttp://www.saurik.com/

Alex Holkner

unread,
Mar 12, 2008, 6:57:07 AM3/12/08
to pyglet...@googlegroups.com
On 3/8/08, Jay Freeman (saurik) <sau...@saurik.com> wrote:
>
> So, I just found this thread, and wanted to point out that I already
> ported PyObjC to the iPhone a couple weeks ago, have been distributing
> it to a rather large number of developers, and it seems to work ;P. If
> you'd like more information, please go here:
>
> http://www.saurik.com/id/5

Great stuff. It's been widely reported on the blogs, slashdot etc
that the license terms for distributing an application over the iPhone
store (the only way for non-developers to get install additional
software) prohibit applications that require a non-Apple-bundled
interpreted language (i.e., Python). Quote:

"No interpreted code may be downloaded and used in an Application
except for code that is interpreted and run by Apple's Published APIs
and builtin interpreter(s)… An Application may not itself install or
launch other executable code by any means, including without
limitation through the use of a plug-in architecture, calling other
frameworks, other APIs or otherwise."
http://blog.mozilla.com/rob-sayre/2008/03/06/apple-bans-firefox-spidermonkey-lisp-lua-ruby-python-rhino-java-opera-gcc/

I haven't checked the license agreement to verify the context of this,
as reading it requires an iPhone developer membership, which in turn
requires me to answer loaded questions that imply I intend to develop
for the iPhone (I don't).

To me this looks like Python/pyglet on the iPhone is restricted to
hobbyist activities only.

Alex.

Brian Fisher

unread,
Mar 12, 2008, 2:22:51 PM3/12/08
to pyglet...@googlegroups.com
Well the spirit of that license term is to make sure there is no way
to get around the restriction of running signed code. All iPhone apps
need to be signed for security.

The key terms are "downloaded and used" and "install or launch other
executable code" - meaning the app is forbidden from running anything
*outside* of the app. If all the code (python or otherwise) the app
executes is part of the signed iPhone bundle, it wouldn't be a
violation of the terms at all. There's nothing in that particular
clause that restricts interpreted code within the app.

Peter Wang

unread,
Mar 16, 2008, 10:58:23 AM3/16/08
to pyglet...@googlegroups.com
On Wed, Mar 12, 2008, Alex Holkner <alex.h...@gmail.com> wrote:
> "No interpreted code may be downloaded and used in an Application
> except for code that is interpreted and run by Apple's Published APIs
> and builtin interpreter(s)…

Either someone at Apple doesn't understand the notion of a Von Neuman
architecture, or *I* don't understand the gist of this license. :)

On Wed, Mar 12, 2008, Brian Fisher <thor...@gmail.com> wrote:
> The key terms are "downloaded and used" and "install or launch other
> executable code" - meaning the app is forbidden from running anything
> *outside* of the app. If all the code (python or otherwise) the app
> executes is part of the signed iPhone bundle, it wouldn't be a
> violation of the terms at all. There's nothing in that particular
> clause that restricts interpreted code within the app.

Is there anyone in the iPhone community that is interested in trying
to get a signed Python framework for the iPhone?


-Peter

Reply all
Reply to author
Forward
0 new messages