Get basic functionalities back to work.
This commit is contained in:
parent
c566726f46
commit
f1778669ba
@ -1,37 +1,79 @@
|
||||
import gtk
|
||||
|
||||
from _sugar import AddressEntry
|
||||
|
||||
class Toolbar(gtk.Toolbar):
|
||||
def __init__(self):
|
||||
def __init__(self, embed):
|
||||
gtk.Toolbar.__init__(self)
|
||||
|
||||
self.set_style(gtk.TOOLBAR_BOTH_HORIZ)
|
||||
|
||||
self._insert_spring()
|
||||
|
||||
self.back = gtk.ToolButton(None, _('Back'))
|
||||
self.back.set_icon_name('stock-back')
|
||||
self.back.connect("clicked", self.__go_back_cb)
|
||||
self.insert(self.back, -1)
|
||||
self.back.show()
|
||||
self._back = gtk.ToolButton()
|
||||
self._back.props.sensitive = False
|
||||
self._back.set_icon_name('stock-back')
|
||||
self._back.connect("clicked", self._go_back_cb)
|
||||
self.insert(self._back, -1)
|
||||
self._back.show()
|
||||
|
||||
self.forward = gtk.ToolButton(None, _('Forward'))
|
||||
self.forward.set_icon_name('stock-forward')
|
||||
self.forward.connect("clicked", self.__go_forward_cb)
|
||||
self.insert(self.forward, -1)
|
||||
self.forward.show()
|
||||
self._forward = gtk.ToolButton()
|
||||
self._forward.props.sensitive = False
|
||||
self._forward.set_icon_name('stock-forward')
|
||||
self._forward.connect("clicked", self._go_forward_cb)
|
||||
self.insert(self._forward, -1)
|
||||
self._forward.show()
|
||||
|
||||
separator = gtk.SeparatorToolItem()
|
||||
separator.set_draw(False)
|
||||
self.insert(separator, -1)
|
||||
separator.show()
|
||||
|
||||
self._address_item = AddressItem()
|
||||
self._address_item.connect('open-address', self.__open_address_cb)
|
||||
self.insert(self._address_item, -1)
|
||||
self._address_item.show()
|
||||
address_item = gtk.ToolItem()
|
||||
|
||||
self._entry = AddressEntry()
|
||||
self._entry.connect("activate", self._entry_activate_cb)
|
||||
|
||||
width = int(gtk.gdk.screen_width() / 3 * 2)
|
||||
self._entry.set_size_request(width, -1)
|
||||
|
||||
address_item.add(self._entry)
|
||||
self._entry.show()
|
||||
|
||||
self.insert(address_item, -1)
|
||||
address_item.show()
|
||||
|
||||
self._insert_spring()
|
||||
|
||||
self._embed = embed
|
||||
self._embed.connect("notify::progress", self._progress_changed_cb)
|
||||
self._embed.connect("notify::address", self._address_changed_cb)
|
||||
self._embed.connect("notify::can-go-back",
|
||||
self._can_go_back_changed_cb)
|
||||
self._embed.connect("notify::can-go-forward",
|
||||
self._can_go_forward_changed_cb)
|
||||
|
||||
def _progress_changed_cb(self, embed, spec):
|
||||
self._entry.props.progress = embed.props.progress
|
||||
|
||||
def _address_changed_cb(self, embed, spec):
|
||||
self._entry.set_text(embed.props.address)
|
||||
|
||||
def _can_go_back_changed_cb(self, embed, spec):
|
||||
self._back.props.sensitive = embed.props.can_go_back
|
||||
|
||||
def _can_go_forward_changed_cb(self, embed, spec):
|
||||
self._forward.props.sensitive = embed.props.can_go_forward
|
||||
|
||||
def _entry_activate_cb(self, entry):
|
||||
self._embed.load_url(entry.get_text())
|
||||
|
||||
def _go_back_cb(self, button):
|
||||
self._embed.go_back()
|
||||
|
||||
def _go_forward_cb(self, button):
|
||||
self._embed.go_forward()
|
||||
|
||||
def _insert_spring(self):
|
||||
separator = gtk.SeparatorToolItem()
|
||||
separator.set_draw(False)
|
||||
|
@ -1,5 +1,8 @@
|
||||
import gtk
|
||||
|
||||
from sugar.activity.Activity import Activity
|
||||
from webbrowser import WebBrowser
|
||||
from toolbar import Toolbar
|
||||
|
||||
_HOMEPAGE = 'http://www.google.com'
|
||||
|
||||
@ -7,8 +10,18 @@ class WebActivity(Activity):
|
||||
def __init__(self):
|
||||
Activity.__init__(self)
|
||||
|
||||
vbox = gtk.VBox()
|
||||
|
||||
self._browser = WebBrowser()
|
||||
self.add(self._browser)
|
||||
|
||||
toolbar = Toolbar(self._browser)
|
||||
vbox.pack_start(toolbar, False)
|
||||
toolbar.show()
|
||||
|
||||
vbox.pack_start(self._browser)
|
||||
self._browser.show()
|
||||
|
||||
self.add(vbox)
|
||||
vbox.show()
|
||||
|
||||
self._browser.load_url(_HOMEPAGE)
|
||||
|
@ -132,12 +132,20 @@ static void
|
||||
update_navigation_properties(SugarBrowser *browser)
|
||||
{
|
||||
GtkMozEmbed *embed = GTK_MOZ_EMBED(browser);
|
||||
gboolean can_go_back;
|
||||
gboolean can_go_forward;
|
||||
|
||||
browser->can_go_back = gtk_moz_embed_can_go_back(embed);
|
||||
g_object_notify (G_OBJECT(browser), "can_go_back");
|
||||
can_go_back = gtk_moz_embed_can_go_back(embed);
|
||||
if (can_go_back != browser->can_go_back) {
|
||||
browser->can_go_back = can_go_back;
|
||||
g_object_notify (G_OBJECT(browser), "can-go-back");
|
||||
}
|
||||
|
||||
browser->can_go_forward = gtk_moz_embed_can_go_forward(embed);
|
||||
g_object_notify (G_OBJECT(browser), "can_go_forward");
|
||||
can_go_forward = gtk_moz_embed_can_go_forward(embed);
|
||||
if (can_go_forward != browser->can_go_forward) {
|
||||
browser->can_go_forward = can_go_forward;
|
||||
g_object_notify (G_OBJECT(browser), "can-go-forward");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -172,8 +180,6 @@ net_state_cb(GtkMozEmbed *embed, const char *aURI, gint state, guint status)
|
||||
browser->current_requests = 0;
|
||||
browser->progress = 0.0;
|
||||
}
|
||||
|
||||
update_navigation_properties(browser);
|
||||
}
|
||||
|
||||
if (state & GTK_MOZ_EMBED_FLAG_IS_REQUEST) {
|
||||
@ -215,6 +221,8 @@ location_cb(GtkMozEmbed *embed)
|
||||
browser->address = gtk_moz_embed_get_location(embed);
|
||||
|
||||
g_object_notify (G_OBJECT(browser), "address");
|
||||
|
||||
update_navigation_properties(browser);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user