Ejemplo n.º 1
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()
Ejemplo n.º 2
0
def main():
    # Obtain the tornado ioloop object
    ioloop = IOLoop.instance()

    # Instantiate the domain model
    motd = MOTD(message="Explicit is better than implicit.")

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

    # Schedule an update to a model variable after 10 seconds. If the user's
    # browser is connected to the web app before 10 seconds, it will see the
    # change in the model variable happening. Otherwise, it will only see the
    # updated value.
    #
    # NOTE: The way to schedule a task in the future has been greatly improved
    # in Tornado 4.1.dev version. You can specify additional arguments to
    # methods etc.
    delay = datetime.timedelta(0, 10)
    ioloop.add_timeout(delay,
        lambda : motd.update_message("Flat is better than nested.")
    )

    # Start serving the web app on port 8000.
    print 'Serving on port 8000...'
    ioloop.start()
Ejemplo n.º 3
0
def main(vixen):
    html_file = join(dirname(__file__), 'html', 'vixen_ui.html')
    template = Template(html_file=html_file, base_url='/', async=True)
    ioloop = IOLoop.instance()
    app = WebApp(
        template=template, context={'vixen':vixen}, port=8000,
        autoreload=True
    )
    autoreload.watch(html_file)
    app.listen(8000)
    url = 'http://localhost:8000'
    print "Point your browser to", url
    ioloop.start()
Ejemplo n.º 4
0
Archivo: web.py Proyecto: dusual/jigna
def start_web_app(template, context, port=8000):
    """
    Start a web app at the given port for serving the jigna view for the given
    template and context.
    """
    from tornado.ioloop import IOLoop
    from jigna.api import WebApp

    ioloop = IOLoop.instance()

    app = WebApp(template=template, context=context)
    app.listen(port)

    print 'Starting the web app on port %s ...' % port
    ioloop.start()
Ejemplo n.º 5
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()
Ejemplo n.º 6
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()
Ejemplo n.º 7
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()
Ejemplo n.º 8
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})
    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()
Ejemplo n.º 9
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()
Ejemplo n.º 10
0
    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
    def tearDownClass(cls):