Newer
Older
import base64
import io
import json
import tarfile
import warnings
import bokehCssPTB
from dsiParser import dsiParser
from bokeh.plotting import curdoc,figure
from bokeh.models import FileInput, Div, CustomJS, Button, TabPanel, Tabs, Dropdown, TextInput, Button, MathText, Label
from bokeh.events import ValueSubmit
VERSION = "0.1.0"
class page():
def __init__(self):
curdoc().template_variables["VERSION"] = VERSION
curdoc().title = "DSI to Latex"
curdoc().add_root(bokehCssPTB.getStyleDiv())
curdoc().theme = bokehCssPTB.getTheme()
self.dsiInput = TextInput(value="", title="DSI unit string:")
self.dsiInput.on_event(ValueSubmit, self.parseInput)
self.dsiSubmitButton = Button(label="Convert", button_type="primary")
self.dsiSubmitButton.on_click(self.parseInput)
self.inputRow = row(children = [self.dsiInput, self.dsiSubmitButton])
curdoc().add_root(self.inputRow)
self.results = column(children = [])
curdoc().add_root(self.results)
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
self.results.children = []
input = self.dsiInput.value
p = dsiParser()
resultTree = p.parse(input)
parsingMessages = []
if resultTree.valid:
parsingMessages.append(
Div(
text = "DSI string parsed without warnings",
css_classes = ["msg-positive"],
)
)
else:
for message in resultTree.warnings:
parsingMessages.append(
Div(
text = message,
css_classes = ["msg-negative"]
)
)
self.resultErrors = column(children = parsingMessages)
# latexOutput = TextInput(value=resultTree.toLatex(), title="DSI unit string:")
# latexOutput.js_on_change()
latexOutput = row(children=[
Div(text = "$$\mathrm{\LaTeX{}}$$ code:"),
Div(text = "<pre><code>"+resultTree.toLatex()+"</code></pre>", disable_math=True)
])
p = figure(width=500, height=100, x_range=(0, 1), y_range=(0, 1), tools="save")
p.xaxis.visible = False
p.yaxis.visible = False
p.grid.visible = False
p.add_layout(Label(
x=0.5, y=0.5, text=resultTree.toLatex(), text_font_size="12px", text_baseline="middle", text_align="center",
))
imageOutput = row(children = [
Div(text = "$$\mathrm{\LaTeX{}}$$ output:"),
p
])
self.results.children = [self.resultErrors, latexOutput, imageOutput]