
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/scene/console.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_scene_console.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_scene_console.py:


Vispy Console
=============

Demonstrate the use of the vispy console.

Note how the console size is independent of the canvas scaling.

.. GENERATED FROM PYTHON SOURCE LINES 15-52



.. image-sg:: /gallery/scene/images/sphx_glr_console_001.png
   :alt: console
   :srcset: /gallery/scene/images/sphx_glr_console_001.png
   :class: sphx-glr-single-img





.. code-block:: Python

    import sys

    from vispy import scene, app
    from vispy.scene.widgets import Console
    from vispy.scene.visuals import Text

    canvas = scene.SceneCanvas(keys='interactive', size=(400, 400))
    grid = canvas.central_widget.add_grid()

    vb = scene.widgets.ViewBox(border_color='b')
    vb.camera = 'panzoom'
    vb.camera.rect = -1, -1, 2, 2
    grid.add_widget(vb, row=0, col=0)
    text = Text('Starting timer...', color='w', font_size=24, parent=vb.scene)

    console = Console(text_color='g', font_size=12., border_color='g')
    grid.add_widget(console, row=1, col=0)


    def on_timer(event):
        text.text = 'Tick #%s' % event.iteration
        if event.iteration > 1 and event.iteration % 10 == 0:
            console.clear()
        console.write('Elapsed:\n  %s' % event.elapsed)
        canvas.update()

    timer = app.Timer(2.0, connect=on_timer, start=True)

    console.write('This is a line that will be wrapped automatically by the '
                  'console.\n')
    console.write('This line will be truncated ....................,\n'
                  'but this next line will survive.\n', wrap=False)

    if __name__ == '__main__':
        canvas.show()
        if sys.flags.interactive != 1:
            canvas.app.run()


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 1.409 seconds)


.. _sphx_glr_download_gallery_scene_console.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: console.ipynb <console.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: console.py <console.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: console.zip <console.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
