Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul gui start #78

Merged
merged 4 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Improvements
- Updated WorkflowResults contexts to accept dynamic result shapes.
- Removed redundant code from plugins (because of changes in shape handling).
- Switched to using ruff instead of black, flake8 and isort in github actions.
- Improved the formatting when displaying Plugin information.


Bugfixes
--------
Expand Down
6 changes: 3 additions & 3 deletions pydidas/core/constants/file_extensions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of pydidas.
#
# Copyright 2023, Helmholtz-Zentrum Hereon
# Copyright 2023 - 2024, Helmholtz-Zentrum Hereon
# SPDX-License-Identifier: GPL-3.0-only
#
# pydidas is free software: you can redistribute it and/or modify
Expand All @@ -20,7 +20,7 @@
"""

__author__ = "Malte Storm"
__copyright__ = "Copyright 2023, Helmholtz-Zentrum Hereon"
__copyright__ = "Copyright 2023 - 2024, Helmholtz-Zentrum Hereon"
__license__ = "GPL-3.0-only"
__maintainer__ = "Malte Storm"
__status__ = "Production"
Expand Down Expand Up @@ -50,4 +50,4 @@

YAML_EXTENSIONS = ["yaml", "yml"]

FILENAME_DELIMITERS = "\.|_|-| "
FILENAME_DELIMITERS = r"\.|_|-| "
10 changes: 5 additions & 5 deletions pydidas/core/constants/qt_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,26 @@

QT_REG_EXP_FLOAT_VALIDATOR = QtGui.QRegularExpressionValidator(
QtCore.QRegularExpression(
"-?\\d*\.?\d*|None|nan", QtCore.QRegularExpression.CaseInsensitiveOption
r"-?\\d*\.?\d*|None|nan", QtCore.QRegularExpression.CaseInsensitiveOption
)
)

QT_REG_EXP_INT_VALIDATOR = QtGui.QRegularExpressionValidator(
QtCore.QRegularExpression(
"-?\\d*|None|nan", QtCore.QRegularExpression.CaseInsensitiveOption
r"-?\\d*|None|nan", QtCore.QRegularExpression.CaseInsensitiveOption
)
)

QT_REG_EXP_SLICE_VALIDATOR = QtGui.QRegularExpressionValidator(
QtCore.QRegularExpression("((-?\\d*:?){1,3},?)*")
QtCore.QRegularExpression(r"((-?\\d*:?){1,3},?)*")
)

QT_REG_EXP_FLOAT_SLICE_VALIDATOR = QtGui.QRegularExpressionValidator(
QtCore.QRegularExpression("((-?\\d*\\.?\\d*:?){1,3},?)*")
QtCore.QRegularExpression(r"((-?\\d*\\.?\\d*:?){1,3},?)*")
)

QT_REG_EXP_RGB_VALIDATOR = QtGui.QRegularExpressionValidator(
QtCore.QRegularExpression("#[0-9A-Fa-f]{6}")
QtCore.QRegularExpression(r"#[0-9A-Fa-f]{6}")
)

POLICY_FIX_EXP = (QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Expanding)
Expand Down
38 changes: 26 additions & 12 deletions pydidas/core/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,28 @@ def export_refkey_and_value(self) -> tuple:
"""
return self.__refkey, self.value_for_export

def get_type_and_default_str(self, check_optional: bool = False) -> str:
"""
Get a string representation of the type and default value.

Parameters
----------
check_optional : bool, optional
A flag to print whether the Parameter is optional. The default is False.

Returns
-------
str
The string representation.
"""
_type = f"{self.__type.__name__}" if self.__type is not None else "None"
_unit = "" if self.__meta["unit"] == "" else f" {self.__meta['unit']}"
_default_val = str(self.default) if len(str(self.default)) >= 0 else '""'
_repr = f"(type: {_type}, "
if check_optional and self.__meta["optional"]:
_repr += "optional, "
return _repr + f"default: {_default_val}{_unit})"

def __str__(self) -> str:
"""
Get a short string representation of the parameter.
Expand Down Expand Up @@ -671,19 +693,11 @@ def __get_string_repr(self, check_optional: bool = False) -> str:
str
The string representation.
"""
_type = f"{self.__type.__name__}" if self.__type is not None else "None"
_unit = "" if self.__meta["unit"] == "" else f" {self.__meta['unit']}"
_val = str(self.value)
if len(_val) == 0:
_val = '""'
_default_val = str(self.__meta["default"])
if len(_default_val) == 0:
_default_val = '""'
_repr = f"{self.__refkey}: {_val}{_unit} (type: {_type}, "
if check_optional and self.__meta["optional"]:
_repr += "optional, "
_repr += f"default: {_default_val}{_unit})"
return _repr
_val = str(self.value) if len(str(self.value)) > 0 else '""'
return f"{self.__refkey}: {_val}{_unit} " + self.get_type_and_default_str(
check_optional
)

def __get_as_numbers(
self, value: Union[str, Iterable]
Expand Down
85 changes: 85 additions & 0 deletions pydidas/core/utils/str_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
"format_input_to_multiline_str",
"get_random_string",
"get_simplified_array_representation",
"get_param_description_from_docstring",
"strip_param_description_from_docstring",
"get_formatted_blocks_from_docstring",
]


Expand Down Expand Up @@ -535,3 +538,85 @@ def get_random_string(length: int, use_digits: bool = False) -> str:
"""
_chars = _string_.ascii_letters + (_string_.digits if use_digits else "")
return "".join(random.choice(_chars) for _ in range(length))


def get_param_description_from_docstring(docstring: str) -> dict[str, str]:
"""
Get the parameter descriptions from a docstring.

Parameters
----------
docstring : str
The input docstring.

Returns
-------
dict[str, str]
The dictionary with the parameter descriptions.
"""
_param_docstrings = {}
if docstring.find("Parameters") > 0:
_param_str = (
docstring[docstring.find("Parameters") + 10 :].strip("\n -").split("\n")
)
while len(_param_str) > 0:
if not _param_str[0].startswith(8 * " "):
_key = _param_str.pop(0).strip()
_param_docstrings[_key] = ""
else:
_param_docstrings[_key] += " " + _param_str.pop(0).strip()
return _param_docstrings


def strip_param_description_from_docstring(docstring: str) -> str:
"""
Strip the parameter description from a docstring.

Parameters
----------
docstring : str
The input docstring.

Returns
-------
str
The stripped docstring.
"""
if docstring.find("Parameters") > 0:
docstring = docstring[: docstring.find("Parameters")]
return docstring


def get_formatted_blocks_from_docstring(docstring: str) -> list[str]:
"""
Get formatted blocks from a docstring.

This function will split the input docstring into blocks of text and strip
leading and trailing whitespaces while retaining the linebreaks.

Parameters
----------
docstring : str
The input docstring.

Returns
-------
list[str]
The list with the formatted blocks.
"""
_blocks = []
for _i, _doc_section in enumerate(docstring.split("\n\n")):
_formatted_section = ""
for _line in _doc_section.strip().split("\n"):
if _line.startswith(8 * " "):
if not _formatted_section.endswith("\n"):
_formatted_section += "\n"
_formatted_section += f" {_line.strip()}\n"
else:
_formatted_section += f"{_line.strip()} "
_formatted_section = _formatted_section.strip()
if _i > 0:
_formatted_section = "\n" + _formatted_section
if _formatted_section != "\n":
_blocks.append(_formatted_section)
return _blocks
5 changes: 3 additions & 2 deletions pydidas/gui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of pydidas.
#
# Copyright 2023, Helmholtz-Zentrum Hereon
# Copyright 2023 - 2024, Helmholtz-Zentrum Hereon
# SPDX-License-Identifier: GPL-3.0-only
#
# pydidas is free software: you can redistribute it and/or modify
Expand All @@ -21,7 +21,7 @@
"""

__author__ = "Malte Storm"
__copyright__ = "Copyright 2023, Helmholtz-Zentrum Hereon"
__copyright__ = "Copyright 2023 - 2024, Helmholtz-Zentrum Hereon"
__license__ = "GPL-3.0-only"
__maintainer__ = "Malte Storm"
__status__ = "Production"
Expand All @@ -38,6 +38,7 @@
# import __all__ items from modules:
from .gui_excepthook_ import *
from .main_window import *
from .start_pydidas_gui import *


# add modules' __all__ items to package's __all__ items and unclutter the
Expand Down
10 changes: 8 additions & 2 deletions pydidas/gui/frames/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of pydidas.
#
# Copyright 2023, Helmholtz-Zentrum Hereon
# Copyright 2023 - 2024, Helmholtz-Zentrum Hereon
# SPDX-License-Identifier: GPL-3.0-only
#
# pydidas is free software: you can redistribute it and/or modify
Expand All @@ -22,7 +22,7 @@
"""

__author__ = "Malte Storm"
__copyright__ = "Copyright 2023, Helmholtz-Zentrum Hereon"
__copyright__ = "Copyright 2023 - 2024, Helmholtz-Zentrum Hereon"
__license__ = "GPL-3.0-only"
__maintainer__ = "Malte Storm"
__status__ = "Production"
Expand All @@ -33,6 +33,7 @@
from .composite_creator_frame import *
from .data_browsing_frame import *
from .define_diffraction_exp_frame import *
from .default_frames import *
from .define_scan_frame import *
from .directory_spy_frame import *
from .home_frame import *
Expand Down Expand Up @@ -67,6 +68,11 @@
__all__.extend(define_scan_frame.__all__)
del define_scan_frame

from . import default_frames

__all__.extend(default_frames.__all__)
del default_frames

from . import directory_spy_frame

__all__.extend(directory_spy_frame.__all__)
Expand Down
57 changes: 57 additions & 0 deletions pydidas/gui/frames/default_frames.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This file is part of pydidas.
#
# Copyright 2024, Helmholtz-Zentrum Hereon
# SPDX-License-Identifier: GPL-3.0-only
#
# pydidas is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# Pydidas is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Pydidas. If not, see <http://www.gnu.org/licenses/>.

"""
Module with the DEFAULT_FRAMES which lists all of pydidas's generic frames.
"""

__author__ = "Malte Storm"
__copyright__ = "Copyright 2024, Helmholtz-Zentrum Hereon"
__license__ = "GPL-3.0-only"
__maintainer__ = "Malte Storm"
__status__ = "Production"
__all__ = ["DEFAULT_FRAMES"]


from .data_browsing_frame import DataBrowsingFrame
from .define_diffraction_exp_frame import DefineDiffractionExpFrame
from .define_scan_frame import DefineScanFrame
from .home_frame import HomeFrame
from .image_math_frame import ImageMathFrame
from .pyfai_calib_frame import PyfaiCalibFrame
from .quick_integration_frame import QuickIntegrationFrame
from .utilities_frame import UtilitiesFrame
from .view_results_frame import ViewResultsFrame
from .workflow_edit_frame import WorkflowEditFrame
from .workflow_run_frame import WorkflowRunFrame
from .workflow_test_frame import WorkflowTestFrame


DEFAULT_FRAMES = (
HomeFrame,
DataBrowsingFrame,
PyfaiCalibFrame,
ImageMathFrame,
QuickIntegrationFrame,
DefineDiffractionExpFrame,
DefineScanFrame,
WorkflowEditFrame,
WorkflowTestFrame,
WorkflowRunFrame,
ViewResultsFrame,
UtilitiesFrame,
)
2 changes: 2 additions & 0 deletions pydidas/gui/main_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ def restore_gui_state(self, state: str = "saved", filename: Optional[str] = None
The filename to be used to restore the state. This kwarg will only be used
if the state kwarg is set to "manual".
"""
if state.upper() == "NONE":
return
if state.upper() == "SAVED":
filename = utils.get_standard_state_full_filename(self.STATE_FILENAME)
elif state.upper() == "EXIT":
Expand Down
Loading