--- a/tuikit/driver_curses.py Sun Oct 09 13:06:58 2011 +0200
+++ b/tuikit/driver_curses.py Sun Oct 09 19:30:25 2011 +0200
@@ -1,13 +1,12 @@
# -*- coding: utf-8 -*-
-import curses
+import curses.wrapper
import curses.ascii
-import curses.wrapper
import locale
import logging
-from tuikit.common import Size, Rect, ClipStack
-
+from tuikit.driver import Driver
+
class MouseEvent:
def __init__(self, x=0, y=0):
@@ -32,7 +31,7 @@
return ev
-class DriverCurses:
+class DriverCurses(Driver):
xterm_codes = (
(0x09, 'tab' ),
(0x0a, 'enter' ),
@@ -83,10 +82,10 @@
def __init__(self):
'''Set driver attributes to default values.'''
+ Driver.__init__(self)
+ self.log = logging.getLogger('tuikit')
self.screen = None
- self.size = Size()
self.cursor = None
- self.clipstack = ClipStack()
self.colors = {} # maps names to curses attributes
self.colorpairs = {} # maps tuple (fg,bg) to curses color_pair
self.colorstack = [] # pushcolor/popcolor puts or gets attributes from this
@@ -94,33 +93,7 @@
self.inputqueue = []
self.mbtnstack = []
- self.log = logging.getLogger('tuikit')
-
- # http://en.wikipedia.org/wiki/List_of_Unicode_characters#Geometric_shapes
- self.UP_ARROW = '▲' #curses.ACS_UARROW
- self.DOWN_ARROW = '▼' #curses.ACS_DARROW
-
- # http://en.wikipedia.org/wiki/Box-drawing_characters
- self.LIGHT_SHADE = '░' #curses.ACS_BOARD
- self.MEDIUM_SHADE = '▒'
- self.DARK_SHADE = '▓'
- self.BLOCK = '█'
-
- self.COLUMN = '▁▂▃▄▅▆▇█'
- self.CORNER_ROUND = '╭╮╰╯'
- self.CORNER = '┌┐└┘'
- self.LINE = '─━│┃┄┅┆┇┈┉┊┋'
-
- self.HLINE = '─' # curses.ACS_HLINE
- self.VLINE = '│' # curses.ACS_VLINE
- self.ULCORNER = '┌' # curses.ACS_ULCORNER
- self.URCORNER = '┐' # curses.ACS_URCORNER
- self.LLCORNER = '└' # curses.ACS_LLCORNER
- self.LRCORNER = '┘' # curses.ACS_LRCORNER
- self.LTEE = '├'
- self.RTEE = '┤'
-
- def init(self):
+ def init_curses(self):
'''Initialize curses'''
self.size.h, self.size.w = self.screen.getmaxyx()
self.screen.immedok(0)
@@ -132,7 +105,7 @@
def start(self, mainfunc):
def main(screen):
self.screen = screen
- self.init()
+ self.init_curses()
mainfunc()
curses.wrapper(main)
@@ -143,7 +116,6 @@
name = name.lower().strip()
return self.color_names[name]
-
def _getcolorpair(self, fg, bg):
pair = (fg, bg)
if pair in self.colorpairs:
@@ -153,7 +125,6 @@
self.colorpairs[pair] = num
return num
-
def _parseattrs(self, attrs):
res = 0
for a in attrs:
@@ -168,7 +139,6 @@
res = res | trans[a]
return res
-
def setcolor(self, name, desc):
parts = desc.split(',')
fg, bg = parts[0].split(' on ')
@@ -179,7 +149,6 @@
attr = self._parseattrs(attrs)
self.colors[name] = curses.color_pair(col) | attr
-
def pushcolor(self, name):
# add prefix if available
if len(self.colorprefix):
@@ -190,7 +159,6 @@
self.screen.attrset(attr)
self.colorstack.append(attr)
-
def popcolor(self):
self.colorstack.pop()
if len(self.colorstack):
@@ -199,11 +167,9 @@
attr = 0
self.screen.attrset(attr)
-
def pushcolorprefix(self, name):
self.colorprefix.append(name)
-
def popcolorprefix(self):
self.colorprefix.pop()
@@ -221,46 +187,9 @@
except curses.error:
pass
-
- def puts(self, x, y, s):
- for c in s:
- self.putch(x, y, c)
- x += 1
-
-
- def hline(self, x, y, w, c=' '):
- if isinstance(c, str):
- s = c*w
- else:
- s = [c]*w
- self.puts(x, y, s)
-
-
- def vline(self, x, y, h, c=' '):
- for i in range(h):
- self.putch(x, y+i, c)
-
-
- def frame(self, x, y, w, h):
- self.putch(x, y, self.ULCORNER)
- self.putch(x+w-1, y, self.URCORNER)
- self.putch(x, y+h-1, self.LLCORNER)
- self.putch(x+w-1, y+h-1, self.LRCORNER)
- self.hline(x+1, y, w-2, self.HLINE)
- self.hline(x+1, y+h-1, w-2, self.HLINE)
- self.vline(x, y+1, h-2, self.VLINE)
- self.vline(x+w-1, y+1, h-2, self.VLINE)
-
-
- def fill(self, x, y, w, h, c=' '):
- for i in range(h):
- self.hline(x, y + i, w, c)
-
-
def erase(self):
self.screen.erase()
-
def commit(self):
if self.cursor:
self.screen.move(*self.cursor)
@@ -277,7 +206,6 @@
return
self.cursor = (y, x)
-
def hidecursor(self):
curses.curs_set(False)
self.cursor = None
@@ -341,7 +269,7 @@
self.inputqueue.append(c)
- def process_input(self, timeout=None):
+ def getevents(self, timeout=None):
# empty queue -> fill
if len(self.inputqueue) == 0:
self.inputqueue_fill(timeout)