Clean up StatusBar and use new StatusBarItems.

This commit is contained in:
Andrew Resch 2007-11-19 07:33:43 +00:00
parent de2e230e4f
commit d8680af277
2 changed files with 28 additions and 34 deletions

View File

@ -84,9 +84,8 @@ class QueuedTorrents(component.Component):
self.on_button_add_clicked(None)
return
# Make sure status bar info is showing
self.status_item = None
self.update_status_bar()
# We only want the add button sensitive if we're connected to a host
self.glade.get_widget("button_add").set_sensitive(True)
self.run()

View File

@ -43,6 +43,7 @@ class StatusBarItem:
self._widgets = []
self._ebox = gtk.EventBox()
self._hbox = gtk.HBox()
self._hbox.set_spacing(5)
self._image = gtk.Image()
self._label = gtk.Label()
self._hbox.add(self._image)
@ -101,45 +102,39 @@ class StatusBar(component.Component):
frame = self.statusbar.get_children()[0]
frame.remove(frame.get_children()[0])
frame.add(self.hbox)
self.statusbar.show_all()
# Show the not connected status bar
self.show_not_connected()
def start(self):
log.debug("StatusBar start..")
# Add in images and labels
self.clear_statusbar()
image = gtk.Image()
image.set_from_stock(gtk.STOCK_NETWORK, gtk.ICON_SIZE_MENU)
self.hbox.pack_start(image, expand=False, fill=False)
self.label_connections = gtk.Label()
self.hbox.pack_start(self.label_connections, expand=False, fill=False)
image = gtk.Image()
image.set_from_file(deluge.common.get_pixmap("downloading16.png"))
self.hbox.pack_start(image, expand=False, fill=False)
self.label_download_speed = gtk.Label()
self.hbox.pack_start(self.label_download_speed,
expand=False, fill=False)
image = gtk.Image()
image.set_from_file(deluge.common.get_pixmap("seeding16.png"))
self.hbox.pack_start(image, expand=False, fill=False)
self.label_upload_speed = gtk.Label()
self.hbox.pack_start(self.label_upload_speed,
expand=False, fill=False)
self.statusbar.show_all()
self.remove_item(self.not_connected_item)
self.connections_item = StatusBarItem(
stock=gtk.STOCK_NETWORK)
self.hbox.pack_start(
self.connections_item.get_eventbox(), expand=False, fill=False)
self.download_item = StatusBarItem(
image=deluge.common.get_pixmap("downloading16.png"))
self.hbox.pack_start(
self.download_item.get_eventbox(), expand=False, fill=False)
self.upload_item = StatusBarItem(
image=deluge.common.get_pixmap("seeding16.png"))
self.hbox.pack_start(
self.upload_item.get_eventbox(), expand=False, fill=False)
def stop(self):
# When stopped, we just show the not connected thingy
self.remove_item(self.connections_item)
self.remove_item(self.download_item)
self.remove_item(self.upload_item)
self.show_not_connected()
def show_not_connected(self):
self.clear_statusbar()
image = gtk.Image()
image.set_from_stock(gtk.STOCK_STOP, gtk.ICON_SIZE_MENU)
self.hbox.pack_start(image, expand=False, fill=False)
label = gtk.Label(_("Not Connected"))
self.hbox.pack_start(label, expand=False, fill=False)
self.statusbar.show_all()
self.not_connected_item = StatusBarItem(
stock=gtk.STOCK_STOP, text=_("Not Connected"))
self.hbox.pack_start(
self.not_connected_item.get_eventbox(), expand=False, fill=False)
def add_item(self, image=None, stock=None, text=None, callback=None):
"""Adds an item to the status bar"""
@ -166,7 +161,7 @@ class StatusBar(component.Component):
if max_connections < 0:
max_connections = _("Unlimited")
self.label_connections.set_text("%s (%s)" % (
self.connections_item.set_text("%s (%s)" % (
client.get_num_connections(), max_connections))
# Set the download speed label
@ -176,7 +171,7 @@ class StatusBar(component.Component):
else:
max_download_speed = "%s %s" % (max_download_speed, _("KiB/s"))
self.label_download_speed.set_text("%s/s (%s)" % (
self.download_item.set_text("%s/s (%s)" % (
deluge.common.fsize(client.get_download_rate()),
max_download_speed))
@ -187,7 +182,7 @@ class StatusBar(component.Component):
else:
max_upload_speed = "%s %s" % (max_upload_speed, _("KiB/s"))
self.label_upload_speed.set_text("%s/s (%s)" % (
self.upload_item.set_text("%s/s (%s)" % (
deluge.common.fsize(client.get_upload_rate()),
max_upload_speed))