Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/view/OverlayWindow.py
blob: 376ca2f5313a1979b1416b76c30e28bb97b5dc4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright (C) 2006-2007 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import gtk
import cairo

def _grab_pixbuf(window=None):
    if not window:
        screen = gtk.gdk.screen_get_default()
        window = screen.get_root_window()
    color_map = gtk.gdk.colormap_get_system()
    (x, y, w, h, bpp) = window.get_geometry()
    return gtk.gdk.pixbuf_get_from_drawable(None, window, color_map, x, y, 0, 0, w, h)

class OverlayWindow(gtk.Window):
    def __init__(self, lower_window):
        gtk.Window.__init__(self)
        self._lower_window = lower_window

        self._img = gtk.Image()
        self.add(self._img)

        self.realize()

        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
        self.window.set_accept_focus(False)
        self.window.set_transient_for(lower_window)

        self.set_decorated(False)
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
        self.set_default_size(gtk.gdk.screen_width(), gtk.gdk.screen_height())
        self.set_app_paintable(True)

#        self.connect('expose-event', self._expose_cb)

    def appear(self):
        pbuf = _grab_pixbuf(self._lower_window)
        #pbuf.saturate_and_pixelate(pbuf, 0.5, False)
        w = pbuf.get_width()
        h = pbuf.get_height()
        pbuf2 = pbuf.composite_color_simple(w, h, gtk.gdk.INTERP_NEAREST, 100, 1024, 0, 0)
        self._img.set_from_pixbuf(pbuf2)
        self.show_all()

    def disappear(self):
        self._img.set_from_pixbuf(None)
        self.hide()

    def _expose_cb(self, widget, event):
        cr = widget.window.cairo_create()
        cr.set_source_rgba(0.0, 0.0, 0.0, 0.4) # Transparent
        cr.set_operator(cairo.OPERATOR_SOURCE)
        cr.paint()
        return False