{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%gui qt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Vispy Console\n\nDemonstrate the use of the vispy console.\n\nNote how the console size is independent of the canvas scaling.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import sys\n\nfrom vispy import scene, app\nfrom vispy.scene.widgets import Console\nfrom vispy.scene.visuals import Text\n\ncanvas = scene.SceneCanvas(keys='interactive', size=(400, 400))\ngrid = canvas.central_widget.add_grid()\n\nvb = scene.widgets.ViewBox(border_color='b')\nvb.camera = 'panzoom'\nvb.camera.rect = -1, -1, 2, 2\ngrid.add_widget(vb, row=0, col=0)\ntext = Text('Starting timer...', color='w', font_size=24, parent=vb.scene)\n\nconsole = Console(text_color='g', font_size=12., border_color='g')\ngrid.add_widget(console, row=1, col=0)\n\n\ndef on_timer(event):\n text.text = 'Tick #%s' % event.iteration\n if event.iteration > 1 and event.iteration % 10 == 0:\n console.clear()\n console.write('Elapsed:\\n %s' % event.elapsed)\n canvas.update()\n\ntimer = app.Timer(2.0, connect=on_timer, start=True)\n\nconsole.write('This is a line that will be wrapped automatically by the '\n 'console.\\n')\nconsole.write('This line will be truncated ....................,\\n'\n 'but this next line will survive.\\n', wrap=False)\n\nif __name__ == '__main__':\n canvas.show()\n if sys.flags.interactive != 1:\n canvas.app.run()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.19" } }, "nbformat": 4, "nbformat_minor": 0 }