mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-04 15:38:43 +00:00
Improve performance of the cell data functions.
This commit is contained in:
parent
39e987d5da
commit
1efe0f7778
1 changed files with 8 additions and 9 deletions
|
@ -46,7 +46,7 @@ from deluge.log import LOG as log
|
||||||
# Cell data functions to pass to add_func_column()
|
# Cell data functions to pass to add_func_column()
|
||||||
def cell_data_speed(column, cell, model, row, data):
|
def cell_data_speed(column, cell, model, row, data):
|
||||||
"""Display value as a speed, eg. 2 KiB/s"""
|
"""Display value as a speed, eg. 2 KiB/s"""
|
||||||
speed = int(model.get_value(row, data))
|
speed = model.get_value(row, data)
|
||||||
speed_str = ""
|
speed_str = ""
|
||||||
if speed > 0:
|
if speed > 0:
|
||||||
speed_str = deluge.common.fspeed(speed)
|
speed_str = deluge.common.fspeed(speed)
|
||||||
|
@ -55,15 +55,13 @@ def cell_data_speed(column, cell, model, row, data):
|
||||||
|
|
||||||
def cell_data_size(column, cell, model, row, data):
|
def cell_data_size(column, cell, model, row, data):
|
||||||
"""Display value in terms of size, eg. 2 MB"""
|
"""Display value in terms of size, eg. 2 MB"""
|
||||||
size = long(model.get_value(row, data))
|
size = model.get_value(row, data)
|
||||||
size_str = deluge.common.fsize(size)
|
size_str = deluge.common.fsize(size)
|
||||||
cell.set_property('text', size_str)
|
cell.set_property('text', size_str)
|
||||||
|
|
||||||
def cell_data_peer(column, cell, model, row, data):
|
def cell_data_peer(column, cell, model, row, data):
|
||||||
"""Display values as 'value1 (value2)'"""
|
"""Display values as 'value1 (value2)'"""
|
||||||
column1, column2 = data
|
(first, second) = model.get(row, *data)
|
||||||
first = int(model.get_value(row, column1))
|
|
||||||
second = int(model.get_value(row, column2))
|
|
||||||
# Only display a (total) if second is greater than -1
|
# Only display a (total) if second is greater than -1
|
||||||
if second > -1:
|
if second > -1:
|
||||||
cell.set_property('text', '%d (%d)' % (first, second))
|
cell.set_property('text', '%d (%d)' % (first, second))
|
||||||
|
@ -72,8 +70,8 @@ def cell_data_peer(column, cell, model, row, data):
|
||||||
|
|
||||||
def cell_data_time(column, cell, model, row, data):
|
def cell_data_time(column, cell, model, row, data):
|
||||||
"""Display value as time, eg 1m10s"""
|
"""Display value as time, eg 1m10s"""
|
||||||
time = int(model.get_value(row, data))
|
time = model.get_value(row, data)
|
||||||
if time < 0 or time == 0:
|
if time <= 0:
|
||||||
time_str = _("Infinity")
|
time_str = _("Infinity")
|
||||||
else:
|
else:
|
||||||
time_str = deluge.common.ftime(time)
|
time_str = deluge.common.ftime(time)
|
||||||
|
@ -81,12 +79,13 @@ def cell_data_time(column, cell, model, row, data):
|
||||||
|
|
||||||
def cell_data_ratio(column, cell, model, row, data):
|
def cell_data_ratio(column, cell, model, row, data):
|
||||||
"""Display value as a ratio with a precision of 3."""
|
"""Display value as a ratio with a precision of 3."""
|
||||||
ratio = float(model.get_value(row, data))
|
ratio = model.get_value(row, data)
|
||||||
if ratio == -1:
|
if ratio == -1:
|
||||||
ratio_str = _("Unknown")
|
ratio_str = _("Unknown")
|
||||||
else:
|
else:
|
||||||
ratio_str = "%.3f" % ratio
|
ratio_str = "%.3f" % ratio
|
||||||
cell.set_property('text', ratio_str)
|
|
||||||
|
cell.set_property('text', ratio_str)
|
||||||
|
|
||||||
class ListViewColumnState:
|
class ListViewColumnState:
|
||||||
"""Used for saving/loading column state"""
|
"""Used for saving/loading column state"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue