diff options
author | makefu <github@syntax-fehler.de> | 2011-07-19 20:52:28 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2011-07-19 20:52:28 +0200 |
commit | 1e604f2408861120d8168a3f88c29f9da3ddf7df (patch) | |
tree | e99a84b854e16edeedcbd1103c31d90e879924e3 | |
parent | 7a0393069af136d1cd72f20fb71e541543688282 (diff) |
added initial version of cholerab-live
-rw-r--r-- | cholerab/cholerab-live/README | 6 | ||||
-rw-r--r-- | cholerab/cholerab-live/cholerab.py | 10 | ||||
-rw-r--r-- | cholerab/cholerab-live/view.py | 71 |
3 files changed, 87 insertions, 0 deletions
diff --git a/cholerab/cholerab-live/README b/cholerab/cholerab-live/README new file mode 100644 index 00000000..b778b98c --- /dev/null +++ b/cholerab/cholerab-live/README @@ -0,0 +1,6 @@ + +view.py: contains view classes for cholerab +cholerab.py: main file + +start with : +python cholerab.py diff --git a/cholerab/cholerab-live/cholerab.py b/cholerab/cholerab-live/cholerab.py new file mode 100644 index 00000000..4739d9cf --- /dev/null +++ b/cholerab/cholerab-live/cholerab.py @@ -0,0 +1,10 @@ +from view import CursesView + +a = CursesView() +a.start() +a.write_char(5,5,'p') +a.write_char(6,5,'e') +a.write_char(7,5,'n') +a.write_char(8,5,'i') +a.write_char(9,5,'s') +a.join() diff --git a/cholerab/cholerab-live/view.py b/cholerab/cholerab-live/view.py new file mode 100644 index 00000000..34891e5c --- /dev/null +++ b/cholerab/cholerab-live/view.py @@ -0,0 +1,71 @@ +#!/usr/bin/python2 + +from curses import * +import socket +import threading + +class CursesView(threading.Thread): + def stop(self): + self.running = False + nocbreak(); self.scr.keypad(0); echo() + endwin() + + def run(self): + self.running = True + def try_move(x,y): + if x >= self.width: x = 0;y = y+1 + if x < 0 : x = self.width-1; y= y-1 + if y >= self.height : x = x+1;y = 0 + if y < 0 : x = x-1; y = self.height-1 + self.win.move(y,x); return x,y + + while self.running: + c = self.scr.getch() + if c == KEY_LEFT : self.x -=1 + elif c == KEY_RIGHT : self.x +=1 + elif c == KEY_UP : self.y -=1 + elif c == KEY_DOWN : self.y +=1 + elif c == ord('q') : self.stop() + else : + try: + self.win.addch(c) #TODO UTF8 here + #self.cholerab.write_char(self.x,self.y,c) + except: + pass + self.x +=1 + self.x,self.y = try_move(self.x,self.y) + self.refresh() + + def write_char(self,x,y,char): + self.win.addch(y,x,char) + self.win.move(self.y,self.x) + self.refresh() + def refresh(self): + self.scr.refresh() + self.win.refresh() + def clear(self): + pass + def write_field(self,ar): + """ + writes the whole field with given 2-dimensional array + """ + self.clear() + pass + + + def __init__(self,height=24,width=80,cholerab=None): + self.cholerab = cholerab + threading.Thread.__init__(self) + self.scr = initscr() + noecho() + cbreak() + self.scr.keypad(1) + curs_set(2) + + begin_x = 0;begin_y = 0 + self.height = height + self.width = width + self.x = 0 ; self.y = 0 + + self.win = newwin(height,width,begin_y,begin_x) + |