Added scrolling to event view, fixed all crashes

This commit is contained in:
Asmageddon 2012-05-28 22:29:19 +02:00
parent 506a98aee2
commit 6269076c7e
1 changed files with 38 additions and 10 deletions

View File

@ -37,6 +37,8 @@
import deluge.component as component import deluge.component as component
from basemode import BaseMode from basemode import BaseMode
from deluge.ui.client import client
try: try:
import curses import curses
except ImportError: except ImportError:
@ -50,12 +52,15 @@ import format_utils
class EventView(BaseMode): class EventView(BaseMode):
def __init__(self, parent_mode, stdscr, encoding=None): def __init__(self, parent_mode, stdscr, encoding=None):
self.parent_mode = parent_mode self.parent_mode = parent_mode
self.offset = 0
BaseMode.__init__(self, stdscr, encoding) BaseMode.__init__(self, stdscr, encoding)
def refresh(self): def refresh(self):
"This method just shows each line of the event log" "This method just shows each line of the event log"
events = component.get("ConsoleUI").events events = component.get("ConsoleUI").events
self.stdscr.erase()
self.add_string(0,self.statusbars.topbar) self.add_string(0,self.statusbars.topbar)
hstr = "%sPress [h] for help"%(" "*(self.cols - len(self.statusbars.bottombar) - 10)) hstr = "%sPress [h] for help"%(" "*(self.cols - len(self.statusbars.bottombar) - 10))
#This will quite likely fail when switching modes #This will quite likely fail when switching modes
@ -72,7 +77,15 @@ class EventView(BaseMode):
if events: if events:
for i,event in enumerate(events): for i,event in enumerate(events):
self.add_string(i+1,event) if i - self.offset >= self.rows - 2:
more = len(events) - self.offset - self.rows + 2
if more > 0:
self.add_string(i-self.offset, " (And %i more)" % more)
break
elif i - self.offset < 0:
continue
self.add_string(i+1-self.offset,event)
else: else:
self.add_string(1,"{!white,black,bold!}No events to show yet") self.add_string(1,"{!white,black,bold!}No events to show yet")
@ -106,13 +119,28 @@ class EventView(BaseMode):
return return
# TODO: Scroll event list # TODO: Scroll event list
if c == curses.KEY_UP: jumplen = self.rows - 3
pass num_events = len( component.get("ConsoleUI").events )
elif c == curses.KEY_PPAGE:
pass
elif c == curses.KEY_DOWN:
pass
elif c == curses.KEY_NPAGE:
pass
#self.refresh() if c == curses.KEY_UP:
self.offset -= 1
elif c == curses.KEY_PPAGE:
self.offset -= jumplen
elif c == curses.KEY_HOME:
self.offset = 0
elif c == curses.KEY_DOWN:
self.offset += 1
elif c == curses.KEY_NPAGE:
self.offset += jumplen
elif c == curses.KEY_END:
self.offset += num_events
if self.offset <= 0:
self.offset = 0
elif num_events > self.rows - 3:
if self.offset > num_events - self.rows + 3:
self.offset = num_events - self.rows + 3
else:
self.offset = 0
self.refresh()