-
Notifications
You must be signed in to change notification settings - Fork 0
/
testCurses.py
79 lines (62 loc) · 1.94 KB
/
testCurses.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import curses
import os
def clear_terminal():
"""
Call the platform specific function to clear the terminal: cls on windows, reset otherwise
"""
os.system('reset')
class testCurses:
def __init__(self):
self.title ="test"
self.subtitle = "coucouc"
def clear_screen(self):
"""
Clear the screen belonging to this menu
"""
self.screen.clear()
def main_loop(self, stdscr=None):
print "main loop"
self.stdscr = stdscr if not None else curses.initscr()
self.screen = curses.newpad(10 + 6, self.stdscr.getmaxyx()[1])
self._set_up_colors()
curses.curs_set(0)
self.stdscr.refresh()
self.draw()
def _set_up_colors(self):
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)
self.highlight = curses.color_pair(1)
self.normal = curses.A_NORMAL
def draw(self):
self.screen.border(0)
if self.title is not None:
self.screen.addstr(2, 2, self.title, curses.A_STANDOUT)
if self.subtitle is not None:
self.screen.addstr(4, 2, self.subtitle, curses.A_BOLD)
screen_rows, screen_cols = self.stdscr.getmaxyx()
top_row = 0
self.screen.refresh(top_row, 0, 0, 0, screen_rows - 1, screen_cols - 1)
def show(self):
#self.main_loop()
curses.wrapper(self.main_loop)
self.clear_screen()
clear_terminal()
def t():
pad = curses.newpad(10, 10)
# These loops fill the pad with letters; this is
# explained in the next section
for y in range(0, 100):
for x in range(0, 100):
try:
pad.addch(y, x, ord('a') + (x * x + y * y) % 26)
except curses.error:
pass
# Displays a section of the pad in the middle of the screen
pad.refresh(0, 0, 5, 5, 20, 75)
'''
test = testCurses()
test.show()
test.stdscr.getch()
'''
st=curses.initscr()
t()
st.getch()