Skip to content

Instantly share code, notes, and snippets.

@asmedrano
Created October 8, 2012 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asmedrano/3853932 to your computer and use it in GitHub Desktop.
Save asmedrano/3853932 to your computer and use it in GitHub Desktop.
Setting up a WebView for Ubuntu App Dev
import gettext
import os
from gettext import gettext as _
gettext.textdomain('html5test')
from gi.repository import Gtk, WebKit # pylint: disable=E0611
import logging
logger = logging.getLogger('html5test')
from html5test_lib import Window
from html5test.AboutHtml5testDialog import AboutHtml5testDialog
from html5test.PreferencesHtml5testDialog import PreferencesHtml5testDialog
# See html5test_lib.Window.py for more details about how this class works
class Html5testWindow(Window):
__gtype_name__ = "Html5testWindow"
def finish_initializing(self, builder): # pylint: disable=E1002
"""Set up the main window"""
super(Html5testWindow, self).finish_initializing(builder)
self.AboutDialog = AboutHtml5testDialog
self.PreferencesDialog = PreferencesHtml5testDialog
# Code for other initialization actions should be added here.
self.vbox = self.builder.get_object('vbox-main')
self.webview = WebKit.WebView()
self.vbox.add(self.webview)
self.webview.show()
self.webview.set_size_request(500,500)
html_string = '<!doctype html><html lang="en"><head><meta charset="utf-8"><link rel="stylesheet" href="data/htmlassets/styles.css"></head><title></title><body><h1>Hi!</h1></body></html>'
root_web_dir = os.path.dirname(os.path.dirname(__file__)) # relative path for all files your html loads
root_web_dir = "file://%s/" % root_web_dir
self.webview.load_html_string(html_string, root_web_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment