PyWebKitGtk 1.1.7
[pywebkitgtk.git] / demos / inspector.py
blobdf3db3846b82b4a853bde581f43bd09ae3ca49f7
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 return False
66 def _detach_window_cb (self, inspector):
67 """Called when the inspector should appear in a separate window"""
68 return False
70 def _close_window_cb (self, inspector, view):
71 """Called when the inspector window should be closed"""
72 self.hide()
73 return True
75 def _finished_cb (self, inspector):
76 """Called when inspection is done"""
77 self._web_inspector = 0
78 self.destroy()
79 return False