Rework toolbar to be more similar to the design. Cleanup code

This commit is contained in:
Marco Pesenti Gritti 2006-09-21 16:09:23 +02:00
parent af54df80ec
commit c982879815
3 changed files with 42 additions and 71 deletions

View File

@ -1,64 +1,21 @@
import gobject
import gtk
class AddressEntry(gtk.HBox):
def __init__(self, callback):
gtk.HBox.__init__(self)
self.callback = callback
self.folded = True
label = gtk.Label("Open")
self.pack_start(label, False)
label.show()
self.button = gtk.Button()
self.button.set_relief(gtk.RELIEF_NONE)
self.button.connect("clicked", self.__button_clicked_cb)
self.pack_start(self.button, False)
self.button.show()
self.entry = gtk.Entry()
self.entry.connect("activate", self.__activate_cb)
self.pack_start(self.entry, False)
self.entry.show()
self._update_folded_state()
def _update_folded_state(self):
if self.folded:
image = gtk.Image()
image.set_from_icon_name('expand', gtk.ICON_SIZE_SMALL_TOOLBAR)
self.button.set_image(image)
image.show()
self.entry.hide()
else:
image = gtk.Image()
image.set_from_icon_name('unexpand', gtk.ICON_SIZE_SMALL_TOOLBAR)
self.button.set_image(image)
image.show()
self.entry.show()
self.entry.grab_focus()
def get_folded(self):
return self.folded
def set_folded(self, folded):
self.folded = folded
self._update_folded_state()
def __button_clicked_cb(self, button):
self.set_folded(not self.get_folded())
def __activate_cb(self, entry):
self.callback(entry.get_text())
self.set_folded(True)
class AddressItem(gtk.ToolItem):
def __init__(self, callback):
__gsignals__ = {
'open-address': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([str])),
}
def __init__(self):
gtk.ToolItem.__init__(self)
address_entry = AddressEntry(callback)
self.add(address_entry)
address_entry.show()
entry = gtk.Entry()
width = int(gtk.gdk.screen_width() / 2)
entry.set_size_request(width, -1)
entry.connect("activate", self.__activate_cb)
self.add(entry)
entry.show()
def __activate_cb(self, entry):
self.emit('open-address', entry.get_text())

View File

@ -28,6 +28,10 @@ class BrowserActivity(Activity):
vbox = gtk.VBox()
nav_toolbar = NavigationToolbar()
vbox.pack_start(nav_toolbar, False)
nav_toolbar.show()
self._notif_bar = NotificationBar()
vbox.pack_start(self._notif_bar, False)
self._notif_bar.connect('action', self.__notif_bar_action_cb)
@ -37,12 +41,9 @@ class BrowserActivity(Activity):
vbox.pack_start(self._embed)
self._embed.show()
nav_toolbar.set_embed(self._embed)
self._embed.load_url('http://www.google.com')
nav_toolbar = NavigationToolbar(self)
vbox.pack_start(nav_toolbar, False)
nav_toolbar.show()
self.add(vbox)
vbox.show()

View File

@ -5,13 +5,13 @@ from gettext import gettext as _
from AddressItem import AddressItem
class NavigationToolbar(gtk.Toolbar):
def __init__(self, browser):
def __init__(self):
gtk.Toolbar.__init__(self)
self._browser = browser
self._embed = self._browser.get_embed()
self.set_style(gtk.TOOLBAR_BOTH_HORIZ)
self._insert_spring()
self.back = gtk.ToolButton(None, _('Back'))
self.back.set_icon_name('back')
self.back.connect("clicked", self.__go_back_cb)
@ -25,16 +25,29 @@ class NavigationToolbar(gtk.Toolbar):
self.forward.show()
separator = gtk.SeparatorToolItem()
separator.set_draw(False)
self.insert(separator, -1)
separator.show()
address_item = AddressItem(self.__open_address_cb)
address_item = AddressItem()
address_item.connect('open-address', self.__open_address_cb)
self.insert(address_item, -1)
address_item.show()
self._update_sensitivity()
self._insert_spring()
def _insert_spring(self):
separator = gtk.SeparatorToolItem()
separator.set_draw(False)
separator.set_expand(True)
self.insert(separator, -1)
separator.show()
def set_embed(self, embed):
self._embed = embed
self._embed.connect("location", self.__location_changed)
self._update_sensitivity()
def _update_sensitivity(self):
self.back.set_sensitive(self._embed.can_go_back())
@ -49,5 +62,5 @@ class NavigationToolbar(gtk.Toolbar):
def __location_changed(self, embed):
self._update_sensitivity()
def __open_address_cb(self, address):
def __open_address_cb(self, item, address):
self._embed.load_url(address)