[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] GSoC



Hi guys,

I'm looking for some input into widget events, and what people think is
the best way to implement this.

There seems to be two main methods, either a widget can have functions
that are called on these events, or the widget can emit a Pygame event
that will then be handled in the main game loop.
	The advantage of the first method is that it is perhaps a little more
OO, in that the functions are encapsulated within the widget's class.
But, from a conversation with someone else about this, it was suggested
that this could complicate the game code, and it would be better to use
events in order to keep the game code and GUI code separated.
	After this conversation, I have come up with a potential solution:
On a widget event, such as clicking on a button or hitting the enter key
in an input box, the widget will check for an appropriate function (e.g.
self.on_click()), and run it. This will be useful for printlining or
running some quick GUI code, e.g. clicking a button that should
add/remove a menu can be easily done this way.
	If the function is not present, then the widget will emit a Pygame
event, that the developers game code can then handle.

What do you think about the best way to do this?

Also, if you like the proposed idea, would it be better to check if the
function exists, or perhaps check if the function returns None.
	The latter may be advantageous, as I can have empty functions in the
base class to simplify documentation. It would also allow a developer to
use the function and return None, so that an event is still emitted and
both methods could be used simultaneously.

Thanks,
Sam Bull

> On Sat, Jan 15, 2011 at 7:46 AM, Sam Bull <sam.hacking@xxxxxxxx>
> wrote:
>         Hi,
>         
>         I was wondering if there was any chance of creating a new GUI
>         toolkit in
>         Pygame, for Google Summer of Code. I know this isn't working
>         directly on
>         Pygame, but I think an easier to use, more detailed toolkit
>         may lower
>         the entry barrier for new developers, and provide a smoother
>         experience
>         to the players that choose to play these games, thus improving
>         the
>         overall quality of the Pygame project.
>         
>         This toolkit will focus more on the widgets than packing
>         features,
>         giving full control to the developer as to where the widgets
>         should be
>         positioned. Each widget should act as a user would expect,
>         with similar
>         behaviour to GTK+ widgets, a lot of attention has gone into
>         the small
>         details.
>         
>         With it's current design, to start using the toolkit it is as
>         simple as:
>         from sgc import *
>         from sgc.locals import * #Import the modules
>         # Create a widget
>         example_widget = widgets.Input_Box(args...) #Create an input
>         box widget
>         example_widget.pos = (x,y) #Set the widget's position
>         example_widget.add() #Add widget to the active widgets
>         Then just add into your event handling:
>         widgets.event(event)
>         And somewhere else in your game loop:
>         widgets.update(time)
>         
>         It should be complete without graphics to keep the total size
>         low and
>         unbloated, all graphics should thus be produced through code
>         only.
>         Although, it will be themeable so that developers can use
>         custom images
>         to change the appearance of the widgets.
>         
>         During this GSoC project I would also like to make this
>         toolkit work in
>         OpenGL under Pygame, with identical behaviour, so developers
>         can have a
>         more seamless transition between 2D and 3D game development.
>         
>         I have started creating a spec for this project as part of my
>         college
>         coursework. Most of the stuff in the spec has already been
>         completed, so
>         if there is a chance I can do this for GSoC then I will expand
>         this spec
>         to show what will be completed during this timeframe. You can
>         download
>         the spec from:
>         http://sambull.org/spec.pdf
>         
>         If you also want to see the current progress of the project,
>         you can
>         download the source from:
>         https://launchpad.net/simplegc
>         Just download the code from the link, then run the run.py file
>         in Python
>         to launch the example program. The widgets should behave as
>         you would
>         expect them to on your desktop, use the "f" key to toggle the
>         FPS
>         counter.
>         The dialog windows and menu are not complete, but the few
>         other widgets
>         are reasonably feature complete.
>         
>         Thank you for your time,
>         Sam Bull

Attachment: signature.asc
Description: This is a digitally signed message part