Skip to content

Commit 93dee35

Browse files
committed
enh: improved visualization of meta data parameters in the Info tab
1 parent fcfbf90 commit 93dee35

File tree

5 files changed

+137
-21
lines changed

5 files changed

+137
-21
lines changed

CHANGELOG

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
0.5.3
2-
- setup: bump afmformats from 0.3.0 to 0.4.0
2+
- enh: improved visualization of meta data parameters in the Info tab
3+
- setup: bump afmformats from 0.3.0 to 0.4.1
34
- setup: bump nanite from 1.2.0 to 1.2.2
45
0.5.2
56
- ref: bump nanite to 1.2.0

pyjibe/fd/main.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,16 +286,7 @@ def get_export_choices():
286286

287287
def info_update(self, fdist):
288288
"""Updates the info tab"""
289-
text = []
290-
text.append("filename: {}".format(fdist.path))
291-
text.append("position index/enum: {}".format(fdist.enum))
292-
text.append("")
293-
keys = list(fdist.metadata.keys())
294-
keys.sort()
295-
for k in keys:
296-
text.append("{}: {}".format(k, fdist.metadata[k]))
297-
textstring = "\n".join(text)
298-
self.info_text.setPlainText(textstring)
289+
self.tab_info.update_info(fdist)
299290

300291
def on_cb_rating_scheme(self):
301292
"""Switch rating scheme or import a new one"""

pyjibe/fd/main.ui

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,22 +310,13 @@
310310
</item>
311311
</layout>
312312
</widget>
313-
<widget class="QWidget" name="tab_info">
313+
<widget class="TabInfo" name="tab_info">
314314
<attribute name="title">
315315
<string>Info</string>
316316
</attribute>
317317
<attribute name="toolTip">
318318
<string>cuve information</string>
319319
</attribute>
320-
<layout class="QHBoxLayout" name="horizontalLayout_5">
321-
<item>
322-
<widget class="QPlainTextEdit" name="info_text">
323-
<property name="readOnly">
324-
<bool>true</bool>
325-
</property>
326-
</widget>
327-
</item>
328-
</layout>
329320
</widget>
330321
<widget class="TabQMap" name="tab_qmap">
331322
<attribute name="title">
@@ -562,6 +553,12 @@
562553
<header>pyjibe.fd.widget_fdist</header>
563554
<container>1</container>
564555
</customwidget>
556+
<customwidget>
557+
<class>TabInfo</class>
558+
<extends>QWidget</extends>
559+
<header>pyjibe.fd.tab_info</header>
560+
<container>1</container>
561+
</customwidget>
565562
</customwidgets>
566563
<resources/>
567564
<connections>

pyjibe/fd/tab_info.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import numbers
2+
import pkg_resources
3+
4+
from afmformats import meta
5+
from PyQt5 import uic, QtWidgets
6+
7+
8+
class TabInfo(QtWidgets.QWidget):
9+
def __init__(self, *args, **kwargs):
10+
super(TabInfo, self).__init__(*args, **kwargs)
11+
path_ui = pkg_resources.resource_filename("pyjibe.fd",
12+
"tab_info.ui")
13+
uic.loadUi(path_ui, self)
14+
15+
def update_info(self, fdist):
16+
text = []
17+
keys = list(fdist.metadata.keys())
18+
19+
text.append("<b>Dataset</b>")
20+
data_keys = ["path", "enum"]
21+
for kk in data_keys:
22+
text.append(get_string_rep(kk, fdist.metadata))
23+
for kk in keys:
24+
if kk in meta.DEF_DATA and kk not in data_keys:
25+
text.append(get_string_rep(kk, fdist.metadata))
26+
27+
if set(keys) & set(meta.DEF_EXPERIMENT.keys()):
28+
text.append("")
29+
text.append("<b>Experiment:</b>")
30+
text_meta = []
31+
for kk in keys:
32+
if kk in meta.DEF_EXPERIMENT:
33+
text_meta.append(get_string_rep(kk, fdist.metadata))
34+
text += sorted(text_meta)
35+
36+
if set(keys) & set(meta.DEF_QMAP.keys()):
37+
text.append("")
38+
text.append("<b>QMap:</b>")
39+
text_meta = []
40+
for kk in keys:
41+
if kk in meta.DEF_QMAP:
42+
text_meta.append(get_string_rep(kk, fdist.metadata))
43+
text += sorted(text_meta)
44+
45+
if set(keys) & set(meta.DEF_ANALYSIS.keys()):
46+
text.append("")
47+
text.append("<b>Analysis:</b>")
48+
text_meta = []
49+
for kk in keys:
50+
if kk in meta.DEF_ANALYSIS:
51+
text_meta.append(get_string_rep(kk, fdist.metadata))
52+
text += sorted(text_meta)
53+
54+
textstring = "<br>".join(text)
55+
56+
self.info_text.setText(textstring)
57+
58+
59+
def get_string_rep(key, metadata):
60+
"""Return a nice string representation for a key in metadata"""
61+
value = metadata[key]
62+
desc, unit, validator = meta.DEF_ALL[key]
63+
64+
value = validator(value)
65+
66+
if unit == "m":
67+
unit = "µm"
68+
value *= 1e6
69+
70+
if isinstance(value, numbers.Integral):
71+
pass
72+
elif isinstance(value, numbers.Real):
73+
if abs(value) > 1:
74+
value = "{:.2f}".format(value)
75+
elif abs(value) > 1e-2:
76+
value = "{:.5f}".format(value)
77+
else:
78+
value = "{:.3e}".format(value)
79+
80+
rep = "{}: {}".format(desc, value)
81+
if unit:
82+
rep += " {}".format(unit)
83+
return rep

pyjibe/fd/tab_info.ui

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>Form</class>
4+
<widget class="QWidget" name="Form">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>411</width>
10+
<height>396</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Form</string>
15+
</property>
16+
<layout class="QVBoxLayout" name="verticalLayout">
17+
<item>
18+
<widget class="QTextEdit" name="info_text">
19+
<property name="lineWrapMode">
20+
<enum>QTextEdit::NoWrap</enum>
21+
</property>
22+
<property name="readOnly">
23+
<bool>true</bool>
24+
</property>
25+
<property name="html">
26+
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
27+
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
28+
p, li { white-space: pre-wrap; }
29+
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
30+
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
31+
</property>
32+
<property name="overwriteMode">
33+
<bool>false</bool>
34+
</property>
35+
<property name="placeholderText">
36+
<string>Nothing here yet.</string>
37+
</property>
38+
</widget>
39+
</item>
40+
</layout>
41+
</widget>
42+
<resources/>
43+
<connections/>
44+
</ui>

0 commit comments

Comments
 (0)