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

test with PySimpleGUI

parent 5809a2b3
No related branches found
No related tags found
No related merge requests found
...@@ -14,4 +14,5 @@ ...@@ -14,4 +14,5 @@
__pycache__/ __pycache__/
*.py[cod] *.py[cod]
*$py.class *$py.class
build/
...@@ -483,6 +483,14 @@ Developpement: ...@@ -483,6 +483,14 @@ Developpement:
> pip install netCDF4 > pip install netCDF4
> pip install seawater > pip install seawater
> pip install numpy > pip install numpy
> pip install PyInstaller
> pip install PySimpleGUI
To create your EXE file from your program that uses PySimpleGUI, my_program.py,
enter this command in your Windows command prompt:
> pyinstaller -wF my_program.py
Tests avec unittest: Tests avec unittest:
-------------------- --------------------
......
...@@ -69,10 +69,12 @@ class FileExtractor: ...@@ -69,10 +69,12 @@ class FileExtractor:
return self.n, self.m return self.n, self.m
# second pass, extract data from roscop code in files and fill array # second pass, extract data from roscop code in files and fill array
def secondPass(self, keys, dic): def secondPass(self, keys, cfg, type):
n = 0 n = 0
m = 0 m = 0
hash = cfg['split'][type]
# initialize arrays, move at the end of firstPass ? # initialize arrays, move at the end of firstPass ?
for key in keys: for key in keys:
# mult by __fillValue next # mult by __fillValue next
...@@ -91,10 +93,10 @@ class FileExtractor: ...@@ -91,10 +93,10 @@ class FileExtractor:
str = ' ' str = ' '
# fill array with extracted value of line for eack key (physical parameter) # fill array with extracted value of line for eack key (physical parameter)
for key in keys: for key in keys:
self.__data[key][n, m] = p[dic[key]] self.__data[key][n, m] = p[hash[key]]
# debug info # debug info
str += "{:>{width}}".format( str += "{:>{width}}".format(
p[dic[key]], width=8) p[hash[key]], width=8)
logging.debug(str) logging.debug(str)
# increment m indice (the line number) # increment m indice (the line number)
...@@ -108,16 +110,21 @@ class FileExtractor: ...@@ -108,16 +110,21 @@ class FileExtractor:
if __name__ == "__main__": if __name__ == "__main__":
# usage: # usage:
# python file_extractor.py data/cnv/dfr29*.cnv -d # > python file_extractor.py data/cnv/dfr2900[1-3].cnv -d
# > python file_extractor.py data/cnv/dfr2900[1-3].cnv -k PRES TEMP PSAL DOX2 DENS
# > python file_extractor.py data/cnv/dfr29*.cnv -d
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='This class read multiple ASCII file, extract physical parameter \ description='This class read multiple ASCII file, extract physical parameter \
from ROSCOP codification at the given column and fill arrays') from ROSCOP codification at the given column and fill arrays ',
parser.add_argument("-d", "--debug", help="display debug informations", epilog='J. Grelet IRD US191 - March 2019')
action="store_true") parser.add_argument('-d', '--debug', help='display debug informations',
parser.add_argument("-k", "--key", nargs='+', action='store_true')
help="display dictionary for key(s), example -k TEMP [PSAL ...]") parser.add_argument('-c', '--config', help="toml configuration file, (default: %(default)s)",
parser.add_argument( default='tests/test.toml')
'files', nargs='*', help="cnv file(s) to parse, example data/cnv/dfr29*.cnv") parser.add_argument('-k', '--key', nargs='+', default=['PRES', 'TEMP', 'PSAL'],
help='display dictionary for key(s), (default: %(default)s)')
parser.add_argument('files', nargs='*',
help='cnv file(s) to parse, (default: data/cnv/dfr29*.cnv)')
# display extra logging info # display extra logging info
# see: https://stackoverflow.com/questions/14097061/easier-way-to-enable-verbose-logging # see: https://stackoverflow.com/questions/14097061/easier-way-to-enable-verbose-logging
...@@ -128,9 +135,11 @@ if __name__ == "__main__": ...@@ -128,9 +135,11 @@ if __name__ == "__main__":
format='%(levelname)s:%(message)s', level=logging.DEBUG) format='%(levelname)s:%(message)s', level=logging.DEBUG)
fe = FileExtractor(args.files) fe = FileExtractor(args.files)
cfg = toml.load('tests/test.toml') print("File(s): {}, Config: {}".format(args.files, args.config))
dic = cfg['split']['ctd'] cfg = toml.load(args.config)
[n, m] = fe.firstPass() [n, m] = fe.firstPass()
print("Indices:", n, m) print("Indices:", n, m)
fe.secondPass(['PRES', 'TEMP', 'PSAL', 'DOX2'], dic) fe.secondPass(args.key, cfg, 'ctd')
fe.disp(['PRES', 'TEMP', 'PSAL', 'DOX2']) #fe.secondPass(['PRES', 'TEMP', 'PSAL', 'DOX2'], cdf, 'ctd')
fe.disp(args.key)
#fe.disp(['PRES', 'TEMP', 'PSAL', 'DOX2'])
import argparse
import sys
import PySimpleGUI as sg
import toml
import logging
from file_extractor import FileExtractor
import pathlib
# 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()
if args.debug:
logging.basicConfig(
format='%(levelname)s:%(message)s', level=logging.DEBUG)
# test arguements from sys.argv, args is never to None with default option set
if len(sys.argv) == 1:
event, fname = sg.Window('My Script').Layout([[sg.Text('Document to open')],
[sg.In(), sg.FileBrowse()],
[sg.CloseButton('Open'), sg.CloseButton('Cancel')]]).Read()
#fname = pathlib.PurePosixPath(fname)
print(event, fname)
else:
fname = args.files
if not fname:
sg.Popup("Cancel", "No filename supplied")
raise SystemExit("Cancelling: no filename supplied")
fe = FileExtractor(fname)
print("File(s): {}, Config: {}".format(fname, args.config))
cfg = toml.load(args.config)
[n, m] = fe.firstPass()
print("Indices:", n, m)
fe.secondPass(args.key, cfg, 'ctd')
# fe.secondPass(['PRES', 'TEMP', 'PSAL', 'DOX2'], cdf, 'ctd')
fe.disp(args.key)
# fe.disp(['PRES', 'TEMP', 'PSAL', 'DOX2'])
# -*- mode: python -*-
block_cipher = None
a = Analysis(['oceano.py'],
pathex=['c:\\git\\python\\pirata'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='oceano',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=False )
...@@ -7,8 +7,8 @@ Run test in single file ...@@ -7,8 +7,8 @@ Run test in single file
> python - m unittest - v tests/test_roscop.py > python - m unittest - v tests/test_roscop.py
Run all test_ * in dir tests: Run all test_ * in dir tests:
> python - m unittest discover tests - v > python -m unittest discover tests - v
> python - m unittest discover - s tests - p 'test_*.py' - v > python -m unittest discover - s tests - p 'test_*.py' - v
''' '''
......
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