Skip to content

Commit

Permalink
Improved Save and Analysis parameters
Browse files Browse the repository at this point in the history
Analysis parameters is now stored in user/documents file on initial use.
- This file is used when user loads from tif file
- can be accessed from application to update/ save under File -> App Analysis Parameters
  • Loading branch information
jtle00 committed Aug 17, 2024
1 parent 04896c3 commit 5984dd0
Show file tree
Hide file tree
Showing 9 changed files with 615 additions and 22 deletions.
15 changes: 15 additions & 0 deletions pymapmanager/interface2/mainMenus.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ def _refreshFileMenu(self):
self.fileMenu.addSeparator()

# abj
enableUndo = False
enableRedo = False
isDirty = False

frontWindow = self.getApp().getFrontWindow()
if isinstance(frontWindow, stackWidget2):
enableUndo = frontWindow.getUndoRedo().numUndo() > 0
Expand Down Expand Up @@ -457,6 +461,12 @@ def _refreshFileMenu(self):

self.settingsMenu = self.fileMenu.addMenu('User Options...')
self.settingsMenu.aboutToShow.connect(self._refreshSettingsMenu)
self.fileMenu.addSeparator()

#abj
analysisParametersAction = QtWidgets.QAction('App Analysis Parameters', self.getApp())
analysisParametersAction.triggered.connect(self.getApp()._showAnalysisParameters)
self.fileMenu.addAction(analysisParametersAction)

def _refreshOpenRecent(self):
"""Dynamically generate the open recent stack/map menu.
Expand Down Expand Up @@ -487,3 +497,8 @@ def _refreshOpenRecent(self):
)

self.openRecentMenu.addAction(loadFolderAction)

def _refreshAnalysisParameters(self):
"""
"""
logger.info(f"refreshing analysis Parameters")
4 changes: 3 additions & 1 deletion pymapmanager/interface2/openFirstWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def _on_recent_stack_click(self, rowIdx : int):
path = self.recentStackList[rowIdx]
logger.info(f'rowId:{rowIdx} path:{path}')

if os.path.isfile(path):
# abj: Changed this to check if it is a directory instead of a file
# if os.path.isfile(path):
if os.path.isdir(path):
self.getApp().loadStackWidget(path)
else:
logger.error(f'did not find path: {path}')
Expand Down
68 changes: 56 additions & 12 deletions pymapmanager/interface2/pyMapManagerApp2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os
import sys
import math
Expand All @@ -11,6 +12,8 @@

import qdarktheme

from pymapmanager.interface2.stackWidgets.analysisParamWidget2 import AnalysisParamWidget

# Enable HiDPI.
qdarktheme.enable_hi_dpi()

Expand All @@ -28,7 +31,9 @@
from pymapmanager.interface2.mainMenus import PyMapManagerMenus

from pymapmanager._logger import logger, setLogLevel
# from pymapmanager.pmmUtils import addUserPath, getBundledDir, getUserAnalysisParamJsonData, saveAnalysisParamJsonFile
from pymapmanager.pmmUtils import getBundledDir
import pymapmanager.pmmUtils

def loadPlugins(verbose=False, pluginType='stack') -> dict:
"""Load stack plugins from both:
Expand Down Expand Up @@ -117,10 +122,18 @@ def loadPlugins(verbose=False, pluginType='stack') -> dict:

return pluginDict


class PyMapManagerApp(QtWidgets.QApplication):
def __init__(self, argv=[], deferFirstWindow=False):
super().__init__(argv)


self._analysisParams = mapmanagercore.analysis_params.AnalysisParams()

firstTimeRunning = self._initUserDocuments()

if firstTimeRunning:
logger.info(" We created <user>/Documents/Pymapmanager-User-Files and need to restart")

self._config = pymapmanager.interface2.Preferences(self)
# util class to save/load app preferences including recent paths

Expand Down Expand Up @@ -167,6 +180,35 @@ def __init__(self, argv=[], deferFirstWindow=False):
self._openFirstWindow = None
self.openFirstWindow()

def _initUserDocuments(self):
"""
"""
# platformdirs
jsonDump = self._analysisParams.getJson()

# Create user's pmm directory in user/documents if necessary and save json to it
return pymapmanager.pmmUtils.addUserPath(jsonDump)

def getAnalysisParams(self):
""" get analysis params from json file within user documents
"""
return self._analysisParams

def getUserJsonData(self):
return pymapmanager.pmmUtils.getUserAnalysisParamJsonData()

def saveAnalysisParams(self, dict):
"""
dict: analysis Parameters dictionary
"""
# aP = self.getAnalysisParams()

# convert dictionary to json
analysisParamJson = json.dumps(dict)

# save to json file in user documents
pymapmanager.pmmUtils.saveAnalysisParamJsonFile(analysisParamJson)

def getNewUntitledNumber(self) -> int:
"""Get a unique number for each new map (From tiff file).
"""
Expand Down Expand Up @@ -320,26 +362,28 @@ def saveFile(self):
stackWidget.save()

def saveAsFile(self):
""" Save change to a new file
2 Scenarios:
1.) mmap file has not been created yet and we need to save a new one
2.) There is already a mmap file and user wants to create a new one
- in this scenario, after creating a new one, save would still save on the old one,
until user loads in that new file
""" Save as a new file
"""
logger.info(f'Saving as file { self._stackWidgetDict.keys()}')

# scenario 1) Should be called when something is dragged and dropped, new file is loaded in
# this is handled in loadTifFile
# scenario 2)
if len(self._stackWidgetDict) > 0:
for key in self._stackWidgetDict.keys():
# looping through every path in stackWidgetDict
# key = path of current stack
stackWidget = self._stackWidgetDict[key]
stackWidget.fileSaveAs()
# stackWidget.saveAs(key)

#abj
def _showAnalysisParameters(self):

if len(self._stackWidgetDict) > 0:
for key in self._stackWidgetDict.keys():
# looping through every path in stackWidgetDict
# key = path of current stack
currentStackWidget = self._stackWidgetDict[key]

self.apWidget = AnalysisParamWidget(stackWidget=currentStackWidget, pmmApp=self)
self.apWidget.show()

def _undo_action(self):
self.getFrontWindow().emitUndoEvent()
Expand Down
10 changes: 5 additions & 5 deletions pymapmanager/interface2/runInterfaceJohnson.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ def run():

def run2():
app = PyMapManagerApp()
# path = '/Users/johns/Documents/GitHub/PyMapManager-Data/one-timepoint/rr30a_s0_ch1.tif'
path = '/Users/johns/Documents/GitHub/PyMapManager-Data/one-timepoint/rr30a_s0_ch1.mmap'
# sw2 = app.loadTifFile(path)
path = '/Users/johns/Documents/GitHub/PyMapManager-Data/one-timepoint/rr30a_s0_ch1.tif'
# path = '/Users/johns/Documents/GitHub/PyMapManager-Data/one-timepoint/rr30a_s0_ch1.mmap'
# # sw2 = app.loadTifFile(path)
sw2 = app.loadStackWidget(path)
sys.exit(app.exec_())

if __name__ == '__main__':
# run()
run2()
run()
# run2()
Loading

0 comments on commit 5984dd0

Please sign in to comment.