Skip to content

Commit 155674c

Browse files
committed
Fixed sorting within list widgets, Adding capability to import new tif channel
Sorting list fixed - column values are interpreted as their actual types rather than as just strings. Fixing try - except code to explicit show what the except errors are Testing 2nd channel import
1 parent f5b4fd5 commit 155674c

File tree

9 files changed

+262
-109
lines changed

9 files changed

+262
-109
lines changed

pymapmanager/interface2/core/scatter_plot_widget.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,16 @@ def getCurrentRow(self):
487487
def getCurrentStat(self):
488488
# assuming single selection
489489
row = self.getCurrentRow()
490-
currentStat = self.myTableWidget.item(row, 0).text()
491-
492-
return currentStat
490+
# currentStat = self.myTableWidget.item(row, 0).text()
491+
492+
# return currentStat
493+
logger.info(f"row {row}")
494+
tableItem = self.myTableWidget.item(row, 0)
495+
if tableItem is not None:
496+
currentStat = tableItem.text()
497+
return currentStat
498+
else:
499+
return None
493500

494501
# @QtCore.pyqtSlot()
495502
def on_scatter_toolbar_table_click(self):
@@ -756,7 +763,7 @@ def setScatterPlot(self, xStat, yStat, xyStatIndex):
756763
myColorMap.append("white")
757764
else:
758765
if hueColumn != "None":
759-
logger.info(f"hueColumn {hueColumn} id:{id}")
766+
# logger.info(f"hueColumn {hueColumn} id:{id}")
760767
hueId = self._df[hueColumn].iloc[id]
761768
myColorMap.append(self.color[hueId])
762769

@@ -994,24 +1001,28 @@ def _buildMainLayout(self):
9941001
self.filteredDF, indexList = self.getfilteredDFWithIndexList(filterStr=filterStr, filterColumn=filterColumn)
9951002
else: # when there is no filterStr
9961003
self.filteredDF, indexList = self.getfilteredDFWithIndexList(filterStr=None, filterColumn=None)
1004+
1005+
if columnNameX is not None:
1006+
xDFStat = np.array(self.filteredDF[columnNameX].tolist())
1007+
yDFStat = np.array(self.filteredDF[columnNameY].tolist())
1008+
indexList = np.array(indexList)
9971009

998-
xDFStat = np.array(self.filteredDF[columnNameX].tolist())
999-
yDFStat = np.array(self.filteredDF[columnNameY].tolist())
1000-
indexList = np.array(indexList)
1010+
self.setScatterPlot(xDFStat, yDFStat, indexList)
10011011

1002-
self.setScatterPlot(xDFStat, yDFStat, indexList)
1012+
self.axScatter.set_xlabel(columnNameX)
1013+
self.axScatter.set_ylabel(columnNameY)
10031014

1004-
self.axScatter.set_xlabel(columnNameX)
1005-
self.axScatter.set_ylabel(columnNameY)
1015+
# Added to test histogram
1016+
self.scatter_hist(xDFStat, yDFStat, self.axHistX, self.axHistY)
10061017

1007-
# Added to test histogram
1008-
self.scatter_hist(xDFStat, yDFStat, self.axHistX, self.axHistY)
1018+
# self.scatterPoints.set_data(xStat, yStat)
1019+
self.axScatter.invert_yaxis()
1020+
self.static_canvas.draw()
1021+
1022+
self.myHighlighter = Highlighter(self, self.axScatter, xDFStat, yDFStat, indexList)
10091023

1010-
# self.scatterPoints.set_data(xStat, yStat)
1011-
self.axScatter.invert_yaxis()
1012-
self.static_canvas.draw()
1013-
1014-
self.myHighlighter = Highlighter(self, self.axScatter, xDFStat, yDFStat, indexList)
1024+
else:
1025+
self.myHighlighter = None
10151026

10161027
plotWidget = QtWidgets.QWidget()
10171028
vLayoutPlot = QtWidgets.QVBoxLayout()
@@ -1219,7 +1230,8 @@ def _switchScatter(self):
12191230
self.axHistX = None
12201231
self.axHistY = None
12211232

1222-
self.myHighlighter.resetHighlighter(self.axScatter, np.array([]), np.array([]), np.array([]))
1233+
if self.myHighlighter is not None: # TODO: go back and retest after adding points
1234+
self.myHighlighter.resetHighlighter(self.axScatter, np.array([]), np.array([]), np.array([]))
12231235

12241236
# IMPORTANT SIGNAL-SLOT CONNECTION (outside wrapper -> inside)
12251237
def selectHighlighterPoints(self, rowIndexes):

pymapmanager/interface2/core/search_widget.py

Lines changed: 98 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -51,77 +51,77 @@ def slot_setNameFilter(self, regExp):
5151
# self.invalidateFilter()
5252

5353
# Write a test function for this for the different cases
54-
def filterAcceptsRow(self, sourceRow, sourceParent):
55-
"""
56-
This function overrides the parent class' function
57-
Args:
58-
sourceRow: row that is being looked at
59-
QModelIndex: QModelIndex of parent that contians source row
60-
"""
61-
# logger.error('')
62-
# logger.error(f' sourceRow:{sourceRow} {type(sourceRow)}')
63-
# logger.error(f' sourceParent:{sourceParent} {type(sourceParent)}')
54+
# def filterAcceptsRow(self, sourceRow, sourceParent):
55+
# """
56+
# This function overrides the parent class' function
57+
# Args:
58+
# sourceRow: row that is being looked at
59+
# QModelIndex: QModelIndex of parent that contians source row
60+
# """
61+
# # logger.error('')
62+
# # logger.error(f' sourceRow:{sourceRow} {type(sourceRow)}')
63+
# # logger.error(f' sourceParent:{sourceParent} {type(sourceParent)}')
6464

65-
# super().filterAcceptsRow(sourceRow)
66-
# Specific column is already set in QTableView and comparison value
67-
68-
# row, column, qmodelindx
69-
filterCol = self.filterKeyColumn()
70-
# logger.error(f' filterCol:{filterCol}')
71-
valIndex = self.sourceModel().index(sourceRow, filterCol, sourceParent)
72-
role = QtCore.Qt.DisplayRole
73-
val = self.sourceModel().data(valIndex, role)
74-
75-
# logger.info(f'self.nameRegExp pattern: {self.nameRegExp.pattern()}, valIndex: {valIndex}, val: {val}')
76-
# logger.info(f'ComparisonValue: {self.currentComparisonValue}, ComparisonSymbol : {self.currentComparisonSymbol}')
77-
78-
checkPattern = self.nameRegExp.pattern() in val
79-
checkComparisonVal = self.currentComparisonValue != ""
80-
81-
#Check for float conversion?
82-
if checkPattern:
83-
if (checkComparisonVal):
84-
# Change this to an enumerated type
85-
if (self.currentComparisonSymbol == ""):
86-
return True
87-
elif(self.currentComparisonSymbol == "="):
88-
if float(self.currentComparisonValue) == float(val):
89-
return True
90-
else:
91-
return False
92-
elif(self.currentComparisonSymbol == ">"):
93-
if float(val) > float(self.currentComparisonValue):
94-
# logger.info(f"here in > !!!")
95-
return True
96-
# return False
97-
else:
98-
return False
99-
elif(self.currentComparisonSymbol == "<"):
100-
if float(val) < float(self.currentComparisonValue):
101-
return True
102-
else:
103-
return False
104-
elif(self.currentComparisonSymbol== "<="):
105-
if float(val) <= float(self.currentComparisonValue):
106-
return True
107-
else:
108-
return False
109-
elif(self.currentComparisonSymbol == ">="):
110-
if float(val) >= float(self.currentComparisonValue):
111-
return True
112-
else:
113-
return False
114-
elif(self.currentComparisonSymbol == "None"):
115-
return True
116-
else:
117-
# Any unaccounted for symbol will be False
118-
logger.info(f'Warning: Symbol is not accounted for.')
119-
return False
120-
else:
121-
# When there is no comparison value show row
122-
return True
123-
else:
124-
return False
65+
# # super().filterAcceptsRow(sourceRow)
66+
# # Specific column is already set in QTableView and comparison value
67+
68+
# # row, column, qmodelindx
69+
# filterCol = self.filterKeyColumn()
70+
# # logger.error(f' filterCol:{filterCol}')
71+
# valIndex = self.sourceModel().index(sourceRow, filterCol, sourceParent)
72+
# role = QtCore.Qt.DisplayRole
73+
# val = self.sourceModel().data(valIndex, role)
74+
75+
# # logger.info(f'self.nameRegExp pattern: {self.nameRegExp.pattern()}, valIndex: {valIndex}, val: {val}')
76+
# # logger.info(f'ComparisonValue: {self.currentComparisonValue}, ComparisonSymbol : {self.currentComparisonSymbol}')
77+
78+
# checkPattern = self.nameRegExp.pattern() in val
79+
# checkComparisonVal = self.currentComparisonValue != ""
80+
81+
# #Check for float conversion?
82+
# if checkPattern:
83+
# if (checkComparisonVal):
84+
# # Change this to an enumerated type
85+
# if (self.currentComparisonSymbol == ""):
86+
# return True
87+
# elif(self.currentComparisonSymbol == "="):
88+
# if float(self.currentComparisonValue) == float(val):
89+
# return True
90+
# else:
91+
# return False
92+
# elif(self.currentComparisonSymbol == ">"):
93+
# if float(val) > float(self.currentComparisonValue):
94+
# # logger.info(f"here in > !!!")
95+
# return True
96+
# # return False
97+
# else:
98+
# return False
99+
# elif(self.currentComparisonSymbol == "<"):
100+
# if float(val) < float(self.currentComparisonValue):
101+
# return True
102+
# else:
103+
# return False
104+
# elif(self.currentComparisonSymbol== "<="):
105+
# if float(val) <= float(self.currentComparisonValue):
106+
# return True
107+
# else:
108+
# return False
109+
# elif(self.currentComparisonSymbol == ">="):
110+
# if float(val) >= float(self.currentComparisonValue):
111+
# return True
112+
# else:
113+
# return False
114+
# elif(self.currentComparisonSymbol == "None"):
115+
# return True
116+
# else:
117+
# # Any unaccounted for symbol will be False
118+
# logger.info(f'Warning: Symbol is not accounted for.')
119+
# return False
120+
# else:
121+
# # When there is no comparison value show row
122+
# return True
123+
# else:
124+
# return False
125125

126126
class TableModel(QAbstractTableModel):
127127
"""
@@ -197,9 +197,31 @@ def data(self, index, role) -> str:
197197

198198
# print('qqq Table model used "at" to get row', row, 'colName', colName, 'returnVal:', returnVal)
199199

200-
# print(f"row: {row} col: {col} colName: {colName} returnVal: {returnVal} returnVal type: {type(returnVal)}")=
200+
# print(f"row: {row} col: {col} colName: {colName} returnVal: {returnVal} returnVal type: {type(returnVal)}")
201201
# TODO: possible type checking
202-
return str(returnVal)
202+
# return str(returnVal)
203+
# return returnVal
204+
# data does not like returning numpy ints
205+
# type checking to see if value can be converted to int
206+
207+
try:
208+
checkVal = float(returnVal)
209+
except TypeError:
210+
checkVal = None
211+
# logger.info(f"Col {colName} values do not have the correct type")
212+
except ValueError:
213+
checkVal = None
214+
# logger.info("table data value is not a float")
215+
216+
if checkVal is not None and not checkVal.is_integer():
217+
return round(float(returnVal), 2)
218+
elif str(returnVal).isdigit(): # check for int
219+
# logger.info(f"colName: {colName}")
220+
return int(returnVal)
221+
else:
222+
return str(returnVal)
223+
224+
# TODO: check if filtering still works after this
203225
except KeyError:
204226
print(f'Error occurred when accessing dataframe: {KeyError}')
205227

@@ -617,7 +639,7 @@ def _selectRow(self, rowList):
617639
Called by other widgets like annotationPlotWidget
618640
"""
619641

620-
logger.info(f'programattic select of row(s) -->> {self.getMyName()} rowList:{rowList}')
642+
# logger.info(f'programattic select of row(s) -->> {self.getMyName()} rowList:{rowList}')
621643

622644
if rowList is None or len(rowList)==0:
623645
with self._blockSlotsManager():
@@ -635,18 +657,18 @@ def _selectRow(self, rowList):
635657
for _idx, rowIdx in enumerate(rowList):
636658
# abb already row label
637659
# abb 20241121 -->> this is not getting the correct row
638-
logger.info(f"rowIdx in _selectRow{rowIdx}")
660+
# logger.info(f"rowIdx in _selectRow{rowIdx}")
639661

640662
modelIndex = self.findModelIndex(column=0, value=rowIdx) # column = 0, assuming index is always first column
641-
logger.info(f"modelIdx in _selectRow {modelIndex}")
663+
# logger.info(f"modelIdx in _selectRow {modelIndex}")
642664

643665
# find the correct model.index get a spine Index(rowIndex)
644666

645667
# 2nd argument is column
646668
# here we default to zero since we will select the entire row regardless
647669
# modelIndex = self.model.index(rowIdx, 0)
648670
proxyIndex = self.proxyModel.mapFromSource(modelIndex)
649-
logger.info(f' modelIndex.row():{modelIndex.row()} proxyIndex.row():{proxyIndex.row()}')
671+
# logger.info(f' modelIndex.row():{modelIndex.row()} proxyIndex.row():{proxyIndex.row()}')
650672

651673
mode = QtCore.QItemSelectionModel.Select | QtCore.QItemSelectionModel.Rows
652674
self.mySelectionModel.select(proxyIndex, mode)

pymapmanager/interface2/mainMenus.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def _refreshWindowsMenu(self):
212212
# never use a bare except (causes lots of problems)
213213
# I think you wanted 'except (AttributeError)' to catch getOpenPluginDict()
214214
# when activeWindow was not a stackwidget2
215-
except:
215+
except AttributeError:
216216
logger.info("Error when adding opened plugins to windows menu!")
217217

218218
#abb
@@ -455,6 +455,11 @@ def _refreshFileMenu(self):
455455
analysisParametersAction.triggered.connect(self.getApp()._showAnalysisParameters)
456456
self.fileMenu.addAction(analysisParametersAction)
457457

458+
self.fileMenu.addSeparator()
459+
importNewTIFAction = QtWidgets.QAction('Import new TIF (channel)', self.getApp())
460+
importNewTIFAction.triggered.connect(self.getApp().importNewTIF)
461+
self.fileMenu.addAction(importNewTIFAction)
462+
458463
def _refreshOpenRecent(self):
459464
"""Dynamically generate the open recent stack/map menu.
460465

pymapmanager/interface2/pyMapManagerApp2.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,8 @@ def loadFolder(self):
653653
_aWidget = self._openWidgetList.openWidgetFromPath(openFilePath)
654654
logger.info(f"opened PATH {openFilePath}")
655655
self.shownFolderPathsList.append(openFilePath)
656-
except:
657-
logger.info(f"failed to open path {openFilePath}")
656+
except Exception as e: # exception: 'timePoints'
657+
logger.info(f"failed to open path {openFilePath} with exception: {e}")
658658

659659
if len(self.shownFolderPathsList) > 0:
660660
self.enableFolderWindow = True
@@ -699,6 +699,19 @@ def clearRecentFiles(self):
699699

700700
# refresh first window
701701
self._openFirstWindow.refreshUI()
702+
703+
def importNewTIF(self):
704+
pass
705+
706+
frontStackWindow = self.getFrontWindow()
707+
# bring up directory
708+
709+
# get newTifPath
710+
711+
# try calling map.loadInNewChannel(self, path: Union[str, np.ndarray], time: int = 0, channel: int = 0):
712+
frontStackWindow.loadInNewChannel()
713+
# might need to somehow refresh stackwidget?
714+
702715

703716
def main():
704717
"""Run the PyMapMAnager app.

pymapmanager/interface2/runInterfaceJohnson.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ def run():
6767
# sw2.zoomToPointAnnotation(1, isAlt=True)
6868

6969
sw2.zoomToPointAnnotation(1, isAlt=True)
70-
spineID = 1
71-
deleteEvent = DeleteSpineEvent(sw2, spineID)
72-
# deleteEvent = DeleteSpineEvent(sw2)
73-
# deleteEvent.addDeleteSpine(spineID)
74-
# sw2.deletedEvent(deleteEvent)
75-
# sw2.emitEvent(deleteEvent, blockSlots=False)
76-
sw2.slot_pmmEvent(deleteEvent)
70+
# spineID = 1
71+
# deleteEvent = DeleteSpineEvent(sw2, spineID)
72+
# # deleteEvent = DeleteSpineEvent(sw2)
73+
# # deleteEvent.addDeleteSpine(spineID)
74+
# # sw2.deletedEvent(deleteEvent)
75+
# # sw2.emitEvent(deleteEvent, blockSlots=False)
76+
# sw2.slot_pmmEvent(deleteEvent)
7777

7878

7979
# _pmmEvent = pmmEvent(pmmEventType.delete, sw2)
@@ -197,7 +197,7 @@ def testingProgrammaticRunClose():
197197
sys.exit(app.exec_())
198198

199199
if __name__ == '__main__':
200-
run()
200+
# run()
201201
# run2()
202202
# run3()
203203
# run4()
@@ -206,4 +206,4 @@ def testingProgrammaticRunClose():
206206
# testingOpenClose()
207207
# runPoochFileDirectly()
208208
# testingProgrammaticRunClose()
209-
# run2_tif()
209+
run2_tif()

pymapmanager/interface2/stackWidgets/base/stacktoolbar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def _setStack(self, theStack):
7070
actionWidget.setVisible(False)
7171

7272
for channelIdx in range(self._myStack.numChannels):
73+
# logger.info(f"channelIdx visible {channelIdx} ")
7374
self._actionDict[channelIdx].setDisabled(False)
7475
self._actionDict[channelIdx].setVisible(True)
7576

@@ -179,6 +180,7 @@ def _buildUI(self):
179180
self.channelActionGroup = QtWidgets.QActionGroup(self)
180181

181182
for channelIdx in range(self._myStack.maxNumChannels):
183+
# logger.info(f"channel idx {channelIdx}")
182184
iconPath = '' # use toolName to get from canvas.util
183185
theIcon = QtGui.QIcon(iconPath)
184186

0 commit comments

Comments
 (0)