Lets run JSGI apps in WSGI! code
Pure sillyness...
Now the observant will realise Iv gone from one problem, quite simple and not important, to a completely different problem thats much bigger and much more complicated.
This seems to be the pattern I follow! Im not entirely sure if its a good thing or not. It results in large projects - that I probably wont ever finish. On the other hand I get to try out some really cool things ( which is surely all I care about ).
Well anyway I have a basic tabbed browser using python-webkit. Lets see what becomes of it...
Been trying this out for spike, written in python of course ;) Does something similar to wordle.net, though I have no idea how their alogorithm works!
Algorithm uses edges and collision detection to work quite fast ( that cloud generated in 0.03s ) - should be fast enough for a little animation :)
update...
Added a bunch of options and actually the ability to render text now. You'll never guess the input to this but I quite like the output :)
Trying to write a new window decorator for samurai-x at the moment. Not an easy task!. Its using my yahiko library which has led me to fix a few bugs. Widget libs are always such a pain in the ass! I see they are discussing one on the pyglet google group at the moment. If only we had a compositing wm we could use their code in an opengl window - zoom zoooom... *evil grin*
Anyway yahiko seems to be working ok with a X window as a child widget...more later
Grrrrrr... it just wont work with samurai-x. I can run a service outside of sx and talk to it with a client, but I cant run the service inside sx!. http://samurai-x.org/browser/sx-dbus/sxdbus.py I even created a gobject main loop plugin to run this! more grrrrr's....
Anyway... I went back to a bit of hacking with the sx-web plugin and made it use webob and mako templates. Mixed in with a theme and some js magic from jquery and we've got something that looks rather nice!
Finally Ive done it and written a window manager in pure python, lots and lots of ctypes, but no actual c code. Presenting Samurai-X
The feature set is pretty small at the moment, just window resizing/moving, virtual desktops and a statusbar (drawn with cairo). Not sure exactly what the full feature list will look like, probably something like awesome/fluxbox - but with more python goodness
I was playing with virtualenv yesterday. Seems to work very well. I found it a little annoying that after sourcing the 'bin/activate' command there is no easy way to get out of the configured environment.
One quick bit of pestering spike and he came back with 'bash --init-file bin/activate'. This launches a new bash shell so you can just hit Control+D and your dumped back to where you started. Joy!
I've just posted an egg and .tar.gz of pyglons 0.3 on the pyglons project site.
0.3 uses a new templating system as I posted about before. I've also done some major work on the front page of the site to try and explain a little better about what the thing actually does. I'm planning on announcing this to the pyglet group soon ...
This is more of a note to myself than a post because I did a few searches and couldnt find it quickly....
The code for uploading to googlecode from distutils/setup tools is here.
Shame pbu's publish cant do it!
How to change/set default values for a function ( I wouldn't actually encourage anyone to use this! ):
>>> def a(b, c): ... print b, c ... >>> a() Traceback (most recent call last): File "", line 1, in TypeError: a() takes exactly 2 arguments (0 given) >>> a.func_defaults = (1, 2) >>> a() 1 2
I just commited the new templating code for pyglons based on what pylons is now doing using the latest PasteScript and tempita modules. This adds the possibility to pass options on the command line when creating your project to better describe what you do and dont want.
For example its now possible to do:
$ paster create -t pyglons my_project_name configobj=true
This will create a new project with the required code to load your config via ConfigObj. Disabling this means your project will use nothing but a simple dictionary for its initial config.
Actually you could always set options on the command line but only now do they include/exclude code from the pyglons templates. If you dont specify the option on the command line you will still get prompted for it ( unless your using --no-interactive ).
There will be more options in the future for adding code for pymunk, windoh etc in future versions of pyglons but this is essentially it for the 0.3 version I think. Ill post new downloads later today.
Sometimes I randomly wonder if something is possible in python the language itself ( and it often is ), this time I wondered if base classes could be callable objects... guess what?...they can!
>>> def b(c): ... class B(object): ... d = c ... return B ... >>> class A(b(1)): ... pass ... >>> A.d 1 >>>
I wanted to save/load JSON to SQLAlchemy transparently, the same way you can with PickleType. Also I wanted to know how to do value conversion generally in SQLAlchemy. So here is a custom SQLAlchemy type: JSONType, it uses simplejson to do the actual JSON parsing/serialization.
import simplejson from sqlalechmy.types import Text, MutableType, TypeDecorator class JSONType(MutableType, TypeDecorator): impl = Text def __init__(self): super(JSONType, self).__init__() def process_bind_param(self, value, dialect): return simplejson.dumps(value) def process_result_value(self, value, dialiect): return simplejson.loads(value) def copy_value(self, value): return simplejson.loads(simplejson.dumps(value))
Another day another project... >_< well i got to thinking i'd really to have something like Ant Tweak Bar but pure python which led on to thinking of a quick and simple UI library for pyglet... which led onto a not so simple UI library for pyglet... :)
windoh uses pyglets event.EventDispatcher class heavily to make a reasonably nice widget system. It includes a resizeable/draggable frame class and fully inheritable style support. There is also a button and a label class at the moment, I expect there will be more as time goes on.
I need to work out whats going on with pyglets batches a bit better but otherwise it all seems to work pretty ok.
Ive also checked how pylons is doing the --with- stuff so ill be adding pymunk, windoh and maybe atb-ctypes to --with- options to pyglons soon.
The source is in the pyglons repository and there is a very basic page at the pyglons wiki.
True to form there is absolutely zero documentation at the moment, you can check the test.py file, other wise may the source be with you...
For every 3d project iv made with python ive always written a way to use Ant Tweak Bar so I thought for historical reasons I should again for use with pyglet ( and pyglons ). So..
atb-ctypes is a ctypes wrapper around Ant Tweak Bar. It includes a pyglet event handler that can easily be pushed onto the event stack. It is of course perfectly possible to use atb-ctypes with any other windowing/event library, it does not depend on pyglet.
A very minimal sample:
import pyglet from pyglet.gl import * import atb from atb.pyglet_handler import ATBEventHandler window = pyglet.window.Window() @window.event def on_close(): pyglet.app.exit() atbhandler = ATBEventHandler(window) if __name__ == '__main__': atb.init() for x in range(2): bar = atb.Bar('my bar %d' % x) myVar = c_float() COLOR4F = c_float * 4 myColor = COLOR4F() bar.add_var("some float", myVar) bar.add_var("some color", myColor) def say_hello(*args): print args, "hello" bar = atb.Bar('buttons') bar.add_button("my button", say_hello) pyglet.app.run()
The code is in the pyglons googlecode repo now.
Now I have to go socialize... Its friday!! :]
pyglons now provides a second paster template: 'pyglons_minimal'. This does away with the states directory and puts just one state in main.py for you to start with. The template is aimed at people who know their way around pyglons and want to do things "their way" or just for very quick test scripts where the developer is used to how pyglons works ;)
Im about to try clutter now inside pyglet as a possible pyglons "recommended" UI library...
A little recipe to list all the actions off a controller automatically:
class SomethingController(BaseController): def index(self): # magic to return a list of actions this controller supports html = [h.link_to(f.replace('_', ' '), h.url_for(controller='something', action=f)) + "<br>" for f in dir(self) if (not f.startswith('_') and callable(getattr(self, f)) and f not in ('index', 'start_response') )] return "\n".join(html)