PJBlog : Pierre-Jean, WinLibre et Cie...

Pierre-Jean Coudert - Logiciels Libres - Développement - etc...

Aller au contenu | Aller au menu | Aller à la recherche

dimanche, septembre 27 2009

Django code snippets for Notepad++

Here is the content for my Quicktext.ini. This adds Django shortcuts to Notepad++ with the QuickText Plugin.

ie: type model + <TAB> to insert the following model's skeleton:


class ModelName(models.Model):
    """Model docstring"""
    slug = models.SlugField(max_length=200)
    name = models.CharField(max_length=100, default='name')

    updated = models.DateTimeField('update date', auto_now=True )
    created = models.DateTimeField('creation date', auto_now_add=True )

    class Meta:
        pass

    def __unicode__(self):
        return name

    def save(self, force_insert=False, force_update=False):
        pass

    @models.permalink
    def get_absolute_url(self):
       return ('view_or_url_name')


class ModelNameAdmin(admin.ModelAdmin):
    list_display = ('name',)
    search_fields = ['name',]

admin.site.register(ModelName, ModelNameAdmin)

Lire la suite...

dimanche, novembre 16 2008

Python Sidebar update

The original Python Sidebar is actually unusable due to the python 2.6 documentation refactoring...

But thanks to Bruno there is now an updated Python 2.6 Sidebar for Firefox.

Click here to bookmark the Python 2.6 Sidebar for Firefox.

lundi, juin 25 2007

Pwytter has now its own domain

Pwytter, the free, multi-platform graphical twitter client has now its own domain:

Calvin Spealman, one of the first tester said: I like it. Such a slick looking Tk app is surprising.

dimanche, juin 24 2007

Pwytter 0.3 Windows executable

Pwytter is a graphical client for Twitter written in Python / tkInter.

If you want to try this 0.3 release, download the following file, decompress it and double click on pwytter.exe

The source distribution should work on Mac OSX and Linux too.

More info on Pwytter 0.3...

vendredi, juin 22 2007

Pwytter 0.3: soon to be usable

Pwytter is a twitter client written in Python.

pwytter, a twitter client written in Python / tkInter

ChangeLog, release 0.3

  • Collapsable edit parameters (Saved in XML Files)
  • clickable profile and user URLs, Names and Images
  • Improved UI
  • Multi-lines message display and improved word wrap
  • Better path management
  • icons on button (from famfamfam)
  • balloons suport (Hints)
  • Bug corrected in UserTimeLine Display : error 404

Download from SVN

lundi, juin 18 2007

Pwytter 0.2 Screenshot

My Python Twitter client

The UI is written with Tkinter.

Runs actually on windows, and soon on Linux and Mac OS X.

Features

  • User TimeLine
  • Friends TimeLine
  • Public TimeLine

Source Code

Package used

mercredi, décembre 13 2006

A SimpleXMLRPCServer with allow_reuse_address

XMLRPCServer / Python

Useful trick on Linux when you need to reconnect often to the same socket.

import SocketServer
import SimpleXMLRPCServer        

class MyTCPServer(SocketServer.TCPServer):
    def server_bind(self):
        self.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
        self.socket.bind(self.server_address)

class MyXMLRPCServer(MyTCPServer, SimpleXMLRPCServer.SimpleXMLRPCDispatcher):
    def __init__(self, addr, requestHandler=SimpleXMLRPCServer.SimpleXMLRPCRequestHandler, logRequests=1):
        self.logRequests = logRequests
        SimpleXMLRPCServer.SimpleXMLRPCDispatcher.__init__(self)
        MyTCPServer.__init__(self, addr, requestHandler)

my_object = MyObject()
server = MyXMLRPCServer(("localhost", 8000),logRequests=False)
server.register_instance(self.my_object)        
while True:
    self.server.handle_request()

mercredi, novembre 29 2006

How to remove SimpleXMLRPCServer Request logs

This is a simple example intended to show how to remove log messages printed on stderr for each request.

 import SimpleXMLRPCServer
 class NoLogHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
     def log_request(self, code='-', size='-'):
         pass
 server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8888), NoLogHandler)
 object = MyObject()
 server.register_instance(object)        
 server.serve_forever()

vendredi, juin 23 2006

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

Links

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