-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
253 lines (213 loc) · 9.01 KB
/
test.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import os
import requests
import json
import curses
from curses import wrapper
from curses.textpad import Textbox, rectangle
from pathlib import Path
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(True)
home = str(Path.home())
rel_path = ".briar/auth_token"
abs_file_path = os.path.join(home, rel_path)
apiURL = "http://127.0.0.1:7000"
auth = {"Authorization" : "Bearer " + open(abs_file_path, "r").read()}
def contacts():
url_format = apiURL + "/v1/contacts"
response = requests.get(url_format, headers = auth)
json_data = response.json()
contactlist = []
for contact in json_data:
contactlist.append( { "id" : str(contact["contactId"]), "name" : contact["author"]["name"] } )
return contactlist
def menuitems(win, item, selected, y, x):
win.attron(curses.color_pair(3))
if selected != True:
win.attron(curses.A_REVERSE)
win.addstr(y, x, item)
if selected != True:
win.attroff(curses.A_REVERSE)
win.attroff(curses.color_pair(3))
def menuBox(menuWin):
menuWin.keypad(True)
# Long strings will wrap to the next line automatically
# to stay within the window
start_y = 1
start_x = 1
menuWin.border(0)
menuindex = 0
menuWin.addstr(start_y,start_x,"MAIN MENU", curses.color_pair(2))
menuitems(menuWin, "Contacts", True, start_y+2, start_x)
menuitems(menuWin, "Groups", False, start_y+3, start_x)
menuitems(menuWin, "Forums", False, start_y+4, start_x)
menuitems(menuWin, "Blogs", False, start_y+5, start_x)
menuitems(menuWin, "Exit", False, start_y+7, start_x)
# Print the window to the screen
menuWin.refresh()
while True:
k = menuWin.getch()
if k == 258:
if menuindex == 0:
menuindex = 1
menuitems(menuWin, "Contacts", False, start_y+2, start_x)
menuitems(menuWin, "Groups", True, start_y+3, start_x)
elif menuindex == 1:
menuindex = 2
menuitems(menuWin, "Groups", False, start_y+3, start_x)
menuitems(menuWin, "Forums", True, start_y+4, start_x)
elif menuindex == 2:
menuindex = 3
menuitems(menuWin, "Forums", False, start_y+4, start_x)
menuitems(menuWin, "Blogs", True, start_y+5, start_x)
elif menuindex == 3:
menuindex = 4
menuitems(menuWin, "Blogs", False, start_y+5, start_x)
menuitems(menuWin, "Exit", True, start_y+7, start_x)
elif menuindex == 4:
menuindex = 0
menuitems(menuWin, "Contacts", True, start_y+2, start_x)
menuitems(menuWin, "Exit", False, start_y+7, start_x)
elif k == 259:
if menuindex == 0:
menuindex = 4
menuitems(menuWin, "Contacts", False, start_y+2, start_x)
menuitems(menuWin, "Exit", True, start_y+7, start_x)
elif menuindex == 1:
menuindex = 0
menuitems(menuWin, "Groups", False, start_y+3, start_x)
menuitems(menuWin, "Contacts", True, start_y+2, start_x)
elif menuindex == 2:
menuindex = 1
menuitems(menuWin, "Forums", False, start_y+4, start_x)
menuitems(menuWin, "Groups", True, start_y+3, start_x)
elif menuindex == 3:
menuindex = 2
menuitems(menuWin, "Blogs", False, start_y+5, start_x)
menuitems(menuWin, "Forums", True, start_y+4, start_x)
elif menuindex == 4:
menuindex = 3
menuitems(menuWin, "Exit", False, start_y+7, start_x)
menuitems(menuWin, "Blogs", True, start_y+5, start_x)
elif k == 10:
if menuindex == 0:
contactBox(curses.newwin(15, 20, 0, 21))
elif menuindex == 1:
menuindex = 0
menuitems(menuWin, "Groups", False, start_y+3, start_x)
menuitems(menuWin, "Contacts", True, start_y+2, start_x)
elif menuindex == 2:
menuindex = 1
menuitems(menuWin, "Forums", False, start_y+4, start_x)
menuitems(menuWin, "Groups", True, start_y+3, start_x)
elif menuindex == 3:
menuindex = 2
menuitems(menuWin, "Blogs", False, start_y+5, start_x)
menuitems(menuWin, "Forums", True, start_y+4, start_x)
elif menuindex == 4:
return
menuWin.refresh()
curses.endwin()
def contactBox(contactWin):
contactlist = contacts()
# Long strings will wrap to the next line automatically
# to stay within the window
start_y = 1
start_x = 1
contactWin.border(0)
menuindex = 0
contactWin.addstr(start_y,start_x,"CONTACTS", curses.color_pair(2))
start_y += 2
selected = True
contactIndex = 0
for contact in contactlist:
menuitems(contactWin, contact["name"], selected, start_y, start_x)
selected = False
start_y += 1
# Print the window to the screen
contactWin.refresh()
''' no esta hecho
while True:
k = contactWin.getch()
if k == ord('s'):#258:
if contactIndex == 0:
contactIndex = 1
menuitems(menuWin, "Contacts", False, start_y+2, start_x)
menuitems(menuWin, "Groups", True, start_y+3, start_x)
elif contactIndex == 1:
contactIndex = 2
menuitems(menuWin, "Groups", False, start_y+3, start_x)
menuitems(menuWin, "Forums", True, start_y+4, start_x)
elif contactIndex == 2:
contactIndex = 3
menuitems(menuWin, "Forums", False, start_y+4, start_x)
menuitems(menuWin, "Blogs", True, start_y+5, start_x)
elif contactIndex == 3:
contactIndex = 4
menuitems(menuWin, "Blogs", False, start_y+5, start_x)
menuitems(menuWin, "Exit", True, start_y+7, start_x)
elif contactIndex == 4:
contactIndex = 0
menuitems(menuWin, "Contacts", True, start_y+2, start_x)
menuitems(menuWin, "Exit", False, start_y+7, start_x)
elif k == ord('w'):#259:
if menuindex == 0:
menuindex = 4
menuitems(menuWin, "Contacts", False, start_y+2, start_x)
menuitems(menuWin, "Exit", True, start_y+7, start_x)
elif menuindex == 1:
menuindex = 0
menuitems(menuWin, "Groups", False, start_y+3, start_x)
menuitems(menuWin, "Contacts", True, start_y+2, start_x)
elif menuindex == 2:
menuindex = 1
menuitems(menuWin, "Forums", False, start_y+4, start_x)
menuitems(menuWin, "Groups", True, start_y+3, start_x)
elif menuindex == 3:
menuindex = 2
menuitems(menuWin, "Blogs", False, start_y+5, start_x)
menuitems(menuWin, "Forums", True, start_y+4, start_x)
elif menuindex == 4:
menuindex = 3
menuitems(menuWin, "Exit", False, start_y+7, start_x)
menuitems(menuWin, "Blogs", True, start_y+5, start_x)
elif k == 10:
if menuindex == 0:
contactBox(curses.newwin(15, 20, 0, 21))
elif menuindex == 1:
menuindex = 0
menuitems(menuWin, "Groups", False, start_y+3, start_x)
menuitems(menuWin, "Contacts", True, start_y+2, start_x)
elif menuindex == 2:
menuindex = 1
menuitems(menuWin, "Forums", False, start_y+4, start_x)
menuitems(menuWin, "Groups", True, start_y+3, start_x)
elif menuindex == 3:
menuindex = 2
menuitems(contactWin, "Blogs", False, start_y+5, start_x)
menuitems(contactWin, "Forums", True, start_y+4, start_x)
elif menuindex == 4:
return
contactWin.refresh()
k = contactWin.getch()
'''
def main(main_screen):
# The `screen` is a window that acts as the master window
# that takes up the whole screen. Other windows created
# later will get painted on to the `screen` window.
screen = curses.initscr()
# Start colors in curses
curses.start_color()
#color de titulo
curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_WHITE)
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLUE)
curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE)
curses.init_pair(4, curses.COLOR_WHITE, curses.COLOR_RED)
#colores de mensajes
curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_CYAN)
curses.init_pair(6, curses.COLOR_WHITE, curses.COLOR_BLUE)
# lines, columns, start line, start column
menuBox(curses.newwin(15, 20, 0, 0))
raise Exception
wrapper(main)