16 |
# write to the Free Software Foundation, Inc., 59 Temple Place |
# write to the Free Software Foundation, Inc., 59 Temple Place |
17 |
# - Suite 330, Boston, MA 02111-1307, USA. |
# - Suite 330, Boston, MA 02111-1307, USA. |
18 |
# |
# |
19 |
# Copyright 2002 Free Software Foundation |
# Copyright 2002-2003 Free Software Foundation |
20 |
# |
# |
21 |
# FILE: |
# FILE: |
22 |
# sio.py |
# sio.py |
37 |
from constants import * |
from constants import * |
38 |
import curses |
import curses |
39 |
|
|
40 |
C_SCREEN = 1 |
#C_SCREEN = 2 |
41 |
C_STATUSBAR = 2 |
#C_TITLEBAR = 3 |
42 |
C_TITLEBAR = 3 |
#C_MENUBAR = 4 |
43 |
C_MENUBAR = 4 |
#C_MENUBAR_FOCUS = 5 |
44 |
C_MENUBAR_FOCUS = 5 |
#C_LABEL = 6 |
45 |
C_LABEL = 6 |
#C_DIALOG = 7 |
46 |
C_DIALOG = 7 |
#C_DIALOG_TITLE = 8 |
47 |
C_DIALOG_TITLE = 8 |
#C_TEXTBOX_FOCUS = 9 |
48 |
C_TEXTBOX_FOCUS = 9 |
#C_TEXTBOX = 10 |
49 |
C_TEXTBOX = 10 |
#C_BUTTON = 11 |
50 |
C_BUTTON = 11 |
#C_BUTTON_FOCUS = 12 |
51 |
C_BUTTON_FOCUS = 12 |
#C_SCROLL_BUTTON = 13 |
52 |
C_SCROLL_BUTTON = 13 |
#C_SCROLL_BUTTON_FOCUS = 14 |
53 |
C_SCROLL_BUTTON_FOCUS = 14 |
#C_SCROLL_BACKGROUND = 15 |
54 |
C_SCROLL_BACKGROUND = 15 |
#C_SCROLL_SLIDER = 16 |
55 |
C_SCROLL_SLIDER = 16 |
#C_SCROLL_SLIDER_FOCUS = 17 |
56 |
C_SCROLL_SLIDER_FOCUS = 17 |
#C_STATUSBAR = 10 |
57 |
C_STATUSBAR = 18 |
#C_STATUSBAR_FIELD = 10 # 7 |
|
C_STATUSBAR_FIELD = 19 |
|
58 |
|
|
59 |
class sio: |
class sio: |
60 |
""" |
""" |
61 |
This class basically acts as an interface to curses. To convert this |
This class basically acts as an interface to curses. |
|
class to NCurses or SLANG, you would only need to change this class. |
|
|
|
|
|
NOT TRUE ANYMORE, I´m sorry to say, but I use curses code in other |
|
|
places as well. (Says the original author) |
|
62 |
|
|
63 |
""" |
""" |
64 |
def __init__(self): |
def __init__(self): |
75 |
self.TokActivate = 10 |
self.TokActivate = 10 |
76 |
|
|
77 |
# get curses keyevents into local tokens |
# get curses keyevents into local tokens |
78 |
# FIXME: what about ascii key maps? ascii.BS? Maybe should |
# TODO: what about ascii key maps? ascii.BS? Maybe should |
79 |
# modify these to handle tuples. |
# modify these to handle tuples. |
80 |
self.TokBackspace = curses.KEY_BACKSPACE |
self.TokBackspace = curses.KEY_BACKSPACE |
81 |
self.TokUpArrow = curses.KEY_UP |
self.TokUpArrow = curses.KEY_UP |
88 |
|
|
89 |
def BeginScreenAccess(self): |
def BeginScreenAccess(self): |
90 |
"""Initialize the screen and setup for action.""" |
"""Initialize the screen and setup for action.""" |
91 |
if self.s <> None: |
GDebug.printMesg(0,'initializing curses screen') |
92 |
return |
#if self.s <> None: |
93 |
|
# return |
94 |
|
GDebug.printMesg(0,'initializing curses screen 1') |
95 |
self.stdscr = curses.initscr() |
self.stdscr = curses.initscr() |
96 |
self._NegotiateScreenSize() |
self._NegotiateScreenSize() |
97 |
|
GDebug.printMesg(0,'initializing curses screen 2') |
98 |
self.s = curses.newwin(self.MAXROW+1, self.MAXCOL+1, 0, 0) |
self.s = curses.newwin(self.MAXROW+1, self.MAXCOL+1, 0, 0) |
99 |
curses.noecho() |
curses.noecho() |
100 |
|
GDebug.printMesg(0,'initializing curses screen 3') |
101 |
#curses.nonl() # disallows usage of <CR> as a selector. |
#curses.nonl() # disallows usage of <CR> as a selector. |
102 |
curses.cbreak() |
curses.cbreak() |
103 |
self.s.keypad(1) |
self.s.keypad(1) |
104 |
|
GDebug.printMesg(0,'initializing curses screen 4') |
105 |
# make the cursor very visible |
# make the cursor very visible |
106 |
#curses.curs_set(2) # throws an ERR, removing. |
#curses.curs_set(2) # throws an ERR, removing. |
107 |
|
|
119 |
tiLTEE : curses.ACS_LTEE, |
tiLTEE : curses.ACS_LTEE, |
120 |
tiRTEE : curses.ACS_RTEE, |
tiRTEE : curses.ACS_RTEE, |
121 |
tiBULL : curses.ACS_PLUS} |
tiBULL : curses.ACS_PLUS} |
122 |
try: |
GDebug.printMesg(0,'initializing curses screen 5') |
123 |
# FIXME |
|
124 |
# should really only do this on configuration says yes, or on |
# TODO: should really only do this if configuration |
125 |
# some other test. |
# TODO: says yes, or on some other test. |
126 |
curses.start_color() |
curses.start_color() |
127 |
|
|
128 |
# don't know why this is here. |
import ColorScheme |
129 |
#self.SetColor(1) |
|
130 |
|
if curses.has_colors(): |
131 |
if curses.has_colors (): |
GDebug.printMesg(1,"Initializing StandardWhiteOnBlue colors") |
132 |
curses.init_pair(C_SCREEN, curses.COLOR_WHITE,curses.COLOR_BLUE) |
self.colors = ColorScheme.StandardWhiteOnBlue() |
133 |
curses.init_pair(C_STATUSBAR, curses.COLOR_WHITE,curses.COLOR_BLUE) |
|
134 |
curses.init_pair(C_TITLEBAR, curses.COLOR_WHITE,curses.COLOR_BLUE) |
# curses.init_pair(C_SCREEN, curses.COLOR_WHITE,curses.COLOR_BLUE) |
135 |
curses.init_pair(C_MENUBAR, curses.COLOR_YELLOW,curses.COLOR_BLUE) |
# curses.init_pair(C_TITLEBAR, curses.COLOR_WHITE,curses.COLOR_BLUE) |
136 |
curses.init_pair(C_MENUBAR_FOCUS, curses.COLOR_BLUE,curses.COLOR_WHITE) |
# curses.init_pair(C_MENUBAR, curses.COLOR_YELLOW,curses.COLOR_BLUE) |
137 |
curses.init_pair(C_LABEL, curses.COLOR_BLACK,curses.COLOR_WHITE) |
# curses.init_pair(C_MENUBAR_FOCUS, curses.COLOR_BLUE,curses.COLOR_WHITE) |
138 |
curses.init_pair(C_DIALOG, curses.COLOR_BLACK,curses.COLOR_WHITE) |
# curses.init_pair(C_LABEL, curses.COLOR_BLACK,curses.COLOR_WHITE) |
139 |
curses.init_pair(C_DIALOG_TITLE, curses.COLOR_YELLOW,curses.COLOR_WHITE) |
# curses.init_pair(C_DIALOG, curses.COLOR_BLACK,curses.COLOR_WHITE) |
140 |
curses.init_pair(C_TEXTBOX_FOCUS, curses.COLOR_BLACK,6) |
# curses.init_pair(C_DIALOG_TITLE, curses.COLOR_YELLOW,curses.COLOR_WHITE) |
141 |
# curses.init_pair(C_TEXTBOX, curses.COLOR_WHITE,curses.COLOR_BLUE) |
# curses.init_pair(C_TEXTBOX_FOCUS, curses.COLOR_BLACK,curses.COLOR_CYAN) |
142 |
curses.init_pair(C_TEXTBOX, curses.COLOR_BLUE,curses.COLOR_WHITE) |
## curses.init_pair(C_TEXTBOX, curses.COLOR_WHITE,curses.COLOR_BLUE) |
143 |
curses.init_pair(C_BUTTON, curses.COLOR_BLUE,curses.COLOR_WHITE) |
# curses.init_pair(C_TEXTBOX, curses.COLOR_BLUE,curses.COLOR_WHITE) |
144 |
curses.init_pair(C_BUTTON_FOCUS, curses.COLOR_WHITE,curses.COLOR_BLUE) |
# curses.init_pair(C_BUTTON, curses.COLOR_BLUE,curses.COLOR_WHITE) |
145 |
curses.init_pair(C_SCROLL_BUTTON, curses.COLOR_BLACK,curses.COLOR_WHITE) |
## curses.init_pair(C_BUTTON_FOCUS, curses.COLOR_WHITE,curses.COLOR_CYAN) |
146 |
curses.init_pair(C_SCROLL_BUTTON_FOCUS, 6,curses.COLOR_WHITE) |
# curses.init_pair(C_SCROLL_BUTTON, curses.COLOR_BLACK,curses.COLOR_WHITE) |
147 |
curses.init_pair(C_SCROLL_BACKGROUND, curses.COLOR_BLUE,curses.COLOR_GRAY) |
# curses.init_pair(C_SCROLL_BUTTON_FOCUS, curses.COLOR_CYAN,curses.COLOR_WHITE) |
148 |
curses.init_pair(C_SCROLL_SLIDER, curses.COLOR_WHITE,curses.COLOR_BLUE) |
# curses.init_pair(C_SCROLL_BACKGROUND, curses.COLOR_BLUE,curses.COLOR_GRAY) |
149 |
curses.init_pair(C_SCROLL_SLIDER_FOCUS, 0, 6) |
# curses.init_pair(C_SCROLL_SLIDER, curses.COLOR_WHITE,curses.COLOR_BLUE) |
150 |
curses.init_pair(C_STATUSBAR, curses.COLOR_BLACK, curses.COLOR_WHITE) |
# curses.init_pair(C_SCROLL_SLIDER_FOCUS, 0, curses.COLOR_CYAN) |
151 |
curses.init_pair(C_STATUSBAR_FIELD, curses.COLOR_BLUE, curses.COLOR_WHITE) |
## curses.init_pair(C_STATUSBAR, curses.COLOR_BLACK, curses.COLOR_WHITE) |
152 |
|
## curses.init_pair(C_STATUSBAR_FIELD, curses.COLOR_BLUE, curses.COLOR_WHITE) |
153 |
|
else: |
154 |
|
GDebug.printMesg(1,"Initializing Monochrome colors") |
155 |
|
self.colors = ColorScheme.Monochrome() |
156 |
|
|
157 |
|
|
|
except: |
|
|
pass |
|
158 |
|
|
159 |
events = curses.mousemask(curses.BUTTON1_CLICKED) |
events = curses.mousemask(curses.BUTTON1_CLICKED) |
160 |
|
|
161 |
if events == 0: |
# if events == 0: |
162 |
self.PrintAt(self.MAXROW, self.MAXCOL-8, 'no mouse.') |
# self.PrintAt(self.MAXROW, self.MAXCOL-8, 'no mouse.') |
163 |
|
|
164 |
self.AutoRefresh = 1 |
self.AutoRefresh = 1 |
165 |
self.Started = 1 |
self.Started = 1 |
262 |
|
|
263 |
|
|
264 |
def GotoYX(self, Row, Col): |
def GotoYX(self, Row, Col): |
|
""" |
|
|
""" |
|
|
#self.s.addstr(Row, Column, "") |
|
|
# not really sure why s.addstr is being used when perhaps a 'move' |
|
|
# will suffice? |
|
|
#print "Row: %s, Col: %s" % (Row, Col) |
|
265 |
self.s.move( Row, Col) |
self.s.move( Row, Col) |
266 |
if self.AutoRefresh : |
if self.AutoRefresh : |
267 |
self.s.refresh() |
self.s.refresh() |
268 |
|
|
269 |
|
def GetYX(self): |
270 |
|
return self.s.getyx() |
271 |
|
|
272 |
def Print(self, String, Mods = None): |
def Print(self, String, Mods = 0): |
273 |
""" |
# PrevMod = self.PrintMods |
274 |
""" |
# if Mods != None: |
275 |
PrevMod = self.PrintMods |
# PrevMod |= Mods |
276 |
if Mods != None: |
PrevMod = Mods |
|
PrevMod |= Mods |
|
277 |
|
|
278 |
refreshState = self.AutoRefresh |
refreshState = self.AutoRefresh |
279 |
self.AutoRefresh = 0 |
self.AutoRefresh = 0 |
306 |
def HiLight(self): |
def HiLight(self): |
307 |
""" |
""" |
308 |
""" |
""" |
309 |
|
return |
310 |
|
|
311 |
|
|
312 |
if curses.has_colors(): |
if curses.has_colors(): |
313 |
# TODO: should this be curses.color_pair(colorHi)? |
# TODO: should this be curses.color_pair(colorHi)? |
314 |
## self.PrintMods = curses.color_pair(colorHi) |
#self.PrintMods = curses.color_pair(colorHi) |
315 |
self.PrintMods = curses.A_BOLD |
self.PrintMods = curses.A_BOLD |
316 |
else: |
else: |
317 |
self.PrintMods = curses.A_NORMAL |
self.PrintMods = curses.A_NORMAL |
320 |
def LoLight(self): |
def LoLight(self): |
321 |
""" |
""" |
322 |
""" |
""" |
323 |
|
return |
324 |
|
|
325 |
|
|
326 |
if curses.has_colors(): |
if curses.has_colors(): |
327 |
self.PrintMods = curses.color_pair(colorLow) |
self.PrintMods = curses.color_pair(colorLow) |
328 |
else: |
else: |
329 |
self.PrintMods = curses.A_DIM |
self.PrintMods = curses.A_DIM |
330 |
|
|
331 |
|
|
332 |
def SetColor(self, n): |
def SetColor(self, ll, hl=None): |
333 |
""" |
""" |
334 |
""" |
""" |
335 |
self.COLOR = n |
return |
336 |
|
|
337 |
|
|
338 |
|
## if type(ll) == type( (0,) ): |
339 |
|
## ll, hl = ll |
340 |
|
|
341 |
|
## self.COLOR = (ll,hl) |
342 |
|
self.COLOR = ll |
343 |
try: |
try: |
344 |
if curses.has_colors(): |
if curses.has_colors(): |
345 |
self.PrintMods = curses.color_pair(n) |
self.PrintMods = curses.color_pair(ll) |
346 |
except AttributeError: |
except AttributeError: |
347 |
pass |
pass |
348 |
|
|
349 |
def GetColor(self): |
def GetColor(self): |
350 |
return self.COLOR |
return 0 |
351 |
|
#return self.COLOR |
352 |
|
|
353 |
|
|
354 |
def PrintAt(self, Row, Col, String, Mods = None): |
def PrintAt(self, Row, Col, String, Mods = 0): |
355 |
""" |
""" |
356 |
""" |
""" |
357 |
self.GotoYX(Row, Col) |
self.GotoYX(Row, Col) |
361 |
def Cls(self): |
def Cls(self): |
362 |
""" |
""" |
363 |
""" |
""" |
|
self.SetColor(1) |
|
364 |
self.AutoRefresh = 0 |
self.AutoRefresh = 0 |
365 |
for row in range(0, self.MAXROW+1): |
for row in range(0, self.MAXROW+1): |
366 |
self.PrintAt(row, 0, " " * self.MAXCOL) |
self.PrintAt(row, 0, " " * self.MAXCOL, self.colors.C_BACKGROUND) |
|
self.SetColor(1) |
|
367 |
self.AutoRefresh = 1 |
self.AutoRefresh = 1 |
368 |
|
|
369 |
|
|