only redraw effected lines on scroll. seems to get rid of the flickering problem :)

This commit is contained in:
Nick 2011-01-29 14:04:32 +01:00
parent ff3c3f7148
commit 007dd67ea1
1 changed files with 35 additions and 10 deletions

View File

@ -150,7 +150,7 @@ class AllTorrents(BaseMode, component.Component):
def __init__(self, stdscr, coreconfig, encoding=None): def __init__(self, stdscr, coreconfig, encoding=None):
self.formatted_rows = None self.formatted_rows = None
self.cursel = 1 self.cursel = 1
self.curoff = 1 self.curoff = 1 # TODO: this should really be 0 indexed
self.column_string = "" self.column_string = ""
self.popup = None self.popup = None
self.messages = deque() self.messages = deque()
@ -255,14 +255,18 @@ class AllTorrents(BaseMode, component.Component):
self.refresh() self.refresh()
def _scroll_up(self, by): def _scroll_up(self, by):
prevoff = self.curoff
self.cursel = max(self.cursel - by,1) self.cursel = max(self.cursel - by,1)
if ((self.cursel - 1) < self.curoff): if ((self.cursel - 1) < self.curoff):
self.curoff = max(self.cursel - 1,1) self.curoff = max(self.cursel - 1,1)
return prevoff != self.curoff
def _scroll_down(self, by): def _scroll_down(self, by):
prevoff = self.curoff
self.cursel = min(self.cursel + by,self.numtorrents) self.cursel = min(self.cursel + by,self.numtorrents)
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
return prevoff != self.curoff
def _current_torrent_id(self): def _current_torrent_id(self):
if self._sorted_ids: if self._sorted_ids:
@ -470,7 +474,7 @@ class AllTorrents(BaseMode, component.Component):
def report_message(self,title,message): def report_message(self,title,message):
self.messages.append((title,message)) self.messages.append((title,message))
def refresh(self): def refresh(self,lines=None):
# Something has requested we scroll to the top of the list # Something has requested we scroll to the top of the list
if self._go_top: if self._go_top:
self.cursel = 1 self.cursel = 1
@ -482,6 +486,7 @@ class AllTorrents(BaseMode, component.Component):
title,msg = self.messages.popleft() title,msg = self.messages.popleft()
self.popup = MessagePopup(self,title,msg) self.popup = MessagePopup(self,title,msg)
if not lines:
self.stdscr.clear() self.stdscr.clear()
# Update the status bars # Update the status bars
@ -501,11 +506,21 @@ class AllTorrents(BaseMode, component.Component):
tidx = self.curoff tidx = self.curoff
currow = 2 currow = 2
for row in self.formatted_rows[tidx-1:]: if lines:
todraw = []
for l in lines:
todraw.append(self.formatted_rows[l])
lines.reverse()
else:
todraw = self.formatted_rows[tidx-1:]
for row in todraw:
# default style # default style
fg = "white" fg = "white"
bg = "black" bg = "black"
attr = None attr = None
if lines:
tidx = lines.pop()+1
if tidx in self.marked: if tidx in self.marked:
bg = "blue" bg = "blue"
@ -534,6 +549,10 @@ class AllTorrents(BaseMode, component.Component):
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)
if lines:
currow = tidx-self.curoff+2
self.add_string(currow,"%s%s"%(colorstr,row[0])) self.add_string(currow,"%s%s"%(colorstr,row[0]))
tidx += 1 tidx += 1
currow += 1 currow += 1
@ -542,7 +561,7 @@ class AllTorrents(BaseMode, component.Component):
else: else:
self.add_string(1, "Waiting for torrents from core...") self.add_string(1, "Waiting for torrents from core...")
self.stdscr.redrawwin() #self.stdscr.redrawwin()
self.stdscr.noutrefresh() self.stdscr.noutrefresh()
if self.popup: if self.popup:
@ -562,6 +581,8 @@ class AllTorrents(BaseMode, component.Component):
def _doRead(self): def _doRead(self):
# Read the character # Read the character
effected_lines = None
c = self.stdscr.getch() c = self.stdscr.getch()
if self.popup: if self.popup:
@ -590,11 +611,13 @@ class AllTorrents(BaseMode, component.Component):
# Navigate the torrent list # Navigate the torrent list
if c == curses.KEY_UP: if c == curses.KEY_UP:
self._scroll_up(1) if not self._scroll_up(1):
effected_lines = [self.cursel-1,self.cursel]
elif c == curses.KEY_PPAGE: elif c == curses.KEY_PPAGE:
self._scroll_up(int(self.rows/2)) self._scroll_up(int(self.rows/2))
elif c == curses.KEY_DOWN: elif c == curses.KEY_DOWN:
self._scroll_down(1) if not self._scroll_down(1):
effected_lines = [self.cursel-2,self.cursel-1]
elif c == curses.KEY_NPAGE: elif c == curses.KEY_NPAGE:
self._scroll_down(int(self.rows/2)) self._scroll_down(int(self.rows/2))
@ -607,9 +630,11 @@ class AllTorrents(BaseMode, component.Component):
else: else:
if c > 31 and c < 256: if c > 31 and c < 256:
if chr(c) == 'j': if chr(c) == 'j':
self._scroll_up(1) if not self._scroll_up(1):
effected_lines = [self.cursel-1,self.cursel]
elif chr(c) == 'k': elif chr(c) == 'k':
self._scroll_down(1) if not self._scroll_down(1):
effected_lines = [self.cursel-2,self.cursel-1]
elif chr(c) == 'i': elif chr(c) == 'i':
cid = self._current_torrent_id() cid = self._current_torrent_id()
if cid: if cid:
@ -635,4 +660,4 @@ class AllTorrents(BaseMode, component.Component):
for l in HELP_LINES: for l in HELP_LINES:
self.popup.add_line(l) self.popup.add_line(l)
self.refresh() self.refresh(effected_lines)