From 616fa74051181a8278351f58f86bf104a49b80df Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Mon, 10 Mar 2008 08:18:39 +0000 Subject: [PATCH] Add timeout items to the StatusBar. These items will disappear after N seconds. Add warning items to the StatusBar. Show warning when trying to resume a torrent past the stop share ratio. --- TODO | 1 - deluge/core/torrent.py | 2 ++ deluge/ui/gtkui/signals.py | 10 +++++++++- deluge/ui/gtkui/statusbar.py | 27 +++++++++++++++++++++++++-- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index 3bcfaf067..d61ca8b86 100644 --- a/TODO +++ b/TODO @@ -7,7 +7,6 @@ * Implement 'Classic' mode * Add autoload folder * Add wizard -* Add decay items to statusbar.. items that will disappear after X seconds * Add command line option to change config dir.. --config * Add method for plugins to add labels * Add context menus for labels.. ie. setting options for all torrents in label diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index c5a3dda86..8ff80fffd 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -53,6 +53,7 @@ class Torrent: # Get a reference to the TorrentQueue self.torrentqueue = component.get("TorrentQueue") + self.signals = component.get("SignalManager") # Set the filename self.filename = filename @@ -323,6 +324,7 @@ class Torrent: # If the torrent has already reached it's 'stop_seed_ratio' then do not do anything if self.config["stop_seed_at_ratio"]: if self.get_ratio() >= self.config["stop_seed_ratio"]: + self.signals.emit("torrent_resume_at_stop_ratio") return # If the torrent is a seed and there are already the max number of seeds diff --git a/deluge/ui/gtkui/signals.py b/deluge/ui/gtkui/signals.py index 27bd01d36..2da59af85 100644 --- a/deluge/ui/gtkui/signals.py +++ b/deluge/ui/gtkui/signals.py @@ -31,6 +31,8 @@ # this exception statement from your version. If you delete this exception # statement from all source files in the program, then also delete it here. +import gtk + import deluge.component as component from deluge.ui.client import aclient as client from deluge.ui.signalreceiver import SignalReceiver @@ -61,6 +63,8 @@ class Signals(component.Component): self.config_value_changed) self.receiver.connect_to_signal("torrent_queue_changed", self.torrent_queue_changed) + self.receiver.connect_to_signal("torrent_resume_at_stop_ratio", + self.torrent_resume_at_stop_ratio) def stop(self): try: @@ -114,4 +118,8 @@ class Signals(component.Component): def torrent_queue_changed(self): log.debug("torrent_queue_changed signal received..") component.get("TorrentView").update() - + + def torrent_resume_at_stop_ratio(self): + log.debug("torrent_resume_at_stop_ratio") + component.get("StatusBar").display_warning( + text=_("Torrent is past stop ratio.")) diff --git a/deluge/ui/gtkui/statusbar.py b/deluge/ui/gtkui/statusbar.py index cc98674ea..70ca5f80a 100644 --- a/deluge/ui/gtkui/statusbar.py +++ b/deluge/ui/gtkui/statusbar.py @@ -32,6 +32,7 @@ # statement from all source files in the program, then also delete it here. import gtk +import gobject import deluge.component as component import deluge.common @@ -91,6 +92,9 @@ class StatusBarItem: def get_eventbox(self): return self._ebox + + def get_text(self): + return self._label.get_text() class StatusBar(component.Component): def __init__(self): @@ -116,6 +120,7 @@ class StatusBar(component.Component): "max_upload_speed": self._on_max_upload_speed, "dht": self._on_dht } + self.current_warnings = [] # Add a HBox to the statusbar after removing the initial label widget self.hbox = gtk.HBox() self.hbox.set_spacing(10) @@ -150,7 +155,7 @@ class StatusBar(component.Component): self.dht_item = StatusBarItem( image=deluge.common.get_pixmap("dht16.png")) self.health_item = self.add_item( - stock=gtk.STOCK_NO, + stock=gtk.STOCK_DIALOG_ERROR, text=_("No Incoming Connections!"), callback=self._on_health_icon_clicked) @@ -199,7 +204,25 @@ class StatusBar(component.Component): self.hbox.remove(item.get_eventbox()) except Exception, e: log.debug("Unable to remove widget: %s", e) - + + def add_timeout_item(self, seconds=3, image=None, stock=None, text=None, callback=None): + """Adds an item to the StatusBar for seconds""" + item = self.add_item(image, stock, text, callback) + # Start a timer to remove this item in seconds + gobject.timeout_add(seconds * 1000, self.remove_item, item) + + def display_warning(self, text, callback=None): + """Displays a warning to the user in the status bar""" + if text not in self.current_warnings: + item = self.add_item( + stock=gtk.STOCK_DIALOG_WARNING, text=text, callback=callback) + self.current_warnings.append(text) + gobject.timeout_add(3000, self.remove_warning, item) + + def remove_warning(self, item): + self.current_warnings.remove(item.get_text()) + self.remove_item(item) + def clear_statusbar(self): def remove(child): self.hbox.remove(child)