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"
self.dsiInput = TextInput(value="", title="DSI unit string:", width=500)
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], css_classes = ["textInputRow"])
self.widget = column(children=[self.inputRow, self.results], css_classes=["textlikeColumn"])
self.results.children = []
input = self.dsiInput.value
p = dsiParser()
resultTree = p.parse(input)
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
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]
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.dsiInput1 = dsiparserInput()
self.dsiInput2 = dsiparserInput()
self.inputs=row([self.dsiInput1.widget, self.dsiInput2.widget])
curdoc().add_root(self.inputs)
self.comapreButton = Button(label="Compare", button_type="primary")
self.comapreButton.on_click(self.compare)
self.compaReresult = Div(text = "", css_classes = ["msg-positive"])
self.compareRow = row(children = [self.comapreButton,self.compaReresult], css_classes = ["textInputRow"])
curdoc().add_root(self.compareRow)
def compare(self):
self.dsiInput1.parseInput()
self.dsiInput2.parseInput()
scalfactor,baseUnit=self.dsiInput1.dsiTree.isScalablyEqualTo(self.dsiInput2.dsiTree)
if scalfactor:
self.compaReresult.text = "The two units are equal up to a scaling factor of "+str(scalfactor)+" and a base unit of "+str(baseUnit)
self.compaReresult.css_classes=["msg-positive"]
else:
self.compaReresult.text = "The two units are not equal"
self.compaReresult.css_classes = ["msg-negative"]