Skip to content

Commit

Permalink
GUI Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TCallaghan2 committed Jun 20, 2024
1 parent 993b5d9 commit 76d41f0
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 41 deletions.
3 changes: 2 additions & 1 deletion PythonScripts/GUI/GeoSAM/FishMortBySpecAcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from Widgets import *
from AreaManager import *
from Globals import *

#===============================================================================================================
##
Expand All @@ -40,7 +41,7 @@ def __init__(self, container, maxAreas, maxCorners):

labelArr = ['Field', 'SpecArea', 'Mortality', '0', '0.4']
self.root = os.getcwd() #os.environ['ROOT']
self.startDir = os.path.join(self.root, 'Configuration', 'SpecialAccess')
self.startDir = os.path.join(self.root, configDir, specAccCfgDir)
self.fmFName = None

self.numDefinedMax = maxAreas
Expand Down
31 changes: 16 additions & 15 deletions PythonScripts/GUI/GeoSAM/GeoSams.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
from SortByAreaFrame import *
from SpecialAreaFrame import *
from FishMortBySpecAcc import *
from Globals import *

#======================================================================================================
##
Expand Down Expand Up @@ -109,17 +110,17 @@ def __init__(self, title, maxAreas, maxCorners, maxYears):
# Now using cwd assuming python is started from there.
# > set ROOT=%CD%
self.root = os.getcwd() #os.environ['ROOT']
self.simConfigFile = os.path.join(self.root,'Configuration', 'Simulation','Scallop.cfg')
self.simConfigFile = os.path.join(self.root,configDir, simCfgDir,'Scallop.cfg')
self.ReadSimConfigFile()
self.notebook = ttk.Notebook(self)

self.frame1 = MainInput(self.notebook, self, self.tsPerYear, self.paramVal)
# NOTE: These will still be default values as the user would not as yet entered anything!!
self.simConfigFile = os.path.join(self.root,'Configuration', 'Simulation', self.frame1.simCfgFile.myEntry.get())
self.mortConfigFile = os.path.join(self.root,'Configuration', 'Simulation', self.frame1.mortCfgFile.myEntry.get())
self.recrConfigFile = os.path.join(self.root,'Configuration', 'Simulation', self.frame1.recrCfgFile.myEntry.get())
self.gmConfigFile = os.path.join(self.root,'Configuration', 'Simulation', self.frame1.gmCfgFile.myEntry.get())
self.ukConfigFile = os.path.join(self.root,'Configuration', 'Interpolation', self.frame1.ukCfgFile.myEntry.get())
self.simConfigFile = os.path.join(self.root,configDir, simCfgDir, self.frame1.simCfgFile.myEntry.get())
self.mortConfigFile = os.path.join(self.root,configDir, simCfgDir, self.frame1.mortCfgFile.myEntry.get())
self.recrConfigFile = os.path.join(self.root,configDir, simCfgDir, self.frame1.recrCfgFile.myEntry.get())
self.gmConfigFile = os.path.join(self.root,configDir, simCfgDir, self.frame1.gmCfgFile.myEntry.get())
self.ukConfigFile = os.path.join(self.root,configDir, interCfgDir, self.frame1.ukCfgFile.myEntry.get())

# Read in configuration parameters
self.ReadSimConfigFile()
Expand Down Expand Up @@ -180,7 +181,7 @@ def Run_Sim(self):
self.SaveConfigFiles()
# exec to be called, ScallopPopDensity, prepends directory structure, ReadSimConfigFile does not
simConfigFile = self.frame1.simCfgFile.myEntry.get()
self.simConfigFile = os.path.join('Configuration', 'Simulation', simConfigFile)
self.simConfigFile = os.path.join(configDir, simCfgDir, simConfigFile)

# exec to be called, UK, prepends directory structure
self.ukCfgFile = self.frame1.ukCfgFile.myEntry.get()
Expand Down Expand Up @@ -492,7 +493,7 @@ def SaveConfigFiles(self):
self.WriteGrowthConfig()
self.WriteGridMgrConfig()
self.WriteUKConfig()
# cfgFile = os.path.join(self.root,'Configuration', 'Interpolation', self.frame4.spatCfgFile.myEntry.get())
# cfgFile = os.path.join(self.root,configDir, interCfgDir, self.frame4.spatCfgFile.myEntry.get())
# self.WriteSpatialFncsConfig(cfgFile)
messagebox.showinfo("Save Files", "Configuration Files Saved")

Expand All @@ -503,7 +504,7 @@ def SaveConfigFiles(self):
#
#-------------------------------------------------------------------------------------
def WriteScallopConfig(self):
simCfgFile = os.path.join(self.root,'Configuration', 'Simulation', self.frame1.simCfgFile.myEntry.get())
simCfgFile = os.path.join(self.root,configDir, simCfgDir, self.frame1.simCfgFile.myEntry.get())
with open(simCfgFile, 'w') as f:
f.write('# input file for Scallops \n')
f.write('Time steps per Year = ' + str(self.frame1.tsPerYear.myEntry.get())+'\n')
Expand Down Expand Up @@ -557,7 +558,7 @@ def ConvertMonthDayToDayOfYr(self, monthDayStr):
#
#-------------------------------------------------------------------------------------
def WriteRecruitmentConfig(self):
cfgFile = os.path.join(self.root,'Configuration', 'Simulation', self.frame1.recrCfgFile.myEntry.get())
cfgFile = os.path.join(self.root,configDir, simCfgDir, self.frame1.recrCfgFile.myEntry.get())

periodMonthStr = self.frame1.startDayComboMonth.get()
periodDayStr = self.frame1.startDayComboDay.get()
Expand Down Expand Up @@ -586,7 +587,7 @@ def WriteRecruitmentConfig(self):
#
#-------------------------------------------------------------------------------------
def WriteGrowthConfig(self):
simCfgFile = os.path.join(self.root,'Configuration', 'Simulation', self.frame1.mortCfgFile.myEntry.get())
simCfgFile = os.path.join(self.root,configDir, simCfgDir, self.frame1.mortCfgFile.myEntry.get())
with open(simCfgFile, 'w') as f:
f.write('# Was configuration file for mortality\n')
f.write('# Actually contains parameters that define both Growth and Mortality\n')
Expand Down Expand Up @@ -630,7 +631,7 @@ def WriteGrowthConfig(self):
#
#-------------------------------------------------------------------------------------
def WriteGridMgrConfig(self):
cfgFile = os.path.join(self.root,'Configuration', 'Simulation', self.frame1.gmCfgFile.myEntry.get())
cfgFile = os.path.join(self.root,configDir, simCfgDir, self.frame1.gmCfgFile.myEntry.get())
with open(cfgFile, 'w') as f:
f.write('# configuration file for GridManager\n')
f.write('# The following is the file name with corner coordinates associated with Special Access Areas.\n')
Expand All @@ -646,7 +647,7 @@ def WriteGridMgrConfig(self):
#
#-------------------------------------------------------------------------------------
def WriteUKConfig(self):
cfgFile = os.path.join(self.root,'Configuration', 'Interpolation', self.frame1.ukCfgFile.myEntry.get())
cfgFile = os.path.join(self.root,configDir, interCfgDir, self.frame1.ukCfgFile.myEntry.get())
self.CloseUKConfig(cfgFile,
self.frame4.formCombo.get(),
self.frame4.useSaturateCombo.get(),
Expand Down Expand Up @@ -790,11 +791,11 @@ def ReadUKConfigFile(self):
self.frame4.UpdateUKParameters(tags)

# MA and GB UK Config Files Names are hardcoded
cfgFile = os.path.join(self.root,'Configuration', 'Interpolation', 'UK_MA.cfg')
cfgFile = os.path.join(self.root,configDir, interCfgDir, 'UK_MA.cfg')
tags = self.ReadConfigFile(cfgFile)
self.frame4.UpdateMAParameters(tags)

cfgFile = os.path.join(self.root,'Configuration', 'Interpolation', 'UK_GB.cfg')
cfgFile = os.path.join(self.root,configDir, interCfgDir, 'UK_GB.cfg')
tags = self.ReadConfigFile(cfgFile)
self.frame4.UpdateGBParameters(tags)

Expand Down
5 changes: 5 additions & 0 deletions PythonScripts/GUI/GeoSAM/Globals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
configDir = 'Configuration'
interCfgDir = 'Interpolation'
simCfgDir = 'Simulation'
specAccCfgDir = 'SpecialAccess'
comboTFStr = ['T', 'F']
44 changes: 24 additions & 20 deletions PythonScripts/GUI/GeoSAM/InterpolationFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
from tkinter import filedialog

from Widgets import *
from Globals import *

#======================================================================================================
##
Expand All @@ -89,7 +90,7 @@ def __init__(self, container, parent, friend):
super().__init__()
self.parent = parent
self.root = os.getcwd() #os.environ['ROOT']
self.startDir = os.path.join(self.root, 'Configuration', 'Interpolation')
self.startDir = os.path.join(self.root, configDir, interCfgDir)
self.friend = friend
self.okToRepaintFunctions = True
self.nsfMax = 20
Expand Down Expand Up @@ -184,7 +185,6 @@ def __init__(self, container, parent, friend):

self.maFuncFrame.grid(row=0, column=1, rowspan=3, sticky='n')
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
self.gbFuncFrame = ttk.LabelFrame(scrollFrame.viewPort, text='GBSpatial Functions', style='SAMS.TFrame', width=400, height=200)
# --------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -247,8 +247,8 @@ def __init__(self, container, parent, friend):
self.useSaturateLabel = ttk.Label(self.paramFrame, text='Use Saturate')
self.useSaturateLabel.grid(row=1, column=0)
#-------------------------------------------------------------------------------------------
self.useSaturateCombo = ttk.Combobox(self.paramFrame, width=3, values=['T', 'F'])
self.useSaturateCombo.current(1)
self.useSaturateCombo = ttk.Combobox(self.paramFrame, width=3, values=comboTFStr)
self.useSaturateCombo.current(comboTFStr.index('F'))
self.useSaturateCombo.grid(row=1, column=1)
#-------------------------------------------------------------------------------------------
self.saturateThresh = SubFrameElement(self, self.paramFrame, 'Saturate\nThreshold', '1E309', 2, 0, 1, width=10)
Expand Down Expand Up @@ -276,8 +276,8 @@ def __init__(self, container, parent, friend):
self.useMASaturateLabel = ttk.Label(self.paramMAFrame, text='Use Saturate')
self.useMASaturateLabel.grid(row=1, column=0)
#-------------------------------------------------------------------------------------------
self.useMASaturateCombo = ttk.Combobox(self.paramMAFrame, width=3, values=['T', 'F'])
self.useMASaturateCombo.current(1)
self.useMASaturateCombo = ttk.Combobox(self.paramMAFrame, width=3, values=comboTFStr)
self.useMASaturateCombo.current(comboTFStr.index('F'))
self.useMASaturateCombo.grid(row=1, column=1)
#-------------------------------------------------------------------------------------------
self.saturateMAThresh = SubFrameElement(self, self.paramMAFrame, 'Saturate\nThreshold', '1E309', 2, 0, 1, width=10)
Expand Down Expand Up @@ -308,8 +308,8 @@ def __init__(self, container, parent, friend):
self.useGBSaturateLabel = ttk.Label(self.paramGBFrame, text='Use Saturate')
self.useGBSaturateLabel.grid(row=1, column=0)
#-------------------------------------------------------------------------------------------
self.useGBSaturateCombo = ttk.Combobox(self.paramGBFrame, width=3, values=['T', 'F'])
self.useGBSaturateCombo.current(1)
self.useGBSaturateCombo = ttk.Combobox(self.paramGBFrame, width=3, values=comboTFStr)
self.useGBSaturateCombo.current(comboTFStr.index('F'))
self.useGBSaturateCombo.grid(row=1, column=1)
#-------------------------------------------------------------------------------------------
self.saturateGBThresh = SubFrameElement(self, self.paramGBFrame, 'Saturate\nThreshold', '1E309', 2, 0, 1, width=10)
Expand Down Expand Up @@ -372,10 +372,7 @@ def UpdateMAParameters(self, tags):
else:
messagebox.showerror('READING UK CONFIG FILE',f'Unknown MA variogram form{str}')
elif (tag == 'Use Saturate'):
if value[0] == 'T':
self.useMASaturateCombo.current(0)
else:
self.useMASaturateCombo.current(1)
self.useMASaturateCombo.current(comboTFStr.index(value[0]))
elif (tag == 'Overflow Threshold'):
self.saturateMAThresh.myEntry.delete(0,tk.END)
self.saturateMAThresh.myEntry.insert(0,value)
Expand All @@ -396,13 +393,10 @@ def UpdateGBParameters(self,tags):
else:
messagebox.showerror('READING UK CONFIG FILE',f'Unknown MA variogram form{str}')
elif (tag == 'Use Saturate'):
if value[0] == 'T':
self.useGBSaturateCombo.current(0)
else:
self.useGBSaturateCombo.current(1)
self.useGBSaturateCombo.current(comboTFStr.index(value[0]))
elif (tag == 'Overflow Threshold'):
self.saturateMAThresh.myEntry.delete(0,tk.END)
self.saturateMAThresh.myEntry.insert(0,value)
self.saturateGBThresh.myEntry.delete(0,tk.END)
self.saturateGBThresh.myEntry.insert(0,value)
elif (tag == 'NLS Spatial Fcn File Name'):
self.spatGBCfgFile.myEntry.delete(0,tk.END)
self.spatGBCfgFile.myEntry.insert(0,value.strip())
Expand Down Expand Up @@ -430,7 +424,7 @@ def SaveMASpatialFcnConfigFName(self):
self.parent.WriteSpatialFncsConfig(file_path, self.maFunctions, self.maNumFncsEntry)

# Save MA Unique UK Config file
cfgFile = os.path.join(self.root,'Configuration', 'Interpolation', 'UK_MA.cfg')
cfgFile = os.path.join(self.root,configDir, interCfgDir, 'UK_MA.cfg')
self.parent.CloseUKConfig(cfgFile,
self.formMACombo.get(),
self.useMASaturateCombo.get(),
Expand All @@ -446,7 +440,7 @@ def SaveGBSpatialFcnConfigFName(self):
self.parent.WriteSpatialFncsConfig(file_path, self.gbFunctions, self.gbNumFncsEntry)

# Save GB Unique UK Config file
cfgFile = os.path.join(self.root,'Configuration', 'Interpolation', 'UK_GB.cfg')
cfgFile = os.path.join(self.root,configDir, interCfgDir, 'UK_GB.cfg')
self.parent.CloseUKConfig(cfgFile,
self.formGBCombo.get(),
self.useGBSaturateCombo.get(),
Expand Down Expand Up @@ -591,6 +585,16 @@ def on_visibility(self, event):
self.maFuncFrame.grid()
self.gbFuncFrame.grid()
self.funcFrame.grid_remove()

# Update MA/GB functions
fname = self.spatMACfgFile.myEntry.get()
filePath = os.path.join(configDir, interCfgDir, fname)
self.maNsf = self.ReadSpactialFunctionFile(filePath, self.maFunctions, self.maNumFncsEntry)

fname = self.spatGBCfgFile.myEntry.get()
filePath = os.path.join(configDir, interCfgDir, fname)
self.maNsf = self.ReadSpactialFunctionFile(filePath, self.gbFunctions, self.gbNumFncsEntry)

else:
self.paramMAFrame.grid_remove()
self.paramGBFrame.grid_remove()
Expand Down
9 changes: 5 additions & 4 deletions PythonScripts/GUI/GeoSAM/MainInputFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from tkinter import ttk
from tkinter import filedialog
from Widgets import *
from Globals import *

#======================================================================================================
##
Expand All @@ -50,8 +51,8 @@ class MainInput(ttk.Frame):
def __init__(self, container, friend, tsPerYear, selectedOutputs):
super().__init__()
self.root = os.getcwd() #os.environ['ROOT']
self.simStartDir = os.path.join(self.root, 'Configuration', 'Simulation')
self.interpStartDir = os.path.join(self.root, 'Configuration', 'Interpolation')
self.simStartDir = os.path.join(self.root, configDir, simCfgDir)
self.interpStartDir = os.path.join(self.root, configDir, interCfgDir)
self.friend = friend

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down Expand Up @@ -134,8 +135,8 @@ def __init__(self, container, friend, tsPerYear, selectedOutputs):
self.useStratumLabel = ttk.Label(durationFrame, text='Use Stratum\n(Not Used by MA)')
self.useStratumLabel.grid(row=4, column=0)
#-------------------------------------------------------------------------------------------
self.useStratumCombo = ttk.Combobox(durationFrame, width=3, values=['T', 'F'])
self.useStratumCombo.current(0)
self.useStratumCombo = ttk.Combobox(durationFrame, width=3, values=comboTFStr)
self.useStratumCombo.current(comboTFStr.index('T'))
self.useStratumCombo.grid(row=4, column=1, sticky='w')
# Not user configurable at this time
self.useStratumLabel.grid_remove()
Expand Down
3 changes: 2 additions & 1 deletion PythonScripts/GUI/GeoSAM/SpecialAreaFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

from Widgets import *
from AreaManager import *
from Globals import *

#===============================================================================================================
##
Expand All @@ -44,7 +45,7 @@ def __init__(self, container, maxAreas, maxCorners):

labelArr = ['Corner', 'Long', 'Lat ', '0.0', '0.0']
self.root = os.getcwd() #os.environ['ROOT']
self.startDir = os.path.join(self.root, 'Configuration', 'SpecialAccess')
self.startDir = os.path.join(self.root, configDir, specAccCfgDir)
self.areaFName = None

self.numAreasMax = maxAreas
Expand Down

0 comments on commit 76d41f0

Please sign in to comment.