Skip to content

Commit dfb9cb7

Browse files
committed
Reimplemented the ProgramTemplate with the new template system. WIP.
1 parent 308e380 commit dfb9cb7

File tree

4 files changed

+10
-106
lines changed

4 files changed

+10
-106
lines changed

floppy/CustomNodes/crystNodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def run(self):
147147
def report(self):
148148
r = super(PDB2INS, self).report()
149149
r['stdout'] = self.stdout
150-
r['template'] = 'programTemplate'
150+
r['template'] = 'ProgramTemplate'
151151
return r
152152

153153

floppy/CustomNodes/shelxNodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def run(self):
6363

6464
def report(self):
6565
r = super(RunShelxl, self).report()
66-
r['template'] = 'programTemplate'
66+
r['template'] = 'ProgramTemplate'
6767
r['stdout'] = self.stdout
6868
return r
6969

floppy/reportWidget.py

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,7 @@
22
from PyQt5 import QtWebEngineWidgets, QtWebEngineCore
33
from PyQt5.QtCore import Qt, QPoint, QSettings
44
from floppy.templates import TEMPLATES
5-
'''
6-
TEMPLATES = {}
75

8-
9-
10-
def template(func):
11-
TEMPLATES[func.__name__] = func
12-
return func
13-
14-
15-
16-
@template
17-
def defaultTemplate(data, cache):
18-
return """<h1 id="head">{nodeName} -- {nodeID}</h1>
19-
<style>
20-
h1 {{ text-align:center; color: white}};
21-
</style>
22-
23-
<style type="text/css">
24-
#wrap {{
25-
width:400;
26-
margin:0 auto;
27-
}}
28-
#left_col {{
29-
float:left;
30-
width:200;
31-
text-align:left;
32-
color: white
33-
}}
34-
#right_col {{
35-
float:right;
36-
width:200;
37-
text-align:right;
38-
color: white
39-
}}
40-
</style>
41-
<div id="wrap">
42-
<div id="left_col">
43-
{inputs}
44-
</div>
45-
<div id="right_col">
46-
{outputs}
47-
</div>
48-
</div>""".format(nodeName=data['class'], nodeID=data['ID'],
49-
inputs='<br>'.join(['{}[{}]: {}'.format(name, varType, value) for name, varType, value in data['inputs']]),
50-
outputs='<br>'.join(['{}[{}]: {}'.format(name, varType, value) for name, varType, value in data['outputs']]))
51-
52-
'''
53-
#class ReportWidget(QtWebKitWidgets.QWebView):
546
class ReportWidget(QtWebEngineWidgets.QWebEngineView):
557

568
def __init__(self, *args, **kwargs):
@@ -106,62 +58,6 @@ def _update(self):
10658
#scrollValue = self.page().scrollPosition()
10759
self.setHtml(tmplt(data, self.cache[:], self.fileBase, self.width()), url)
10860

109-
'''
110-
@template
111-
def defaultTemplate(data, cache, fileBase):
112-
return """
113-
<style>
114-
h1 {{ text-align:center; color: white}}
115-
</style>
116-
117-
<style type="text/css">
118-
#wrap {{
119-
width:400;
120-
margin:0 auto;
121-
}}
122-
#left_col {{
123-
float:left;
124-
width:200;
125-
text-align:left;
126-
color: white
127-
}}
128-
#right_col {{
129-
float:right;
130-
width:200;
131-
text-align:right;
132-
color: white
133-
}}
134-
</style>
135-
<HTML>
136-
<h1 id="head">{nodeName} -- {nodeID}</h1>
137-
<div id="wrap">
138-
<div id="left_col">
139-
{inputs}
140-
</div>
141-
<div id="right_col">
142-
{outputs}
143-
</div>
144-
</div></HTML>
145-
""".format(nodeName=data['class'], nodeID=data['ID'],
146-
inputs='<br>'.join(['{}[{}]: {}'.format(name, varType, value) for name, varType, value in data['inputs']]),
147-
outputs='<br>'.join(['{}[{}]: {}'.format(name, varType, value) for name, varType, value in data['outputs']]))
148-
'''
149-
from floppy.quickPlot import test
150-
def defaultTemplate(data, cache, fileBase, width):
151-
print(width)
152-
153-
return '''
154-
<HTML>
15561

156-
<BODY bgcolor="#606060">
157-
<H1>{nodeName}</H1>
158-
<div id=nodeID>ID: {ID} </div>
159-
<P>This is very minimal "hello world" HTML document.</P>
160-
{plot}
161-
</BODY>
162-
</HTML>
163-
'''.format(nodeName=data['class'],
164-
ID=data['ID'],
165-
plot=test(width-30))
16662

16763

floppy/templates.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ def __call__(self, data, cache, fileBase, width):
159159
else:
160160
return str(self.document)
161161

162+
class StdoutElement(TemplateElement):
163+
def __call__(self, data, cache, fileBase, width):
164+
return data['stdout'].replace('\\n', '<br>')
165+
162166

163167
class MetaTemplate(type):
164168
def __new__(cls, name, bases, classdict):
@@ -213,3 +217,7 @@ def __call__(self, data, cache, fileBase, width):
213217
</BODY>
214218
</HTML>
215219
'''.format(body='\n<br>\n'.join([element(data, cache, fileBase, width) for element in self.elements]))
220+
221+
222+
class ProgramTemplate(DefaultTemplate):
223+
ELEMENTS = [IOElement, StdoutElement]

0 commit comments

Comments
 (0)