features() and docs() in the session instead of URLs in the banner

features(): the "Did you know?" tip window (same as eco.tip()); docs():
the docs site in the web browser, or a given page (docs("scanning")),
printing the URL where there is no display. Both are imported into the
session at startup, and the banner names them instead of showing links.
This commit is contained in:
Henrik Lemke committed 2026-10-25 23:24:01 +01:00
1 parent 28aced6ded
commit e4d074cb86
5 files changed
+62 -9

No files matched your search

+4 -4
View File
@@ -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:
+17
View File
@@ -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)
+7 -5
View File
@@ -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()
+17
View File
@@ -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
+17
View File
@@ -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