Merge lp:~stefano-palazzo/python-snippets/python-snippets-stefano0 into lp:~jonobacon/python-snippets/trunk

Proposed by Stefano Palazzo
Status: Needs review
Proposed branch: lp:~stefano-palazzo/python-snippets/python-snippets-stefano0
Merge into: lp:~jonobacon/python-snippets/trunk
Diff against target: 29 lines (+24/-0)
1 file modified
pygtk/save_screenshot.py (+24/-0)
To merge this branch: bzr merge lp:~stefano-palazzo/python-snippets/python-snippets-stefano0
Reviewer Review Type Date Requested Status
Stefano Palazzo (community) Needs Resubmitting
Jono Bacon Needs Fixing
Review via email: mp+24012@code.launchpad.net

Description of the change

Taking a screen shot and saving it to disk.

To post a comment you must log in.
Revision history for this message
Jono Bacon (jonobacon) wrote :

Hi Stefano,

Thanks for your contribution, but it needs some fixes:

 * gtk snippets go in the pygtk dir and use the PyGTK category. See the other snippets for examples.
 * can you fix the snippet so that it saves the file to the users home directory.

Thanks!

review: Needs Fixing
95. By Stefano Palazzo <stefano@3000-G530>

changes made:
 moved to the pygtk directory
 category changed to PyGTK
 changed to save in users home

thank you for the review
stefano

Revision history for this message
Stefano Palazzo (stefano-palazzo) wrote :

Made the requested changes,
thanks for the quick and helpful review.

- Stefano

review: Needs Resubmitting

Unmerged revisions

95. By Stefano Palazzo <stefano@3000-G530>

changes made:
 moved to the pygtk directory
 category changed to PyGTK
 changed to save in users home

thank you for the review
stefano

94. By Stefano Palazzo <stefano@3000-G530>

Taking and saving a screenshot

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'gtk'
2=== added file 'pygtk/save_screenshot.py'
3--- pygtk/save_screenshot.py 1970-01-01 00:00:00 +0000
4+++ pygtk/save_screenshot.py 2010-04-25 12:33:30 +0000
5@@ -0,0 +1,24 @@
6+#!/usr/bin/env python
7+#-*- coding:utf-8 -*-#
8+
9+# [SNIPPET_NAME: Screenshot]
10+# [SNIPPET_CATEGORIES: PyGTK]
11+# [SNIPPET_AUTHOR: Stefano Palazzo <stefano.palazo@gmail.com>]
12+# [SNIPPET_LICENSE: GPL]
13+# [SNIPPET_DESCRIPTION: Take a screenshot and save it to disk.]
14+
15+import gtk.gdk
16+import os
17+
18+def save_screenshot(name="screenshot.png", mimetype="png"):
19+ """
20+ Take a screenshot and save it to disk.
21+ """
22+ window = gtk.gdk.get_default_root_window()
23+ screensize = window.get_size()
24+ pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, screensize[0], screensize[1])
25+ pixbuf = pixbuf.get_from_drawable(window,window.get_colormap(), 0, 0, 0, 0, screensize[0], screensize[1])
26+ pixbuf.save(os.path.expanduser('~/') + "%s" % (name),mimetype)
27+
28+if __name__ == '__main__':
29+ save_screenshot()

Subscribers

People subscribed via source and target branches