[GTKUI] Move Tab data funcs to new common file

This commit is contained in:
Calum Lind 2016-10-27 23:01:56 +01:00
parent fab0af1b40
commit 5607bb3d61
5 changed files with 100 additions and 86 deletions

View File

@ -12,23 +12,12 @@ from xml.sax.saxutils import escape as xml_escape
import deluge.component as component
from deluge.common import fdate, fsize, is_url
from deluge.ui.gtkui.tab_data_funcs import fdate_or_dash, fpieces_num_size
from deluge.ui.gtkui.torrentdetails import Tab
log = logging.getLogger(__name__)
def fpieces_num_size(num_pieces, piece_size):
return "%s (%s)" % (num_pieces, fsize(piece_size, precision=0))
def fdate_or_dash(value):
"""Display value as date, eg 05/05/08 or dash"""
if value > 0.0:
return fdate(value)
else:
return "-"
class DetailsTab(Tab):
def __init__(self):
Tab.__init__(self)

View File

@ -17,8 +17,8 @@ import pango
import pangocairo
from cairo import FORMAT_ARGB32, Context, ImageSurface
import deluge.ui.gtkui.status_tab
from deluge.configmanager import ConfigManager
from deluge.ui.gtkui.tab_data_funcs import fpcnt
log = logging.getLogger(__name__)
@ -170,7 +170,7 @@ class PiecesBar(gtk.DrawingArea):
if self.__text:
text = self.__text
else:
text = deluge.ui.gtkui.status_tab.fpcnt(self.__fraction, self.__state, self.__message)
text = fpcnt(self.__fraction, self.__state, self.__message)
log.trace("PiecesBar text %r", text)
pl.set_text(text)

View File

@ -12,69 +12,16 @@ from __future__ import division
import logging
import deluge.component as component
from deluge.common import fdate, fpeer, fsize, fspeed, ftime
from deluge.common import fpeer
from deluge.configmanager import ConfigManager
from deluge.ui.gtkui.piecesbar import PiecesBar
from deluge.ui.gtkui.tab_data_funcs import (fdate_or_never, flast_active, fpcnt, fratio, fseed_rank_or_dash, fspeed_max,
ftime_or_dash, ftotal_sized)
from deluge.ui.gtkui.torrentdetails import Tab
log = logging.getLogger(__name__)
def ftotal_sized(first, second):
return "%s (%s)" % (fsize(first, shortform=True), fsize(second, shortform=True))
def fratio(value):
return ("%.3f" % value).rstrip('0').rstrip('.') if value > 0 else ""
def fpcnt(value, state, message):
textstr = _(state)
if state not in ("Error", "Seeding") and value < 100:
textstr = ('%s %.2f' % (textstr, value)).rstrip('0').rstrip('.') + '%'
elif state == "Error":
textstr = _("%s: %s") % (textstr, message)
return textstr
def fspeed_max(value, max_value=-1):
value = fspeed(value, shortform=True)
return "%s (%s %s)" % (value, max_value, _("K/s")) if max_value > -1 else value
def fdate_or_never(value):
"""Display value as date, eg 05/05/08 or Never"""
return fdate(value, date_only=True) if value > 0 else _("Never")
def ftime_or_dash(value):
"""Display value as time, eg 2h 30m or dash"""
return ftime(value) if value > 0 else "-"
def fseed_rank_or_dash(seed_rank, seeding_time):
"""Display value if seeding otherwise dash"""
if seeding_time > 0:
if seed_rank >= 1000:
return "%ik" % (seed_rank // 1000)
else:
return str(seed_rank)
else:
return "-"
def flast_active(time_since_download, time_since_upload):
"""The last time the torrent was active as time e.g. 2h 30m or dash"""
try:
last_time_since = min((x for x in (time_since_download, time_since_upload) if x != -1))
except ValueError:
return "-"
else:
return ftime(last_time_since)
class StatusTab(Tab):
def __init__(self):
Tab.__init__(self)

View File

@ -0,0 +1,92 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com>
#
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
#
from deluge.common import fdate, fsize, fspeed, ftime
def ftotal_sized(first, second):
return "%s (%s)" % (fsize(first, shortform=True), fsize(second, shortform=True))
def fratio(value):
return ("%.3f" % value).rstrip('0').rstrip('.') if value > 0 else ""
def fpcnt(value, state, message):
textstr = _(state)
if state not in ("Error", "Seeding") and value < 100:
textstr = ('%s %.2f' % (textstr, value)).rstrip('0').rstrip('.') + '%'
elif state == "Error":
textstr = _("%s: %s") % (textstr, message)
return textstr
def fspeed_max(value, max_value=-1):
value = fspeed(value, shortform=True)
return "%s (%s %s)" % (value, max_value, _("K/s")) if max_value > -1 else value
def fdate_or_never(value):
"""Display value as date, eg 05/05/08 or Never"""
return fdate(value, date_only=True) if value > 0 else _("Never")
def fdate_or_dash(value):
"""Display value as date, eg 05/05/08 or dash"""
if value > 0.0:
return fdate(value)
else:
return "-"
def ftime_or_dash(value):
"""Display value as time, eg 2h 30m or dash"""
return ftime(value) if value > 0 else "-"
def fseed_rank_or_dash(seed_rank, seeding_time):
"""Display value if seeding otherwise dash"""
if seeding_time > 0:
if seed_rank >= 1000:
return "%ik" % (seed_rank // 1000)
else:
return str(seed_rank)
else:
return "-"
def flast_active(time_since_download, time_since_upload):
"""The last time the torrent was active as time e.g. 2h 30m or dash"""
try:
last_time_since = min((x for x in (time_since_download, time_since_upload) if x != -1))
except ValueError:
return "-"
else:
return ftime(last_time_since)
def fpieces_num_size(num_pieces, piece_size):
return "%s (%s)" % (num_pieces, fsize(piece_size, precision=0))
def fcount(value):
return "%s" % len(value)
def ftranslate(text):
if text:
text = _(text)
return text
def fyes_no(value):
"""Return Yes or No to bool value"""
return _("Yes") if value else _("No")

View File

@ -11,26 +11,12 @@ import logging
import deluge.component as component
from deluge.common import ftime
from deluge.ui.gtkui.tab_data_funcs import fcount, ftranslate, fyes_no
from deluge.ui.gtkui.torrentdetails import Tab
log = logging.getLogger(__name__)
def fcount(value):
return "%s" % len(value)
def ftranslate(text):
if text:
text = _(text)
return text
def str_yes_no(value):
"""Return Yes or No to bool value"""
return _("Yes") if value else _("No")
class TrackersTab(Tab):
def __init__(self):
Tab.__init__(self)
@ -47,7 +33,7 @@ class TrackersTab(Tab):
(builder.get_object("summary_tracker"), None, ("tracker_host",)),
(builder.get_object("summary_tracker_status"), ftranslate, ("tracker_status",)),
(builder.get_object("summary_tracker_total"), fcount, ("trackers",)),
(builder.get_object("summary_private"), str_yes_no, ("private",)),
(builder.get_object("summary_private"), fyes_no, ("private",)),
]
self.status_keys = [status for widget in self.label_widgets for status in widget[2]]