Subversion Repositories basico

Rev

Rev 368 | Rev 372 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
340 t00mlabs 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
"""
4
# File: browser.py
5
# Author: Tomás Vírseda
6
# License: GPL v3
7
# Description: Web browser module
8
"""
9
 
10
import gi
11
gi.require_version('Gtk', '3.0')
12
 
371 t00mlabs 13
try:
14
    gi.require_version('WebKit', '4.0')
15
    from gi.repository import WebKit2 as WebKit
16
except:
17
    gi.require_version('WebKit', '3.0')
18
    from gi.repository import WebKit
19
 
340 t00mlabs 20
from gi.repository import Gtk
21
 
371 t00mlabs 22
 
364 t00mlabs 23
from basico.core.mod_wdg import BasicoWidget
340 t00mlabs 24
 
25
 
364 t00mlabs 26
class BasicoBrowser(BasicoWidget, Gtk.VBox):
27
    def __init__(self, app):
28
        # ~ def __init__(self, *args, **kwargs):
29
        super().__init__(app, __class__.__name__)
30
        # ~ super(BasicoBrowser, self).__init__(*args, **kwargs)
31
        Gtk.VBox.__init__(self)
32
        self.app = app
340 t00mlabs 33
        self.webview = WebKit.WebView()
34
 
35
        settings = self.webview.get_settings()
367 t00mlabs 36
        settings.set_property('enable-developer-extras', False)
368 t00mlabs 37
        settings.set_property('enable-default-context-menu', True)
340 t00mlabs 38
        settings.set_property('default-encoding', 'utf-8')
367 t00mlabs 39
        settings.set_property('enable-private-browsing', False)
368 t00mlabs 40
        settings.set_property('enable-html5-local-storage', True)
340 t00mlabs 41
 
42
        # disable plugins, like Adobe Flash and Java
43
        settings.set_property('enable-plugins', True)
44
 
45
        # scale other content besides from text as well
46
        self.webview.set_full_content_zoom(True)
47
 
48
        self.show()
49
        scrolled_window = Gtk.ScrolledWindow()
50
        scrolled_window.add(self.webview)
51
        scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
364 t00mlabs 52
        scrolled_window.set_shadow_type(Gtk.ShadowType.IN)
340 t00mlabs 53
        scrolled_window.set_hexpand(True)
54
        scrolled_window.set_vexpand(True)
55
        self.pack_start(scrolled_window, True, True, 0)
56
        scrolled_window.show_all()
57
 
58
 
59
    def load_url(self, url):
60
        self.webview.load_uri(url)