| 1 | #! /usr/bin/env python |
|---|
| 2 | # -*- coding: utf8 -*- |
|---|
| 3 | # |
|---|
| 4 | # Itaka is free software; you can redistribute it and/or modify |
|---|
| 5 | # it under the terms of the GNU General Public License as published by |
|---|
| 6 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 | # any later version. |
|---|
| 8 | # |
|---|
| 9 | # Itaka is distributed in the hope that it will be useful, |
|---|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | # GNU General Public License for more details. |
|---|
| 13 | # |
|---|
| 14 | # You should have received a copy of the GNU General Public License |
|---|
| 15 | # along with Itaka; if not, write to the Free Software |
|---|
| 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 17 | # |
|---|
| 18 | # Copyright 2003-2007 Marc E. <santusmarc_at_gmail.com>. |
|---|
| 19 | # http://itaka.jardinpresente.com.ar |
|---|
| 20 | # |
|---|
| 21 | # $Id$ |
|---|
| 22 | |
|---|
| 23 | """ Itaka screenshot engine """ |
|---|
| 24 | |
|---|
| 25 | import gc, os, gtk, pygtk |
|---|
| 26 | pygtk.require("2.0") |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | def Screenshot(guiinstance): |
|---|
| 30 | """ Returns a screenshot file. """ |
|---|
| 31 | # Use the GUI's instance configuration, to support dynamic preferences |
|---|
| 32 | configuration = guiinstance.configuration |
|---|
| 33 | console = guiinstance.console |
|---|
| 34 | |
|---|
| 35 | # Final absolute path to the screenshot file |
|---|
| 36 | shotFile = os.path.join(configuration['screenshot']['path'], 'itakashot.%s' % (configuration['screenshot']['format'])) |
|---|
| 37 | |
|---|
| 38 | w = gtk.gdk.screen_width() |
|---|
| 39 | h = gtk.gdk.screen_height() |
|---|
| 40 | screenshot = gtk.gdk.Pixbuf.get_from_drawable( |
|---|
| 41 | gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, w, h), |
|---|
| 42 | gtk.gdk.get_default_root_window(), |
|---|
| 43 | gtk.gdk.colormap_get_system(), |
|---|
| 44 | 0, 0, 0, 0, w, h) |
|---|
| 45 | |
|---|
| 46 | # Save the screnshot, checking before if to set JPEG quality |
|---|
| 47 | try: |
|---|
| 48 | if configuration['screenshot']['format'] == 'jpeg': |
|---|
| 49 | screenshot.save(shotFile, configuration['screenshot']['format'].lower(), {"quality":str(configuration['screenshot']['quality'])}) |
|---|
| 50 | |
|---|
| 51 | else: |
|---|
| 52 | screenshot.save(shotFile, configuration['screenshot']['format'].lower()) |
|---|
| 53 | except: |
|---|
| 54 | console.error(['ImageResource','screenshot'], "Could not save screenshot", guiinstance) |
|---|
| 55 | return False |
|---|
| 56 | |
|---|
| 57 | # Important workaround to avoid a memory leak. |
|---|
| 58 | # http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq08.004.htp |
|---|
| 59 | del screenshot |
|---|
| 60 | gc.collect() |
|---|
| 61 | |
|---|
| 62 | return shotFile |
|---|