-
Notifications
You must be signed in to change notification settings - Fork 0
/
notebook_selection_scene.py
69 lines (49 loc) · 1.8 KB
/
notebook_selection_scene.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
import curses
import notebooks
import scene_handler
from modes.selection import browsing
from modes.selection import editing
index = 0
insert_index = -1
insert_pos = []
mode = browsing
def handle_input(scr, c):
ret = mode.handle_input(scr, c)
return ret
def init(scr):
pass
def redraw(scr):
# Redraw the scene
scr.erase()
__draw_notebooks(scr)
__draw_mode(scr)
if (not insert_index == -1) and scr.getmaxyx()[0] > insert_pos[0] and scr.getmaxyx()[1] > insert_pos[1]:
scr.move(insert_pos[0], insert_pos[1])
else:
scr.move(scr.getmaxyx()[0] - 1, scr.getmaxyx()[1] - 1)
def __draw_notebooks(scr):
# Draw the notebook_list
global insert_pos
pos = [2, 2]
for notebook in notebooks.notebook_list:
# pos is inside screen
if pos[0] < scr.getmaxyx()[0] and pos[1] < scr.getmaxyx()[1]:
notebook_str = ("[ %s ]" % notebook.name)[0:scr.getmaxyx()[1] - pos[1]]
# notebook is selected_notebook
if notebook is notebooks.notebook_list[index]:
if not mode == editing:
scr.addstr(pos[0], pos[1], notebook_str, curses.color_pair(1))
else:
scr.addstr(pos[0], pos[1], notebook_str)
# cursor should be moved
if editing and (not insert_index == -1):
insert_pos = [pos[0], pos[1] + 2 + insert_index]
else:
scr.addstr(pos[0], pos[1], notebook_str)
pos[0] += 1
def __draw_mode(scr):
# Draw mode
scr.addstr(scr.getmaxyx()[0] - 1, 0, ("--%s--" % mode.get_name())[0:scr.getmaxyx()[1] - 1], curses.color_pair(1))
def __get_selected_notebook():
# Return the Notebook in notebooks.index_list at index
return notebooks.notebook_list[index]