Improve the demo browser
[pywebkitgtk.git] / demos / inspector.py
blob09a8a2045c29a27b151ec23c9694cc9e21082f35
1 # Copyright (C) 2008 Jan Alonzo <jmalonzo@unpluggable.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 import gtk
18 import webkit
20 class Inspector (gtk.Window):
21 def __init__ (self, inspector):
22 """initialize the WebInspector class"""
23 gtk.Window.__init__(self)
24 self.set_default_size(600, 480)
26 self._web_inspector = inspector
28 self._web_inspector.connect("inspect-web-view",
29 self._inspect_web_view_cb)
30 self._web_inspector.connect("show-window",
31 self._show_window_cb)
32 self._web_inspector.connect("attach-window",
33 self._attach_window_cb)
34 self._web_inspector.connect("detach-window",
35 self._detach_window_cb)
36 self._web_inspector.connect("close-window",
37 self._close_window_cb)
38 self._web_inspector.connect("finished",
39 self._finished_cb)
41 self.connect("delete-event", self._close_window_cb)
43 def _inspect_web_view_cb (self, inspector, web_view):
44 """Called when the 'inspect' menu item is activated"""
45 scrolled_window = gtk.ScrolledWindow()
46 scrolled_window.props.hscrollbar_policy = gtk.POLICY_AUTOMATIC
47 scrolled_window.props.vscrollbar_policy = gtk.POLICY_AUTOMATIC
48 webview = webkit.WebView()
49 scrolled_window.add(webview)
50 scrolled_window.show_all()
52 self.add(scrolled_window)
53 return webview
55 def _show_window_cb (self, inspector):
56 """Called when the inspector window should be displayed"""
57 self.present()
58 return True
60 def _attach_window_cb (self, inspector):
61 """Called when the inspector should displayed in the same
62 window as the WebView being inspected
63 """
64 print "attach"
65 return False
67 def _detach_window_cb (self, inspector):
68 """Called when the inspector should appear in a separate window"""
69 print "detach"
70 return False
72 def _close_window_cb (self, inspector, web_view):
73 """Called when the inspector window should be closed"""
74 print "close"
75 self.hide()
76 return True
78 def _finished_cb (self, inspector):
79 """Called when inspection is done"""
80 print "finished"
81 self._web_inspector = 0
82 self.destroy()
83 return False