Skip to content

Commit

Permalink
Edit Math Startup Files
Browse files Browse the repository at this point in the history
  • Loading branch information
TCallaghan2 committed Jun 23, 2024
1 parent 6fbe83c commit 45e5a86
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .octaverc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
addpath mfiles/
addpath mfiles/latlonutm/
addpath PreProcess/
addpath /Users/tomcallaghan/.local/share/octave/api-v58/packages/io-2.6.4/
addpath /Users/tomcallaghan/.local/share/octave/api-v58/packages/geometry-4.0.0
addpath /Users/tomcallaghan/.local/share/octave/api-v58/packages/mapping-1.4.2/
addpath /Users/tomcallaghan/.local/share/octave/api-v58/packages/io-2.6.4/
addpath /Users/tomcallaghan/.local/share/octave/api-v58/packages/statistics-1.6.6
145 changes: 145 additions & 0 deletions PythonScripts/GUI/GeoSAM/EditMathSetupFrame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#======================================================================================================
## @page MathSetupFile Math Setup Frame
#
#======================================================================================================
import os
import tkinter as tk

from tkinter import ttk
from tkinter import messagebox

from Widgets import *

#===============================================================================================================
##
# This class allows the user to edit the Matlab/Octave setup files to fit their environment.
#
#===============================================================================================================
class EditMathSetup(ttk.Frame):
##
# Constructor for Growth Class
#
def __init__(self, container):
super().__init__()
self.matlabFName = 'startup.m'
self.octaveFName = '.octaverc'
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
self.editMathFrame = ttk.LabelFrame(self, text='Math Setup Text', style='SAMS.TFrame')
# --------------------------------------------------------------------------------------------------------
self.editText = tk.Text(self.editMathFrame, height = 15, width = 90)
self.editText.grid(row=0, column=0, columnspan=3, padx=5, sticky='sw')
self.editTextButton = ttk.Button(self.editMathFrame, text='Write Startup File', style="BtnGreen.TLabel", command=self.WriteStartupFile)
self.editTextButton.grid(row=1, column=0)
#-------------------------------------------------------------------------------------------
# Radio Buttons, it's either Matlab or Octave
self.isMatlab = True
self.usingMatlab = tk.BooleanVar(self.editMathFrame, self.isMatlab)
self.useMatlabRB = ttk.Radiobutton(self.editMathFrame, text='Matlab', value=True, variable=self.usingMatlab, command=self.LoadStartupFile)
self.useMatlabRB.grid(row=1, column=1)
self.useOctaveRB = ttk.Radiobutton(self.editMathFrame, text='Octave', value=False, variable=self.usingMatlab, command=self.LoadStartupFile)
self.useOctaveRB.grid(row=1, column=2)
#-------------------------------------------------------------------------------------------
self.editMathFrame.grid(row=1, column=0, padx=5, sticky='sw')
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
helpButton = ttk.Button(self, text= "Math Help", style="Help.TLabel", command = self.pop_up)
helpButton.grid(row=0, column=0)

self.bind("<Visibility>", self.on_visibility)

#---------------------------------------------------------------------------------------------------------
## Opens either startup.m or .octaverc depending if user selected Matlab or Octave resp
#---------------------------------------------------------------------------------------------------------
def on_visibility(self, event):
self.ReadFile(False)

def LoadStartupFile(self):
self.ReadFile(True)

def ReadFile(self, showMsg):
if self.usingMatlab.get():
if os.path.isfile(self.matlabFName):
# Unpack.sh has not renamed Matlab startup.m
self.usingMatlab.set(True)
self.editText.delete(1.0,tk.END)
with open(self.matlabFName, 'r') as f:
while True:
line = f.readline()
if not line:
f.close()
break
self.editText.insert('current',line)
else:
# File does not exist default to Octave
if showMsg: messagebox.showinfo('Read Startup File','File has been renamed by Unpack.sh')
self.isMatlab = False
self.usingMatlab.set(False)

if not self.usingMatlab.get():
# Unpack.sh has not renamed Matlab startup.m
self.editText.delete(1.0,tk.END)
with open(self.octaveFName, 'r') as f:
while True:
line = f.readline()
if not line:
f.close()
break
self.editText.insert('current',line)

#-------------------------------------------------------------------------------------
##
#-------------------------------------------------------------------------------------
def WriteStartupFile(self):
lines = self.editText.get(1.0,tk.END)
n = len(lines)
# remove extr CRLF
if lines[n-1] == '\n': lines = lines[0:n-1]
if self.usingMatlab.get():
fname = self.matlabFName
else:
fname = self.octaveFName
f = open(fname, 'w')
f.write(lines)
f.close()
messagebox.showinfo('WRITING TO STARTUP FILE', 'File successfully writen.')


#-------------------------------------------------------------------------------------
##
#-------------------------------------------------------------------------------------
def pop_up(self):
about = '''(This frame is scrollable, use mouse wheel)
This frame allows the user to modify the Matlab/Octave startup files.
Matlab should not need any modification as these are the installed directories.
The user should not need to run any Matlab scripts as these are called from the
GUI.
Octave on the other hand does require some setup. The user will need to install
the desired packages from https://gnu-octave.github.io/packages/
- io
- geometry
- mapping
- statistics
The user then needs to modify .octaverc to point to where these are installed.
Either click the Octave radio button or on a non-Windows platform the Unpack.sh
renames startup.m to startup.xxx such that this frame will default to .octaverc
At this point simply edit the text box to reflect your environment and click
Write Startup File.
'''
#about = re.sub("\n\s*", "\n", about) # remove leading whitespace from each line
popup = tk.Toplevel()
nrows = 35
ncols = 80
parentPosn = '+'+str(self.winfo_rootx()+helpXoffset)+'+'+str(self.winfo_rooty()+helpYoffset)
popup.geometry(str(int(ncols*8.5))+"x"+str(nrows*18)+parentPosn)
T = tk.Text(popup, width=ncols, height=nrows, padx=10)
T.insert('end', about)
T.config(state='disabled')
T.grid()
btn = tk.Button(popup, text ="Close", command= popup.destroy)
btn.grid(row =1)

2 changes: 1 addition & 1 deletion PythonScripts/GUI/GeoSAM/FishMortBySpecAcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def pop_up(self):
popup = tk.Toplevel()
nrows = 35
ncols = 80
parentPosn = '+'+str(self.winfo_rootx()+700)+'+'+str(self.winfo_rooty()+50)
parentPosn = '+'+str(self.winfo_rootx()+helpXoffset)+'+'+str(self.winfo_rooty()+helpYoffset)
popup.geometry(str(int(ncols*8.5))+"x"+str(nrows*18)+parentPosn)
T = tk.Text(popup, width=ncols, height=nrows, padx=10)
T.insert('end', about)
Expand Down
6 changes: 4 additions & 2 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 EditMathSetupFrame import *
from Globals import *

#======================================================================================================
Expand Down Expand Up @@ -127,12 +128,12 @@ def __init__(self, title, maxAreas, maxCorners, maxYears):
#
# NOTE: MA does not use stratum and forces it to false
#
#self.frame2 = SpecialAccess(self.notebook)
self.frame3 = Growth(self.notebook, self.mortConfigFile)
self.frame4 = UKInterpolation(self.notebook, self, self.frame1)
self.frame5 = SortByArea(self.notebook, self.frame1, self.maxAreas, self.maxCorners, self.maxYears, self.paramStr)
self.frame6 = SpecialArea(self.notebook, self.maxAreas, self.maxCorners)
self.frame7 = FishMortBySpecAcc(self.notebook, self.maxAreas, self.maxCorners)
self.frame2 = EditMathSetup(self.notebook)
self.ReadUKConfigFile()

# Update strings based on given configuration files
Expand All @@ -149,6 +150,7 @@ def __init__(self, title, maxAreas, maxCorners, maxYears):
self.notebook.add(self.frame7, text='Fishing Mort in\n Special Access')
self.notebook.add(self.frame5, text='SortByArea')
self.notebook.add(self.frame4, text='UKInterpolation')
self.notebook.add(self.frame2, text='Math Setup')
self.notebook.pack()

ttk.Button(self, text='SHOW Args', style="BtnGreen.TLabel", command=self.ShowArgs).place(relx=0, rely=1, anchor='sw')
Expand Down Expand Up @@ -837,7 +839,7 @@ def pop_up(self):
popup = tk.Toplevel()
nrows = 31
ncols = 80
parentPosn = '+'+str(self.winfo_rootx()+700)+'+'+str(self.winfo_rooty()+50)
parentPosn = '+'+str(self.winfo_rootx()+helpXoffset)+'+'+str(self.winfo_rooty()+helpYoffset)
popup.geometry(str(int(ncols*8.5))+"x"+str(nrows*18)+parentPosn)
T = tk.Text(popup, width=ncols, height=nrows, padx=10)
T.insert('end', about)
Expand Down
2 changes: 2 additions & 0 deletions PythonScripts/GUI/GeoSAM/Globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
frameWidth = 400
frameHeight= 200
scrollFrameHeight = 600
helpXoffset = 700
helpYoffset = 50

if platform.system() == 'Windows':
scrollFrameWidth = 900
Expand Down
2 changes: 1 addition & 1 deletion PythonScripts/GUI/GeoSAM/GrowthFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def pop_up(self):
popup = tk.Toplevel()
nrows = 37
ncols = 80
parentPosn = '+'+str(self.winfo_rootx()+700)+'+'+str(self.winfo_rooty()+50)
parentPosn = '+'+str(self.winfo_rootx()+helpXoffset)+'+'+str(self.winfo_rooty()+helpYoffset)
popup.geometry(str(int(ncols*8.5))+"x"+str(nrows*18)+parentPosn)
T = tk.Text(popup, width=ncols, height=nrows, padx=10)
T.insert('end', about)
Expand Down
2 changes: 1 addition & 1 deletion PythonScripts/GUI/GeoSAM/InterpolationFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ def pop_up(self):
popup = tk.Toplevel()
nrows = 35
ncols = 80
parentPosn = '+'+str(self.winfo_rootx()+700)+'+'+str(self.winfo_rooty()+50)
parentPosn = '+'+str(self.winfo_rootx()+helpXoffset)+'+'+str(self.winfo_rooty()+helpYoffset)
popup.geometry(str(int(ncols*8.5))+"x"+str(nrows*18)+parentPosn)
T = tk.Text(popup, width=ncols, height=nrows, padx=10)
T.insert('end', about)
Expand Down
8 changes: 1 addition & 7 deletions PythonScripts/GUI/GeoSAM/MainInputFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def __init__(self, container, friend, tsPerYear, selectedOutputs):
#-------------------------------------------------------------------------------------------
simFrame.grid(row=1, column=0, padx=5, sticky='n')
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
interpFrame = ttk.LabelFrame(self, text='Interpolation Configuration Files', style='SAMS.TFrame')
self.ukCfgFile = SubFrameElement(self, interpFrame, 'UK Config File', 'UK.cfg', 0, 0, 1, width=20)
self.openUKConfigButton = ttk.Button(interpFrame, text='Change/Save UK File', style="BtnBluGrn.TLabel", command=self.GetUKConfigFName)
Expand All @@ -94,7 +93,6 @@ def __init__(self, container, friend, tsPerYear, selectedOutputs):
#-------------------------------------------------------------------------------------------
showResultsFrame.grid(row=2, column=0, padx=5, sticky='sw')
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
recruitFrame = ttk.LabelFrame(self, text='Recruitment', style='SAMS.TFrame')

self.monthsArr = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
Expand Down Expand Up @@ -126,7 +124,6 @@ def __init__(self, container, friend, tsPerYear, selectedOutputs):
#-------------------------------------------------------------------------------------------
recruitFrame.grid(row=2, column=1, padx=5, sticky='e')
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
durationFrame = ttk.LabelFrame(self, text='Duration', style='SAMS.TFrame')
self.startYr = SubFrameElement(self, durationFrame, 'Start Year', '2015', 0, 0, 1)
#-------------------------------------------------------------------------------------------
Expand All @@ -153,7 +150,6 @@ def __init__(self, container, friend, tsPerYear, selectedOutputs):
#-------------------------------------------------------------------------------------------
durationFrame.grid(row=2, column=1, padx=5, sticky='w')
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
outputSelFrame = ttk.LabelFrame(self, text='Output Selection', style='SAMS.TFrame')
#-------------------------------------------------------------------------------------------
# Check Buttons
Expand Down Expand Up @@ -411,13 +407,11 @@ def pop_up(self):
popup = tk.Toplevel()
nrows = 35
ncols = 80
parentPosn = '+'+str(self.winfo_rootx()+700)+'+'+str(self.winfo_rooty()+50)
parentPosn = '+'+str(self.winfo_rootx()+helpXoffset)+'+'+str(self.winfo_rooty()+helpYoffset)
popup.geometry(str(int(ncols*8.5))+"x"+str(nrows*18)+parentPosn)
T = tk.Text(popup, width=ncols, height=nrows, padx=10)
T.insert('end', about)
T.config(state='disabled')
T.grid()
btn = tk.Button(popup, text ="Close", command= popup.destroy)
btn.grid(row =1)


2 changes: 1 addition & 1 deletion PythonScripts/GUI/GeoSAM/SortByAreaFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def pop_up(self):
popup = tk.Toplevel()
nrows = 35
ncols = 80
parentPosn = '+'+str(self.winfo_rootx()+700)+'+'+str(self.winfo_rooty()+50)
parentPosn = '+'+str(self.winfo_rootx()+helpXoffset)+'+'+str(self.winfo_rooty()+helpYoffset)
popup.geometry(str(int(ncols*8.5))+"x"+str(nrows*18)+parentPosn)
T = tk.Text(popup, width=ncols, height=nrows, padx=10)
T.insert('end', about)
Expand Down
2 changes: 1 addition & 1 deletion PythonScripts/GUI/GeoSAM/SpecialAreaFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def pop_up(self):
popup = tk.Toplevel()
nrows = 35
ncols = 80
parentPosn = '+'+str(self.winfo_rootx()+700)+'+'+str(self.winfo_rooty()+50)
parentPosn = '+'+str(self.winfo_rootx()+helpXoffset)+'+'+str(self.winfo_rooty()+helpYoffset)
popup.geometry(str(int(ncols*8.5))+"x"+str(nrows*18)+parentPosn)
T = tk.Text(popup, width=ncols, height=nrows, padx=10)
T.insert('end', about)
Expand Down

0 comments on commit 45e5a86

Please sign in to comment.