Skip to content

Commit

Permalink
Fix GUI bugs, headspace selector better (#19)
Browse files Browse the repository at this point in the history
* edit head space setting to be smarter

* deactivate debug mode

* update pre-commit and workflows

* workflow update

* add tests for latex string
  • Loading branch information
trappitsch authored Apr 5, 2024
1 parent d3e1a89 commit ccb5711
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 23 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/package_testing.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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
args: [ --fix ]
# 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 ]
35 changes: 27 additions & 8 deletions src/rimsschemedrawer/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<sup>-1</sup>."
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 1 addition & 3 deletions src/rimsschemedrawer/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 10 additions & 2 deletions src/rimsschemedrawer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit ccb5711

Please sign in to comment.