forked from cream/melange
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontainer.py
65 lines (45 loc) · 1.78 KB
/
container.py
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
import gobject
import cairo
import gtk
import webkit
import javascriptcore as jscore
from widget import MelangeWindow
from common import HTTPSERVER_BASE_URL, \
MOUSE_BUTTON_LEFT, MOUSE_BUTTON_MIDDLE, MOUSE_BUTTON_RIGHT
ORIENTATION_TOP = 'top'
ORIENTATION_BOTTOM = 'bottom'
ORIENTATION_LEFT = 'left'
ORIENTATION_RIGHT = 'right'
ORIENTATION_CENTER = 'center'
class ContainerWindow(MelangeWindow):
__gsignals__ = {
'begin-move': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
'end-move': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
}
def __init__(self):
MelangeWindow.__init__(self)
self.set_property('accept-focus', False)
self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DOCK)
self.set_keep_below(True)
self.view = webkit.WebView()
self.view.set_transparent(True)
self.view.connect('button-press-event', self.button_press_cb)
self.view.connect('button-release-event', self.button_release_cb)
self.add(self.view)
self.js_context = jscore.JSContext(self.view.get_main_frame().get_global_context()).globalObject
url = HTTPSERVER_BASE_URL + '/chrome/container.html'
self.view.open(url)
def set_orientation(self, orientation):
self.js_context.set_orientation(orientation)
def button_press_cb(self, source, event):
""" Handle clicking on the widget (e. g. by showing context menu). """
if event.button == MOUSE_BUTTON_RIGHT:
pass
return True
elif event.button == MOUSE_BUTTON_MIDDLE:
self.emit('begin-move')
return True
def button_release_cb(self, source, event):
if event.button == MOUSE_BUTTON_MIDDLE:
self.emit('end-move')
return True