Exemple #1
0
 def __init__(self, canvas, num):
     FigureManagerWebAgg.__init__(self, canvas, num)
     toolitems = []
     for name, tooltip, image, method in self.ToolbarCls.toolitems:
         if name is None:
             toolitems.append(['', '', '', ''])
         else:
             toolitems.append([name, tooltip, image, method])
     canvas._toolbar_items = toolitems
     self.web_sockets = [self.canvas]
 def __init__(self, canvas, num):
     FigureManagerWebAgg.__init__(self, canvas, num)
     toolitems = []
     for name, tooltip, image, method in self.ToolbarCls.toolitems:
         if name is None:
             toolitems.append(['', '', '', ''])
         else:
             toolitems.append([name, tooltip, image, method])
     canvas._toolbar_items = toolitems
     self.web_sockets = [self.canvas]
    def __init__(self, figure):
        self.figure = figure
        self.manager = new_figure_manager_given_figure(id(figure), figure)

        super().__init__([
            # Static files for the CSS and JS
            (r'/_static/(.*)', tornado.web.StaticFileHandler, {
                'path': FigureManagerWebAgg.get_static_file_path()
            }),

            # Static images for the toolbar
            (r'/_images/(.*)', tornado.web.StaticFileHandler, {
                'path': Path(mpl.get_data_path(), 'images')
            }),

            # The page that contains all of the pieces
            ('/', self.MainPage),
            ('/mpl.js', self.MplJs),

            # Sends images and events to the browser, and receives
            # events from the browser
            ('/ws', self.WebSocket),

            # Handles the downloading (i.e., saving) of static images
            (r'/download.([a-z0-9.]+)', self.Download),
        ])
Exemple #4
0
def create_application():
    application = Application([
        ('/_static/(.*)', StaticFileHandler, {
            'path': FigureManagerWebAgg.get_static_file_path()
        }),
        ('/mpl.js', MplJavaScriptHandler),
        (url_pattern(
            '/mpl/download/{{base_dir}}/{{figure_id}}/{{format_name}}'),
         MplDownloadHandler),
        (url_pattern('/mpl/figures/{{base_dir}}/{{figure_id}}'),
         MplWebSocketHandler),
        (url_pattern('/'), WebAPIVersionHandler),
        (url_pattern('/exit'), WebAPIExitHandler),
        (url_pattern('/api'), JsonRpcWebSocketHandler,
         dict(service_factory=service_factory,
              validation_exception_class=ValidationError,
              report_defer_period=WEBAPI_PROGRESS_DEFER_PERIOD)),
        (url_pattern('/ws/res/plot/{{base_dir}}/{{res_name}}'),
         ResourcePlotHandler),
        (url_pattern('/ws/res/geojson/{{base_dir}}/{{res_id}}'),
         ResFeatureCollectionHandler),
        (url_pattern(
            '/ws/res/geojson/{{base_dir}}/{{res_id}}/{{feature_index}}'),
         ResFeatureHandler),
        (url_pattern('/ws/res/csv/{{base_dir}}/{{res_id}}'), ResVarCsvHandler),
        (url_pattern('/ws/res/html/{{base_dir}}/{{res_id}}'),
         ResVarHtmlHandler),
        (url_pattern(
            '/ws/res/tile/{{base_dir}}/{{res_id}}/{{z}}/{{y}}/{{x}}.png'),
         ResVarTileHandler),
        (url_pattern('/ws/ne2/tile/{{z}}/{{y}}/{{x}}.jpg'), NE2Handler),
        (url_pattern('/ws/countries'), CountriesGeoJSONHandler),
    ])
    application.workspace_manager = FSWorkspaceManager()
    return application
Exemple #5
0
    def __init__(self, title, funcs):
        mpl_static = FigureManagerWebAgg.get_static_file_path()
        mpl_images = os.path.normpath(
            os.path.join(mpl_static, '../../mpl-data/images'))
        routes = [
            (r'/', FrontendHandler, dict(title=title, funcs=funcs)),
            (r'/([0-9]+)/download.([a-z0-9.]+)', DownloadHandler),
            (r'/([0-9a-f]+)/([0-9]+)/ws', WebSocketHandler),
            (r'/mpl.js', MplJsHandler),
            (r'/_static/(.*)', tornado.web.StaticFileHandler,
             dict(path=mpl_static)),
            (r'/_images/(.*)', tornado.web.StaticFileHandler,
             dict(path=mpl_images)),
        ]
        for name in funcs:
            f = funcs[name]
            if not hasattr(f, '_webtool_args'):
                raise ValueError(
                    'Function %s must be decorated with @webtool.webfn')
            routes.append(('/' + name, BackendHandler, dict(func=funcs[name])))
        tornado.web.Application.__init__(self, routes)

        # keep track of per-session state, maps from string uid -> dict
        self.sessions = {}
        # keep track of active figures, including a fake one for the keepalive
        # maps from fignum -> managers
        self.fig_managers = {'0': MockFigureManager()}
Exemple #6
0
def create_application():
    application = Application([
        ('/_static/(.*)', StaticFileHandler, {'path': FigureManagerWebAgg.get_static_file_path()}),
        ('/mpl.js', MplJavaScriptHandler),

        (url_pattern('/mpl/download/{{base_dir}}/{{figure_id}}/{{format_name}}'), MplDownloadHandler),
        (url_pattern('/mpl/figures/{{base_dir}}/{{figure_id}}'), MplWebSocketHandler),

        (url_pattern('/'), WebAPIVersionHandler),
        (url_pattern('/exit'), WebAPIExitHandler),
        (url_pattern('/api'), JsonRpcWebSocketHandler, dict(
            service_factory=service_factory,
            validation_exception_class=ValidationError,
            report_defer_period=WEBAPI_PROGRESS_DEFER_PERIOD)
         ),
        (url_pattern('/ws/res/plot/{{base_dir}}/{{res_name}}'), ResourcePlotHandler),
        (url_pattern('/ws/res/geojson/{{base_dir}}/{{res_id}}'), ResFeatureCollectionHandler),
        (url_pattern('/ws/res/geojson/{{base_dir}}/{{res_id}}/{{feature_index}}'), ResFeatureHandler),
        (url_pattern('/ws/res/csv/{{base_dir}}/{{res_id}}'), ResVarCsvHandler),
        (url_pattern('/ws/res/html/{{base_dir}}/{{res_id}}'), ResVarHtmlHandler),
        (url_pattern('/ws/res/tile/{{base_dir}}/{{res_id}}/{{z}}/{{y}}/{{x}}.png'), ResVarTileHandler),
        (url_pattern('/ws/ne2/tile/{{z}}/{{y}}/{{x}}.jpg'), NE2Handler),
        (url_pattern('/ws/countries'), CountriesGeoJSONHandler),
    ])
    application.workspace_manager = FSWorkspaceManager()
    return application
Exemple #7
0
    def __init__(self):

        super(MyApplication, self).__init__([
            # Static files for the CSS and JS
            (r'/_static/(.*)',
            #(r'/(.*)',
             tornado.web.StaticFileHandler,
             {'path': FigureManagerWebAgg.get_static_file_path()}),

            (r'/', MainPage),

            # The pages that contain the plot (or maybe the plots)
            (r'/DataFrame\d', PlotPage),

            (r'/mpl.js', self.MplJs),

            # Sends images and events to the browser, and receives
            # events from the browser
            (r'/([0-9]+)/ws', self.WebSocket),

            # Handles the downloading (i.e., saving) of static images
            (r'/download.([a-z0-9.]+)', self.Download),

            ],
            static_path='static',
            template_path='templates',
            debug=True
            )
Exemple #8
0
    def __init__(self, stop_callback=None):
        super(MyApplication, self).__init__([
            # Static files for the CSS and JS
            (r'/_static/(.*)', tornado.web.StaticFileHandler, {
                'path': FigureManagerWebAgg.get_static_file_path()
            }),

            # The page that contains all of the pieces
            ('/', self.MainPage),
            ('/mpl.js', self.MplJs),

            # Sends images and events to the browser, and receives
            # events from the browser
            ('/ws', self.WebSocket),

            # Handles the downloading (i.e., saving) of static images
            (r'/download.([a-z0-9.]+)', self.Download),
        ])

        figure = Figure()

        self.manager = new_figure_manager_given_figure(id(figure), figure)

        ax = figure.add_subplot(1, 1, 1)

        def callback(event):
            '''Sends event to front end'''
            event.info.pop(
                'caller',
                None)  # HACK: popping caller b/c it's not JSONizable.
            self.manager._send_event(event.type, **event.info)

        self.fc_manager = fc_widget.FCGateManager(ax, callback_list=callback)
        self.stop_callback = stop_callback
Exemple #9
0
    def __init__(self, stop_callback=None):
        super(MyApplication, self).__init__([
            # Static files for the CSS and JS
            (r'/_static/(.*)',
             tornado.web.StaticFileHandler,
             {'path': FigureManagerWebAgg.get_static_file_path()}),

            # The page that contains all of the pieces
            ('/', self.MainPage),

            ('/mpl.js', self.MplJs),

            # Sends images and events to the browser, and receives
            # events from the browser
            ('/ws', self.WebSocket),

            # Handles the downloading (i.e., saving) of static images
            (r'/download.([a-z0-9.]+)', self.Download),
        ])

        figure = Figure()

        self.manager = new_figure_manager_given_figure(
            id(figure), figure)

        ax = figure.add_subplot(1, 1, 1)

        def callback(event):
            '''Sends event to front end'''
            event.info.pop('caller', None)  # HACK: popping caller b/c it's not JSONizable.
            self.manager._send_event(event.type, **event.info)

        self.fc_manager = fc_widget.FCGateManager(ax, callback_list=callback)
        self.stop_callback = stop_callback
    def __init__(self, fc):
        self.fig_container = fc
        # self.figure = figure[1]
        # self.manager = figure._managers[1]
        # self.manager = new_figure_manager_given_figure(id(figure), figure)

        print(str(Path(config['WEB']['favicon_path'])))
        print(Path(config['WEB']['favicon_path']).exists())

        super().__init__(
            [
                # MPL Static files for the CSS and JS
                (r'/_static/(.*)', tornado.web.StaticFileHandler, {
                    'path': FigureManagerWebAgg.get_static_file_path()
                }),

                # My static files
                (r'/s/(.*)', tornado.web.StaticFileHandler, {
                    'path': str(Path(config['WEB']['static_path']))
                }),

                # Waveforms static path
                (r'/wf/(.*)', tornado.web.StaticFileHandler, {
                    'path': str(Path(config['WEB']['waveform_path']))
                }),

                # favicon
                (r'/(favicon.ico)', tornado.web.StaticFileHandler, {
                    'path': str(Path(config['WEB']['favicon_path']))
                }),

                # The page that contains all of the pieces
                ('/', self.MainPage),
                #('/', self.TxFunction),
                ('/waveforms.html', self.ListWaveforms),
                (r'/waveform/(.*)', self.Waveform),
                (r'/saveandwait', self.WaitForWaveform),
                ('/mpl.js', self.MplJs),

                # Sends images and events to the browser, and receives
                # events from the browser
                ('/([a-z0-9]+)/ws', self.WebSocket),

                # Handles the downloading (i.e., saving) of static images
                (r'/([a-z0-9]+)/download.([a-z0-9.]+)', self.Download),
                (r'/dosomething', self.dosomething),
                (r'/step', self.step),
                (r'/init', self.init_plots),
                (r'/tek/start', self.start),
                (r'/tek/state', self.state),
                (r'/tek/converse', self.converse),
                (r'/tek/save', self.save)
            ],
            debug=True,
            cookie_secret=str(uuid4()))
Exemple #11
0
def MplJs():
    """
    Serves the generated matplotlib javascript file.  The content
    is dynamically generated based on which toolbar functions the
    user has defined.  Call `FigureManagerWebAgg` to get its
    content.
    """
    js_content = FigureManagerWebAgg.get_javascript()
    resp = make_response(js_content, 200)
    resp.headers['Content-Type'] = 'application/javascript'
    return resp
Exemple #12
0
 def __init__(self, handlers, password=None, **kwargs):
   handlers = [
       (r'/_static/(.*)',
        tornado.web.StaticFileHandler,
        {'path': FigureManagerWebAgg.get_static_file_path()}),
       ('/mpl.js', self.MplJs),
       (r'/([0-9]+)/ws', self.WebSocket),
       (r'/([0-9]+)/download.([a-z0-9.]+)', self.Download),
   ] + list(handlers)
   super(MatplotlibServer, self).__init__(handlers, **kwargs)
   self.figure_data = {}  # id -> FigData
   self.login_password = str(password)
Exemple #13
0
 def __init__(self, routes, **kwargs):
   # routes common to all webagg servers
   mplweb_routes = [
       (r'/([0-9]+)/download.([a-z0-9.]+)', DownloadHandler),
       (r'/([0-9a-f]+)/([0-9]+)/ws', WebSocketHandler),
       (r'/mpl.js', MplJsHandler),
       (r'/_static/(.*)', tornado.web.StaticFileHandler,
        dict(path=FigureManagerWebAgg.get_static_file_path())),
   ]
   tornado.web.Application.__init__(self, routes + mplweb_routes, **kwargs)
   self.prog_states = {}  # uid -> ProgramState
   self.fig_managers = {}  # fignum -> manager
   # hack in a mock manager for keep-alive sockets
   self.fig_managers['0'] = _MockFigureManager()
Exemple #14
0
    def __init__(self, figure):
        self.figure = figure
        self.manager = new_figure_manager_given_figure(id(figure), figure)

        handlers = [(r'/_static/(.*)', tornado.web.StaticFileHandler, {
            'path': FigureManagerWebAgg.get_static_file_path()
        }), (r"/sin", self.MainHandler), (r"/ws", self.SocketHandler),
                    (r'/download.([a-z0-9.]+)', self.Download),
                    ('/mpl.js', self.MplJs), (r'/lines', self.LinesHandler)]
        settings = dict(
            cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
            template_path=os.path.join(os.path.dirname(__file__), "templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            xsrf_cookies=False,
        )
        super(Application, self).__init__(handlers, **settings)
Exemple #15
0
def create_application(user_root_path: str = None):
    default_url_root = "/"
    # replace default url_root with /user/username/ if running in Cate Hub context.
    url_root = os.environ.get("JUPYTERHUB_SERVICE_PREFIX", default_url_root)
    if url_root is not default_url_root:
        print(f"warning: detected jupyterhub environment variable JUPYTERHUB_SERVICE_PREFIX "
              f"using {url_root} as default root url for the api.")

    application = Application([
        (url_root + '_static/(.*)', StaticFileHandler, {'path': FigureManagerWebAgg.get_static_file_path()}),
        (url_root + 'mpl.js', MplJavaScriptHandler),
        (url_pattern(url_root + 'mpl/download/{{base_dir}}/{{figure_id}}/{{format_name}}'), MplDownloadHandler),
        (url_pattern(url_root + 'mpl/figures/{{base_dir}}/{{figure_id}}'), MplWebSocketHandler),
        (url_pattern(url_root + 'files/upload'), FilesUploadHandler),
        (url_pattern(url_root + 'files/download'), FilesDownloadHandler),
        (url_pattern(url_root), WebAPIInfoHandler),
        (url_pattern(url_root + 'exit'), WebAPIExitHandler),
        (url_pattern(url_root + 'api'), JsonRpcWebSocketHandler, dict(
            service_factory=service_factory,
            validation_exception_class=ValidationError,
            report_defer_period=WEBAPI_PROGRESS_DEFER_PERIOD)
         ),
        (url_pattern(url_root + 'ws/res/plot/{{base_dir}}/{{res_name}}'), ResourcePlotHandler),
        (url_pattern(url_root + 'ws/res/geojson/{{base_dir}}/{{res_id}}'), ResFeatureCollectionHandler),
        (url_pattern(url_root + 'ws/res/geojson/{{base_dir}}/{{res_id}}/{{feature_index}}'), ResFeatureHandler),
        (url_pattern(url_root + 'ws/res/csv/{{base_dir}}/{{res_id}}'), ResVarCsvHandler),
        (url_pattern(url_root + 'ws/res/html/{{base_dir}}/{{res_id}}'), ResVarHtmlHandler),
        (url_pattern(url_root + 'ws/res/tile/{{base_dir}}/{{res_id}}/{{z}}/{{y}}/{{x}}.png'), ResVarTileHandler),
        (url_pattern(url_root + 'ws/ne2/tile/{{z}}/{{y}}/{{x}}.jpg'), NE2Handler),
        (url_pattern(url_root + 'ws/countries'), CountriesGeoJSONHandler),
    ])

    default_user_root_path = os.environ.get('CATE_USER_ROOT')
    if user_root_path is None:
        user_root_path = default_user_root_path
    elif default_user_root_path:
        print(f"warning: user root path given by environment variable CATE_USER_ROOT superseded by {user_root_path}")

    application.workspace_manager = FSWorkspaceManager(user_root_path)

    return application
    def __init__(self, figure):
        self.figure = figure
        self.manager = new_figure_manager_given_figure(id(figure), figure)

        super().__init__([
            # Static files for the CSS and JS
            (r'/_static/(.*)',
             tornado.web.StaticFileHandler,
             {'path': FigureManagerWebAgg.get_static_file_path()}),

            # The page that contains all of the pieces
            ('/', self.MainPage),

            ('/mpl.js', self.MplJs),

            # Sends images and events to the browser, and receives
            # events from the browser
            ('/ws', self.WebSocket),

            # Handles the downloading (i.e., saving) of static images
            (r'/download.([a-z0-9.]+)', self.Download),
        ])
Exemple #17
0
    def __init__(self, fc):
        self.fig_container = fc
        # self.figure = figure[1]
        # self.manager = figure._managers[1]
        # self.manager = new_figure_manager_given_figure(id(figure), figure)

        super().__init__(
            [
                # MPL Static files for the CSS and JS
                (r'/_static/(.*)', tornado.web.StaticFileHandler, {
                    'path': FigureManagerWebAgg.get_static_file_path()
                }),

                # My static files
                (r'/static/(.*)', tornado.web.StaticFileHandler, {
                    'path': ''
                }),

                # The page that contains all of the pieces
                ('/', self.MainPage),
                ('/mpl.js', self.MplJs),

                # Sends images and events to the browser, and receives
                # events from the browser
                ('/([a-z0-9]+)/ws', self.WebSocket),

                # Handles the downloading (i.e., saving) of static images
                (r'/([a-z0-9]+)/download.([a-z0-9.]+)', self.Download),
                (r'/dosomething', self.dosomething),
                (r'/step', self.step),
                (r'/init', self.init_plots),
                (r'/tek/start', self.start),
                (r'/tek/state', self.state),
                (r'/tek/converse', self.converse)
            ],
            debug=True)
 def __init__(self, canvas, num):
     self._shown = False
     FigureManagerWebAgg.__init__(self, canvas, num)
        def get(self):
            self.set_header('Content-Type', 'application/javascript')
            js_content = FigureManagerWebAgg.get_javascript()

            self.write(js_content)
Exemple #20
0
 def get(self):
     self.set_header('Content-Type', 'application/javascript')
     js_content = FigureManagerWebAgg.get_javascript()
     with open('static/mpl.js', 'r') as fh:
         local_content = fh.read()
     self.write(local_content)
Exemple #21
0
 def __init__(self, canvas, num):
     FigureManagerWebAgg.__init__(self, canvas, num)
     self.web_sockets = [self.canvas]
Exemple #22
0
 def __init__(self, canvas, num):
     self._shown = False
     FigureManagerWebAgg.__init__(self, canvas, num)
        def get(self):
            self.set_header('Content-Type', 'application/javascript')
            js_content = FigureManagerWebAgg.get_javascript()

            self.write(js_content)