From 73de76565bf8d14f76c1e661a2a339b8912cc51a Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Mon, 11 Nov 2019 09:39:52 +0100 Subject: [PATCH] added optional GUI script --- pyproject.toml | 10 +++++++++- sartorius_logger/__init__.py | 16 ++++++++++++++++ sartorius_logger/parsers.py | 19 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8152683..2508c48 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,13 +30,21 @@ test = [ "black", "flake8", "flake8-comprehensions", - "pytest >=4.0.0", + "pytest >= 4.0.0", "pytest-cov", "pytest-mock", ] dev = [ "keyring", ] +gui = [ + "Gooey >= 1.0.3", + "pyinstaller >= 3.5" +] + +[tool.flit.scripts] +loggercli = "sartorius_logger:cli" +SartoriusLogger = "sartorius_logger:gui" [tool.black] line-length = 79 diff --git a/sartorius_logger/__init__.py b/sartorius_logger/__init__.py index 8ef0ef7..63a1a58 100644 --- a/sartorius_logger/__init__.py +++ b/sartorius_logger/__init__.py @@ -16,6 +16,13 @@ from tqdm import tqdm from .datalogger import DataLogger, NullLogger from .parsers import parse_cli_arguments +try: + from gooey import Gooey +except ImportError as exc: + def Gooey(*args, **kargs): + msg = "The graphilcal user interface must be installed separately" + raise NotImplementedError(msg) + SCALE_INFO_LABELS = { sartoriusb.CMD_INFO_TYPE: "Scale Model", @@ -173,3 +180,12 @@ def cli(): settings, progress_bar=tqdm, data_logger=DataLogger(log_file_path) ) export_as_excel(result) + +@Gooey(program_name="SartoriusLogger") +def gui(): + settings = parse_cli_arguments() + log_file_path = _get_log_file_path(settings) + result = measure_series( + settings, progress_bar=tqdm, data_logger=DataLogger(log_file_path) + ) + export_as_excel(result) diff --git a/sartorius_logger/parsers.py b/sartorius_logger/parsers.py index 11d1317..cfa60ba 100644 --- a/sartorius_logger/parsers.py +++ b/sartorius_logger/parsers.py @@ -52,6 +52,25 @@ def parse_cli_arguments(): return _normalize_cli_arguments(raw_arguments) +def parse_gui_arguments(): + from gooey import GooeyParser + """ parses command line interface arguments """ + parser = argparse.GooeyParser( + description="Make time series measurements with a Sartorius scale.", + epilog=( + "Times can be specified as 10s, 10m, or 10h" + "for seconds, minutes or hours respectively." + "A relative directory path starts at the Desktop." + ), + ) + parser.add_argument("port", nargs="?", default="COM4", metavar="COMPORT", help="Serial Port that connects the Scale, defaults to 'COM4'") + parser.add_argument("-d", "--duration", nargs="?", default="30m", help="Measurement duration, e.g. 10s, 30m, 2h") + parser.add_argument("-i", "--interval", nargs="?", default="10s", help="Measurement interval, e.g. 5s, 1m, 1h") + parser.add_argument("-o", "--output", nargs="?", metavar="DIRECTORY", widget='DirChooser', help="Select Output Directory, defaults to 'Desktop'") + raw_arguments = parser.parse_args() + return _normalize_cli_arguments(raw_arguments) + + # helper functions