mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-07 17:08:42 +00:00
use some caching to speed up row drawing.
still some flicker unfortunatly. seems to be related to the length of the row line, not sure if there's much i can do there
This commit is contained in:
parent
182ec0cd97
commit
44676f282a
1 changed files with 29 additions and 28 deletions
|
@ -145,7 +145,7 @@ class StateUpdater(component.Component):
|
||||||
|
|
||||||
class AllTorrents(BaseMode, component.Component):
|
class AllTorrents(BaseMode, component.Component):
|
||||||
def __init__(self, stdscr, coreconfig, encoding=None):
|
def __init__(self, stdscr, coreconfig, encoding=None):
|
||||||
self.curstate = None
|
self.formatted_rows = None
|
||||||
self.cursel = 1
|
self.cursel = 1
|
||||||
self.curoff = 1
|
self.curoff = 1
|
||||||
self.column_string = ""
|
self.column_string = ""
|
||||||
|
@ -231,8 +231,23 @@ class AllTorrents(BaseMode, component.Component):
|
||||||
return "".join([self._format_column(row[i],self.column_widths[i]) for i in range(0,len(row))])
|
return "".join([self._format_column(row[i],self.column_widths[i]) for i in range(0,len(row))])
|
||||||
|
|
||||||
def set_state(self, state, refresh):
|
def set_state(self, state, refresh):
|
||||||
self.curstate = state
|
self.curstate = state # cache in case we change sort order
|
||||||
|
newrows = []
|
||||||
|
self._sorted_ids = self._sort_torrents(self.curstate)
|
||||||
|
for torrent_id in self._sorted_ids:
|
||||||
|
ts = self.curstate[torrent_id]
|
||||||
|
newrows.append((self._format_row([self._format_queue(ts["queue"]),
|
||||||
|
ts["name"],
|
||||||
|
"%s"%deluge.common.fsize(ts["total_wanted"]),
|
||||||
|
ts["state"],
|
||||||
|
self._format_progress(ts["progress"]),
|
||||||
|
self._format_seeds_peers(ts["num_seeds"],ts["total_seeds"]),
|
||||||
|
self._format_seeds_peers(ts["num_peers"],ts["total_peers"]),
|
||||||
|
self._format_speed(ts["download_payload_rate"]),
|
||||||
|
self._format_speed(ts["upload_payload_rate"])
|
||||||
|
]),ts["state"]))
|
||||||
self.numtorrents = len(state)
|
self.numtorrents = len(state)
|
||||||
|
self.formatted_rows = newrows
|
||||||
if refresh:
|
if refresh:
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
|
@ -243,6 +258,7 @@ class AllTorrents(BaseMode, component.Component):
|
||||||
|
|
||||||
def _scroll_down(self, by):
|
def _scroll_down(self, by):
|
||||||
self.cursel = min(self.cursel + by,self.numtorrents)
|
self.cursel = min(self.cursel + by,self.numtorrents)
|
||||||
|
log.error("cursel: %d",self.cursel)
|
||||||
if ((self.curoff + self.rows - 5) < self.cursel):
|
if ((self.curoff + self.rows - 5) < self.cursel):
|
||||||
self.curoff = self.cursel - self.rows + 5
|
self.curoff = self.cursel - self.rows + 5
|
||||||
|
|
||||||
|
@ -448,29 +464,14 @@ class AllTorrents(BaseMode, component.Component):
|
||||||
self.add_string(self.rows - 1, "%s%s"%(self.bottombar,hstr))
|
self.add_string(self.rows - 1, "%s%s"%(self.bottombar,hstr))
|
||||||
|
|
||||||
# add all the torrents
|
# add all the torrents
|
||||||
if self.curstate == {}:
|
if self.formatted_rows == []:
|
||||||
msg = "No torrents match filter".center(self.cols)
|
msg = "No torrents match filter".center(self.cols)
|
||||||
self.add_string(3, "{!info!}%s"%msg)
|
self.add_string(3, "{!info!}%s"%msg)
|
||||||
elif self.curstate != None:
|
elif self.formatted_rows:
|
||||||
tidx = 1
|
tidx = self.curoff
|
||||||
currow = 2
|
currow = 2
|
||||||
self._sorted_ids = self._sort_torrents(self.curstate)
|
|
||||||
for torrent_id in self._sorted_ids:
|
|
||||||
if (tidx < self.curoff):
|
|
||||||
tidx += 1
|
|
||||||
continue
|
|
||||||
ts = self.curstate[torrent_id]
|
|
||||||
s = self._format_row([self._format_queue(ts["queue"]),
|
|
||||||
ts["name"],
|
|
||||||
"%s"%deluge.common.fsize(ts["total_wanted"]),
|
|
||||||
ts["state"],
|
|
||||||
self._format_progress(ts["progress"]),
|
|
||||||
self._format_seeds_peers(ts["num_seeds"],ts["total_seeds"]),
|
|
||||||
self._format_seeds_peers(ts["num_peers"],ts["total_peers"]),
|
|
||||||
self._format_speed(ts["download_payload_rate"]),
|
|
||||||
self._format_speed(ts["upload_payload_rate"])
|
|
||||||
])
|
|
||||||
|
|
||||||
|
for row in self.formatted_rows[tidx-1:]:
|
||||||
# default style
|
# default style
|
||||||
fg = "white"
|
fg = "white"
|
||||||
bg = "black"
|
bg = "black"
|
||||||
|
@ -488,22 +489,22 @@ class AllTorrents(BaseMode, component.Component):
|
||||||
else:
|
else:
|
||||||
fg = "black"
|
fg = "black"
|
||||||
|
|
||||||
if ts["state"] == "Downloading":
|
if row[1] == "Downloading":
|
||||||
fg = "green"
|
fg = "green"
|
||||||
elif ts["state"] == "Seeding":
|
elif row[1] == "Seeding":
|
||||||
fg = "cyan"
|
fg = "cyan"
|
||||||
elif ts["state"] == "Error":
|
elif row[1] == "Error":
|
||||||
fg = "red"
|
fg = "red"
|
||||||
elif ts["state"] == "Queued":
|
elif row[1] == "Queued":
|
||||||
fg = "yellow"
|
fg = "yellow"
|
||||||
elif ts["state"] == "Checking":
|
elif row[1] == "Checking":
|
||||||
fg = "blue"
|
fg = "blue"
|
||||||
|
|
||||||
if attr:
|
if attr:
|
||||||
colorstr = "{!%s,%s,%s!}"%(fg,bg,attr)
|
colorstr = "{!%s,%s,%s!}"%(fg,bg,attr)
|
||||||
else:
|
else:
|
||||||
colorstr = "{!%s,%s!}"%(fg,bg)
|
colorstr = "{!%s,%s!}"%(fg,bg)
|
||||||
self.add_string(currow,"%s%s"%(colorstr,s))
|
self.add_string(currow,"%s%s"%(colorstr,row[0]))
|
||||||
tidx += 1
|
tidx += 1
|
||||||
currow += 1
|
currow += 1
|
||||||
if (currow > (self.rows - 2)):
|
if (currow > (self.rows - 2)):
|
||||||
|
@ -550,7 +551,7 @@ class AllTorrents(BaseMode, component.Component):
|
||||||
reactor.stop()
|
reactor.stop()
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.curstate==None or self.popup:
|
if self.formatted_rows==None or self.popup:
|
||||||
return
|
return
|
||||||
|
|
||||||
#log.error("pressed key: %d\n",c)
|
#log.error("pressed key: %d\n",c)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue