コード例 #1
0
 def inner(simulation):
     database = dataset.connect('sqlite:///parameter.db')
     abcEconomics.parameter_database = database['parameter']
     Form = form(parameter_mask, names)  # pylint: disable=C0103
     if serve:
         flexx.config.hostname = hostname
         flexx.config.port = port
         app.serve(
             basiclayout(Form,
                         simulation,
                         title,
                         header,
                         truncate_rounds,
                         texts=texts,
                         pages=pages,
                         histograms=histograms))
         app.start()
     else:
         app.launch(basiclayout(Form,
                                simulation,
                                title,
                                header,
                                truncate_rounds,
                                texts=texts,
                                pages=pages,
                                histograms=histograms),
                    windowmode='maximized',
                    runtime=runtime)
         app.run()
     return lambda _: None
コード例 #2
0
def main():
    if len(sys.argv) > 1:
        app.export(BeetMe, "beetme.html", link=0)
    else:
        app.serve(BeetMe)
        tornado_app = app.current_server().app
        tornado_app.add_handlers(r".*", [
            (r"/beet.*", BeetHandler),
        ])
        app.start()
コード例 #3
0
ファイル: __init__.py プロジェクト: John-M-Walls/abce
    def inner(simulation):
        if not IMPORTERROR:
            if pypy is not None:

                def simulation(parameters):
                    print("CALLING PYPY")
                    call([
                        pypy, sys.argv[0],
                        json.dumps(parameters), abce.simulation_name
                    ])

            database = dataset.connect('sqlite:///parameter.db')
            abce.parameter_database = database['parameter']
            Form = form(parameter_mask, names)  # pylint: disable=C0103
            if serve:
                flexx.config.hostname = hostname
                flexx.config.port = port
                app.serve(
                    basiclayout(Form,
                                simulation,
                                title,
                                header,
                                truncate_rounds,
                                texts=texts,
                                pages=pages,
                                histograms=histograms))
                app.start()
            else:
                app.launch(basiclayout(Form,
                                       simulation,
                                       title,
                                       header,
                                       truncate_rounds,
                                       texts=texts,
                                       pages=pages,
                                       histograms=histograms),
                           windowmode='maximized',
                           runtime=runtime)
                app.run()
        else:
            print("RUN PYPY")
            abce.simulation_name = sys.argv[2]
            simulation(json.loads(sys.argv[1]))
        return lambda _: None
コード例 #4
0
    def _update_participants(self):
        if not self.session.status:
            return  # and dont't invoke a new call
        proxies = app.manager.get_connections(self.__class__.__name__)
        names = [p.app.name.text for p in proxies]
        del proxies
        text = '<br />%i persons in this chat:<br /><br />' % len(names)
        text += '<br />'.join([name or 'anonymous' for name in sorted(names)])
        self.people.text = text
        app.call_later(3, self._update_participants)

    @event.connect('ok.mouse_down', 'message.submit')
    def _send_message(self, *events):
        text = self.message.text
        if text:
            name = self.name.text or 'anonymous'
            relay.new_message('<i>%s</i>: %s' % (name, text))
            self.message.text = ''

    class JS:
        @event.connect('!new_message')
        def _update_total_text(self, *events):
            self.messages.text += ''.join([ev.msg for ev in events])


if __name__ == '__main__':
    app.serve(ChatRoom)
    # m = app.launch(ChatRoom)  # for use during development
    app.start()
コード例 #5
0
Application served through this server is loaded on the browser with 'https'
protocol and its websocket is using 'wss'.
"""

from flexx import app, ui, config

# generate self-signed certificate for this example
import os

CERTFILE = '/tmp/self-signed.crt'
KEYFILE = '/tmp/self-signed.key'

os.system('openssl req -x509 -nodes -days 1 -batch -newkey rsa:2048 '
          '-keyout %s -out %s' % (KEYFILE, CERTFILE))

# use the self-signed certificate as if specified in normal config
config.ssl_certfile = CERTFILE
config.ssl_keyfile = KEYFILE


# Some very secret Model
class Example(ui.Widget):
    def init(self):
        ui.Button(text='Secret Button')


# run application
app.serve(Example, 'Example')
app.start()
コード例 #6
0
"""
Import apps from other example modules, and host these as separate apps
from one process.
"""

from flexx import app

from flexx.ui.examples.monitor import Monitor
from flexx.ui.examples.chatroom import ChatRoom
from flexx.ui.examples.twente import Twente

if __name__ == '__main__':
    # This example is setup as a server app
    app.serve(Monitor)
    app.serve(ChatRoom)
    app.serve(Twente)
    app.start()
コード例 #7
0
ファイル: colab_painting.py プロジェクト: ajithpad/flexx
        def init(self):
            super().init()
            self._ctx = self.canvas.node.getContext('2d')
        
        @event.connect('color')
        def _update_color(self, *events):
            self.canvas.style = 'border: 10px solid ' + events[-1].new_value
        
        @event.connect('new_dot')
        def _paint_dot(self, *events):
            for ev in events:
                # Slowly hide old paint
                self._ctx.globalAlpha = 0.01
                self._ctx.fillStyle = '#fff'
                self._ctx.fillRect(0, 0, 400, 400)
                # Add new dot
                self._ctx.globalAlpha = 0.8
                self._ctx.beginPath()
                self._ctx.fillStyle = ev.color
                self._ctx.arc(ev.pos[0], ev.pos[1], 5, 0, 6.2831)
                self._ctx.fill()


# Create global relay
relay = Relay()

if __name__ == '__main__':
    app.serve(ColabPainting)
    m = app.launch(ColabPainting)  # for use during development
    app.start()
コード例 #8
0
ファイル: adding_handlers.py プロジェクト: xyzonline/flexx
* http://localhost:port/ to see a list of served web apps
* http://localhost:port/about to see a the custom about page
* http://localhost:port/api/foo/bar to see the echo api in action


"""

from flexx import app
from flexx.ui.examples.drawing import Drawing
from flexx.ui.examples.chatroom import ChatRoom

import tornado.web

# Serve some web apps, just for fun
app.serve(Drawing)
app.serve(ChatRoom)


class MyAboutHandler(tornado.web.RequestHandler):
    
    def get(self):
        self.write('<html>This is just an <i>example</i>.</html>')


class MyAPIHandler(tornado.web.RequestHandler):
    
    def get(self, path):
        # self.request.path -> full path
        # path -> the regexp group specified in add_handlers
        self.write('echo ' + path)
コード例 #9
0
ファイル: cookies.py プロジェクト: silky/flexx
"""
Tiny example for using cookies to store user data accross sessions.
"""

from flexx import app, ui, event


class Cookies(ui.Widget):
    def init(self):

        ui.Label(
            text=
            'Refreshing the page should maintain the value of the line edit.')
        self.edit = ui.LineEdit(placeholder_text='username',
                                text=self.session.get_cookie('username', ''))

    @event.connect('edit.text')
    def _update_cookie(self, *events):
        self.session.set_cookie('username', self.edit.text)


if __name__ == '__main__':
    m = app.launch(Cookies, 'browser')
    app.serve()
コード例 #10
0
ファイル: serve_multiple1.py プロジェクト: zoofIO/flexx
"""
Import apps from other example modules, and host these as separate apps
from one process.
"""

from flexx import app

from flexxamples.demos.monitor import Monitor
from flexxamples.demos.chatroom import ChatRoom
from flexxamples.demos.demo import Demo
from flexxamples.demos.colab_painting import ColabPainting


if __name__ == '__main__':
    # This example is setup as a server app
    app.serve(Monitor)
    app.serve(ChatRoom)
    app.serve(ColabPainting)
    app.serve(Demo)
    app.start()
コード例 #11
0
ファイル: colab_painting.py プロジェクト: simonclouds/flexx
        def init(self):
            super().init()
            self._ctx = self.canvas.node.getContext('2d')

        @event.connect('color')
        def _update_color(self, *events):
            self.canvas.style = 'border: 10px solid ' + events[-1].new_value

        @event.connect('new_dot')
        def _paint_dot(self, *events):
            for ev in events:
                # Slowly hide old paint
                self._ctx.globalAlpha = 0.01
                self._ctx.fillStyle = '#fff'
                self._ctx.fillRect(0, 0, 400, 400)
                # Add new dot
                self._ctx.globalAlpha = 0.8
                self._ctx.beginPath()
                self._ctx.fillStyle = ev.color
                self._ctx.arc(ev.pos[0], ev.pos[1], 5, 0, 6.2831)
                self._ctx.fill()


# Create global relay
relay = Relay()

if __name__ == '__main__':
    app.serve(ColabPainting)
    m = app.launch(ColabPainting)  # for use during development
    app.start()
コード例 #12
0
            
            # Set connections
            n = ev.sessions, ev.total_sessions
            self.info.text = ('There are %i connected clients.<br />' % n[0] +
                              'And in total we served %i connections.<br />' % n[1])
            
            # Prepare plots
            times = self.cpu_plot.xdata.copy()
            times.append(time() - self.start_time)
            times = times[-self.nsamples:]
            self.cpu_plot.xdata = times
            self.mem_plot.xdata = times
            
            # cpu data
            usage = self.cpu_plot.ydata
            usage.append(ev.cpu)
            usage = usage[-self.nsamples:]
            self.cpu_plot.ydata = usage
            
            # mem data
            usage = self.mem_plot.ydata
            usage.append(ev.mem)
            usage = usage[-self.nsamples:]
            self.mem_plot.ydata = usage


if __name__ == '__main__':
    app.serve(Monitor)
    # m = app.launch(Monitor)  # for use during development
    app.start()
コード例 #13
0
from flexx import app

from flexxamples.demos.monitor import Monitor
from flexxamples.demos.chatroom import ChatRoom
from flexxamples.demos.demo import Demo
from flexxamples.demos.colab_painting import ColabPainting
from flexxamples.demos.d3_collision import CollisionDemo
from flexxamples.demos.plotly_gdp import PlotlyGeoDemo


async def exit_server_after_a_while():
    # Exit the server after 12 hours, after which it will start up again
    # (using Docker with auto-restart). This makes sure that the server
    # is not bother too much in case we have a memory leak.
    await asyncio.sleep(12 * 3600)
    sys.exit()


asyncio.ensure_future(exit_server_after_a_while())

if __name__ == '__main__':
    # This example is setup as a server app
    # app.serve(Monitor)
    # app.serve(ChatRoom)
    app.serve(ColabPainting)
    app.serve(CollisionDemo)
    # app.serve(PlotlyGeoDemo)  # CORS fail?
    app.serve(Demo)
    app.start()
コード例 #14
0
                self.ab = APPBox(flex=0)
                self.fb = FlowBox(flex=0)
                self.show = ShowBox(flex=1)

    @testpmd.reaction('!output')
    def print_testpmd_output(self, *events):
        self.show.input.set_disabled(not testpmd.alive)
        for ev in events:
            for line in ev.buffer:
                self.show.testpmdout.add_line(line)


if __name__ == '__main__':
    if sys.argv[-1] in ["--help", "-h"]:
        print("""
		Start Testpmd web GUI in server mode.
		Please open URL in broswer Chrome or Firefox
        
		Options:
			--flexx-hostname=<host> Host/IP to listen on
			--flexx-port=<port>     Port number to listen on
			--app:                  Start as application single user mode, quit once page close.
			--help(-h)              Show this help
		""")
    elif sys.argv[-1] == "--app":
        flx.launch(TestpmdUI)
        flx.run()
    else:
        app.serve(TestpmdUI)
        app.start()
コード例 #15
0
ファイル: serve_ssl.py プロジェクト: Konubinix/flexx
a SSL enabled web server (through Tornado ssl_option argument).

Application served through this server is loaded on the browser with 'https'
protocol and its websocket is using 'wss'.
"""

from flexx import app, ui, config

# generate self-signed certificate for this example
import os

CERTFILE = '/tmp/self-signed.crt'
KEYFILE = '/tmp/self-signed.key'

os.system('openssl req -x509 -nodes -days 1 -batch -newkey rsa:2048 '
          '-keyout %s -out %s' % (KEYFILE, CERTFILE))

# use the self-signed certificate as if specified in normal config
config.ssl_certfile = CERTFILE
config.ssl_keyfile = KEYFILE


# Some very secret Model
class Example(ui.Widget):
    def init(self):
        ui.Button(text='Secret Button')

# run application
app.serve(Example, 'Example')
app.start()
コード例 #16
0
"""
Import apps from other example modules, and host these as separate apps
from one process.
"""

from flexx import app

from flexxamples.demos.monitor import Monitor
from flexxamples.demos.chatroom import ChatRoom
from flexxamples.demos.demo import Demo
from flexxamples.demos.colab_painting import ColabPainting

if __name__ == '__main__':
    # This example is setup as a server app
    app.serve(Monitor)
    app.serve(ChatRoom)
    app.serve(ColabPainting)
    app.serve(Demo)
    app.start()
コード例 #17
0
ファイル: cookies.py プロジェクト: Konubinix/flexx
"""
Tiny example for using cookies to store user data accross sessions.
"""

from flexx import app, ui, event


class Cookies(ui.Widget):
    
    def init(self):
        
        ui.Label(text='Refreshing the page should maintain the value of the line edit.')
        self.edit = ui.LineEdit(placeholder_text='username',
                                text=self.session.get_cookie('username', ''))
        
    @event.connect('edit.text')
    def _update_cookie(self, *events):
        self.session.set_cookie('username', self.edit.text)


if __name__ == '__main__':
    m = app.launch(Cookies, 'browser')
    app.serve()
コード例 #18
0
ファイル: adding_handlers.py プロジェクト: hainm/flexx
* http://localhost:port/ to see a list of served web apps
* http://localhost:port/about to see a the custom about page
* http://localhost:port/api/foo/bar to see the echo api in action


"""

from flexx import app
from flexx.ui.examples.drawing import Drawing
from flexx.ui.examples.chatroom import ChatRoom

import tornado.web

# Serve some web apps, just for fun
app.serve(Drawing)
app.serve(ChatRoom)


class MyAboutHandler(tornado.web.RequestHandler):
    
    def get(self):
        self.write('<html>This is just an <i>example</i>.</html>')


class MyAPIHandler(tornado.web.RequestHandler):
    
    def get(self, path):
        # self.request.path -> full path
        # path -> the regexp group specified in add_handlers
        self.write('echo ' + path)
コード例 #19
0
    def _on_save_file(self, file, pkt):
        wrpcap(file, pkt)
        self.set_status(f"Saved to file: {file}")

    def load_pcap(self):
        self.pnl_browser.set_callback(self._on_load_file)
        self.activate_panel(self.pnl_browser)

    def save_pcap(self, pkt):
        self.pnl_browser.set_callback(self._on_save_file, pkt)
        self.activate_panel(self.pnl_browser)

if __name__ == '__main__':
    if sys.argv[-1] in ["--help","-h"]:
        print("""
        Start Scapy web GUI in server mode which support multiple users.
        Please open URL in broswer Chrome or Firefox
        
        Options:
            --flexx-hostname=<host> Host/IP to listen on
            --flexx-port=<port>     Port number to listen on
            --app:                  Start as application single user mode, quit once page close.
            --help(-h)              Show this help
            """)
    elif sys.argv[-1] == "--app":
        flx.launch(ScapyUI)
        flx.run()
    else:
        app.serve(ScapyUI)
        app.start()
コード例 #20
0
ファイル: chatroom.py プロジェクト: ajithpad/flexx
        proxies = app.manager.get_connections(self.__class__.__name__)
        names = [p.app.name.text for p in proxies]
        del proxies
        text = '<br />%i persons in this chat:<br /><br />' % len(names)
        text += '<br />'.join([name or 'anonymous' for name in sorted(names)])
        self.people.text = text
        app.call_later(3, self._update_participants)
    
    @event.connect('ok.mouse_down', 'message.submit')
    def _send_message(self, *events):
        text = self.message.text
        if text:
            name = self.name.text or 'anonymous'
            relay.new_message('<i>%s</i>: %s' % (name, text))
            self.message.text = ''
    
    class JS:
        
        @event.connect('new_message')
        def _update_total_text(self, *events):
            self.messages.text += ''.join([ev.msg for ev in events])


# Create global relay
relay = Relay()

if __name__ == '__main__':
    app.serve(ChatRoom)
    # m = app.launch(ChatRoom)  # for use during development
    app.start()
コード例 #21
0
ファイル: serve_multiple1.py プロジェクト: ajithpad/flexx
"""
Import apps from other example modules, and host these as separate apps
from one process.
"""

from flexx import app

from flexx.ui.examples.monitor import Monitor
from flexx.ui.examples.chatroom import ChatRoom
from flexx.ui.examples.twente import Twente


if __name__ == '__main__':
    # This example is setup as a server app
    app.serve(Monitor)
    app.serve(ChatRoom)
    app.serve(Twente)
    app.start()