15/07/2008

Running multiple X servers with Ubuntu

Developing Samurai-X ive definatly needed to be running two X servers. Finding how to do this on Ubuntu was a bit of a pita so here is a quick guide:

  • sudo dpkg-reconfigure x11-common
    select "console users"
  • create/copy a .xinit file, make sure it has at least something like
    exec /usr/bin/xterm
  • Press Control+Alt+F1 and login
  • Run
    xinit .your-xinit -- :1
  • Switch to the new x server with Control+Alt+F9

You can run more by changing the :1 to :2 or whatever

Ive read lots of alternatives but this is the only way Ive got it to work on Ubuntu Hardy.

14/07/2008

Samurai-X

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

23/04/2008

jquery and iframes

I needed to select some attributes that were in an iframe today with jquery. The iframe had an id of "preview" so I thought it would be possible to do:

 $('#preview .some_class')

Unfortunately that doesn't work. A quick google turned up nothing so I dug into the source and soon enough it became obvious you can do it like this:

 $('.some_class', $('#preview')[0].content_document)

Only tested in Firefox so far, I've got no idea if it will work in anything else...

Update: I wrote this little function to (hopefully) make this cross browser and a little easier to use:

jQuery.fn.frameselect = function(selector) {
        var oDoc = (this[0].contentWindow || this[0].contentDocument);
        if (oDoc.document) {
            oDoc = oDoc.document;
        }
        return this.pushStack( $(selector, oDoc) );
    }

This means you can write code like:

  $('#id_of_my_iframe').frameselect('div.something_in_the_iframe')

playing with virtualenv

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!

22/04/2008

conditional paster templates

I found a few things out tonight, the most important of which is the skip_template(condition=True) command that's inserted into paster contexts. This has allowed me to reduce the code in pyglons quite a bit. There is no more "minimal_project" directory, both "pyglons_minimal" and "pyglons" templates are generated from the same "default_template" directory. Also now there is a new "pyglons_game" template which includes a splash screen over the "pyglons" template.

Ive listed the files generated by each template below:

pyglons_minimal:

./minimal/__init__.py
./minimal/lib/__init__.py
./minimal/lib/base.py
./minimal/load_config.py
./minimal/main.py
./minimal/states/__init__.py
./minimal/states/main.py
./run.py
./setup.py

pyglons:

./regular/__init__.py
./regular/lib/__init__.py
./regular/lib/base.py
./regular/load_config.py
./regular/main.py
./regular/states/__init__.py
./regular/states/help.py
./regular/states/main.py
./regular/states/menu.py
./run.py
./setup.py

pyglons_game:

./game/__init__.py
./game/lib/__init__.py
./game/lib/base.py
./game/load_config.py
./game/main.py
./game/states/__init__.py
./game/states/help.py
./game/states/main.py
./game/states/menu.py
./game/states/splash.py
./run.py
./setup.py

There is also a new option "euclid=<boolean>" which if True includes pyeuclid. At the moment this file is included in the pyglons code but hopefully will be removed to an easy_install dependency when I get the chance to email the owner and get him to change his project page slightly :)

17/04/2008

pyglons 0.3 release

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 ...

distutils upload to google code

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!

Messing with default values

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

pyglons 0.3 on its way

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.

15/04/2008

Base class from callable

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
>>>