I want a simple webview based on webkit, with a fixed size (e.g. 200x200) and without any scrollbars. I use X with no window manager.
I tried the following Python code:
import gtk
import webkit
view = webkit.WebView()
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
sw.add(view)
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.add(sw)
win.set_default_size(200, 200)
win.show_all()
view.open("http://www.blackle.com")
gtk.main()
The scrollbars still show, although they should not.
I also tried to follow a different path and completely remove scrollbars on GTK by using ~/.gtkrc-2.0
:
style "custom-scrollbar-style"
{
GtkScrollbar::slider_width = 0
GtkScrollbar::min-slider-length = 0
GtkScrollbar::activate_slider = 0
GtkScrollbar::trough_border = 0
GtkScrollbar::has-forward-stepper = 0
GtkScrollbar::has-backward-stepper = 0
GtkScrollbar::stepper_size = 0
GtkScrollbar::stepper_spacing = 0
GtkScrollbar::trough-side-details = 0
GtkScrollbar::default_border = { 0, 0, 0, 0 }
GtkScrollbar::default_outside_border = { 0, 0, 0, 0 }
}
widget_class "*Scrollbar" style "custom-scrollbar-style"
Even with this, it still shows thin white lines on the two sides of the window where the scrollbars are.
Any ideas?
I tried to play around with the signal handler, but it did not work.
Going through the GTK documentation, I saw the 2 style properties of ScrolledWindow which I had not included in the previous style (scrollbar-spacing
and scrollbar-within-bevel
). So the final code (without writing the ~/.gtkrc-2.0
) is now:
import gtk
import webkit
gtk.rc_parse_string("""style "hide-scrollbar-style"
{
GtkScrollbar::slider_width = 0
GtkScrollbar::min-slider-length = 0
GtkScrollbar::activate_slider = 0
GtkScrollbar::trough_border = 0
GtkScrollbar::has-forward-stepper = 0
GtkScrollbar::has-backward-stepper = 0
GtkScrollbar::stepper_size = 0
GtkScrollbar::stepper_spacing = 0
GtkScrollbar::trough-side-details = 0
GtkScrollbar::default_border = { 0, 0, 0, 0 }
GtkScrollbar::default_outside_border = { 0, 0, 0, 0 }
GtkScrolledWindow::scrollbar-spacing = 0
GtkScrolledWindow::scrollbar-within-bevel = False
}
widget_class "*Scrollbar" style "hide-scrollbar-style"
widget_class "*ScrolledWindow" style "hide-scrollbar-style"
""")
view = webkit.WebView()
sw = gtk.ScrolledWindow()
sw.add(view)
sw.set_policy(gtk.POLICY_ALWAYS, gtk.POLICY_ALWAYS)
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.add(sw)
win.set_default_size(200, 200)
win.show_all()
view.open("http://www.blackle.com/")
gtk.main()
Although not elegant, this works for me since I do not care about scrollbars throughout the X session.