Skip to content
Snippets Groups Projects
Commit e154d6e7 authored by Benedikt's avatar Benedikt
Browse files

fixes #4

parent 64c92fc1
No related branches found
No related tags found
No related merge requests found
...@@ -41,7 +41,8 @@ If there was an error with the calculation, please fill out the table above. Fee ...@@ -41,7 +41,8 @@ If there was an error with the calculation, please fill out the table above. Fee
*Free text comment*""" *Free text comment*"""
class dsiparserInput(): class dsiparserInput():
def __init__(self,defaultInput=""): def __init__(self,defaultInput="",additionalComparisonCallbacks=[]):
self.additionalComparisonCallbacks=additionalComparisonCallbacks
self.dsiInput = TextInput(value=defaultInput, title="DSI unit string:", width=500) self.dsiInput = TextInput(value=defaultInput, title="DSI unit string:", width=500)
self.dsiInput.on_event(ValueSubmit, self.parseInput) self.dsiInput.on_event(ValueSubmit, self.parseInput)
self.dsiSubmitButton = Button(label="Convert", button_type="primary") self.dsiSubmitButton = Button(label="Convert", button_type="primary")
...@@ -50,7 +51,12 @@ class dsiparserInput(): ...@@ -50,7 +51,12 @@ class dsiparserInput():
self.results = column(children = []) self.results = column(children = [])
self.widget = column(children=[self.inputRow, self.results], css_classes=["doubleColumn"]) self.widget = column(children=[self.inputRow, self.results], css_classes=["doubleColumn"])
self.valideUnit = False self.valideUnit = False
self.dsiTree = None
def parseInpuitWithCallbacls(self):
self.parseInput()
for callback in self.additionalComparisonCallbacks:
callback()
def parseInput(self): def parseInput(self):
self.results.children = [] self.results.children = []
input = self.dsiInput.value input = self.dsiInput.value
...@@ -202,8 +208,8 @@ class page(): ...@@ -202,8 +208,8 @@ class page():
curdoc().title = "DSI to Latex" curdoc().title = "DSI to Latex"
curdoc().add_root(bokehCssPTB.getStyleDiv()) curdoc().add_root(bokehCssPTB.getStyleDiv())
curdoc().theme = bokehCssPTB.getTheme() curdoc().theme = bokehCssPTB.getTheme()
self.dsiInput1 = dsiparserInput(defaultInput="\\milli\\newton\\metre") self.dsiInput1 = dsiparserInput(defaultInput="\\milli\\newton\\metre",additionalComparisonCallbacks=[self.clearComparison,self.tryComparison])
self.dsiInput2 = dsiparserInput(defaultInput="\\kilo\\joule") self.dsiInput2 = dsiparserInput(defaultInput="\\kilo\\joule",additionalComparisonCallbacks=[self.clearComparison,self.tryComparison])
self.inputs=row([self.dsiInput1.widget, self.dsiInput2.widget]) self.inputs=row([self.dsiInput1.widget, self.dsiInput2.widget])
curdoc().add_root(self.inputs) curdoc().add_root(self.inputs)
...@@ -244,9 +250,16 @@ class page(): ...@@ -244,9 +250,16 @@ class page():
self.createIssueButton.js_on_event("button_click",CustomJS(code=f"window.open('{self.createIssueUrl()}', '_blank');")) self.createIssueButton.js_on_event("button_click",CustomJS(code=f"window.open('{self.createIssueUrl()}', '_blank');"))
def createIssueUrl(self): def createIssueUrl(self):
quantitiesToAdd=[self.dsiInput1.dsiInput.value,str(self.dsiInput1.dsiTree),self.dsiInput2.dsiInput.value,str(self.dsiInput2.dsiTree),str(self.dsiCompGraphGen.baseUnit),self.dsiCompGraphGen.scalfactorAB,self.dsiCompGraphGen.scalfactorBA,self.dsiCompGraphGen.scalfactorABase,self.dsiCompGraphGen.scalfactorBaseA,self.dsiCompGraphGen.scalfactorBBase,self.dsiCompGraphGen.scalfactorBaseB] issueArgs=[self.dsiInput1.dsiInput.value,str(self.dsiInput1.dsiTree),self.dsiInput2.dsiInput.value,str(self.dsiInput2.dsiTree)]
comGenAtrssFroIssue=['baseUnit', 'scalfactorAB', 'scalfactorBA', 'scalfactorABase', 'scalfactorBaseA', 'scalfactorBBase', 'scalfactorBaseB']
for comGenAtrss in comGenAtrssFroIssue:
try:
issueArgs.append(str(getattr(self.dsiCompGraphGen,comGenAtrss)))
except AttributeError as Ae:
issueArgs.append("AttributeError: "+str(Ae))
#quantitiesToAdd=[self.dsiInput1.dsiInput.value,str(self.dsiInput1.dsiTree),self.dsiInput2.dsiInput.value,str(self.dsiInput2.dsiTree),str(self.dsiCompGraphGen.baseUnit),self.dsiCompGraphGen.scalfactorAB,self.dsiCompGraphGen.scalfactorBA,self.dsiCompGraphGen.scalfactorABase,self.dsiCompGraphGen.scalfactorBaseA,self.dsiCompGraphGen.scalfactorBBase,self.dsiCompGraphGen.scalfactorBaseB]
#issueTemplate=open('./issue.md').read() #TODO add file inculde instead of the str.... #issueTemplate=open('./issue.md').read() #TODO add file inculde instead of the str....
filledResult=issueTemplate.format(*quantitiesToAdd) filledResult=issueTemplate.format(*issueArgs)
filledTitle = f'Unexpected comparison result: {self.dsiInput1.dsiInput.value} to {self.dsiInput2.dsiInput.value}' filledTitle = f'Unexpected comparison result: {self.dsiInput1.dsiInput.value} to {self.dsiInput2.dsiInput.value}'
issueUrl = r'https://gitlab1.ptb.de/digitaldynamicmeasurement/dsi-parser-frontend/-/issues/new?' issueUrl = r'https://gitlab1.ptb.de/digitaldynamicmeasurement/dsi-parser-frontend/-/issues/new?'
title = quote(filledTitle) title = quote(filledTitle)
...@@ -256,4 +269,14 @@ class page(): ...@@ -256,4 +269,14 @@ class page():
return url return url
def clearComparison(self):
self.dsiCompGraphGen.flush()
self.compaReresult.text = ""
self.createIssueButton.disabled=True
self.createIssueButton.button_type="primary"
def tryComparison(self):
if self.dsiInput1.valideUnit and self.dsiInput2.valideUnit:
self.compare()
thisPage = page() thisPage = page()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment