Beispiel #1
0
def main():
    # Start the tornado ioloop application
    ioloop = IOLoop.instance()

    # Instantiate the domain model
    plotter = Plotter3D(expression="x*x*0.5 + y*y + z*z*2.0", n_contour=4)

    # Create a web app serving the view with the domain model added to its
    # context.
    app = WebApp(template=template, context={'plotter': plotter})
    app.listen(8000)

    # Start serving the web app on port 8000.
    print 'Serving on port 8000...'
    ioloop.start()
Beispiel #2
0
def display_jigna(context, template, size=None):
    """
    A `display_html` style method to show rich jigna display for the objects
    within the context.
    """
    PORT = get_free_port()

    app = WebApp(context=context, template=template, port=PORT)
    application = app.create_application()
    application.listen(app.port)

    width, height = size or template.recommended_size
    html = ('<iframe src="http://localhost:%s" width=%s height=%s></iframe>' %
            (PORT, width, height))

    return HTML(html)
Beispiel #3
0
def main():
    # Start the tornado ioloop application
    ioloop = IOLoop.instance()

    # Instantiate the domain model
    fred = Person(name='Fred', age=42)

    # Create a web app serving the view with the domain model added to its
    # context.
    app = WebApp(template=template, context={'person': fred}, port=8000)
    app.listen(8000)

    # Start serving the web app on port 8000.
    #
    # Point your web browser to http://localhost:8000/ to connect to this jigna
    # web app. Any operation performed on the client directly update the
    # model attributes on the server.
    print 'Serving on port 8000...'
    ioloop.start()
Beispiel #4
0
def main():
    # Start the tornado ioloop application
    ioloop = IOLoop.instance()

    # Instantiate the domain model and the plot controller
    domain_model = DomainModel(scaling_factor=15)
    plot_controller = PlotController(domain_model=domain_model)

    # Create a WebApp to render the HTML template with the given context.
    #
    # The web app shows a matplotlib plot in a browser by displaying the png
    # image of the plot. Moving the HTML slider on the UI changes the domain
    # model and hence the plot image.
    app = WebApp(template=template,
                 context={
                     'domain_model': domain_model,
                     'plot_controller': plot_controller
                 })
    app.listen(8000)

    # Start serving the web app on port 8000.
    print('Serving on port 8000...')
    ioloop.start()
except ImportError:
    raise unittest.SkipTest("Tornado not installed")

# Local imports.
from jigna.api import Template, WebApp
from jigna.utils.web import get_free_port
from test_jigna_qt import TestJignaQt, Person, body_html

class TestJignaWebSync(TestJignaQt):
    @classmethod
    def setUpClass(cls, async=False):
        ioloop = IOLoop.instance()
        fred = Person(name='Fred', age=42)
        template = Template(body_html=body_html, async=async)
        port = get_free_port()
        app = WebApp(template=template, context={'model':fred})
        app.listen(port)

        # Start the tornado server in a different thread so that we can write
        # test statements here in the main loop
        t = Thread(target=ioloop.start)
        t.setDaemon(True)
        t.start()

        browser = webdriver.Firefox()
        browser.get('http://localhost:%d'%port)
        cls.app = app
        cls.fred = fred
        cls.browser = browser

    @classmethod