diff --git a/docs/did_you_know/index.md b/docs/did_you_know/index.md index 61c5b37..ea278c4 100644 --- a/docs/did_you_know/index.md +++ b/docs/did_you_know/index.md @@ -4,11 +4,11 @@ Short tips on eco features, newest first. Each one gives the main usage and what you gain from it, with a link to the full documentation where there is one. The collection so far covers features added since May 2026. -In an eco session, `eco.tip()` opens a small window where **Back** / **Next** +In an eco session, `features()` opens a small window where **Back** / **Next** go through the tips you have seen in this session and then on to new random -ones. Without a display, it prints the next tip instead. On the docs site, -`did_you_know/random.html` shows one random tip without the sidebar (linked -from the session's startup banner). +ones. Without a display, it prints the next tip instead. `docs()` opens this +documentation. On the docs site, `did_you_know/random.html` shows one random +tip without the sidebar. ```{toctree} :glob: diff --git a/eco/__init__.py b/eco/__init__.py index 5ea15f6..73b6b83 100644 --- a/eco/__init__.py +++ b/eco/__init__.py @@ -146,3 +146,20 @@ def tip(*args, **kwargs): from eco.utilities.tips import tip as _tip return _tip(*args, **kwargs) + + +def features(*args, **kwargs): + """What eco can do: "Did you know?" tips about its features, in a small + window (Back / Next), or printed where there is no display. Same as + eco.tip().""" + from eco.utilities.tips import tip as _tip + + return _tip(*args, **kwargs) + + +def docs(page=None): + """Open the eco documentation in the web browser; `docs("scanning")` + opens that page. Without a display, prints the URL.""" + from eco.utilities.tips import docs as _docs + + return _docs(page) diff --git a/eco/startup_inline.py b/eco/startup_inline.py index cd78395..175a90d 100644 --- a/eco/startup_inline.py +++ b/eco/startup_inline.py @@ -77,11 +77,8 @@ if arguments.scopes_available: print( " ___ _______\n / -_) __/ _ \ \n Experiment Control \__/\__/\___/ \n" ) -# Docs site and its "Did you know?" feature tips (eco.utilities.tips; -# eco.tip() shows them in a window from the session). -_docs_url = os.environ.get("ECO_DOCS_URL", "http://saresb-cons-04.psi.ch:8095/").rstrip("/") -print(f" docs: {_docs_url}/") -print(f" features: {_docs_url}/did_you_know/random.html (or eco.tip())\n") +# features() / docs() are imported into the session below (eco.utilities.tips). +print(" features() what eco can do docs() the documentation\n") term = Terminal(scope=scope) @@ -92,6 +89,11 @@ if scope: exec(f"from eco.{scope} import *") term.set_title() + +# features(): "Did you know?" tips in a small window; docs(): the docs site +# in the browser (eco.utilities.tips). Imported after the scope's star import +# so a component of the same name could not silently replace them. +from eco import features, docs from IPython import get_ipython _ipy = get_ipython() diff --git a/eco/utilities/tips.py b/eco/utilities/tips.py index 3ac66bc..cff8d41 100644 --- a/eco/utilities/tips.py +++ b/eco/utilities/tips.py @@ -280,3 +280,20 @@ def tip(name=None, window=None): elif history.current is None: history.next() return show_tip_window() + + +def docs(page=None): + """Open the eco documentation (ECO_DOCS_URL) in the web browser, or a + given page of it (``docs("scanning")``); without a display, print the + URL instead. Returns the URL.""" + url = doc_url(page) if page else DOCS_URL + from eco.widgets.tweak_recorder import display_available + + if display_available(): + import webbrowser + + if webbrowser.open(url): + print(f"opened {url}") + return url + print(url) + return url diff --git a/tests/test_tips.py b/tests/test_tips.py index 1e654d4..aafadea 100644 --- a/tests/test_tips.py +++ b/tests/test_tips.py @@ -126,3 +126,20 @@ def test_window_navigation(tip_dir, monkeypatch): finally: handle.stop() assert tip_qt._open_window is None + + +def test_docs_without_display_prints_url(monkeypatch, capsys): + monkeypatch.setenv("ECO_NO_X", "1") + monkeypatch.setattr(tips, "DOCS_URL", "http://host:8095/") + assert tips.docs() == "http://host:8095/" + assert tips.docs("../scanning") == "http://host:8095/scanning.html" + assert capsys.readouterr().out.split() == ["http://host:8095/", "http://host:8095/scanning.html"] + + +def test_features_is_the_tip_window(tip_dir, monkeypatch, capsys): + import eco + + monkeypatch.setenv("ECO_NO_X", "1") + shown = eco.features("tip2") + assert shown.title == "Third tip" + assert "Third tip" in capsys.readouterr().out