Scp of a screenshot ( using wxpython and paramiko )

Thursday, November 16, 2006

Try this one.
This takes a screenshot and send it to a server using scp ( paramiko )
All you need is WxPython.



import wx
import paramiko
import sys
from time import sleep

class Screenshot(object):
def __init__(self, filename = "snap.png"):
self.filename = filename
try:
p = wx.GetDisplaySize()
self.p = p
bitmap = wx.EmptyBitmap( p.x, p.y)
dc = wx.ScreenDC()
memdc = wx.MemoryDC()
memdc.SelectObject(bitmap)
memdc.Blit(0,0, p.x, p.y, dc, 0,0)
memdc.SelectObject(wx.NullBitmap)
bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG )

except:
self.filename = ""

def main():
paramiko.util.log_to_file('snap.log')

caption = u"Required data"
path = "/var/www/html/screenshots" # change this to make it your default path
hostname = "www.whateverdomain.com" # change this to make it your default targe host
username = "batok" # change this to make it your default user
port = 22 # change this to another port if necessary....

app = wx.PySimpleApp()
time_to_wait = wx.GetNumberFromUser(message = "Time",
prompt = "Secs.",
caption = "Enter Seconds to Wait...",
value = 5,
min = 5,
max = 20,
parent= None )
try:
tw = int(time_to_wait)
except:
sys.exit(-1)
sleep( tw )
try:
wx.Bell()
except:
pass

s_shot = Screenshot()

filename = s_shot.filename
if filename == "":
sys.exit(-1)

if wx.YES == wx.MessageBox("Do you want to see the screenshot/nreduced by the half ?", "Hey!", wx.YES_NO | wx.ICON_QUESTION):
dlg = wx.Dialog(None,-1, "Your screenshot half the size")
img = wx.Image("snap.png" , wx.BITMAP_TYPE_ANY)
w = img.GetWidth()
h = img.GetHeight()
img2 = img.Scale(w/2,h/2)
wx.StaticBitmap(dlg,-1, wx.BitmapFromImage(img2))
dlg.Fit()
dlg.Show()


target = "%s/%s" % ( path, filename )
wx.MessageBox("A %s X %s screenshot\nis at %s" % (s_shot.p.x, s_shot.p.y, filename ), "Hey!")
hostname = wx.GetTextFromUser("Host", caption = caption , default_value=hostname)
username = wx.GetTextFromUser("User Name", caption = caption , default_value=username)
password = wx.GetPasswordFromUser("Password", caption = caption )
s_target = wx.GetTextFromUser("Destination File", caption= caption, default_value = target)

if "" in (hostname, username, s_target):
wx.MessageBox("Mmmm... some required fields are empty", "Hey!")
sys.exit(-1)

# Now paramiko's stuff... a.k.a secure copy
try:

t = paramiko.Transport((hostname, port))
t.use_compression(True)
t.connect(username=username, password=password, hostkey=None)
sftp = paramiko.SFTPClient.from_transport(t)
data = open(filename, 'rb').read()
sftp.open(s_target, 'wb').write(data)
t.close()
wx.MessageBox("The %s file was sent to server" % filename, "Hey!")

except Exception, e:
print e
try:
t.close()
except:
pass

return

if __name__ == "__main__":
main()

Turbogears and Genshi baby steps

Wednesday, September 20, 2006

These are the baby steps for using Genshi template system in Turbogears.

1 - In case you have not installed Genshi do....
easy_install Genshi

2 - Create a new turbogears project with...
tg-admin quickstart genshibasic

3 - Go to controllers.py in ./genshibasic/genshibasic directory

add this to the Root class


@expose(template="genshi:genshibasic.templates.genshi")
def genshi(self):
return dict(pretty="basic")


4 - create a new template file ( genshi.html ) in the templates directory of the project.

include this in genshi.html ...

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
lang="en">
pretty ${pretty}
</html>

5 - Start your project with

python start-genshibasic.py


6 - Open your browser and type http://localhost:8080/genshi

Enjoy!
The rest is to study carefully genshi documentation to be a black belt.

A snap of the screen in wxPython and scp afterwards

Wednesday, August 30, 2006

This python program takes a snapshot of the screen, saving it to snap.png file, and copying the file via sftp to a server.

Python 2.4 , Wxpython and paramiko are required.


---------------------------------------------------


import wx
import paramiko

paramiko.util.log_to_file('snap.log')
filename = "snap.png"
app = wx.PySimpleApp()
p = wx.GetDisplaySize()
bitmap = wx.EmptyBitmap( p.x, p.y)
dc = wx.ScreenDC()
memdc = wx.MemoryDC()
memdc.SelectObject(bitmap)
memdc.Blit(0,0, p.x, p.y, dc, 0,0)
memdc.SelectObject(wx.NullBitmap)
bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG )
hostname = wx.GetTextFromUser("Host")
username = wx.GetTextFromUser("User Name")
password = wx.GetPasswordFromUser("Password")
port = 22

wx.MessageBox("A %s X %s snap of the screen\nis at %s" % (p.x, p.y, filename ), "Hey!")

try:
t = paramiko.Transport((hostname, port))
t.connect(username=username, password=password, hostkey=None)
sftp = paramiko.SFTPClient.from_transport(t)

data = open(filename, 'rb').read()
sftp.open(filename, 'wb').write(data)

t.close()
wx.MessageBox("The %s file was sent to server" % filename, "Hey!")

except Exception, e:
print e
try:
t.close()
except:
pass

A snap of the screen in wxPython

Saturday, August 26, 2006

This python program takes a snapshot of the screen.
WxPython is required.

import wx
filename = "snap.png"
app = wx.PySimpleApp()
p = wx.GetDisplaySize()
bitmap = wx.EmptyBitmap( p.x, p.y)
dc = wx.ScreenDC()
memdc = wx.MemoryDC()
memdc.SelectObject(bitmap)
memdc.Blit(0,0, p.x, p.y, dc, 0,0)
memdc.SelectObject(wx.NullBitmap)
bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG )
wx.MessageBox("A %s X %s snap of the screen\nis at %s" % (p.x, p.y, filename ), "Hey!")

Friday, August 18, 2006


vmware server win32 console Posted by Picasa

In search of the python web framework

Saturday, June 03, 2006

-Look no further, a good guy yell me at IRC.
Try Nevow.

That was about a year and half.

-If you are looking for a python based web framework try Nevow!, this guy insisted.

There was no Turbogears or Django then, the very hyped framewords of these very days.

TG and Django have good screencast and nice looking websites. Speaking about their features, well, they seem very well integrated. In the case of TG, an impressive tie of disperate projects. Django includes everything from the same project.

Despite facts and popularity of the two, I still love the swiss army knife freedom and power of Nevow.

Nevow has nice features!

Tuesday, January 03, 2006

Nevow , a python based web construction toolkit , has a lot of nice features, that deserve attention:

1 - LivePage ( Ajax ).
2 - Canvas ( Flash to server ).
3 - XUL , the python way.
4 - Stan ( Python...ized XHTML )
5 - Formless ( automatic Form generation ).