48 themes for your IPython notebook
OK, a short post to give you some material to play with over the weekend ;-).
Today, I woke up early and whereas I was drinking a mate (a native drink here in Argentina) for breakfast, I remember a tweet from Nikhil Sonnad where I was mentioned:
Sent PR to base16 for IPython notebook colorschemes. Check them out at https://t.co/SBbwBfLGli cc @oceankidbilly @damian_avila
— Nikhil Sonnad (@nsonnad) April 12, 2014
Essentially, he made available 48 IPython notebook themes based in the base16 color scheme generator. Thanks Nikhil for your work!!!
Well, I want to try them all and quickly, so I wrote some little code to do it:
First, some imports...
import os
import subprocess
import urllib
Second, make a list with all the theme names...
theme_names = ['3024-dark',
'3024-light',
'atelierdune-dark',
'atelierdune-light',
'atelierforest-dark',
'atelierforest-light',
'atelierheath-dark',
'atelierheath-light',
'atelierlakeside-dark',
'atelierlakeside-light',
'atelierseaside-dark',
'atelierseaside-light',
'bespin-dark',
'bespin-light',
'chalk-dark',
'chalk-light',
'default-dark',
'default-light',
'eighties-dark',
'eighties-light',
'grayscale-dark',
'grayscale-light',
'greenscreen-dark',
'greenscreen-light',
'isotope-dark',
'isotope-light',
'londontube-dark',
'londontube-light',
'marrakesh-dark',
'marrakesh-light',
'mocha-dark',
'mocha-light',
'monokai-dark',
'monokai-light',
'ocean-dark',
'ocean-light',
'paraiso-dark',
'paraiso-light',
'railscasts-dark',
'railscasts-light',
'shapeshifter-dark',
'shapeshifter-light',
'solarized-dark',
'solarized-light',
'tomorrow-dark',
'tomorrow-light',
'twilight-dark',
'twilight-light']
The themes are css
files, so we can create a new profile for each theme and add the css content to the custom.css
file inside each profile.
To do it, I use some little magic tricks from IPython...
for i in theme_names:
!ipython profile create $i
profile_dir = !ipython locate profile $i
url = "https://raw.githubusercontent.com/nsonnad/base16-ipython-notebook/master/base16-" + i + ".css"
tgt = os.path.join(profile_dir[0], 'static', 'custom', "custom.css")
urllib.urlretrieve (url, tgt)
Now, I want to try it... quickly... so I launch a new IPython server for each profile in specific ports. I also pass the --no-browser
option to avoid opening 48 tabs in a row (depending of your computing power this can be problematic).
for i, name in enumerate(theme_names):
port = str(9000 + i)
subprocess.Popen(["ipython", "notebook", "--profile=" + name, "--port=" + port, "--no-browser"])
Finally, because I am lazy ;-), I build the urls to see this same notebook with each different theme (don't forget to use the incognito mode of your browser to avoid css
caching and at least IPython 2.0).
base_url = "http://127.0.0.1:"
notebook = "/notebooks/48-themes-for-your-ipython-notebook.ipynb"
for i, name in enumerate(theme_names):
port = str(9000 + i)
url = base_url + port + notebook
print url, name
Easy and quick, don't you think?
OK, a lot of IPython servers opened, let's kill them all!!! I feel like George R. R. Martin ;-).
!killall -9 ipython
Obviously, this command also killed the current notebook (remember, this post is in fact an IPython notebook, and you can get it from the source link at the top of the post)... but I am right with that... this is the end of this post.
Final note: I did not like any complete theme, but I really like some part from several themes, so it worths to see them to take each nice part and make my own theme in the future.
Good weekend!
Damián
Did you like the content? Great!
Or visit my support page for more information.
Btw, don't forget this blog post is an ipynb file itself! So, you can download it from the "Source" link at the top of the post if you want to play with it ;-)
Comments powered by Disqus