Skip to content

Commit

Permalink
API: rename mg.show -> mg.display
Browse files Browse the repository at this point in the history
Having a conversation about this it was impossible to keep straight with the
two meanings of `show`.

closes #16
  • Loading branch information
tacaswell committed Nov 1, 2023
1 parent ac05a41 commit fecb3c0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ Select the backend
mpl_gui.select_gui_toolkit


Show
----
Display
-------

.. autosummary::
:toctree: _as_gen
:nosignatures:


mpl_gui.show
mpl_gui.display


Interactivity
Expand Down
16 changes: 8 additions & 8 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ track of the created figures and shows them on exit ::


This will create 3 figures and block on ``__exit__``. The blocking
behavior depends on ``mg.is_interacitve()`` (and follow the behavior of
``mg.show`` or can explicitly controlled via the *block* keyword argument).
behavior depends on `~mpl_gui.is_interactive()` (and follow the behavior of
`.display` and `.FigureRegistry.show` can explicitly controlled via the *block* keyword argument).

The `.registry` module is implemented by having a singleton `.FigureRegistry`
at the module level.
Expand All @@ -164,7 +164,7 @@ explicitly available ::

fig2 = Figure()

mg.show(fig1, fig2)
mg.display(fig1, fig2)


which will show both figures and block until they are closed. As part of the
Expand All @@ -182,23 +182,23 @@ Similar to `plt.ion<matplotlib.pyplot.ion>` and
print(mg.is_interactive())
fig = Figure()

mg.show([fig]) # will not block
mg.display([fig]) # will not block

mg.ioff()
print(mg.is_interactive())
mg.show(fig) # will block!
mg.display(fig) # will block!


As with `plt.show<matplotlib.pyplot.show>`, you can explicitly control the
blocking behavior of `mg.show<mpl_gui.show>` via the *block* keyword argument ::
blocking behavior of `mg.display<mpl_gui.display>` via the *block* keyword argument ::

import mpl_gui as mg
from matplotlib.figure import Figure

fig = Figure(label='control blocking')

mg.show(fig, block=False) # will never block
mg.show(fig, block=True) # will always block
mg.display(fig, block=False) # will never block
mg.display(fig, block=True) # will always block


The interactive state is shared Matplotlib and can also be controlled with
Expand Down
8 changes: 4 additions & 4 deletions mpl_gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
_log = logging.getLogger(__name__)


def show(*figs, block=None, timeout=0):
def display(*figs, block=None, timeout=0):
"""
Show the figures and maybe block.
Expand Down Expand Up @@ -247,7 +247,7 @@ def show_all(self, *, block=None, timeout=None):
if timeout is None:
timeout = self._timeout
self._ensure_all_figures_promoted()
show(*self.figures, block=self._block, timeout=self._timeout)
display(*self.figures, block=self._block, timeout=self._timeout)

# alias to easy pyplot compatibility
show = show_all
Expand All @@ -264,7 +264,7 @@ def close_all(self):
4. drops its hard reference to the Figure
If the user still holds a reference to the Figure it can be revived by
passing it to `mpl_gui.show`.
passing it to `mpl_gui.display`.
"""
for fig in list(self.figures):
Expand Down Expand Up @@ -368,7 +368,7 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, traceback):
if exc_value is not None and not self._forgive_failure:
return
show(*self.figures, block=self._block, timeout=self._timeout)
display(*self.figures, block=self._block, timeout=self._timeout)


# from mpl_gui import * # is a langauge miss-feature
Expand Down
10 changes: 5 additions & 5 deletions mpl_gui/_manage_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ def is_interactive():
- newly created figures will be shown immediately;
- figures will automatically redraw on change;
- `mpl_gui.show` will not block by default.
- `.display` will not block by default.
- `mpl_gui.FigureContext` will not block on ``__exit__`` by default.
In non-interactive mode:
- newly created figures and changes to figures will not be reflected until
explicitly asked to be;
- `mpl_gui.show` will block by default.
- `.display` will block by default.
- `mpl_gui.FigureContext` will block on ``__exit__`` by default.
See Also
--------
ion : Enable interactive mode.
ioff : Disable interactive mode.
mpl_gui.show : Show all figures (and maybe block).
mpl_gui.display : Show all figures (and maybe block).
"""
return _is_interact()

Expand Down Expand Up @@ -89,7 +89,7 @@ def ioff():
--------
ion : Enable interactive mode.
is_interactive : Whether interactive mode is enabled.
mpl_gui.show : Show all figures (and maybe block).
mpl_gui.display : Show all figures (and maybe block).
Notes
-----
Expand Down Expand Up @@ -124,7 +124,7 @@ def ion():
--------
ioff : Disable interactive mode.
is_interactive : Whether interactive mode is enabled.
mpl_gui.show : Show all figures (and maybe block).
mpl_gui.display : Show all figures (and maybe block).
Notes
-----
Expand Down
8 changes: 4 additions & 4 deletions mpl_gui/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_no_pyplot():
def test_promotion():
fig = mg.Figure(label="test")
assert fig.canvas.manager is None
mg.show(*[fig], block=False)
mg.display(*[fig], block=False)
assert fig.canvas.manager is not None


Expand All @@ -32,7 +32,7 @@ def test_ion():
ax = fig.subplots()
(ln,) = ax.plot(range(5))
ln.set_color("k")
mg.show(*[fig], timeout=1)
mg.display(*[fig], timeout=1)
assert "start_event_loop" not in fig.canvas.call_info


Expand All @@ -43,7 +43,7 @@ def test_ioff():

def test_timeout():
fig = mg.Figure()
mg.show(*[fig], block=True, timeout=1)
mg.display(*[fig], block=True, timeout=1)
assert "start_event_loop" in fig.canvas.call_info


Expand Down Expand Up @@ -89,7 +89,7 @@ def test_close_all():

# test revive
old_canvas = fig.canvas
mg.show(fig)
mg.display(fig)
assert fig.canvas is not old_canvas


Expand Down

0 comments on commit fecb3c0

Please sign in to comment.