Improve the torrent status string.
This commit is contained in:
parent
dcede9acd3
commit
38e1b61c60
|
@ -20,6 +20,7 @@
|
|||
#
|
||||
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
try:
|
||||
from evas import EVAS_ASPECT_CONTROL_VERTICAL
|
||||
|
@ -44,13 +45,15 @@ from TorrentInfo import TorrentInfo
|
|||
from Preferences import Preferences
|
||||
from Notify import ConfirmExit
|
||||
|
||||
from intrepr import intrepr
|
||||
|
||||
class TorrentClass(GenlistItemClass):
|
||||
|
||||
def text_get(self, obj, part, item_data):
|
||||
state_str = ['Queued', 'Checking', 'Downloading metadata', \
|
||||
'Downloading', 'Finished', 'Seeding', 'Allocating', \
|
||||
'Checking resume data']
|
||||
state_str = ['Queued', 'Checking', 'Downloading metadata', \
|
||||
'Downloading', 'Finished', 'Seeding', 'Allocating', \
|
||||
'Checking resume data']
|
||||
|
||||
def text_get(self, obj, part, item_data):
|
||||
h = item_data
|
||||
name = h.get_torrent_info().name() if h.has_metadata() else "-"
|
||||
|
||||
|
@ -60,11 +63,12 @@ class TorrentClass(GenlistItemClass):
|
|||
)
|
||||
elif part == "elm.text.sub":
|
||||
s = h.status()
|
||||
return '%s - %.2f%% complete (down: %.1f kB/s up: %.1f kB/s peers: %d)' % (
|
||||
state_str[s.state],
|
||||
s.progress * 100,
|
||||
s.download_payload_rate / 1000,
|
||||
s.upload_payload_rate / 1000,
|
||||
|
||||
return '{:.0%} complete, ETA: {} (Down: {}/s Up: {}/s Peers: {})'.format(
|
||||
s.progress,
|
||||
timedelta(seconds=self.get_eta(h)),
|
||||
intrepr(s.download_payload_rate, precision=0),
|
||||
intrepr(s.upload_payload_rate, precision=0),
|
||||
s.num_peers
|
||||
)
|
||||
|
||||
|
@ -75,16 +79,35 @@ class TorrentClass(GenlistItemClass):
|
|||
ic = Icon(obj)
|
||||
if h.is_paused():
|
||||
ic.standard = "player_pause"
|
||||
ic.tooltip_text_set("Paused")
|
||||
elif h.is_seed():
|
||||
ic.standard = "player_play"
|
||||
ic.tooltip_text_set("Seeding")
|
||||
else:
|
||||
ic.standard = "player_record"
|
||||
ic.tooltip_text_set("Downloading")
|
||||
ic.tooltip_text_set(self.state_str[s.state])
|
||||
ic.size_hint_aspect_set(EVAS_ASPECT_CONTROL_VERTICAL, 1, 1)
|
||||
return ic
|
||||
|
||||
def get_eta(self, h):
|
||||
s = h.status()
|
||||
if False: #self.is_finished and self.options["stop_at_ratio"]:
|
||||
# We're a seed, so calculate the time to the 'stop_share_ratio'
|
||||
if not s.upload_payload_rate:
|
||||
return 0
|
||||
stop_ratio = self.options["stop_ratio"]
|
||||
return ((s.all_time_download * stop_ratio) - s.all_time_upload) / s.upload_payload_rate
|
||||
|
||||
left = s.total_wanted - s.total_wanted_done
|
||||
|
||||
if left <= 0 or s.download_payload_rate == 0:
|
||||
return 0
|
||||
|
||||
try:
|
||||
eta = left / s.download_payload_rate
|
||||
except ZeroDivisionError:
|
||||
eta = 0
|
||||
|
||||
return eta
|
||||
|
||||
class MainInterface(object):
|
||||
def __init__(self, parent):
|
||||
self.parent = parent
|
||||
|
@ -109,8 +132,11 @@ class MainInterface(object):
|
|||
|
||||
s = parent.session.status()
|
||||
status = self.status = Label(self.win)
|
||||
status.text_set("down: %.1f kB/s up: %.1f kB/s peers: %d" % \
|
||||
(s.payload_download_rate, s.payload_upload_rate, s.num_peers))
|
||||
status.text = "down: {0}/s up: {1}/s peers: {2}".format(
|
||||
intrepr(s.payload_download_rate),
|
||||
intrepr(s.payload_upload_rate),
|
||||
s.num_peers
|
||||
)
|
||||
box.pack_end(status)
|
||||
status.show()
|
||||
|
||||
|
@ -147,11 +173,11 @@ class MainInterface(object):
|
|||
v.fields_update("elm.text", ELM_GENLIST_ITEM_FIELD_TEXT)
|
||||
v.fields_update("elm.text.sub", ELM_GENLIST_ITEM_FIELD_TEXT)
|
||||
s = session.status()
|
||||
self.status.text_set("down: %.1f kB/s up: %.1f kB/s peers: %d" % (
|
||||
s.payload_download_rate / 1000,
|
||||
s.payload_upload_rate / 1000,
|
||||
self.status.text = "down: {0}/s up: {1}/s peers: {2}".format(
|
||||
intrepr(s.payload_download_rate),
|
||||
intrepr(s.payload_upload_rate),
|
||||
s.num_peers
|
||||
))
|
||||
)
|
||||
|
||||
def update_icon(self, ihash):
|
||||
self.torrentitems[ihash].fields_update("elm.swallow.icon", ELM_GENLIST_ITEM_FIELD_CONTENT)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
def intrepr(size,precision=2):
|
||||
suffixes=['B','KiB','MiB','GiB','TiB']
|
||||
suffixIndex = 0
|
||||
while size > 1024:
|
||||
suffixIndex += 1
|
||||
size = size/1024.0
|
||||
return "%.*f %s"%(precision,size,suffixes[suffixIndex])
|
Loading…
Reference in New Issue