Skip to content
Snippets Groups Projects
Commit 4fa5b00a authored by jacques.grelet_ird.fr's avatar jacques.grelet_ird.fr
Browse files

PopupScrolled

parent b32dc5f4
No related branches found
No related tags found
No related merge requests found
/.vscode
.vscode
.vstags
*.exe
*.o
*.a
......
......@@ -532,4 +532,15 @@ assertAlmostEqual()
assertNotAlmostEqual()
assertRegex()
assertNotRegex()
assertRaisesRegex()
\ No newline at end of file
assertRaisesRegex()
Git:
-------
Pour mettre à jour le depot distant après l'avoir créé sur github.com
> git pull origin master --allow-unrelated-histories
From https://github.com/jgrelet/oceano2python
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
README.md | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 README.md
\ No newline at end of file
......@@ -36,9 +36,14 @@ class FileExtractor:
return 'Class FileExtractor, file: %s, size = %d' % (self.files, len(self))
def disp(self, keys):
# for key in keys:
# print("{}:".format(key))
# print(self.__data[key])
buf = ''
for key in keys:
print("{}:".format(key))
print(self.__data[key])
buf += "{}:\n".format(key)
buf += "{}\n".format(self.__data[key])
return buf
# first pass on file(s)
def firstPass(self):
......@@ -140,6 +145,6 @@ if __name__ == "__main__":
[n, m] = fe.firstPass()
print("Indices:", n, m)
fe.secondPass(args.key, cfg, 'ctd')
#fe.secondPass(['PRES', 'TEMP', 'PSAL', 'DOX2'], cdf, 'ctd')
# fe.secondPass(['PRES', 'TEMP', 'PSAL', 'DOX2'], cdf, 'ctd')
fe.disp(args.key)
#fe.disp(['PRES', 'TEMP', 'PSAL', 'DOX2'])
# fe.disp(['PRES', 'TEMP', 'PSAL', 'DOX2'])
......@@ -10,90 +10,109 @@ from configparser import ConfigParser
import os
import distutils.util as du
# usage:
# > python oceano.py data/cnv/dfr2900[1-3].cnv -d
# > python oceano.py data/cnv/dfr2900[1-3].cnv -k PRES TEMP PSAL DOX2 DENS
# > python oceano.py data/cnv/dfr29*.cnv -d
parser = argparse.ArgumentParser(
description='This program read multiple ASCII file, extract physical parameter \
following ROSCOP codification at the given column, fill arrays, write header file',
epilog='J. Grelet IRD US191 - March 2019')
parser.add_argument('-d', '--debug', help='display debug informations',
action='store_true')
parser.add_argument('-c', '--config', help="toml configuration file, (default: %(default)s)",
default='tests/test.toml')
parser.add_argument('-k', '--key', nargs='+', default=['PRES', 'TEMP', 'PSAL'],
help='display dictionary for key(s), (default: %(default)s)')
parser.add_argument('-g', '--gui', action='store_true',
help='use GUI interface')
parser.add_argument('files', nargs='*',
help='cnv file(s) to parse, (default: data/cnv/dfr29*.cnv)')
args = parser.parse_args()
# initialize filename use to save GUI configuration
configfile = 'oceano.cfg'
# set looging mode if debug
if args.debug:
logging.basicConfig(
format='%(levelname)s:%(message)s', level=logging.DEBUG)
# read config Toml file and get the physical parameter, Roscop code
cfg = toml.load(args.config)
keys = cfg['split']['ctd'].keys()
# test arguements from sys.argv, args is never to None with default option set
if args.gui or args.debug or len(sys.argv) == 1:
# change look and feel color scheme
sg.ChangeLookAndFeel('SandyBeach')
# define GUI layout
layout = ([[sg.Text('File(s) to read and convert')],
[sg.FilesBrowse(key='_FILE',
initial_folder='data/cnv', file_types=(("cnv files", "*.cnv"),))],
*[[sg.Checkbox(k, key=k)] for k in keys],
[sg.CloseButton('Run'), sg.CloseButton('Cancel')]])
# create a local instance windows used to reload the saved config from file
window = sg.Window('Oceano converter').Layout(layout)
window.LoadFromDisk(configfile)
# display the main windows
event, values = window.Read()
# save program configuration
window.SaveToDisk(configfile)
# debug return values from GUI
logging.debug("Event: {}, Values: {}".format(event, values))
# extract selected parameters (true) from dict values
new_values = values.copy()
for k in values.keys():
if k == '_FILE' or values[k] == False:
del new_values[k]
args.key = new_values.keys()
# values['_FILE'] is a string with files separated by ';' and fileExtractor need a list
files = values['_FILE'].split(';')
args.files = files
else:
# in command line mode (console)
args.files
# check if no file selected or cancel button pressed
logging.debug("File(s): {}, config: {}, Keys: {}".format(
args.files, args.config, args.key))
if not all(args.files):
sg.Popup("Cancel", "No filename supplied")
raise SystemExit("Cancelling: no filename supplied")
# fileExtractor
fe = FileExtractor(args.files)
# cfg = toml.load(args.config)
[n, m] = fe.firstPass()
fe.secondPass(args.key, cfg, 'ctd')
# fe.secondPass(['PRES', 'TEMP', 'PSAL', 'DOX2'], cdf, 'ctd')
fe.disp(args.key)
# fe.disp(['PRES', 'TEMP', 'PSAL', 'DOX2'])
def process(args, cfg, type):
# check if no file selected or cancel button pressed
logging.debug("File(s): {}, config: {}, Keys: {}".format(
args.files, args.config, args.key))
# fileExtractor
fe = FileExtractor(args.files)
# cfg = toml.load(args.config)
[n, m] = fe.firstPass()
fe.secondPass(args.key, cfg, type)
# fe.secondPass(['PRES', 'TEMP', 'PSAL', 'DOX2'], cdf, 'ctd')
# fe.disp(['PRES', 'TEMP', 'PSAL', 'DOX2'])
return fe, n, m
if __name__ == "__main__":
'''
usage:
> python oceano.py data/cnv/dfr2900[1-3].cnv -d
> python oceano.py data/cnv/dfr2900[1-3].cnv -k PRES TEMP PSAL DOX2 DENS
> python oceano.py data/cnv/dfr29*.cnv -d
'''
parser = argparse.ArgumentParser(
description='This program read multiple ASCII file, extract physical parameter \
following ROSCOP codification at the given column, fill arrays, write header file',
epilog='J. Grelet IRD US191 - March 2019')
parser.add_argument('-d', '--debug', help='display debug informations',
action='store_true')
parser.add_argument('-c', '--config', help="toml configuration file, (default: %(default)s)",
default='tests/test.toml')
parser.add_argument('-k', '--key', nargs='+', default=['PRES', 'TEMP', 'PSAL'],
help='display dictionary for key(s), (default: %(default)s)')
parser.add_argument('-g', '--gui', action='store_true',
help='use GUI interface')
parser.add_argument('files', nargs='*',
help='cnv file(s) to parse, (default: data/cnv/dfr29*.cnv)')
args = parser.parse_args()
# initialize filename use to save GUI configuration
configfile = 'oceano.cfg'
# set looging mode if debug
if args.debug:
logging.basicConfig(
format='%(levelname)s:%(message)s', level=logging.DEBUG)
# read config Toml file and get the physical parameter, Roscop code
cfg = toml.load(args.config)
keys = cfg['split']['ctd'].keys()
# test arguements from sys.argv, args is never to None with default option set
if args.gui or args.debug or len(sys.argv) == 1:
# change look and feel color scheme
sg.ChangeLookAndFeel('SandyBeach')
# define GUI layout
layout = ([[sg.Text('File(s) to read and convert')],
[sg.FilesBrowse(key='_FILE',
initial_folder='data/cnv', file_types=(("cnv files", "*.cnv"),))],
*[[sg.Checkbox(k, key=k)] for k in keys],
[sg.CloseButton('Run'), sg.CloseButton('Cancel')]])
# create a local instance windows used to reload the saved config from file
window = sg.Window('Oceano converter').Layout(layout)
window.LoadFromDisk(configfile)
# display the main windows
event, values = window.Read()
# save program configuration
window.SaveToDisk(configfile)
# debug return values from GUI
logging.debug("Event: {}, Values: {}".format(event, values))
# extract selected parameters (true) from dict values
new_values = values.copy()
for k in values.keys():
if k == '_FILE' or values[k] == False:
del new_values[k]
args.key = new_values.keys()
# values['_FILE'] is a string with files separated by ';' and fileExtractor need a list
files = values['_FILE'].split(';')
args.files = files
# test if a or more file are selected
if not all(args.files):
sg.Popup("Cancel", "No filename supplied")
raise SystemExit("Cancelling: no filename supplied")
# process of files start here
fe, n, m = process(args, cfg, 'ctd')
# display result in popup GUI
dims = "Dimensions: {} x {}".format(m, n)
sg.PopupScrolled('Oceano2python', dims,
fe.disp(args.key), size=(50, 60))
else:
# in command line mode (console)
fe, n, m = process(args, cfg, 'ctd')
print("Dimensions: {} x {}".format(m, n))
print(fe.disp(args.key))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment