-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChooseMode.py
110 lines (89 loc) · 3.01 KB
/
ChooseMode.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
# choose mode menu
# created Aug 5, 2023
import curses
from curses import wrapper
from curses.textpad import rectangle
from subprocess import call
import os
# define variables
cardSet = []
with open("CurrentSet.txt", "r") as file:
homeFileName = file.readline().replace("\n", "")
for line in file:
card = line.replace("\n", "").split("|")
cardSet.append(card)
selected = 1
def drawOptionsMenu(stdscr):
magenta = curses.color_pair(1)
cyan = curses.color_pair(2)
yellow = curses.color_pair(3)
white = curses.color_pair(4)
centerRow = curses.LINES // 2
centerCol = curses.COLS // 2
boxTL = (centerRow - 14, centerCol - 38)
boxBR = (centerRow + 14, centerCol + 38)
stdscr.clear()
text = "Choose an option:"
stdscr.addstr(centerRow - 11, centerCol - len(text) // 2, text, white)
text = f"Current file: {homeFileName}"
stdscr.addstr(centerRow + 7, centerCol - len(text) // 2, text, white)
text = "exit (esc)"
stdscr.addstr(centerRow + 12, centerCol - 30 - len(text) // 2, text, white)
text = "accept (enter)"
stdscr.addstr(centerRow + 12, centerCol + 30 - len(text) // 2, text, white)
for i in range(3):
if i + 1 == selected:
color = yellow
else:
color = cyan
if i == 0:
text = "Practice"
stdscr.addstr(centerRow - 7, centerCol - len(text) // 2, text, color)
elif i == 1:
text = "Edit File"
stdscr.addstr(centerRow - 2, centerCol - len(text) // 2, text, color)
elif i == 2:
text = "Delete File"
stdscr.addstr(centerRow + 3, centerCol - len(text) // 2, text, color)
rectangle(stdscr, boxTL[0], boxTL[1], boxBR[0], boxBR[1])
stdscr.refresh()
# move cursor function
def moveCursor(dir):
global selected, page
if dir == "up" and selected != 1:
selected -= 1
elif dir == "down" and selected != 3:
selected += 1
# select item function
def selectItem():
if selected == 3:
os.remove(f"Sets/{homeFileName}")
file = open("CurrentSet.txt", "w")
file.close()
# main function
def main(stdscr):
curses.init_pair(1, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
curses.init_pair(4, curses.COLOR_WHITE, curses.COLOR_BLACK)
exitFile = False
while True:
drawOptionsMenu(stdscr)
key = stdscr.getch()
if key == curses.KEY_UP:
moveCursor("up")
elif key == curses.KEY_DOWN:
moveCursor("down")
elif chr(key) == "\n":
selectItem()
break
elif key == 27:
exitFile = True
break
if selected == 1 and not exitFile:
call(["python", "Practice.py"])
elif selected == 2 and not exitFile:
call(["python", "EditFile.py"])
elif selected == 3 or exitFile:
call(["python", "QuizletSucks.py"])
wrapper(main)