-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Pyglet playground file where I was playing with Pyglet and Jupyter
integration. Ideally, it would be nice if the graphics from Pyglet would display inline in Jupyter.
- Loading branch information
Showing
2 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Pyglet + Jupyter Inline?\n", | ||
"It's maybe possible to make Pyglet graphics display inline? I read [this google groups post](https://groups.google.com/forum/#!topic/pyglet-users/Ma04eKqBwlE) talking about adding Pyglet support, and it looks like that [found its way to IPython](https://github.com/ipython/ipython/pull/743)? And there is some Pyglet code [still around](https://github.com/ipython/ipython/search?q=pyglet).\n", | ||
"\n", | ||
"But, for all of that, I'm not sure how to make it work. It seems like `%gui pyglet` is not supported." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"ERROR: Invalid GUI request u'pyglet', valid ones are:['osx', 'qt4', 'qt5', None, 'nbagg', 'gtk', 'gtk3', 'notebook', 'tk', 'inline', 'wx', 'qt']\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%gui pyglet" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import pyglet" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"window = pyglet.window.Window(display=None)\n", | ||
"window.on_close = lambda:window.close()\n", | ||
"label = pyglet.text.Label('Hello, world',\n", | ||
" font_name='Times New Roman',\n", | ||
" font_size=36,\n", | ||
" x=window.width//2, y=window.height//2,\n", | ||
" anchor_x='center', anchor_y='center')\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"def draw_triangle():\n", | ||
" pyglet.gl.glBegin(pyglet.gl.GL_TRIANGLES)\n", | ||
" for p in [(20,30), (200,100), (100,200)]:\n", | ||
" pyglet.gl.glVertex3f(p[0], p[1],0) # draw each vertex\n", | ||
" pyglet.gl.glEnd()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"for _ in range(200):\n", | ||
" window.clear()\n", | ||
" window.switch_to()\n", | ||
" window.dispatch_events()\n", | ||
"\n", | ||
" label.draw()\n", | ||
" draw_triangle()\n", | ||
" \n", | ||
" window.flip()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"On my Mac, this opens a separate Cocoa window through the Python/Idle program, and displays the window:\n", | ||
"<img src=\"pyglet-screenshot.png\">\n", | ||
"\n", | ||
"But I would like it to display inline, here, so that you can see the window when running Jupyter on a server, such as the MyBinder server." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 2", | ||
"language": "python", | ||
"name": "python2" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.11" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.