2
# This file is part of GNU Enterprise.
4
# GNU Enterprise is free software; you can redistribute it
5
# and/or modify it under the terms of the GNU General Public
6
# License as published by the Free Software Foundation; either
7
# version 2, or (at your option) any later version.
9
# GNU Enterprise is distributed in the hope that it will be
10
# useful, but WITHOUT ANY WARRANTY; without even the implied
11
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
# PURPOSE. See the GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public
15
# License along with program; see the file COPYING. If not,
16
# write to the Free Software Foundation, Inc., 59 Temple Place
17
# - Suite 330, Boston, MA 02111-1307, USA.
19
# Copyright 2002-2005 Free Software Foundation
34
# An interface to curses
37
from constants import *
52
#C_SCROLL_BUTTON_FOCUS = 14
53
#C_SCROLL_BACKGROUND = 15
55
#C_SCROLL_SLIDER_FOCUS = 17
57
#C_STATUSBAR_FIELD = 10 # 7
60
def sio(*args, **parms):
63
_sio = _Sio(*args, **parms)
70
This class basically acts as an interface to curses.
80
self.s = None # s is a full screen curses window
81
self.stdscr = None # holds instance of full console screen
86
# get curses keyevents into local tokens
87
# TODO: what about ascii key maps? ascii.BS? Maybe should
88
# modify these to handle tuples.
89
self.TokBackspace = curses.KEY_BACKSPACE
90
self.TokUpArrow = curses.KEY_UP
91
self.TokDownArrow = curses.KEY_DOWN
92
self.TokRightArrow = curses.KEY_RIGHT
93
self.TokLeftArrow = curses.KEY_LEFT
94
self.TokHomeKey = curses.KEY_HOME
95
self.TokEndKey = curses.KEY_END
98
def BeginScreenAccess(self):
99
"""Initialize the screen and setup for action."""
100
gDebug(0,'initializing curses screen')
103
gDebug(0,'initializing curses screen 1')
104
self.stdscr = curses.initscr()
105
self._NegotiateScreenSize()
106
gDebug(0,'initializing curses screen 2')
107
self.s = curses.newwin(self.MAXROW+1, self.MAXCOL+1, 0, 0)
109
gDebug(0,'initializing curses screen 3')
110
#curses.nonl() # disallows usage of <CR> as a selector.
113
gDebug(0,'initializing curses screen 4')
114
# make the cursor very visible
115
#curses.curs_set(2) # throws an ERR, removing.
119
tiHLINE : curses.ACS_HLINE,
120
tiVLINE : curses.ACS_VLINE,
121
tiBOX : curses.ACS_BOARD,
122
tiLLC : curses.ACS_LLCORNER,
123
tiLRC : curses.ACS_LRCORNER,
124
tiDAW : curses.ACS_DARROW,
125
tiULC : curses.ACS_ULCORNER,
126
tiURC : curses.ACS_URCORNER,
127
tiUTEE : curses.ACS_TTEE,
128
tiLTEE : curses.ACS_LTEE,
129
tiRTEE : curses.ACS_RTEE,
130
tiBULL : curses.ACS_PLUS}
131
gDebug(0,'initializing curses screen 5')
133
# TODO: should really only do this if configuration
134
# TODO: says yes, or on some other test.
139
if curses.has_colors():
140
gDebug(1,"Initializing StandardWhiteOnBlue colors")
141
self.colors = ColorScheme.StandardWhiteOnBlue()
143
# curses.init_pair(C_SCREEN, curses.COLOR_WHITE,curses.COLOR_BLUE)
144
# curses.init_pair(C_TITLEBAR, curses.COLOR_WHITE,curses.COLOR_BLUE)
145
# curses.init_pair(C_MENUBAR, curses.COLOR_YELLOW,curses.COLOR_BLUE)
146
# curses.init_pair(C_MENUBAR_FOCUS, curses.COLOR_BLUE,curses.COLOR_WHITE)
147
# curses.init_pair(C_LABEL, curses.COLOR_BLACK,curses.COLOR_WHITE)
148
# curses.init_pair(C_DIALOG, curses.COLOR_BLACK,curses.COLOR_WHITE)
149
# curses.init_pair(C_DIALOG_TITLE, curses.COLOR_YELLOW,curses.COLOR_WHITE)
150
# curses.init_pair(C_TEXTBOX_FOCUS, curses.COLOR_BLACK,curses.COLOR_CYAN)
151
## curses.init_pair(C_TEXTBOX, curses.COLOR_WHITE,curses.COLOR_BLUE)
152
# curses.init_pair(C_TEXTBOX, curses.COLOR_BLUE,curses.COLOR_WHITE)
153
# curses.init_pair(C_BUTTON, curses.COLOR_BLUE,curses.COLOR_WHITE)
154
## curses.init_pair(C_BUTTON_FOCUS, curses.COLOR_WHITE,curses.COLOR_CYAN)
155
# curses.init_pair(C_SCROLL_BUTTON, curses.COLOR_BLACK,curses.COLOR_WHITE)
156
# curses.init_pair(C_SCROLL_BUTTON_FOCUS, curses.COLOR_CYAN,curses.COLOR_WHITE)
157
# curses.init_pair(C_SCROLL_BACKGROUND, curses.COLOR_BLUE,curses.COLOR_GRAY)
158
# curses.init_pair(C_SCROLL_SLIDER, curses.COLOR_WHITE,curses.COLOR_BLUE)
159
# curses.init_pair(C_SCROLL_SLIDER_FOCUS, 0, curses.COLOR_CYAN)
160
## curses.init_pair(C_STATUSBAR, curses.COLOR_BLACK, curses.COLOR_WHITE)
161
## curses.init_pair(C_STATUSBAR_FIELD, curses.COLOR_BLUE, curses.COLOR_WHITE)
163
gDebug(1,"Initializing Monochrome colors")
164
self.colors = ColorScheme.Monochrome()
168
events = curses.mousemask(curses.BUTTON1_CLICKED)
171
# self.PrintAt(self.MAXROW, self.MAXCOL-8, 'no mouse.')
180
def EndScreenAccess(self):
181
# S is nothing, no need to end curses stuff
191
def CaptureScreen(self, r1, c1, r2, c2):
193
Return a rectangle within the screen specified from corner 1 at
194
(r1,c1) to corner 2 at (r2,c2).
198
for rows in range(r1, r2):
199
for cols in range(c1, c2):
200
scrnbuff[str(rows)+"X"+str(cols)]=self.GetCharAt(rows,cols)
204
def RestoreScreen(self, r1, c1, r2, c2, scrnbuff):
206
Redraw screen within any rectangle from buffer. Does nothing if
215
for rows in range(r1, r2):
216
for cols in range(c1, c2):
217
self.PutAt(rows,cols, scrnbuff[str(rows)+"X"+str(cols)])
223
def _NegotiateScreenSize(self):
225
Set self.MAXROW and self.MAXCOL less one pixel from
226
stdscr.getmaxyx() which returns tuple (y,x) of height and width of
228
(lmaxY, lmaxX) = self.stdscr.getmaxyx()
229
self.MAXROW = lmaxY - 1
230
self.MAXCOL = lmaxX - 1
235
# suggest depricate and remove this def. Is it used for
236
# forms compatibility?
238
def GetScreenInstance(self):
244
def SetScreenInstance(self, s):
250
def GetCharAt(self, Row, Col):
253
return self.s.inch(Row, Col)
259
return self.s.getch()
262
def GetStr(self,Y,X,N):
265
Retrieve a string N long from (X,Y) traveling along
269
result.append(self.s.inch(Y+i,X))
273
def GotoYX(self, Row, Col):
274
self.s.move( Row, Col)
275
if self.AutoRefresh :
279
return self.s.getyx()
281
def Print(self, String, Mods = 0):
282
# PrevMod = self.PrintMods
287
refreshState = self.AutoRefresh
290
for i in range(0,len(String)):
291
if ti_chars.has_key(ord(String[i])):
292
actch = ti_chars[ord(String[i])]
293
self.s.addch(actch, PrevMod)
295
self.s.addstr(str(String[i]), PrevMod)
297
self.AutoRefresh = refreshState
299
if self.AutoRefresh :
303
def PutAt(self,Y,X,Char, Mods = None):
306
PrevMod = self.PrintMods
310
self.s.addch(Y,X,Char,PrevMod)
321
if curses.has_colors():
322
# TODO: should this be curses.color_pair(colorHi)?
323
#self.PrintMods = curses.color_pair(colorHi)
324
self.PrintMods = curses.A_BOLD
326
self.PrintMods = curses.A_NORMAL
335
if curses.has_colors():
336
self.PrintMods = curses.color_pair(colorLow)
338
self.PrintMods = curses.A_DIM
341
def SetColor(self, ll, hl=None):
347
## if type(ll) == type( (0,) ):
350
## self.COLOR = (ll,hl)
353
if curses.has_colors():
354
self.PrintMods = curses.color_pair(ll)
355
except AttributeError:
363
def PrintAt(self, Row, Col, String, Mods = 0):
366
self.GotoYX(Row, Col)
367
self.Print(String,Mods)
374
for row in range(0, self.MAXROW+1):
375
self.PrintAt(row, 0, " " * self.MAXCOL, self.colors.C_BACKGROUND)