diff --git a/.github/workflows/package_testing.yml b/.github/workflows/package_testing.yml index 6de4552..6db1a21 100644 --- a/.github/workflows/package_testing.yml +++ b/.github/workflows/package_testing.yml @@ -1,6 +1,3 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - name: tests on: @@ -23,16 +20,16 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - name: Install the latest version of rye - uses: eifinger/setup-rye@v1 + uses: eifinger/setup-rye@v2 - name: Sync Rye run: | rye pin ${{ matrix.python-version }} rye sync - name: Run Tests for python interface run: rye run test -# - name: Run Lint on one python -# if: ${{ matrix.python-version == env.MAIN_PYTHON_VERSION }} -# run: rye lint + - name: Run Lint on one python + if: ${{ matrix.python-version == env.MAIN_PYTHON_VERSION }} + run: rye lint - name: Run Pytest with coverage if: ${{ matrix.python-version == env.MAIN_PYTHON_VERSION }} run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 479dedf..0c021a2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - name: Install the latest version of rye - uses: eifinger/setup-rye@v1 + uses: eifinger/setup-rye@v2 - name: Sync Rye run: | rye pin ${{ env.PYTHON_VERSION }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d28da8f..a3f62cf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.2.1 + rev: v0.3.5 hooks: # Run the linter. - id: ruff @@ -14,7 +14,7 @@ repos: # Run the formatter. - id: ruff-format - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 + rev: v3.15.2 hooks: - id: pyupgrade args: [ --py38-plus ] diff --git a/src/rimsschemedrawer/gui.py b/src/rimsschemedrawer/gui.py index 2a84e40..c0eb0f3 100644 --- a/src/rimsschemedrawer/gui.py +++ b/src/rimsschemedrawer/gui.py @@ -392,7 +392,7 @@ def init_ui(self): ) self.edt_sett_headspace.setToolTip( "Set how much space is added on top of the " - "IP level: the head space. Adjust this " + "highest transition: the head space. Adjust this " "value whenever there is not enough space " "on top to fit all the text in. The value " "is given in cm-1." @@ -652,11 +652,11 @@ def check_fields(self): Check if the required fields are filled in. """ # throw an error if not at least one box is filled - if self.edt_level[0].text() == "": + if self.edt_level[0].text() == "" or self.edt_gslevel.text() == "": QtWidgets.QMessageBox.warning( self, "No entries", - "Need at least one level to make a plot!", + "Need at least ground state and one level to make a plot!", QtWidgets.QMessageBox.Ok, ) return False @@ -679,6 +679,9 @@ def plot(self): """ Call the plotting window """ + if not self.check_fields(): + return + # fill default values - if not already there self.fill_default_values() @@ -717,7 +720,16 @@ def load_config(self, **kwargs): # load the json file _load_dict = rimsschemedrawer.json_parser.json_reader(filename) - config_parser = rimsschemedrawer.json_parser.ConfigParser(_load_dict) + try: + config_parser = rimsschemedrawer.json_parser.ConfigParser(_load_dict) + except Exception as err: + QtWidgets.QMessageBox.warning( + self, + "Error", + f"An error occurred while reading the file.\n{'\n'.join(err.args)}", + QtWidgets.QMessageBox.Ok, + ) + return # set the settings for the levels if config_parser.sett_unit_nm: @@ -744,7 +756,11 @@ def load_config(self, **kwargs): self.chk_lowlying[it].setChecked(config_parser.is_low_lying[it]) self.chk_forbidden[it].setChecked(config_parser.step_forbidden[it]) except IndexError: - break + self.edt_level[it].setText("") + self.edt_term[it].setText("") + self.edt_transition_strengths[it].setText("") + self.chk_lowlying[it].setChecked(False) + self.chk_forbidden[it].setChecked(False) # IP level self.cmb_element.setCurrentText(config_parser.element) @@ -857,9 +873,9 @@ def write_json(self) -> dict: dispforbidden = "noshow" savedict["settings"]["show_forbidden_transitions"] = dispforbidden savedict["settings"]["plot_title"] = self.edt_sett_plttitle.text() - savedict["settings"][ - "show_transition_strength" - ] = self.chk_sett_trans_strength.isChecked() + savedict["settings"]["show_transition_strength"] = ( + self.chk_sett_trans_strength.isChecked() + ) savedict["settings"]["line_breaks"] = self.chk_sett_linebreaks.isChecked() savedict["settings"]["show_cm-1_axis"] = self.chk_sett_showcmax.isChecked() savedict["settings"]["show_eV_axis"] = self.chk_sett_showevax.isChecked() @@ -931,6 +947,9 @@ def test(self): "Documents/code/RIMSCode/RIMSSchemeDrawer/examples/example_titanium.json" ) self.load_config(fname=fname) + self.user_path = Path( + "/home/reto/Documents/code/RIMSCode/rims-code.github.io/temp/out" + ) class MplCanvas(FigureCanvasQTAgg): diff --git a/src/rimsschemedrawer/plotter.py b/src/rimsschemedrawer/plotter.py index 4487aec..8f96b2f 100644 --- a/src/rimsschemedrawer/plotter.py +++ b/src/rimsschemedrawer/plotter.py @@ -158,10 +158,8 @@ def _plotit(self): # ymax: if ipvalue > totwavenumber_photons + wavenumber_gs: ymax = ipvalue + sett_headspace - elif totwavenumber_photons + wavenumber_gs - ipvalue < sett_headspace: - ymax = ipvalue + sett_headspace else: - ymax = totwavenumber_photons + wavenumber_gs + ymax = totwavenumber_photons + wavenumber_gs + sett_headspace # ### CREATE FIGURE ### a2 = self._axes.twinx() diff --git a/src/rimsschemedrawer/utils.py b/src/rimsschemedrawer/utils.py index 13df4ef..134887a 100644 --- a/src/rimsschemedrawer/utils.py +++ b/src/rimsschemedrawer/utils.py @@ -14,7 +14,7 @@ "fs_axes": 12, "fs_axes_labels": 12, "fs_labels": 12, - "headspace": 3000, + "headspace": 1300, "arrow_width": 0.2, "arrow_head_width": 0.6, "prec_wavelength": 3, @@ -225,14 +225,22 @@ def nm_to_cm_2(nm: Union[float, np.ndarray]) -> Union[float, np.ndarray]: def term_to_string(tstr: str): - """ + """Convert term symbol to LaTeX enabled string. + Converts a term symbol string to a LaTeX enabled matplotlib string + If already a LaTeX string, just return it. :param tstr: Input string to convert :return: Output string LaTeX enabled for Matplotlib """ if tstr == "": return None + latex_characters = ["{", "}", "^", "_"] + for lch in latex_characters: + if lch in tstr: + tstr = tstr.replace(" ", "\\,") + return f"${tstr}$" + # some exceptionslike AI and IP if tstr == "IP": return "IP" diff --git a/tests/test_utils.py b/tests/test_utils.py index 65949c0..b3eef29 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -87,6 +87,13 @@ def test_term_to_string(vals): assert ut.term_to_string(vals[0]) == vals[1] +def test_term_to_string_latex(): + """Return a string surrounded by $ if LaTeX characters found.""" + str_in = "^{3}F_{2}" + str_exp = f"${str_in}$" + assert ut.term_to_string(str_in) == str_exp + + @pytest.mark.parametrize("val", ["IP", "AI", "Rydberg", "Ryd"]) def test_term_to_string_no_change(val): """Leave these symbols / strings unchanged."""