pythonverse

Python-based client for OpenVerse with extra features
git clone https://code.literati.org/pythonverse.git
Log | Files | Refs | README | LICENSE

commit 49c9553797a0343102e884a253fa64391652faf6
parent f991a8c9a89053e0a8ce2e186b773948949ae0c8
Author: renze <renze>
Date:   Wed,  6 Feb 2002 01:22:48 +0000

scrolling of console via Ctrl-(Up/Down/PgUp/PgDown)

Diffstat:
Mpvui_pygame.py | 31+++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/pvui_pygame.py b/pvui_pygame.py @@ -827,18 +827,35 @@ class Console(Sprite): self.linesize = linesize(font) self.numlines = int(self.rect.height / self.linesize) + 1 self.currentcolor = (255, 255, 255) + self.offset = 0 def add_lines(self, paragraphs): for paragraph in paragraphs: del self.buffer[0] self.buffer.append(paragraph) + if self.offset > 0: + self.offset = self.offset + 1 + if self.offset > self.scrollback - self.numlines: + self.offset = self.scrollback - self.numlines return self.render() + def scroll_up(self, lines): + self.offset = self.offset + lines + if self.offset > self.scrollback - self.numlines: + self.offset = self.scrollback - self.numlines + return self.render() + + def scroll_down(self, lines): + self.offset = self.offset - lines + if self.offset < 0: self.offset = 0 + return self.render() + def render(self): """Update my image to match the current buffer""" self.image.fill(self.bg) - lines = self.buffer[(self.scrollback - self.numlines):] + lines = self.buffer[(self.scrollback - (self.numlines + self.offset)): + (self.scrollback - (self.numlines + self.offset)) + self.numlines] newlines = [] for line in lines: if line != '': @@ -846,6 +863,10 @@ class Console(Sprite): else: newlines.append('') lines = newlines[len(newlines) - self.numlines:] + if self.offset > 0: + bgcolor = (127, 0, 0) + else: + bgcolor = (0, 0, 0) x = 1 y = self.rect.height - ((self.numlines * self.linesize) + 1) for line in lines: @@ -863,7 +884,7 @@ class Console(Sprite): self.currentcolor = (0, 255, 0) if line[0:2] == '->': self.currentcolor = (0, 0, 255) - ss = self.font.render(line, 0, (0,0,0)) + ss = self.font.render(line, 0, bgcolor) for xx in range(3): for yy in range(3): self.image.blit(ss, (x + (xx - 1), y + (yy - 1))) @@ -1046,6 +1067,12 @@ class Client: if event.type == KEYDOWN: if event.mod & KMOD_CTRL: if event.key == K_u: self.redraw(self.entry.clear()) + if event.key == K_UP: self.redraw(self.console.scroll_up(1)) + if event.key == K_DOWN: self.redraw(self.console.scroll_down(1)) + if event.key == K_PAGEUP: + self.redraw(self.console.scroll_up(self.console.numlines)) + if event.key == K_PAGEDOWN: + self.redraw(self.console.scroll_down(self.console.numlines)) elif event.key == K_BACKSPACE: self.redraw(self.entry.backspace()) elif event.key == K_DELETE: self.redraw(self.entry.delete()) elif event.key == K_LEFT: self.redraw(self.entry.move_cursor(-1))