Skip to content

Commit

Permalink
Formatting for dict in DT.info()
Browse files Browse the repository at this point in the history
  • Loading branch information
jpn-- committed Feb 3, 2017
1 parent a9d97c8 commit e0365a2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions doc/_static/larch_rtfd.css
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,10 @@ h3.larch_art, h3.larch_art_xhtml {
h2.larch_art + h3.larch_art, h2.larch_art_xhtml + h3.larch_art_xhtml,
h2.larch_art + a.toc + h3.larch_art, h2.larch_art_xhtml + a.toc + h3.larch_art_xhtml {
margin-top: 5px;

table.dictionary {
border:0px hidden !important;
border-collapse: collapse !important;
}

}
8 changes: 7 additions & 1 deletion py/dt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import re
from .groupnode import GroupNode
from contextlib import contextmanager
from ..util.xhtml import ElemTableFromDict

class IncompatibleShape(LarchError):
pass
Expand Down Expand Up @@ -3484,7 +3485,12 @@ def info(self, extra=None, relative_paths=True):
a.set_jrow_loc(rownum, 'TITLE', the_node._v_attrs.TITLE)
if 'DICTIONARY' in extra:
if 'DICTIONARY' in the_node._v_attrs:
a.set_jrow_loc(rownum, 'DICTIONARY', str(the_node._v_attrs.DICTIONARY))
di = the_node._v_attrs.DICTIONARY
if isinstance(di,dict):
di = ElemTableFromDict(di)
else:
di = str(di)
a.set_jrow_loc(rownum, 'DICTIONARY', di)


## Content: Expr
Expand Down
3 changes: 3 additions & 0 deletions py/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def __call__(self, *arg):
font-weight: 500;
font-size: 100%;
}
table.dictionary { border:0px hidden !important; border-collapse: collapse !important; }
"""


Expand Down
1 change: 1 addition & 0 deletions py/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def multireport(models_or_filenames, params=(), ratios=(), *, filename=None, ove
td.tstat { font-size: 80%; font-weight: 300;}
.larch_signature {""" + styles.signature_font + """}
.larch_name_signature {""" + styles.signature_name_font + """}
table.dictionary { border:0px hidden !important; border-collapse: collapse !important; }
</style>
"""

Expand Down
13 changes: 13 additions & 0 deletions py/util/xhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
font-weight: 100;
font-size: 80%;
}
table.dictionary { border:0px hidden !important; border-collapse: collapse !important; }
"""


Expand Down Expand Up @@ -168,6 +171,16 @@ def save(self, filename, overwrite=True):
f << self


def ElemTableFromDict(dictionary, toptag='div'):
e = Elem(tag=toptag)
table = e.put('table', attrib={'class':'dictionary'})
for k in sorted(dictionary.keys()):
trow = table.put('tr')
trow.put('td', text=str(k))
trow.put('td', text=str(dictionary[k]))
return e


def Anchor_Elem(reftxt, cls, toclevel):
return Elem('a', {'name':_uid(), 'reftxt':str(reftxt), 'class':str(cls), 'toclevel':str(toclevel)})

Expand Down

0 comments on commit e0365a2

Please sign in to comment.