forked from mrob95/mathfly-talon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
maths_help.py
130 lines (100 loc) · 3.5 KB
/
maths_help.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
from talon import Module, Context, imgui, registry
from typing import Tuple
mod = Module()
ctx = Context()
current_page = 1
lines_per_page = 20
extra_padding = 50
current_view = "Start"
lyx_help_text = """LyX help
To get started, use the 'new file' command
to create a new file, then use the 'math mode'
command to start inserting mathematics.
Try the following sequence:
integral plex squared equals one third plex cubed
For a full list of available commands, click
the buttons below.
To modify or add commands, see the following files:
- lyx.py
- lyx.talon
- tex_maths.py
"""
sn55_help_text = """Scientific Notebook 5.5 help
To get started, use the 'body maths' command
to start inserting mathematics.
Try the following sequence:
integral plex squared equals one third plex cubed
For a full list of available commands, click
the buttons below.
To modify or add commands, see the following files:
- scientific_notebook_55.py
- scientific_notebook_55.talon
- tex_maths.py
"""
def draw_multiline_text(gui: imgui.GUI, text: str):
for line in text.split("\n"):
gui.text(line)
def draw_page_buttons(gui: imgui.GUI, total_items: int):
global current_page
num_pages = (total_items // lines_per_page) + 1
gui.text(f"| {current_view} - Page {current_page} / {num_pages} {' '*extra_padding} |")
if gui.button("Next page") and current_page < num_pages:
current_page += 1
if gui.button("Previous page") and current_page > 1:
current_page -= 1
def get_bounds_of_items_shown(total_items: int) -> Tuple[int, int]:
start = lines_per_page * (current_page - 1)
end = lines_per_page * (current_page)
if end >= total_items:
end = total_items - 1
return start, end
def draw_view_picker(gui: imgui.GUI):
global current_view
global current_page
for view in ("Symbols", "Greek letters", "Other"):
if gui.button(view):
current_page = 1
current_view = view
@imgui.open(y=0)
def gui_maths_help(gui: imgui.GUI):
maths_contexts = [context for context in registry.active_contexts() if "user.maths" in context.tags]
if not maths_contexts:
gui.text("Maths context not currently focused")
return
# [maths.talon, app.talon]
context = maths_contexts[1]
if current_view == "Start":
if "lyx" in str(context):
draw_multiline_text(gui, lyx_help_text)
elif "scientific_notebook" in str(context):
draw_multiline_text(gui, sn55_help_text)
else:
items = []
if current_view == "Symbols":
items = list(registry.lists["user.tex_symbols"][0].keys())
items = sorted(items)
elif current_view == "Greek letters":
greek_letters = list(registry.lists["user.greek_letters"][0].keys())
items = [f"greek {g}" for g in greek_letters]
elif current_view == "Other":
items = []
for con in maths_contexts:
for c in con.commands.values():
items.append(c.rule.rule)
draw_page_buttons(gui, len(items))
gui.text("")
start, end = get_bounds_of_items_shown(len(items))
for i in range(start, end):
gui.text(items[i])
gui.text("")
draw_view_picker(gui)
if gui.button("Close"):
gui_maths_help.hide()
@mod.action_class
class Actions:
def maths_help_show():
"""Show help dialogue"""
gui_maths_help.show()
def maths_help_hide():
"""Hide help dialogue"""
gui_maths_help.hide()