Using pyCairo with pyGame surface

I wanted to use pyCairo with pyGame but can’t find any sample on the net.

So, here is a little bit of code to do this without using pyGTK.

#!/usr/bin/env python
import cairo 
import pygame 
import array 
import math 

def draw(surface): 
    x,y, radius = (250,250, 200) 
    ctx = cairo.Context(surface) 
    ctx.set_line_width(15) 
    ctx.arc(x, y, radius, 0, 2.0 * math.pi) 
    ctx.set_source_rgb(0.8, 0.8, 0.8) 
    ctx.fill_preserve() 
    ctx.set_source_rgb(1, 1, 1) 
    ctx.stroke() 
    
def input(events): 
    for event in events: 
        if event.type == pygame.QUIT: 
            sys.exit(0) 
        else: 
            print event 
            
#Create Cairo Surface 
Width, Height = 512, 512 
data = array.array('c', chr(0) * Width * Height * 4) 
stride = Width * 4 
surface = cairo.ImageSurface.create_for_data (data, cairo.FORMAT_ARGB32,Width, Height, stride) 

#init PyGame 
pygame.init() 
window = pygame.display.set_mode( (Width,Height) ) 
screen = pygame.display.get_surface() 

#Draw with Cairo 
draw(surface) 

#Create PyGame surface from Cairo Surface 
image = pygame.image.frombuffer(data.tostring(),(Width,Height),"ARGB",) 

#Tranfer to Screen 
screen.blit(image, (0,0)) 
pygame.display.flip() 
while True: 
    input(pygame.event.get())

Notes

  • This is working on Linux and Windows.
  • I’m using pyGame 1.7.1. There seems to be a bug in the surface creation with the “ARGB” byte order…

Pour mémoire : Configuration Ubuntu, Clavier, serveur X, mp3

Pour le clavier de la console

$ dpkg-reconfigure console-data

Clavier et carte graphique sous X

  • Sur mon Dell GX-110 avec carte graphique additionnelle Nvidia TNT2 sur bus PCI

$ dpkg-reconfigure xserver-xorg

  • extrait du fichier /etc/X11/xorg.conf

Section “Device” Identifier “TNT2” Driver “nv” BusID “PCI:1:7:0” EndSection #### Ajout des codecs mp3

$ sudo apt-get install gstreamer0.10-plugins-ugly

WinLibre, SoC 2006

WinLibre - logiciels libres et gratuits pour windows

La bonne nouvelle de la semaine

Google vient d’allouer 6 slots à WinLibre pour l’édition 2006 du Summer of Code.

6 étudiants financés par Google vont donc coder cet été pour WinLibre pour améliorer les futures versions.

Au menu
  1. Une version en Python de WinLibre
  2. Un prototype de WinLibre développé avec XUL
  3. MacLibre 2 : la future version de MacLibre
  4. Un programme libre de gravure de CD
  5. Final Touch 2 : Un programme libre de retouche d’image.
  6. Un programme simple et didactique de configuration de FireWall
  7. Update : Un logiciel de proxy personnel pour gérer au mieux la sécurité de son accès internet.

Bonne chance aux 6 étudiants et merci Google !

WinLibre, Google Summer of Code - Début des candidatures pour les étudiants

WinLibre - logiciels libres et gratuits pour windows

Vous êtes étudiants ? Vous voulez passer l’été à écrire du code pour WinLibre tout en étant payé par Google ? Alors inscrivez vous pour participer au Summer of Code 2006 !

Google accepte à partir d’aujourd’hui, 1er Mai 2006, les candidatures des étudiants. Et vous n’avez que jusqu’au 8 Mai pour finaliser votre candidature… Vous trouverez toutes les informations sur la page student FAQ.