Skip to content

Commit

Permalink
PEP8 fixes. Rename web_static -> web_backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Jan 4, 2013
1 parent c5479c2 commit ae884b0
Show file tree
Hide file tree
Showing 23 changed files with 77 additions and 54 deletions.
63 changes: 39 additions & 24 deletions lib/matplotlib/backends/backend_webagg.py
Expand Up @@ -46,7 +46,7 @@ def mainloop(self):
WebAggApplication.initialize()
for manager in Gcf.get_all_fig_managers():
url = "http://127.0.0.1:{0}/{1}/".format(
WebAggApplication.port, manager.num)
WebAggApplication.port, manager.num)
if rcParams['webagg.open_in_browser']:
import webbrowser
webbrowser.open(url)
Expand Down Expand Up @@ -191,8 +191,8 @@ def get_diff_image(self):
self._png_buffer)

# Swap the renderer frames
self._renderer, self._last_renderer = \
self._last_renderer, self._renderer
self._renderer, self._last_renderer = (
self._last_renderer, self._renderer)
self._force_full = False
self._png_is_old = False
return self._png_buffer.getvalue()
Expand All @@ -208,8 +208,10 @@ def get_renderer(self):
need_new_renderer = (self._lastKey != key)

if need_new_renderer:
self._renderer = backend_agg.RendererAgg(w, h, self.figure.dpi)
self._last_renderer = backend_agg.RendererAgg(w, h, self.figure.dpi)
self._renderer = backend_agg.RendererAgg(
w, h, self.figure.dpi)
self._last_renderer = backend_agg.RendererAgg(
w, h, self.figure.dpi)
self._lastKey = key

return self._renderer
Expand Down Expand Up @@ -261,11 +263,13 @@ def new_timer(self, *args, **kwargs):
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__
start_event_loop.__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__
stop_event_loop.__doc__ = \
backend_bases.FigureCanvasBase.stop_event_loop_default.__doc__


class FigureManagerWebAgg(backend_bases.FigureManagerBase):
Expand Down Expand Up @@ -304,18 +308,22 @@ def resize(self, w, h):
class NavigationToolbar2WebAgg(backend_bases.NavigationToolbar2):
toolitems = list(backend_bases.NavigationToolbar2.toolitems[:6]) + [
('Download', 'Download plot', 'filesave', 'download')
]
]

def _init_toolbar(self):
jqueryui_icons = ['ui-icon ui-icon-home',
jqueryui_icons = [
'ui-icon ui-icon-home',
'ui-icon ui-icon-circle-arrow-w',
'ui-icon ui-icon-circle-arrow-e', None,
'ui-icon ui-icon-circle-arrow-e',
None,
'ui-icon ui-icon-arrow-4',
'ui-icon ui-icon-search',
'ui-icon ui-icon-disk']
'ui-icon ui-icon-disk'
]
for index, item in enumerate(self.toolitems):
if item[0] is not None:
self.toolitems[index]=(item[0],item[1],jqueryui_icons[index],item[3])
self.toolitems[index] = (
item[0], item[1], jqueryui_icons[index], item[3])
self.message = ''
self.cursor = 0

Expand Down Expand Up @@ -361,7 +369,7 @@ class IndexPage(tornado.web.RequestHandler):
def get(self, fignum):
with open(os.path.join(
os.path.dirname(__file__),
'web_static', 'index.html')) as fd:
'web_backend', 'index.html')) as fd:
tpl = fd.read()

fignum = int(fignum)
Expand All @@ -387,7 +395,7 @@ def get(self, fignum, format):
'jpeg': 'image/jpeg',
'tif': 'image/tiff',
'emf': 'application/emf'
}
}

self.set_header('Content-Type', mimetypes.get(format, 'binary'))

Expand Down Expand Up @@ -438,25 +446,32 @@ def send_image(self):
def __init__(self):
super(WebAggApplication, self).__init__([
# Static files for the CSS and JS
(r'/static/(.*)', tornado.web.StaticFileHandler,
(r'/static/(.*)',
tornado.web.StaticFileHandler,
{'path':
os.path.join(os.path.dirname(__file__), 'web_static')}),
os.path.join(os.path.dirname(__file__), 'web_backend')}),
# Static images for toolbar buttons
(r'/images/(.*)', tornado.web.StaticFileHandler,
(r'/images/(.*)',
tornado.web.StaticFileHandler,
{'path':
os.path.join(os.path.dirname(__file__), '../mpl-data/images')}),
(r'/static/jquery/css/themes/base/(.*)', tornado.web.StaticFileHandler,
(r'/static/jquery/css/themes/base/(.*)',
tornado.web.StaticFileHandler,
{'path':
os.path.join(os.path.dirname(__file__), 'web_static/jquery/css/themes/base')}),
(r'/static/jquery/css/themes/base/images/(.*)', tornado.web.StaticFileHandler,
os.path.join(os.path.dirname(__file__),
'web_backend/jquery/css/themes/base')}),
(r'/static/jquery/css/themes/base/images/(.*)',
tornado.web.StaticFileHandler,
{'path':
os.path.join(os.path.dirname(__file__), 'web_static/jquery/css/themes/base/images')}),
os.path.join(os.path.dirname(__file__),
'web_backend/jquery/css/themes/base/images')}),
(r'/static/jquery/js/(.*)', tornado.web.StaticFileHandler,
{'path':
os.path.join(os.path.dirname(__file__), 'web_static/jquery/js')}),
os.path.join(os.path.dirname(__file__),
'web_backend/jquery/js')}),
(r'/static/css/(.*)', tornado.web.StaticFileHandler,
{'path':
os.path.join(os.path.dirname(__file__), 'web_static/css')}),
os.path.join(os.path.dirname(__file__), 'web_backend/css')}),
# An MPL favicon
(r'/favicon.ico', self.FavIcon),
# The page that contains all of the pieces
Expand All @@ -466,7 +481,7 @@ def __init__(self):
(r'/([0-9]+)/ws', self.WebSocket),
# Handles the downloading (i.e., saving) of static images
(r'/([0-9]+)/download.([a-z]+)', self.Download)
])
])

@classmethod
def initialize(cls):
Expand Down
@@ -1,5 +1,5 @@
<html>
<head>
<head>
<link rel="stylesheet" href="/static/css/page.css" type="text/css">
<link rel="stylesheet" href="/static/css/boilerplate.css" type="text/css" />
<link rel="stylesheet" href="/static/css/fbm.css" type="text/css" />
Expand All @@ -24,7 +24,8 @@
<body
onkeydown="key_event(event, 'key_press')"
onkeyup="key_event(event, 'key_release')">
<div id="mpl-div" style="margin-left: auto ; margin-right: auto ; width: 800px;">
<div id="mpl-div"
style="margin-left: auto ; margin-right: auto ; width: 800px;">
<div id="mpl-warnings" class="mpl-warnings">
</div>

Expand All @@ -46,37 +47,44 @@
</div>

<div id="toolbar" class="ui-widget ui-widget-content"
style="border-top-style: none; border-left-style: none; border-right-style: none; border-bottom-style: none;">
style="border-top-style: none; border-left-style: none;
border-right-style: none; border-bottom-style: none;">
{% for name, tooltip, image, method in toolitems %}
{% if name is None %}
<span style='width: 0.1em'></span>
{% else %}
<button id="{{ name }}"
onclick="toolbar_button_onclick('{{ method }}');"
role="button"
aria-disabled="false"
class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only">
<span class="ui-button-icon-primary ui-icon {{ image }} ui-corner-all"></span>
<span class="ui-button-text">{{ tooltip }}</span>
</button>
{% end %}
{% if name is None %}
<span style='width: 0.1em'></span>
{% else %}
<button id="{{ name }}"
onclick="toolbar_button_onclick('{{ method }}');"
role="button"
aria-disabled="false"
class="ui-button ui-widget ui-state-default ui-corner-all
ui-button-icon-only">
<span
class="ui-button-icon-primary ui-icon {{ image }}
ui-corner-all">
</span>
<span class="ui-button-text">
{{ tooltip }}
</span>
</button>
{% end %}
<span>
<select id="mpl-format" class="mpl-toolbar-option ui-widget ui-widget-content" style="margin-top: 0px;">
{% for filetype, extensions in sorted(canvas.get_supported_filetypes_grouped().items()) %}
<option value="{{ extensions[0] }}"
{% if extensions[0] == canvas.get_default_filetype() %}
selected
{% end %}
>{{filetype}} ({{", ".join(extensions)}})</option>
{% end %}
</select>
</span>

{% end %}
<span>
<select id="mpl-format" class="mpl-toolbar-option ui-widget ui-widget-content" style="margin-top: 0px;">
{% for filetype, extensions in sorted(canvas.get_supported_filetypes_grouped().items()) %}
<option value="{{ extensions[0] }}"
{% if extensions[0] == canvas.get_default_filetype() %}
selected
{% end %}
>{{filetype}} ({{", ".join(extensions)}})
</option>
{% end %}
</select>
</span>
</div>
<div>
<span id="mpl-message" class="mpl-message"/>
</div>
<div>
<span id="mpl-message" class="mpl-message"/>
</div>
</div>
</body>
</html>
File renamed without changes.

0 comments on commit ae884b0

Please sign in to comment.