Ejemplo n.º 1
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.º 2
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.º 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
def main():
    app_manager = AppManager(STORE_URL='store', LOCAL_URL='local')
    template = Template(
        html_file=join('gui', 'app_manager.html'),
        base_url='gui',
        recommended_size=(600,500)
    )

    if len(sys.argv)>1 and sys.argv[1] == 'web':
        app = WebApp(template=template, context={'app_manager': app_manager}, port=8000)
    else:
        app = QtApp(template=template, context={'app_manager': app_manager})
    app.start()
Ejemplo n.º 5
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.º 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
    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.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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.º 11
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.º 12
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.º 13
0
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
Ejemplo n.º 14
0
                    Name: {{person.name}}
                    Age: {{person.age}}
                """),
                command='ipython notebook examples_notebook.ipynb'
            ),
        ]

        return examples

    def get_example(self, ID):
        ''' Return the example with the given ID.'''

        example = None
        for example in self.examples:
            if example.ID == ID:
                return example

        return None

#### UI layer ####

template = Template(html_file='demo.html', recommended_size=(1400, 800))

#### Entry point ####

if __name__ == '__main__':
    examples_server = ExamplesServer(root=expanduser('~/work/jigna/examples'))

    app = WebApp(template=template, context={'server': examples_server}, port=8001)
    app.start()