#!/usr/bin/python # pssc.py: the linux part # PhoneScreenSequentialCapture: capture the phone screen on a ws window # Requires: Python, wxPython, stream.py # (C) 2007 Michele Andreoli, GPL VERSION="pssc.py for Linux v%s" % '0.2' import traceback,sys,os,time import wx # some required external modules is in the dir ./ext for p in ('.','/home/michele/devel/pyfs','/usr/local/pssc'): if os.path.isdir(p): sys.path.append(p) from stream import Stream # configuration refresh=100 # milli-seconds class MyFrame(wx.Frame): def __init__(self, parent, id, title,s,size): wx.Frame.__init__(self, parent, id, title, size=size) self.s=s self.bitmap= wx.EmptyBitmap( size[0],size[1],-1) self.timer = wx.Timer(self, -1) wx.EVT_PAINT(self, self.OnPaint) self.Bind(wx.EVT_TIMER, self.OnTimer,self.timer) self.timer.Start(milliseconds=refresh,oneShot=True) self.OnTimer(None) self.CentreOnParent() def OnPaint(self, event): #print "paint ..." dc = wx.PaintDC(self) dc.DrawBitmap(self.bitmap, 0, 0) def OnTimer(self, event): print "requesting the phone screen ...", self.s.write('SCREEN') self.s.recfile(image) print "... received (%s)" % time.ctime() try: self.bitmap = wx.Bitmap(image) self.Refresh(True) except: print "error reading image ..." pass self.timer.Start(milliseconds=refresh,oneShot=True) class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, -1, 'PSSC',conn,size) frame.Show(True) self.SetTopWindow(frame) return True def OnExit(self): print "closing connections ... ", conn.write('END') time.sleep(1) print "ok" conn=Stream(mode='BT',verbose=0); # stream.py support also TCP connections conn.accept(service='PSSC') x,y=conn.read().split(',') size=(int(x),int(y)) print "phone screen size is %s" % str(size) image='/tmp/phone.jpg' if sys.platform.find('win32')>=0: # win32 :-( image='c:\\tmp\\phone.jpg' size=(int(x)+10,int(y)+35) app = MyApp(0) app.MainLoop() # End