Skip to content

Commit

Permalink
enh: improved visualization of meta data parameters in the Info tab
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Oct 1, 2019
1 parent fcfbf90 commit 93dee35
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 21 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
0.5.3
- setup: bump afmformats from 0.3.0 to 0.4.0
- enh: improved visualization of meta data parameters in the Info tab
- setup: bump afmformats from 0.3.0 to 0.4.1
- setup: bump nanite from 1.2.0 to 1.2.2
0.5.2
- ref: bump nanite to 1.2.0
Expand Down
11 changes: 1 addition & 10 deletions pyjibe/fd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,7 @@ def get_export_choices():

def info_update(self, fdist):
"""Updates the info tab"""
text = []
text.append("filename: {}".format(fdist.path))
text.append("position index/enum: {}".format(fdist.enum))
text.append("")
keys = list(fdist.metadata.keys())
keys.sort()
for k in keys:
text.append("{}: {}".format(k, fdist.metadata[k]))
textstring = "\n".join(text)
self.info_text.setPlainText(textstring)
self.tab_info.update_info(fdist)

def on_cb_rating_scheme(self):
"""Switch rating scheme or import a new one"""
Expand Down
17 changes: 7 additions & 10 deletions pyjibe/fd/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -310,22 +310,13 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_info">
<widget class="TabInfo" name="tab_info">
<attribute name="title">
<string>Info</string>
</attribute>
<attribute name="toolTip">
<string>cuve information</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QPlainTextEdit" name="info_text">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="TabQMap" name="tab_qmap">
<attribute name="title">
Expand Down Expand Up @@ -562,6 +553,12 @@
<header>pyjibe.fd.widget_fdist</header>
<container>1</container>
</customwidget>
<customwidget>
<class>TabInfo</class>
<extends>QWidget</extends>
<header>pyjibe.fd.tab_info</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
Expand Down
83 changes: 83 additions & 0 deletions pyjibe/fd/tab_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import numbers
import pkg_resources

from afmformats import meta
from PyQt5 import uic, QtWidgets


class TabInfo(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super(TabInfo, self).__init__(*args, **kwargs)
path_ui = pkg_resources.resource_filename("pyjibe.fd",
"tab_info.ui")
uic.loadUi(path_ui, self)

def update_info(self, fdist):
text = []
keys = list(fdist.metadata.keys())

text.append("<b>Dataset</b>")
data_keys = ["path", "enum"]
for kk in data_keys:
text.append(get_string_rep(kk, fdist.metadata))
for kk in keys:
if kk in meta.DEF_DATA and kk not in data_keys:
text.append(get_string_rep(kk, fdist.metadata))

if set(keys) & set(meta.DEF_EXPERIMENT.keys()):
text.append("")
text.append("<b>Experiment:</b>")
text_meta = []
for kk in keys:
if kk in meta.DEF_EXPERIMENT:
text_meta.append(get_string_rep(kk, fdist.metadata))
text += sorted(text_meta)

if set(keys) & set(meta.DEF_QMAP.keys()):
text.append("")
text.append("<b>QMap:</b>")
text_meta = []
for kk in keys:
if kk in meta.DEF_QMAP:
text_meta.append(get_string_rep(kk, fdist.metadata))
text += sorted(text_meta)

if set(keys) & set(meta.DEF_ANALYSIS.keys()):
text.append("")
text.append("<b>Analysis:</b>")
text_meta = []
for kk in keys:
if kk in meta.DEF_ANALYSIS:
text_meta.append(get_string_rep(kk, fdist.metadata))
text += sorted(text_meta)

textstring = "<br>".join(text)

self.info_text.setText(textstring)


def get_string_rep(key, metadata):
"""Return a nice string representation for a key in metadata"""
value = metadata[key]
desc, unit, validator = meta.DEF_ALL[key]

value = validator(value)

if unit == "m":
unit = "µm"
value *= 1e6

if isinstance(value, numbers.Integral):
pass
elif isinstance(value, numbers.Real):
if abs(value) > 1:
value = "{:.2f}".format(value)
elif abs(value) > 1e-2:
value = "{:.5f}".format(value)
else:
value = "{:.3e}".format(value)

rep = "{}: {}".format(desc, value)
if unit:
rep += " {}".format(unit)
return rep
44 changes: 44 additions & 0 deletions pyjibe/fd/tab_info.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>411</width>
<height>396</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextEdit" name="info_text">
<property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="html">
<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;
&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;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&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>
</property>
<property name="overwriteMode">
<bool>false</bool>
</property>
<property name="placeholderText">
<string>Nothing here yet.</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

0 comments on commit 93dee35

Please sign in to comment.