Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar/graphics/popup.py
blob: e617c2234535e944b7a2c139489ba9e675103e48 (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
# Copyright (C) 2007, One Laptop Per Child
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

#
# DEPRECATED. Do not use in new code. We will reimplement it in gtk
#

import sys
import logging

import gobject
import gtk
import hippo

class Popup(hippo.CanvasBox, hippo.CanvasItem):
    __gtype_name__ = 'SugarPopup'

    __gsignals__ = {
        'action-completed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([]))
    }

    def __init__(self):
        hippo.CanvasBox.__init__(self)
        self._visible = False
        self._window = hippo.CanvasWindow(gtk.WINDOW_POPUP)
        self._window.set_root(self)
        self.connect('button-press-event', self._button_press_event_cb)

    def popup(self, x, y):
        if not self._visible:
            self._window.move(x, y)
            self._window.show()
            self._visible = True

    def popdown(self):
        if self._visible:
            self._window.hide()
            self._visible = False

    def grab_pointer(self):
        gtk.gdk.pointer_grab(self._window.window, owner_events=False,
                             event_mask=gtk.gdk.BUTTON_PRESS_MASK |
                                        gtk.gdk.BUTTON_RELEASE_MASK |
			                gtk.gdk.ENTER_NOTIFY_MASK |
			                gtk.gdk.LEAVE_NOTIFY_MASK |
			                gtk.gdk.POINTER_MOTION_MASK)

    def _button_press_event_cb(self, menu, event):
        self.emit('action-completed')