Code blog
SyncAdapter android
Nov 8, 2011 5:28:47 PMApplication : todolist android. L'ensemble des copies d'écran en grand format est visible à http://www.migniot.com/Photos.html?album=Droid
L'application liste les listes de taches, comme sur
Pour cela on crée un custom Authenticator comme indiqué à http://developer.android.com/resources/samples/SampleSyncAdapter/index.html
Ce compte doit être déclaré Syncable
Puis on écrit une liste de taches
On crée la liste des taches dans Zope après avoir codé le produit correspondant avec ses compétences pythonesques
On vérifie qu'elle a bien été importée dans zope
Revenant à android, on lance écrit un SyncAdapter comme indiqué à http://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter.html .
Puis en ouvrant l'application android à nouveau, les listes sont apparues, avec leur contenu
Et on peut exulter à ne pas avoir de compte Google mais un compte Custom
Capture d'écran en PIL et wxPython
Apr 19, 2011 8:29:53 AMLa capture d'écran en python avec PIL est relativement triviale:
from PIL import ImageGrab pilimage = ImageGrab.grab()
L'image peut être convertie au format Bitmap de wxPython:
from wx import EmptyImage, BitmapFromImage
wximage = EmptyImage(pilimage.size[0], pilimage.size[1])
wximage.SetData(pilimage.convert('RGB').tostring())
bitmap = BitmapFromImage(wximage)
Une application wxPython peut être construite autour de cette Bitmap pour en sélectionner une partie. L'application complète est disponible ci-dessous:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from PIL import ImageGrab
from wx import App,Frame, EmptyImage, BitmapFromImage, NO_BORDER
from wx import StaticBitmap, PaintDC, EVT_PAINT, EVT_LEFT_DOWN
from wx import EVT_LEFT_UP, EVT_MOTION, Pen, Colour, SOLID, Brush
from wx import TRANSPARENT, TheClipboard, BitmapDataObject, Rect
class GrabbedFrame(Frame):
def __init__(self, title, image):
Frame.__init__(self, None, title=title,
size=image.size, style=NO_BORDER)
wximage = EmptyImage(image.size[0], image.size[1])
wximage.SetData(image.convert('RGB').tostring())
self.bitmap = BitmapFromImage(wximage)
self.down,self.start,self.end = False,None, None
EVT_PAINT(self, self.OnPaint)
EVT_LEFT_DOWN(self, self.OnMouse)
EVT_LEFT_UP(self, self.OnMouse)
EVT_MOTION(self, self.OnMouse)
def OnPaint(self, event):
dc = PaintDC(self)
dc.DrawBitmap(self.bitmap, 0,0)
if self.start and self.end:
x = min(self.start[0], self.end[0])
y = min(self.start[1], self.end[1])
w = abs(self.end[0]-self.start[0])
h = abs(self.end[1]-self.start[1])
dc.SetBrush(Brush(Colour(255,255,255),TRANSPARENT))
dc.SetPen(Pen(Colour(200,200,200),1,SOLID))
dc.BeginDrawing()
dc.DrawRectangle(x,y,w,h)
dc.EndDrawing()
def OnMouse(self, event):
if event.LeftDown():
self.down = True
self.start = event.GetPosition()
if event.LeftUp():
self.down = False
self.end = event.GetPosition()
self.Refresh(False)
self.capture()
if self.down and event.Dragging():
self.end = event.GetPosition()
self.Refresh(False)
def capture(self):
x = min(self.start[0], self.end[0])
y = min(self.start[1], self.end[1])
w = abs(self.end[0]-self.start[0])
h = abs(self.end[1]-self.start[1])
data = BitmapDataObject()
data.SetBitmap(self.bitmap.GetSubBitmap(
Rect(x,y,w,h)))
if TheClipboard.Open():
TheClipboard.SetData(data)
TheClipboard.Flush()
TheClipboard.Close()
self.Close()
def grab():
pilimage = ImageGrab.grab()
frame = GrabbedFrame('Image grabbed', pilimage)
frame.Show()
if __name__ == '__main__':
app = App()
grab()
app.MainLoop()


-1°