Get basic functionalities back to work.

This commit is contained in:
Marco Pesenti Gritti 2006-10-13 11:05:47 +02:00
parent c566726f46
commit f1778669ba
3 changed files with 85 additions and 22 deletions

View File

@ -1,37 +1,79 @@
import gtk import gtk
from _sugar import AddressEntry
class Toolbar(gtk.Toolbar): class Toolbar(gtk.Toolbar):
def __init__(self): def __init__(self, embed):
gtk.Toolbar.__init__(self) gtk.Toolbar.__init__(self)
self.set_style(gtk.TOOLBAR_BOTH_HORIZ) self.set_style(gtk.TOOLBAR_BOTH_HORIZ)
self._insert_spring() self._insert_spring()
self.back = gtk.ToolButton(None, _('Back')) self._back = gtk.ToolButton()
self.back.set_icon_name('stock-back') self._back.props.sensitive = False
self.back.connect("clicked", self.__go_back_cb) self._back.set_icon_name('stock-back')
self.insert(self.back, -1) self._back.connect("clicked", self._go_back_cb)
self.back.show() self.insert(self._back, -1)
self._back.show()
self.forward = gtk.ToolButton(None, _('Forward')) self._forward = gtk.ToolButton()
self.forward.set_icon_name('stock-forward') self._forward.props.sensitive = False
self.forward.connect("clicked", self.__go_forward_cb) self._forward.set_icon_name('stock-forward')
self.insert(self.forward, -1) self._forward.connect("clicked", self._go_forward_cb)
self.forward.show() self.insert(self._forward, -1)
self._forward.show()
separator = gtk.SeparatorToolItem() separator = gtk.SeparatorToolItem()
separator.set_draw(False) separator.set_draw(False)
self.insert(separator, -1) self.insert(separator, -1)
separator.show() separator.show()
self._address_item = AddressItem() address_item = gtk.ToolItem()
self._address_item.connect('open-address', self.__open_address_cb)
self.insert(self._address_item, -1) self._entry = AddressEntry()
self._address_item.show() 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._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): def _insert_spring(self):
separator = gtk.SeparatorToolItem() separator = gtk.SeparatorToolItem()
separator.set_draw(False) separator.set_draw(False)

View File

@ -1,5 +1,8 @@
import gtk
from sugar.activity.Activity import Activity from sugar.activity.Activity import Activity
from webbrowser import WebBrowser from webbrowser import WebBrowser
from toolbar import Toolbar
_HOMEPAGE = 'http://www.google.com' _HOMEPAGE = 'http://www.google.com'
@ -7,8 +10,18 @@ class WebActivity(Activity):
def __init__(self): def __init__(self):
Activity.__init__(self) Activity.__init__(self)
vbox = gtk.VBox()
self._browser = WebBrowser() 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._browser.show()
self.add(vbox)
vbox.show()
self._browser.load_url(_HOMEPAGE) self._browser.load_url(_HOMEPAGE)

View File

@ -132,12 +132,20 @@ static void
update_navigation_properties(SugarBrowser *browser) update_navigation_properties(SugarBrowser *browser)
{ {
GtkMozEmbed *embed = GTK_MOZ_EMBED(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); can_go_back = gtk_moz_embed_can_go_back(embed);
g_object_notify (G_OBJECT(browser), "can_go_back"); 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); can_go_forward = gtk_moz_embed_can_go_forward(embed);
g_object_notify (G_OBJECT(browser), "can_go_forward"); 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 static void
@ -172,8 +180,6 @@ net_state_cb(GtkMozEmbed *embed, const char *aURI, gint state, guint status)
browser->current_requests = 0; browser->current_requests = 0;
browser->progress = 0.0; browser->progress = 0.0;
} }
update_navigation_properties(browser);
} }
if (state & GTK_MOZ_EMBED_FLAG_IS_REQUEST) { if (state & GTK_MOZ_EMBED_FLAG_IS_REQUEST) {
@ -215,6 +221,8 @@ location_cb(GtkMozEmbed *embed)
browser->address = gtk_moz_embed_get_location(embed); browser->address = gtk_moz_embed_get_location(embed);
g_object_notify (G_OBJECT(browser), "address"); g_object_notify (G_OBJECT(browser), "address");
update_navigation_properties(browser);
} }
static void static void