diff --git a/saenopy/gui/common/ModuleScaleBar.py b/saenopy/gui/common/ModuleScaleBar.py
new file mode 100644
index 0000000..0703659
--- /dev/null
+++ b/saenopy/gui/common/ModuleScaleBar.py
@@ -0,0 +1,62 @@
+import numpy as np
+from qtpy import QtCore, QtWidgets, QtGui
+
+
+class ModuleScaleBar(QtWidgets.QGroupBox):
+ pixtomu = None
+
+ def __init__(self, parent, view):
+ QtWidgets.QWidget.__init__(self)
+ self.parent = parent
+
+ self.font = QtGui.QFont()
+ self.font.setPointSize(16)
+
+ self.scale = 1
+
+ self.scalebar = QtWidgets.QGraphicsRectItem(0, 0, 1, 1, view.hud_lowerRight)
+ self.scalebar.setBrush(QtGui.QBrush(QtGui.QColor("white")))
+ self.scalebar.setPen(QtGui.QPen(QtGui.QColor("white")))
+ self.scalebar.setPos(-20, -20)
+ self.scalebar_text = QtWidgets.QGraphicsTextItem("", view.hud_lowerRight)
+ self.scalebar_text.setFont(self.font)
+ self.scalebar_text.setDefaultTextColor(QtGui.QColor("white"))
+
+ self.time_text = QtWidgets.QGraphicsTextItem("", view.hud_upperRight)
+ self.time_text.setFont(self.font)
+ self.time_text.setDefaultTextColor(QtGui.QColor("white"))
+
+ view.signal_zoom.connect(self.zoomEvent)
+
+ self.updateStatus()
+
+ def updateStatus(self):
+ self.updateBar()
+
+ def zoomEvent(self, scale, pos):
+ self.scale = scale
+ self.updateBar()
+
+ def setScale(self, voxel_size):
+ self.pixtomu = voxel_size[0]
+ self.updateBar()
+
+ def updateBar(self):
+ if self.scale == 0 or self.pixtomu is None:
+ return
+ mu = 100*self.pixtomu/self.scale
+ values = [1, 5, 10, 25, 50, 75, 100, 150, 200, 250, 500, 1000, 1500, 2000, 2500, 5000, 10000]
+ old_v = mu
+ for v in values:
+ if mu < v:
+ mu = old_v
+ break
+ old_v = v
+ if np.abs(self.pixtomu) < 1e-10:
+ pixel = 0
+ else:
+ pixel = mu/(self.pixtomu)*self.scale
+ self.scalebar.setRect(0, 0, -pixel, 5)
+ self.scalebar_text.setPos(-pixel-20-25, -20-30)
+ self.scalebar_text.setTextWidth(pixel+50)
+ self.scalebar_text.setHtml(u"
%d µm" % mu)
diff --git a/saenopy/gui/solver/modules/StackDisplay.py b/saenopy/gui/solver/modules/StackDisplay.py
index 9500956..f127e6a 100644
--- a/saenopy/gui/solver/modules/StackDisplay.py
+++ b/saenopy/gui/solver/modules/StackDisplay.py
@@ -26,6 +26,7 @@
from saenopy.gui.common.PipelineModule import PipelineModule
from saenopy.gui.common.QTimeSlider import QTimeSlider
from saenopy.gui.common.code_export import get_code
+from saenopy.gui.common.ModuleScaleBar import ModuleScaleBar
class StackDisplay(PipelineModule):
@@ -353,63 +354,3 @@ def code(filename, output1, voxel_size1, time_delta1, result_file, crop1): # pr
code = get_code(code, data)
return import_code, code
-
-
-class ModuleScaleBar(QtWidgets.QGroupBox):
- pixtomu = None
-
- def __init__(self, parent, view):
- QtWidgets.QWidget.__init__(self)
- self.parent = parent
-
- self.font = QtGui.QFont()
- self.font.setPointSize(16)
-
- self.scale = 1
-
- self.scalebar = QtWidgets.QGraphicsRectItem(0, 0, 1, 1, view.hud_lowerRight)
- self.scalebar.setBrush(QtGui.QBrush(QtGui.QColor("white")))
- self.scalebar.setPen(QtGui.QPen(QtGui.QColor("white")))
- self.scalebar.setPos(-20, -20)
- self.scalebar_text = QtWidgets.QGraphicsTextItem("", view.hud_lowerRight)
- self.scalebar_text.setFont(self.font)
- self.scalebar_text.setDefaultTextColor(QtGui.QColor("white"))
-
- self.time_text = QtWidgets.QGraphicsTextItem("", view.hud_upperRight)
- self.time_text.setFont(self.font)
- self.time_text.setDefaultTextColor(QtGui.QColor("white"))
-
- view.signal_zoom.connect(self.zoomEvent)
-
- self.updateStatus()
-
- def updateStatus(self):
- self.updateBar()
-
- def zoomEvent(self, scale, pos):
- self.scale = scale
- self.updateBar()
-
- def setScale(self, voxel_size):
- self.pixtomu = voxel_size[0]
- self.updateBar()
-
- def updateBar(self):
- if self.scale == 0 or self.pixtomu is None:
- return
- mu = 100*self.pixtomu/self.scale
- values = [1, 5, 10, 25, 50, 75, 100, 150, 200, 250, 500, 1000, 1500, 2000, 2500, 5000, 10000]
- old_v = mu
- for v in values:
- if mu < v:
- mu = old_v
- break
- old_v = v
- if np.abs(self.pixtomu) < 1e-10:
- pixel = 0
- else:
- pixel = mu/(self.pixtomu)*self.scale
- self.scalebar.setRect(0, 0, -pixel, 5)
- self.scalebar_text.setPos(-pixel-20-25, -20-30)
- self.scalebar_text.setTextWidth(pixel+50)
- self.scalebar_text.setHtml(u"%d µm" % mu)
diff --git a/saenopy/gui/spheroid/modules/DeformationDetector.py b/saenopy/gui/spheroid/modules/DeformationDetector.py
index 2a6cbe8..e0f1ed2 100644
--- a/saenopy/gui/spheroid/modules/DeformationDetector.py
+++ b/saenopy/gui/spheroid/modules/DeformationDetector.py
@@ -14,6 +14,7 @@
from saenopy.gui.common.QTimeSlider import QTimeSlider
from saenopy.gui.common.resources import resource_icon
from saenopy.gui.common.code_export import get_code
+from saenopy.gui.common.ModuleScaleBar import ModuleScaleBar
class DeformationDetector(PipelineModule):
@@ -74,6 +75,7 @@ def __init__(self, parent: "BatchEvaluate", layout):
#self.plotter.set_background("black")
#layout.addWidget(self.plotter.interactor)
self.label = QExtendedGraphicsView.QExtendedGraphicsView().addToLayout()
+ self.scale1 = ModuleScaleBar(self, self.label)
#self.label.setMinimumWidth(300)
self.pixmap = QtWidgets.QGraphicsPixmapItem(self.label.origin)
self.contour = QtWidgets.QGraphicsPathItem(self.label.origin)
@@ -222,6 +224,7 @@ def update_display(self, *, plotter=None):
im = np.asarray(pil_image)
self.pixmap.setPixmap(QtGui.QPixmap(array2qimage(im)))
self.label.setExtend(im.shape[1], im.shape[0])
+ self.scale1.setScale([self.result.pixel_size])
if self.show_seg.value():
thresh_segmentation = self.thresh_segmentation.value()
diff --git a/saenopy/gui/tfm2d/modules/BatchEvaluate.py b/saenopy/gui/tfm2d/modules/BatchEvaluate.py
index 8b213bf..76d749a 100644
--- a/saenopy/gui/tfm2d/modules/BatchEvaluate.py
+++ b/saenopy/gui/tfm2d/modules/BatchEvaluate.py
@@ -22,6 +22,7 @@
from saenopy.gui.common.BatchEvaluate import BatchEvaluate
from ...solver.modules.exporter.Exporter import ExportViewer
+from saenopy.gui.common.ModuleScaleBar import ModuleScaleBar
class BatchEvaluate(BatchEvaluate):
@@ -75,6 +76,7 @@ def tab_changed(x):
pass
self.draw = DrawWindow(self, QtShortCuts.currentLayout())
self.draw.signal_mask_drawn.connect(self.on_mask_drawn)
+ self.scale1 = ModuleScaleBar(self, self.draw.view1)
def generate_data(self):
new_path = QtWidgets.QFileDialog.getSaveFileName(None, "Save Data CSV", os.getcwd(),
@@ -237,6 +239,7 @@ def listSelected(self):
self.draw.setMask(np.zeros(pipe.shape, dtype=np.uint8))
else:
self.draw.setMask(pipe.mask.astype(np.uint8))
+ self.scale1.setScale([pipe.pixel_size])
self.set_current_result.emit(pipe)
tab = self.tabs.currentWidget()
self.tab_changed.emit(tab)