source: epoptes/trunk/fuentes/epoptes-client/screenshot @ 295

Last change on this file since 295 was 295, checked in by mabarracus, 3 years ago

copy trusty epoptes code

  • Property svn:executable set to *
File size: 1.9 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4###########################################################################
5# Screenshot.
6#
7# Copyright (C) 2010 Fotis Tsamis <ftsamis@gmail.com>
8# Many thanks to Uli Schlachter <psychon@znc.in> for helping with the cairo stuff
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FINESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22#
23# On Debian GNU/Linux systems, the complete text of the GNU General
24# Public License can be found in `/usr/share/common-licenses/GPL".
25############################################################################
26
27import gtk.gdk as gdk
28from sys import stdout, stderr, argv
29
30if len(argv) == 3:
31    width, height = int(argv[1]), int(argv[2])
32else:
33    exit(1)
34
35root = gdk.get_default_root_window()
36if root is None:
37    exit(1)
38r_width, r_height = root.get_size()
39
40pmap = gdk.Pixmap(root, width, height)
41cr = pmap.cairo_create()
42cr.scale(float(width)/r_width, float(height)/r_height)
43cr.set_source_pixmap(root, 0, 0)
44cr.paint()
45
46pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, width, height)
47pixbuf.get_from_drawable(pmap, root.get_colormap(), 0, 0, 0, 0, width, height)
48
49rowst = str(pixbuf.get_rowstride())
50pixels = pixbuf.get_pixels()
51
52try:
53    stdout.flush()
54    stdout.write('%s\n%ix%i\n%s' %(rowst, width, height, pixels))
55    stdout.flush()
56except:
57    stderr.write("Error while sending screenshot\n")
Note: See TracBrowser for help on using the repository browser.