Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
PEP8 fixes
  • Loading branch information
mdboom committed Aug 26, 2013
commit bdb85ec27f675256750d5297dd3142f0bda81a58
62 changes: 33 additions & 29 deletions lib/matplotlib/backends/backend_webagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import random
import socket
import threading
import types

import numpy as np

Expand All @@ -22,7 +21,6 @@
import tornado.web
import tornado.ioloop
import tornado.websocket
import tornado.template

import matplotlib
from matplotlib import rcParams
Expand Down Expand Up @@ -57,8 +55,8 @@ def mainloop(self):
WebAggApplication.initialize()

url = "http://127.0.0.1:{port}{prefix}".format(
port=WebAggApplication.port,
prefix=WebAggApplication.url_prefix)
port=WebAggApplication.port,
prefix=WebAggApplication.url_prefix)

if rcParams['webagg.open_in_browser']:
import webbrowser
Expand Down Expand Up @@ -308,12 +306,12 @@ def start_event_loop(self, timeout):
backend_bases.FigureCanvasBase.start_event_loop_default(
self, timeout)
start_event_loop.__doc__ = \
backend_bases.FigureCanvasBase.start_event_loop_default.__doc__
backend_bases.FigureCanvasBase.start_event_loop_default.__doc__

def stop_event_loop(self):
backend_bases.FigureCanvasBase.stop_event_loop_default(self)
stop_event_loop.__doc__ = \
backend_bases.FigureCanvasBase.stop_event_loop_default.__doc__
backend_bases.FigureCanvasBase.stop_event_loop_default.__doc__


class FigureManagerWebAgg(backend_bases.FigureManagerBase):
Expand Down Expand Up @@ -352,26 +350,29 @@ def resize(self, w, h):


class NavigationToolbar2WebAgg(backend_bases.NavigationToolbar2):
_jquery_icon_classes = {'home': 'ui-icon ui-icon-home',
'back': 'ui-icon ui-icon-circle-arrow-w',
'forward': 'ui-icon ui-icon-circle-arrow-e',
'zoom_to_rect': 'ui-icon ui-icon-search',
'move': 'ui-icon ui-icon-arrow-4',
'download': 'ui-icon ui-icon-disk',
None: None
}
_jquery_icon_classes = {
'home': 'ui-icon ui-icon-home',
'back': 'ui-icon ui-icon-circle-arrow-w',
'forward': 'ui-icon ui-icon-circle-arrow-e',
'zoom_to_rect': 'ui-icon ui-icon-search',
'move': 'ui-icon ui-icon-arrow-4',
'download': 'ui-icon ui-icon-disk',
None: None
}

def _init_toolbar(self):
# Use the standard toolbar items + download button
toolitems = (backend_bases.NavigationToolbar2.toolitems +
(('Download', 'Download plot', 'download', 'download'),))
toolitems = (
backend_bases.NavigationToolbar2.toolitems +
(('Download', 'Download plot', 'download', 'download'),)
)

NavigationToolbar2WebAgg.toolitems = \
tuple(
(text, tooltip_text, self._jquery_icon_classes[image_file],
name_of_method)
for text, tooltip_text, image_file, name_of_method
in toolitems if image_file in self._jquery_icon_classes)
(text, tooltip_text, self._jquery_icon_classes[image_file],
name_of_method)
for text, tooltip_text, image_file, name_of_method
in toolitems if image_file in self._jquery_icon_classes)

self.message = ''
self.cursor = 0
Expand Down Expand Up @@ -432,7 +433,8 @@ def get(self, fignum):

ws_uri = 'ws://{req.host}{prefix}/'.format(req=self.request,
prefix=self.url_prefix)
self.render('single_figure.html',
self.render(
"single_figure.html",
prefix=self.url_prefix,
ws_uri=ws_uri,
fig_id=fignum,
Expand All @@ -452,22 +454,22 @@ def get(self):
"all_figures.html",
prefix=self.url_prefix,
ws_uri=ws_uri,
figures=sorted(list(Gcf.figs.items()), key=lambda item: item[0]),
figures=sorted(
list(Gcf.figs.items()), key=lambda item: item[0]),
toolitems=NavigationToolbar2WebAgg.toolitems)


class MPLInterfaceJS(tornado.web.RequestHandler):
def get(self):
manager = Gcf.get_fig_manager(1)
canvas = manager.canvas

self.set_header('Content-Type', 'application/javascript')

self.render("mpl_interface.js",
self.render(
"mpl_interface.js",
toolitems=NavigationToolbar2WebAgg.toolitems,
canvas=canvas)


class Download(tornado.web.RequestHandler):
def get(self, fignum, fmt):
self.fignum = int(fignum)
Expand Down Expand Up @@ -543,7 +545,7 @@ def send_diff_image(self, diff):
def __init__(self, url_prefix=''):
if url_prefix:
assert url_prefix[0] == '/' and url_prefix[-1] != '/', \
'url_prefix must start with a "/" and not end with one.'
'url_prefix must start with a "/" and not end with one.'

super(WebAggApplication, self).__init__([
# Static files for the CSS and JS
Expand All @@ -566,11 +568,13 @@ def __init__(self, url_prefix=''):
{'path': os.path.join(self._mpl_dirs['web_backend'], 'jquery',
'css', 'themes', 'base', 'images')}),

(url_prefix + r'/_static/jquery/js/(.*)', tornado.web.StaticFileHandler,
(url_prefix + r'/_static/jquery/js/(.*)',
tornado.web.StaticFileHandler,
{'path': os.path.join(self._mpl_dirs['web_backend'],
'jquery', 'js')}),

(url_prefix + r'/_static/css/(.*)', tornado.web.StaticFileHandler,
(url_prefix + r'/_static/css/(.*)',
tornado.web.StaticFileHandler,
{'path': os.path.join(self._mpl_dirs['web_backend'], 'css')}),

# An MPL favicon
Expand Down Expand Up @@ -655,6 +659,7 @@ def start(cls):

def ipython_inline_display(figure):
import matplotlib._pylab_helpers as pylab_helpers
import tornado.template

WebAggApplication.initialize()
if not server_thread.is_alive():
Expand All @@ -666,7 +671,6 @@ def ipython_inline_display(figure):
tpl = fd.read()

fignum = figure.number
manager = pylab_helpers.Gcf.get_fig_manager(fignum)

t = tornado.template.Template(tpl)
return t.generate(
Expand Down