Rework toolbar to be more similar to the design. Cleanup code
This commit is contained in:
parent
af54df80ec
commit
c982879815
@ -1,64 +1,21 @@
|
|||||||
|
import gobject
|
||||||
import gtk
|
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):
|
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)
|
gtk.ToolItem.__init__(self)
|
||||||
|
|
||||||
address_entry = AddressEntry(callback)
|
entry = gtk.Entry()
|
||||||
self.add(address_entry)
|
width = int(gtk.gdk.screen_width() / 2)
|
||||||
address_entry.show()
|
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())
|
||||||
|
@ -28,6 +28,10 @@ class BrowserActivity(Activity):
|
|||||||
|
|
||||||
vbox = gtk.VBox()
|
vbox = gtk.VBox()
|
||||||
|
|
||||||
|
nav_toolbar = NavigationToolbar()
|
||||||
|
vbox.pack_start(nav_toolbar, False)
|
||||||
|
nav_toolbar.show()
|
||||||
|
|
||||||
self._notif_bar = NotificationBar()
|
self._notif_bar = NotificationBar()
|
||||||
vbox.pack_start(self._notif_bar, False)
|
vbox.pack_start(self._notif_bar, False)
|
||||||
self._notif_bar.connect('action', self.__notif_bar_action_cb)
|
self._notif_bar.connect('action', self.__notif_bar_action_cb)
|
||||||
@ -37,12 +41,9 @@ class BrowserActivity(Activity):
|
|||||||
vbox.pack_start(self._embed)
|
vbox.pack_start(self._embed)
|
||||||
self._embed.show()
|
self._embed.show()
|
||||||
|
|
||||||
|
nav_toolbar.set_embed(self._embed)
|
||||||
self._embed.load_url('http://www.google.com')
|
self._embed.load_url('http://www.google.com')
|
||||||
|
|
||||||
nav_toolbar = NavigationToolbar(self)
|
|
||||||
vbox.pack_start(nav_toolbar, False)
|
|
||||||
nav_toolbar.show()
|
|
||||||
|
|
||||||
self.add(vbox)
|
self.add(vbox)
|
||||||
vbox.show()
|
vbox.show()
|
||||||
|
|
||||||
|
@ -5,13 +5,13 @@ from gettext import gettext as _
|
|||||||
from AddressItem import AddressItem
|
from AddressItem import AddressItem
|
||||||
|
|
||||||
class NavigationToolbar(gtk.Toolbar):
|
class NavigationToolbar(gtk.Toolbar):
|
||||||
def __init__(self, browser):
|
def __init__(self):
|
||||||
gtk.Toolbar.__init__(self)
|
gtk.Toolbar.__init__(self)
|
||||||
self._browser = browser
|
|
||||||
self._embed = self._browser.get_embed()
|
|
||||||
|
|
||||||
self.set_style(gtk.TOOLBAR_BOTH_HORIZ)
|
self.set_style(gtk.TOOLBAR_BOTH_HORIZ)
|
||||||
|
|
||||||
|
self._insert_spring()
|
||||||
|
|
||||||
self.back = gtk.ToolButton(None, _('Back'))
|
self.back = gtk.ToolButton(None, _('Back'))
|
||||||
self.back.set_icon_name('back')
|
self.back.set_icon_name('back')
|
||||||
self.back.connect("clicked", self.__go_back_cb)
|
self.back.connect("clicked", self.__go_back_cb)
|
||||||
@ -25,16 +25,29 @@ class NavigationToolbar(gtk.Toolbar):
|
|||||||
self.forward.show()
|
self.forward.show()
|
||||||
|
|
||||||
separator = gtk.SeparatorToolItem()
|
separator = gtk.SeparatorToolItem()
|
||||||
|
separator.set_draw(False)
|
||||||
self.insert(separator, -1)
|
self.insert(separator, -1)
|
||||||
separator.show()
|
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)
|
self.insert(address_item, -1)
|
||||||
address_item.show()
|
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._embed.connect("location", self.__location_changed)
|
||||||
|
self._update_sensitivity()
|
||||||
|
|
||||||
def _update_sensitivity(self):
|
def _update_sensitivity(self):
|
||||||
self.back.set_sensitive(self._embed.can_go_back())
|
self.back.set_sensitive(self._embed.can_go_back())
|
||||||
@ -49,5 +62,5 @@ class NavigationToolbar(gtk.Toolbar):
|
|||||||
def __location_changed(self, embed):
|
def __location_changed(self, embed):
|
||||||
self._update_sensitivity()
|
self._update_sensitivity()
|
||||||
|
|
||||||
def __open_address_cb(self, address):
|
def __open_address_cb(self, item, address):
|
||||||
self._embed.load_url(address)
|
self._embed.load_url(address)
|
||||||
|
Loading…
Reference in New Issue
Block a user