Skip to content

Commit

Permalink
Make all example scripts downloadable (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdickinson committed Jul 1, 2021
1 parent 014f4a7 commit 70ef564
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
11 changes: 9 additions & 2 deletions docs/source/guide/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,15 @@ encapsulate that operation in a function:
An example GUI
~~~~~~~~~~~~~~

Putting everything together, here's an example GUI that makes use of the new
background task type:
Here's the :download:`complete script <examples/fizz_buzz_task.py>` obtained
from putting together the above snippets:

.. literalinclude:: examples/fizz_buzz_task.py
:start-after: Thanks for using Enthought
:lines: 2-

And here's an :download:`example GUI <examples/fizz_buzz_ui.py>` that makes use
of the new background task type:

.. literalinclude:: examples/fizz_buzz_ui.py
:start-after: Thanks for using Enthought
Expand Down
6 changes: 4 additions & 2 deletions docs/source/guide/cancel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ user after execution has started, the future may not move from |CANCELLING| to
|CANCELLED| state until several seconds after cancellation is requested. Note,
however, that the GUI will remain responsive and usable during those seconds.

Here's a complete TraitsUI application that demonstrates this behaviour.
Here's a :download:`complete TraitsUI application
<examples/non_interruptible_task.py>` that demonstrates this behaviour.

.. literalinclude:: examples/non_interruptible_task.py
:start-after: Thanks for using Enthought
Expand Down Expand Up @@ -143,7 +144,8 @@ Here's a version of the approximation code that yields partial results at each
return 4 * inside / total
Here's a complete TraitsUI example making use of the above.
Here's a :download:`complete TraitsUI example <examples/interruptible_task.py>`
making use of the above.

.. literalinclude:: examples/interruptible_task.py
:start-after: Thanks for using Enthought
Expand Down
3 changes: 2 additions & 1 deletion docs/source/guide/contexts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ a multiprocessing context::
traits_executor.stop()
context.close()

Here's a complete TraitsUI example that makes use of this.
Here's a :download:`complete TraitsUI example
<examples/background_processes.py>` that makes use of this.

.. literalinclude:: examples/background_processes.py
:start-after: Thanks for using Enthought
Expand Down
10 changes: 6 additions & 4 deletions docs/source/guide/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ a particular callback is executing, the GUI cannot respond to other user
interactions. This presents a problem if you want to run a calculation (for
example) from within a GUI.

The following example code demonstrates this effect. It provides a simple GUI
wrapper for a slow calculation. In this case, the slowness is simulated via a
call to :func:`time.sleep`.
The following :download:`example code <examples/calculate_in_main_thread.py>`
demonstrates this effect. It provides a simple GUI wrapper for a slow
calculation. In this case, the slowness is simulated via a call to
:func:`time.sleep`.

.. literalinclude:: examples/calculate_in_main_thread.py
:start-after: Thanks for using Enthought
Expand Down Expand Up @@ -92,7 +93,8 @@ usually the main thread. For example, given a ``QLabel`` object ``label``,
calling ``label.setText("some text")`` from anything other than the thread that
"owns" the ``label`` object is unsafe.

To demonstrate this, here's a variation of the example script above that
To demonstrate this, here's a :download:`variation
<examples/calculate_in_worker_thread.py>` of the example script above that
dispatches squaring jobs to a background thread. Unlike the previous version,
the GUI remains responsive and usable while a background job is executing.

Expand Down
3 changes: 2 additions & 1 deletion docs/source/guide/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Traits Futures. Those tests face two main challenges:
An example test
---------------

Here's an example of testing a simple future.
Here's an :download:`example <examples/test_future.py>` of testing a simple
future.

.. literalinclude:: examples/test_future.py
:start-after: Thanks for using Enthought
Expand Down
5 changes: 3 additions & 2 deletions docs/source/guide/toolkits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ available. In that case, Traits Futures can use the |AsyncioContext| to
deliver results to the main thread's |asyncio| event loop instead of to
a GUI framework's event loop.

Here's an example script that uses the |AsyncioContext| in order to execute
Traits Futures tasks within the context of an asyncio event loop.
Here's an :download:`example script <examples/headless.py>` that uses the
|AsyncioContext| in order to execute Traits Futures tasks within the context of
an asyncio event loop.

.. literalinclude:: examples/headless.py

Expand Down
6 changes: 3 additions & 3 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ Limitations
Quick start
-----------

Here's a complete example showing a minimal TraitsUI application that fires off
a background computation when its "Calculate" button is pressed, and shows the
result when it arrives.
Here's a :download:`complete example <examples/quick_start.py>` showing a
minimal TraitsUI application that fires off a background computation when its
"Calculate" button is pressed, and shows the result when it arrives.

.. literalinclude:: examples/quick_start.py
:start-after: Thanks for using Enthought
Expand Down

0 comments on commit 70ef564

Please sign in to comment.