Mini Browser
Use left and right arrow keys to navigate
from gi.repository import Gtk
from gi.repository import WebKit
def toolbutton_factory(stock, label, callback):
button = Gtk.ToolButton.new_from_stock(stock)
button.connect('clicked', callback)
button.set_tooltip_text(label)
button.show()
return button
class Window(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.connect('destroy', Gtk.main_quit)
self.set_title('Web Browser')
toolbar = Gtk.Toolbar()
webview = WebKit.WebView()
entry = Gtk.Entry()
buttons = [(
Gtk.STOCK_GO_BACK, 'Back', lambda w: webview.go_back()),
(Gtk.STOCK_GO_FORWARD, 'Forward', lambda w: webview.go_forward()),
(Gtk.STOCK_REFRESH, 'Refresh', lambda w: webview.reload()),
(Gtk.STOCK_OK, 'Load', lambda w: webview.load_uri(entry.get_text()))]
for stock, label, callback in buttons[:3]:
button = toolbutton_factory(stock, label, callback)
toolbar.insert(button, -1)
item = Gtk.ToolItem()
item.set_expand(True)
entry.show()
item.add(entry)
item.show()
toolbar.insert(item, -1)
stock, label, callback = buttons[-1]
button = toolbutton_factory(stock, label, callback)
toolbar.insert(button, -1)
toolbar.show()
webview.connect('load-finished', lambda w, x: entry.set_text(w.get_uri()))
entry.connect('activate', lambda w: webview.load_uri(w.get_text()))
webview.load_uri('http://www.google.com/')
webview.show()
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
box.pack_start(toolbar, True, False, 0)
box.pack_start(webview, True, True, 0)
box.show()
self.add(box)
self.show()
Window()
Gtk.main()
from sugar3.activity import activity
from sugar3.graphics.toolbutton import ToolButton
from sugar3.graphics.toolbarbox import ToolbarBox
from sugar3.activity.widgets import ActivityToolbarButton
from sugar3.activity.widgets import StopButton
activity.Activity
activity.Activity
, handler
, handler
toolbarbox = ToolbarBox()
toolbarbox.toolbar
activitybutton = ActivityToolbarButton(self)
activitybutton.show()
toolbar.insert(activitybutton, -1)
'go-left'
'go-right'
'view-refresh'
'dialog-ok'
box
stopbtn = StopButton(self)
stopbtn.show()
toolbar.insert(stopbtn, -1)
self.set_toolbar_box(toolbarbox)
self.set_canvas(webview)