0

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?

mihalop
  • 138
  • 1
  • 7
  • Could the scrollbars be coming from the WebView, rather than the Scrolled Window? Have a look at the [WebKitGTK+ Reference: Self-Scrolling](http://webkitgtk.org/reference/webkitgtk/stable/webkitgtk-webkitwebview.html#WebKitWebView--self-scrolling). Although, it does say that this is `False` by default – SiHa Jul 18 '14 at 18:17
  • 1
    WebKit allows the page being displayed to override the scrollbar policy you set on the scrolled window. It's discussed [here](https://bugs.webkit.org/show_bug.cgi?id=36697) - it's not intuitive at first, but they explain it there. – ptomato Jul 22 '14 at 01:40
  • @ptomato tried adding the following, but it did not work as advertised: `def sig_handler(*args): return True frame = view.get_main_frame() handler_id = frame.connect('scrollbars-policy-changed', sig_handler)` It is nice to know though that this is webkit behavior and not generic gtk. – mihalop Aug 04 '14 at 08:58

3 Answers3

0

ok here's the thing. You don't want a scrollbar but you construct a Gtk.ScrolledWindow to be the container of WebKit.WebView. If you don't want a scrollbar, just put inside a container that doesn't implement a Gtk.Scrollable, say Gtk.Grid. It will not showing scrollbar at all. Few downsides:

  1. your main window will not down size beyond it's content minimum width and height.
  2. if your view content change size, and it will (unless you restrict every last detail on how your view will be displayed), the window will follow the current size as well
  3. in WebKit.WebView widget, there is no such thing as Gtk.Widget.set_size_request, it will still follow its content. By the way, Gtk.Widget.set_default_size () does not create a fix size for a widget, only set the size when first time it is shown.
luciomrx
  • 1,165
  • 1
  • 7
  • 7
  • 1. that is exactly what I need, to cut-off content that does not fit the webview, 2. the view must remain at a fixed geometry, 3. if scrollbars are enabled, the windows does not get resized, so the initial default size seems to work ok for me – mihalop Aug 04 '14 at 09:36
0

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.

mihalop
  • 138
  • 1
  • 7
0

The following works for me

class PREview(object):
    def __init__(self, project_directory):
        # Make the HTML viewable area
        self.wv = webkit.WebView()
        self.wf = self.wv.get_main_frame()
        self.wf.connect("scrollbars-policy-changed", self.on_webkit_webframe_scrollbars_policy_changed)

def on_webkit_webframe_scrollbars_policy_changed(self, widget):
    return True # to stop propagation

and then in the main program ...

self.out_scroll = gtk.ScrolledWindow()
self.out_scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
self.PV = PREview(self)
self.out_scroll.add(self.PV.wv)