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.
This commit is contained in:
Andrew Resch 2008-03-10 08:18:39 +00:00
commit 616fa74051
4 changed files with 36 additions and 4 deletions

1
TODO
View file

@ -7,7 +7,6 @@
* Implement 'Classic' mode * Implement 'Classic' mode
* Add autoload folder * Add autoload folder
* Add wizard * Add wizard
* Add decay items to statusbar.. items that will disappear after X seconds
* Add command line option to change config dir.. --config * Add command line option to change config dir.. --config
* Add method for plugins to add labels * Add method for plugins to add labels
* Add context menus for labels.. ie. setting options for all torrents in label * Add context menus for labels.. ie. setting options for all torrents in label

View file

@ -53,6 +53,7 @@ class Torrent:
# Get a reference to the TorrentQueue # Get a reference to the TorrentQueue
self.torrentqueue = component.get("TorrentQueue") self.torrentqueue = component.get("TorrentQueue")
self.signals = component.get("SignalManager")
# Set the filename # Set the filename
self.filename = 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 the torrent has already reached it's 'stop_seed_ratio' then do not do anything
if self.config["stop_seed_at_ratio"]: if self.config["stop_seed_at_ratio"]:
if self.get_ratio() >= self.config["stop_seed_ratio"]: if self.get_ratio() >= self.config["stop_seed_ratio"]:
self.signals.emit("torrent_resume_at_stop_ratio")
return return
# If the torrent is a seed and there are already the max number of seeds # If the torrent is a seed and there are already the max number of seeds

View file

@ -31,6 +31,8 @@
# this exception statement from your version. If you delete this exception # this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here. # statement from all source files in the program, then also delete it here.
import gtk
import deluge.component as component import deluge.component as component
from deluge.ui.client import aclient as client from deluge.ui.client import aclient as client
from deluge.ui.signalreceiver import SignalReceiver from deluge.ui.signalreceiver import SignalReceiver
@ -61,6 +63,8 @@ class Signals(component.Component):
self.config_value_changed) self.config_value_changed)
self.receiver.connect_to_signal("torrent_queue_changed", self.receiver.connect_to_signal("torrent_queue_changed",
self.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): def stop(self):
try: try:
@ -114,4 +118,8 @@ class Signals(component.Component):
def torrent_queue_changed(self): def torrent_queue_changed(self):
log.debug("torrent_queue_changed signal received..") log.debug("torrent_queue_changed signal received..")
component.get("TorrentView").update() 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."))

View file

@ -32,6 +32,7 @@
# statement from all source files in the program, then also delete it here. # statement from all source files in the program, then also delete it here.
import gtk import gtk
import gobject
import deluge.component as component import deluge.component as component
import deluge.common import deluge.common
@ -91,6 +92,9 @@ class StatusBarItem:
def get_eventbox(self): def get_eventbox(self):
return self._ebox return self._ebox
def get_text(self):
return self._label.get_text()
class StatusBar(component.Component): class StatusBar(component.Component):
def __init__(self): def __init__(self):
@ -116,6 +120,7 @@ class StatusBar(component.Component):
"max_upload_speed": self._on_max_upload_speed, "max_upload_speed": self._on_max_upload_speed,
"dht": self._on_dht "dht": self._on_dht
} }
self.current_warnings = []
# Add a HBox to the statusbar after removing the initial label widget # Add a HBox to the statusbar after removing the initial label widget
self.hbox = gtk.HBox() self.hbox = gtk.HBox()
self.hbox.set_spacing(10) self.hbox.set_spacing(10)
@ -150,7 +155,7 @@ class StatusBar(component.Component):
self.dht_item = StatusBarItem( self.dht_item = StatusBarItem(
image=deluge.common.get_pixmap("dht16.png")) image=deluge.common.get_pixmap("dht16.png"))
self.health_item = self.add_item( self.health_item = self.add_item(
stock=gtk.STOCK_NO, stock=gtk.STOCK_DIALOG_ERROR,
text=_("No Incoming Connections!"), text=_("No Incoming Connections!"),
callback=self._on_health_icon_clicked) callback=self._on_health_icon_clicked)
@ -199,7 +204,25 @@ class StatusBar(component.Component):
self.hbox.remove(item.get_eventbox()) self.hbox.remove(item.get_eventbox())
except Exception, e: except Exception, e:
log.debug("Unable to remove widget: %s", 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 clear_statusbar(self):
def remove(child): def remove(child):
self.hbox.remove(child) self.hbox.remove(child)