@@ -48,7 +48,10 @@ def _refreshSlice(self):
4848 def _setSlice (self , sliceNumber ):
4949 self ._sliceNumber = sliceNumber
5050
51- for histWidget in self .histWidgetList :
51+ # for histWidget in self.histWidgetList:
52+ # histWidget._setSlice(sliceNumber)
53+
54+ for histWidget in self .histWidgetDict .values ():
5255 histWidget ._setSlice (sliceNumber )
5356
5457 def setSliceEvent (self , event : pmmEvent ):
@@ -69,9 +72,9 @@ def slot_setChannel(self, channelIdx : int):
6972 # need to set max of spinbox and slider(s)
7073 # self.minSpinBox.setMaximum(globalMax)
7174
72- _channelKeys = self .getStackWidget () .getChannelKeys ()
75+ _channelKeys = self ._myStack .getChannelKeys ()
7376 if channelIdx in _channelKeys :
74- for histWidget in self .histWidgetList :
77+ for histWidget in self .histWidgetDict . values () :
7578 histWidget .isRgb = False
7679 if histWidget ._channelIdx == channelIdx :
7780 histWidget .show ()
@@ -81,7 +84,8 @@ def slot_setChannel(self, channelIdx : int):
8184 histWidget .hide ()
8285 elif channelIdx == 'rgb' :
8386 # show all
84- for histWidget in self .histWidgetList :
87+ # for histWidget in self.histWidgetList:
88+ for histWidget in self .histWidgetDict .values ():
8589 histWidget .isRgb = True
8690 histWidget .show ()
8791 histWidget ._refreshContrast ()
@@ -126,7 +130,8 @@ def _checkbox_callback(self, isChecked):
126130 self .repaint ()
127131
128132 elif title == 'Log' :
129- for histWidget in self .histWidgetList :
133+ # for histWidget in self.histWidgetList:
134+ for histWidget in self .histWidgetDict .values ():
130135 histWidget .setLog (isChecked )
131136
132137 def _buildUI (self ):
@@ -170,25 +175,45 @@ def _buildUI(self):
170175 hBoxLayout2 = QtWidgets .QHBoxLayout () # main layout
171176
172177 # a _histogram for each channel
173- self .histWidgetList = []
178+ # self.histWidgetList = []
179+ self .histWidgetDict = {}
174180 for channelIdx in self ._myStack .getChannelKeys ():
181+ #TODO: add check for to integer?
182+ # logger.info(f"channelIdx when initializing {channelIdx}")
175183 oneHistWidget = _histogram (self , self ._myStack , channelIdx , sliceNumber = self ._sliceNumber )
176184 oneHistWidget .signalContrastChange .connect (self .slot_contrastChanged )
177- self .histWidgetList .append (oneHistWidget )
185+ # self.histWidgetList.append(oneHistWidget)
186+ self .histWidgetDict [channelIdx ] = oneHistWidget
178187 hBoxLayout2 .addWidget (oneHistWidget )
179188 vBoxLayout .addLayout (hBoxLayout2 )
180189
181190 def _onAutoContrast (self ):
182191 """Reset to min/max from metadata.
183192 """
184193 logger .error ('BROKEN' )
185-
186- self ._myStack .getChannelMetadata (self ._channelIdx ).resetAutoContrast ()
194+ logger .info (f"self._channelIdx { self ._channelIdx } " )
195+ logger .info (f"self._channel { self ._channel } " )
196+
197+ # TODO: fix this abj - need to figure out decisively when its rgb
198+ # For some reason channel idx 2 is being used instead of 1 for resetting slider in rgb
199+
200+ if self ._channel == "rgb" :
201+ # TODO: loop through all channel indexes and reset rgb contrast
202+ for channelIdx in self ._myStack .getChannelKeys ():
203+ logger .info (f"channelIdx being reset { channelIdx } type { type (channelIdx )} " )
204+ self ._myStack .getChannelMetadata (channelIdx ).resetAutoRgbContrast ()
205+ self .getStackWidget ().slot_contrastChanged ()
206+ # TODO: switch from list to dictionary?
207+ # self.histWidgetList[channelIdx]._refreshContrast()
208+ self .histWidgetDict [channelIdx ]._refreshContrast ()
187209
188- self .getStackWidget ().slot_contrastChanged ()
210+ else :
211+ self ._myStack .getChannelMetadata (self ._channelIdx ).resetAutoContrast ()
212+ self .getStackWidget ().slot_contrastChanged ()
189213
190- # cludge, need to properly connect signal/slot
191- self .histWidgetList [self ._channelIdx ]._refreshContrast ()
214+ # cludge, need to properly connect signal/slot
215+ # self.histWidgetList[self._channelIdx]._refreshContrast()
216+ self .histWidgetDict [self ._channelIdx ]._refreshContrast ()
192217
193218#class _histogram(QtWidgets.QToolBar):
194219class _histogram (QtWidgets .QWidget ):
@@ -232,6 +257,8 @@ def _sliderValueChanged(self):
232257 theMin = self .minContrastSlider .value ()
233258 theMax = self .maxContrastSlider .value ()
234259
260+ # logger.info(f"theMin {theMin} theMax {theMax}")
261+
235262 # set spinbox(s) to current slider values
236263 self .minSpinBox .setValue (theMin )
237264 self .maxSpinBox .setValue (theMax )
@@ -260,19 +287,23 @@ def _spinBoxValueChanged(self):
260287 def _updateContrast (self , theMin , theMax ):
261288 # set contrast in metadata
262289 if self .isRgb :
263- self ._myStack .getChannelMetadata (self ._channelIdx ).setValue ('minAutoContrast_rgb' , theMin )
264- self ._myStack .getChannelMetadata (self ._channelIdx ).setValue ('maxAutoContrast_rgb' , theMax )
290+ # self._myStack.getChannelMetadata(self._channelIdx).setValue('minAutoContrast_rgb', theMin)
291+ # self._myStack.getChannelMetadata(self._channelIdx).setValue('maxAutoContrast_rgb', theMax)
292+ # logger.info(f"upadting min and max rgb to {theMin} and {theMax}")
293+ # logger.info(f"self._channelIdx being updated in rgb{ self._channelIdx}")
294+ self ._myStack .getChannelMetadata (self ._channelIdx ).setValue ('minContrast_rgb' , theMin )
295+ self ._myStack .getChannelMetadata (self ._channelIdx ).setValue ('maxContrast_rgb' , theMax )
265296 else :
266297 self ._myStack .getChannelMetadata (self ._channelIdx ).setUserContrast (theMin , theMax )
267298
268299 def _refreshSlice (self ):
269300 self ._setSlice (self ._sliceNumber )
270301
271302 def _setSlice (self , sliceNumber , doInit = False ):
272- logger .info (f'_histogram _channelIdx:{ self ._channelIdx } sliceNumber:{ sliceNumber } ' )
303+ # logger.info(f'_histogram _channelIdx:{self._channelIdx} sliceNumber:{sliceNumber}')
273304
274- if not self .isVisible ():
275- return
305+ # if not self.isVisible(): # abj: not needed prevents initial loading
306+ # return
276307
277308 self ._sliceNumber = sliceNumber
278309
@@ -297,7 +328,6 @@ def _setSlice(self, sliceNumber, doInit=False):
297328 if self ._plotLogHist :
298329 y = np .log10 (y , where = y > 0 )
299330
300-
301331 self .pgHist .setData (x = x , y = y )
302332
303333 # color the hist based on channel number
@@ -320,26 +350,30 @@ def setLog(self, value):
320350
321351 def _refreshContrast (self ):
322352 _channelMetadata = self ._myStack .getChannelMetadata (self ._channelIdx )
323-
353+
324354 globalMin = 0
325355 if self .isRgb :
326- minContrast = _channelMetadata .getValue ('minAutoContrast_rgb' )
327- maxContrast = _channelMetadata .getValue ('maxAutoContrast_rgb' )
356+ # minContrast = _channelMetadata.getValue('minAutoContrast_rgb')
357+ # maxContrast = _channelMetadata.getValue('maxAutoContrast_rgb')
358+ minContrast = _channelMetadata .getValue ('minContrast_rgb' )
359+ maxContrast = _channelMetadata .getValue ('maxContrast_rgb' )
328360 globalMax = 256
329361 else :
330362 minContrast , maxContrast = _channelMetadata .getUserContrast ()
331363 globalMax = _channelMetadata .getValue ('maxInt' )
332364
333- # logger.info(f'isRgb:{self.isRgb} _channelIdx:{self._channelIdx} minContrast:{minContrast} maxContrast:{maxContrast}')
365+ logger .info (f'isRgb:{ self .isRgb } _channelIdx:{ self ._channelIdx } minContrast:{ minContrast } maxContrast:{ maxContrast } ' )
334366
335367 # set the x-range of histogram plot
336368 self .pgPlotWidget .setXRange (globalMin , globalMax , padding = 0 )
337369
338370 self .maxSpinBox .setMaximum (globalMax ) # order matters, must be first
371+ self .minSpinBox .setMaximum (globalMax ) # abj: ensure minimum doesnt go above max
339372 self .minSpinBox .setValue (minContrast )
340373 self .maxSpinBox .setValue (maxContrast )
341374
342375 self .maxContrastSlider .setMaximum (globalMax ) # order matters, must be first
376+ self .minContrastSlider .setMaximum (globalMax ) # abj: ensure minimum doesnt go above max
343377 self .minContrastSlider .setValue (minContrast )
344378 self .maxContrastSlider .setValue (maxContrast )
345379
0 commit comments