Skip to content

Commit

Permalink
feat: allow editing pixel size in props dock widget
Browse files Browse the repository at this point in the history
  • Loading branch information
ElpadoCan committed Apr 23, 2024
1 parent 0249ad3 commit e20e0ed
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 6 deletions.
53 changes: 48 additions & 5 deletions cellacdc/gui.py
Expand Up @@ -2061,7 +2061,7 @@ def gui_createRegionPropsDockWidget(self, side=Qt.LeftDockWidgetArea):
self.propsDockWidget.setAllowedAreas(
Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea
)

self.addDockWidget(side, self.propsDockWidget)
self.propsDockWidget.hide()

Expand Down Expand Up @@ -5714,8 +5714,11 @@ def updatePropsWidget(self, ID, fromHover=False):

propsQGBox.cellAreaPxlSB.setValue(area_pxl)

PhysicalSizeY = posData.PhysicalSizeY
PhysicalSizeX = posData.PhysicalSizeX
pixelSizeQGBox = self.guiTabControl.pixelSizeQGBox
PhysicalSizeX = pixelSizeQGBox.pixelWidthWidget.value()
PhysicalSizeY = pixelSizeQGBox.pixelHeightWidget.value()
PhysicalSizeZ = pixelSizeQGBox.voxelDepthWidget.value()

yx_pxl_to_um2 = PhysicalSizeY*PhysicalSizeX

area_um2 = area_pxl*yx_pxl_to_um2
Expand Down Expand Up @@ -8182,6 +8185,10 @@ def ruler_cb(self, checked):
self.ax1_rulerPlotItem.setData([], [])
self.ax1_rulerAnchorsItem.setData([], [])

def updatePixelSize(self):
posData = self.data[self.pos_i]
...

def editImgProperties(self, checked=True):
posData = self.data[self.pos_i]
posData.askInputMetadata(
Expand All @@ -8192,6 +8199,7 @@ def editImgProperties(self, checked=True):
save=True, singlePos=True,
askSegm3D=False
)
self.updatePixelSize()

def setHoverToolSymbolData(self, xx, yy, ScatterItems, size=None):
if not xx:
Expand Down Expand Up @@ -15405,6 +15413,7 @@ def loadingDataCompleted(self):
self.updateImageValueFormatter()
self.checkManageVersions()
self.initManualBackgroundImage()
self.initPixelSizePropsDockWidget()

self.setWindowTitle(f'Cell-ACDC - GUI - "{posData.exp_path}"')

Expand Down Expand Up @@ -16046,9 +16055,11 @@ def onZsliceSpinboxValueChange(self, value):
def update_z_slice(self, z):
posData = self.data[self.pos_i]
idx = (posData.filename, posData.frame_i)
fn = posData.filename
i = posData.frame_i
if self.switchPlaneCombobox.depthAxes() == 'z':
try:
posData.segmInfo_df.loc[idx:, 'z_slice_used_gui'] = z
posData.segmInfo_df.loc[fn].loc[i:, 'z_slice_used_gui'] = z
except Exception as err:
printl(posData.segmInfo_df)
printl(idx)
Expand Down Expand Up @@ -22331,7 +22342,7 @@ def openNewWindow(self):
)
win.run()
self.newWindows.append(win)

def helpNewFile(self):
msg = widgets.myMessageBox(showCentered=False)
href = f'<a href="{user_manual_url}">user manual</a>'
Expand Down Expand Up @@ -24758,9 +24769,31 @@ def onEscape(self):
except Exception as e:
pass

def askCloseAllWindows(self):
txt = html_utils.paragraph("""
There are other open windows that were created from this window.
<br><br>
If you proceed, the <b>other windows will be closed too.<br>
""")
msg = widgets.myMessageBox(wrapText=False)
msg.warning(
self, 'Open windows', txt,
buttonsTexts=('Cancel', 'Ok, close now')
)
return msg.cancel

def closeEvent(self, event):
self.onEscape()
self.saveWindowGeometry()

if self.newWindows:
cancel = self.askCloseAllWindows()
if cancel:
event.ignore()
return

for window in self.newWindows:
window.close()

if self.slideshowWin is not None:
self.slideshowWin.close()
Expand All @@ -24769,6 +24802,7 @@ def closeEvent(self, event):

proceed = self.askSaveOnClosing(event)
if not proceed:
event.ignore()
return

self.autoSaveClose()
Expand Down Expand Up @@ -24834,6 +24868,15 @@ def storeDefaultAndCustomColors(self):
self.defaultToolBarButtonColor = c
self.doublePressKeyButtonColor = '#fa693b'

def initPixelSizePropsDockWidget(self):
posData = self.data[self.pos_i]
PhysicalSizeX = posData.PhysicalSizeX
PhysicalSizeY = posData.PhysicalSizeY
PhysicalSizeZ = posData.PhysicalSizeZ
self.guiTabControl.initPixelSize(
PhysicalSizeX, PhysicalSizeY, PhysicalSizeZ
)

def showPropsDockWidget(self, checked=False):
if self.showPropsDockButton.isExpand:
self.propsDockWidget.setVisible(False)
Expand Down
95 changes: 94 additions & 1 deletion cellacdc/widgets.py
Expand Up @@ -4109,6 +4109,61 @@ def checkFavouriteFuncs(self):
groupbox.checkFavouriteFuncs()
self.doNotWarn = False

class PixelSizeGroupbox(QGroupBox):
sigValueChanged = Signal(float, float, float)
sigReset = Signal()

def __init__(self, parent=None):
super().__init__('Pixel size', parent)

mainLayout = QGridLayout()

row = 0
label = QLabel('Pixel width (μm): ')
self.pixelWidthWidget = FloatLineEdit(initial=1.0)
mainLayout.addWidget(label, row, 0)
mainLayout.addWidget(self.pixelWidthWidget, row, 1)

row += 1
label = QLabel('Pixel height (μm): ')
self.pixelHeightWidget = FloatLineEdit(initial=1.0)
mainLayout.addWidget(label, row, 0)
mainLayout.addWidget(self.pixelHeightWidget, row, 1)

row += 1
label = QLabel('Voxel depth (μm): ')
self.voxelDepthWidget = FloatLineEdit(initial=1.0)
mainLayout.addWidget(label, row, 0)
mainLayout.addWidget(self.voxelDepthWidget, row, 1)

row += 1
resetButton = reloadPushButton('Reset')
mainLayout.addWidget(
resetButton, row, 1, alignment=Qt.AlignRight
)

row += 1
mainLayout.addWidget(QHLine(), row, 0, 1, 2)

mainLayout.setColumnStretch(0, 0)
mainLayout.setColumnStretch(1, 1)

self.setLayout(mainLayout)

self.pixelWidthWidget.valueChanged.connect(self.emitValueChanged)
self.pixelHeightWidget.valueChanged.connect(self.emitValueChanged)
self.voxelDepthWidget.valueChanged.connect(self.emitValueChanged)
resetButton.clicked.connect(self.emitReset)

def emitReset(self):
self.sigReset.emit()

def emitValueChanged(self, value):
PhysicalSizeX = self.pixelWidthWidget.value()
PhysicalSizeY = self.pixelHeightWidget.value()
PhysicalSizeZ = self.voxelDepthWidget.value()
self.sigValueChanged.emit(PhysicalSizeX, PhysicalSizeY, PhysicalSizeZ)

class objPropsQGBox(QGroupBox):
def __init__(self, parent=None):
QGroupBox.__init__(self, 'Properties', parent)
Expand Down Expand Up @@ -4285,11 +4340,14 @@ class guiTabControl(QTabWidget):
def __init__(self, *args):
super().__init__(args[0])

self._defaultPixelSize = None

self.propsTab = QScrollArea(self)

container = QWidget()
layout = QVBoxLayout()

self.pixelSizeQGBox = PixelSizeGroupbox(parent=self.propsTab)
self.propsQGBox = objPropsQGBox(parent=self.propsTab)
self.intensMeasurQGBox = objIntesityMeasurQGBox(parent=self.propsTab)

Expand All @@ -4307,6 +4365,7 @@ def __init__(self, *args):
highlightLayout.addWidget(self.highlightSearchedCheckbox)

layout.addLayout(highlightLayout)
layout.addWidget(self.pixelSizeQGBox)
layout.addWidget(self.propsQGBox)
layout.addWidget(self.intensMeasurQGBox)
layout.addStretch(1)
Expand All @@ -4315,9 +4374,43 @@ def __init__(self, *args):
self.propsTab.setWidgetResizable(True)
self.propsTab.setWidget(container)
self.addTab(self.propsTab, 'Measurements')


self.pixelSizeQGBox.sigValueChanged.connect(self.pixelSizeChanged)
self.pixelSizeQGBox.sigReset.connect(self.resetPixelSize)

def addChannels(self, channels):
self.intensMeasurQGBox.addChannels(channels)

def resetPixelSize(self):
if self._defaultPixelSize is None:
return

self.initPixelSize(*self._defaultPixelSize)

def initPixelSize(self, PhysicalSizeX, PhysicalSizeY, PhysicalSizeZ):
self.pixelSizeQGBox.pixelWidthWidget.setValue(PhysicalSizeX)
self.pixelSizeQGBox.pixelHeightWidget.setValue(PhysicalSizeY)
self.pixelSizeQGBox.voxelDepthWidget.setValue(PhysicalSizeZ)
self._defaultPixelSize = (PhysicalSizeX, PhysicalSizeY, PhysicalSizeZ)

def pixelSizeChanged(self, PhysicalSizeX, PhysicalSizeY, PhysicalSizeZ):
propsQGBox = self.propsQGBox
yx_pxl_to_um2 = PhysicalSizeY*PhysicalSizeX
vox_rot_to_fl = float(PhysicalSizeY)*pow(float(PhysicalSizeX), 2)
vox_3D_to_fl = PhysicalSizeZ*PhysicalSizeY*PhysicalSizeX

area_pxl = propsQGBox.cellAreaPxlSB.value()
area_um2 = area_pxl*yx_pxl_to_um2
propsQGBox.cellAreaUm2DSB.setValue(area_um2)

vol_rot_vox = propsQGBox.cellVolVoxSB.value()
vol_rot_fl = vol_rot_vox*vox_rot_to_fl
propsQGBox.cellVolFlDSB.setValue(vol_rot_fl)

vol_3D_vox = propsQGBox.cellVolVox3D_SB.value()
vol_3D_fl = vol_3D_vox*vox_3D_to_fl
propsQGBox.cellVolFl3D_DSB.setValue(vol_3D_fl)


class expandCollapseButton(PushButton):
sigClicked = Signal()
Expand Down

0 comments on commit e20e0ed

Please sign in to comment.