Esempio n. 1
0
File: _app.py Progetto: zoofIO/flexx
    def launch(self, runtime=None, **runtime_kwargs):
        """ Launch this app as a desktop app in the given runtime.
        See https://webruntime.readthedocs.io for details.

        Arguments:
            runtime (str): the runtime to launch the application in.
                Default 'app or browser'.
            runtime_kwargs: kwargs to pass to the ``webruntime.launch`` function.
                A few names are passed to runtime kwargs if not already present
                ('title' and 'icon').

        Returns:
            Component: an instance of the given class.
        """
        # creates server (and event loop) if it did not yet exist
        current_server()

        # Create session
        if not self._is_served:
            self.serve()
        session = manager.create_session(self.name)

        # Transfer title and icon
        if runtime_kwargs.get('title', None) is None and 'title' in self.kwargs:
            runtime_kwargs['title'] = self.kwargs['title']
        if runtime_kwargs.get('icon', None) is None and 'icon' in self.kwargs:
            runtime_kwargs['icon'] = self.kwargs['icon']
        # Launch web runtime, the server will wait for the connection
        url = self.url + '?session_id=%s' % session.id
        if not runtime or '!' in config.webruntime:
            runtime = config.webruntime.strip('!')
        session._runtime = webruntime.launch(url, runtime=runtime, **runtime_kwargs)
        return session.app
Esempio n. 2
0
    def launch(self, runtime=None, **runtime_kwargs):
        """ Launch this app as a desktop app in the given runtime.

        Arguments:
            runtime (str): the runtime to launch the application in.
                Default 'app or browser'.
            runtime_kwargs: kwargs to pass to the ``webruntime.launch`` function.
                A few names are passed to runtime kwargs if not already present
                ('title' and 'icon').

        Returns:
            Component: an instance of the given class.
        """
        # creates server (and event loop) if it did not yet exist
        current_server()

        # Create session
        if not self._is_served:
            self.serve()
        session = manager.create_session(self.name)

        # Transfer title and icon
        if runtime_kwargs.get('title',
                              None) is None and 'title' in self.kwargs:
            runtime_kwargs['title'] = self.kwargs['title']
        if runtime_kwargs.get('icon', None) is None and 'icon' in self.kwargs:
            runtime_kwargs['icon'] = self.kwargs['icon']
        # Launch web runtime, the server will wait for the connection
        url = self.url + '?session_id=%s' % session.id
        if not runtime or '!' in config.webruntime:
            runtime = config.webruntime.strip('!')
        session._runtime = webruntime.launch(url,
                                             runtime=runtime,
                                             **runtime_kwargs)
        return session.app
Esempio n. 3
0
def launch(cls, runtime=None, properties=None, **runtime_kwargs):
    """ Shorthand for ``app.App(cls).launch(runtime, **runtime_kwargs)``.
    """
    if properties is not None:
        raise RuntimeError('launch(... properties) is deprecated, '
                           'use app.App().launch() instead.')
    if isinstance(cls, str):
        return webruntime.launch(cls, runtime, **runtime_kwargs)
    assert (isinstance(cls, type) and issubclass(cls, (PyComponent, JsComponent)))
    a = App(cls)
    return a.launch(runtime, **runtime_kwargs)
Esempio n. 4
0
 def run(self) -> None:
     # put the application HTML in a temporary file
     self._html = tempfile.NamedTemporaryFile(
         mode='w+',
         prefix='my-app-',
         suffix='.html',
         delete=False,
     )
     self._html.write(self.body)
     self._html.close()
     # launch the application HTML file
     self._runtime = webruntime.launch(f'file://{self._html.name}', 'app')
     self._dom.wait_for_connection()
Esempio n. 5
0
def main():
    if len(sys.argv) == 1:
        help()
    elif len(sys.argv) == 2:
        if sys.argv[1] in ('-h', '--help'):
            help()
        elif sys.argv[1] in ('--version', 'version'):
            print(webruntime.__version__)
        else:
            sys.exit('Invalid use of webruntime CLI.')
    elif len(sys.argv) == 3:
        rt = webruntime.launch(sys.argv[1], sys.argv[2])
        rt._proc = None  # don't close it when Python exits
    else:
        sys.exit('Invalid use of webruntime CLI.')
Esempio n. 6
0
    def start(self):
        url = self.connection_url
        if self.token and self._token_generated:
            url = url_concat(url, {'token': self.token})

        rt = launch(url,
                    runtime,
                    title="Jupyterlab",
                    icon=iconfile,
                    size=(1024, 768))

        self._watcher = Watcher(rt._proc)
        self._watcher.start()

        self.open_browser = False
        super().start()
Esempio n. 7
0
    def launch(self, runtime=None, **runtime_kwargs):
        """ Launch this app as a desktop app in the given runtime.
        See https://webruntime.readthedocs.io for details.

        Arguments:
            runtime (str): the runtime to launch the application in.
                Default 'app or browser'.
            runtime_kwargs: kwargs to pass to the ``webruntime.launch`` function
                and the create_server function.
                create_server takes 'host', 'port', 'loop', 'backend' as parameters.
                For webruntime.launch, a few names are passed to runtime kwargs if not 
                already present ('title' and 'icon').

        Returns:
            Component: an instance of the given class.
        """
        # creates server (and event loop) if it did not yet exist
        server_kwargs = {}
        server_keys = ['host', 'port', 'loop', 'backend']
        for key, value in runtime_kwargs.items():
            if key in server_keys:
                server_kwargs[key] = value
        current_server(**server_kwargs)
        # remove the server_keys
        for key in server_keys:
            if key in runtime_kwargs:
                del runtime_kwargs[key]

        # Create session
        if not self._is_served:
            self.serve()
        session = manager.create_session(self.name)

        # Transfer title and icon
        if runtime_kwargs.get('title',
                              None) is None and 'title' in self.kwargs:
            runtime_kwargs['title'] = self.kwargs['title']
        if runtime_kwargs.get('icon', None) is None and 'icon' in self.kwargs:
            runtime_kwargs['icon'] = self.kwargs['icon']
        # Launch web runtime, the server will wait for the connection
        url = self.url + '?session_id=%s' % session.id
        if not runtime or '!' in config.webruntime:
            runtime = config.webruntime.strip('!')
        session._runtime = webruntime.launch(url,
                                             runtime=runtime,
                                             **runtime_kwargs)
        return session.app
Esempio n. 8
0
def run_once(html_filename, runtime):
    x = webruntime.launch(html_filename, runtime)
    time.sleep(1.5)
    x.close()
    time.sleep(0.5)
Esempio n. 9
0
from datetime import datetime
from shutil import copy
from webruntime import launch
from aiohttp import web

# work around buggy _clean_nw_dirs()
from webruntime._nw import NWRuntime
NWRuntime._clean_nw_dirs = lambda x: x

filename = "nwjs-v0.30.4-win-ia32.zip"
if platform.system() == "Darwin":
    filename = "nwjs-v0.30.4-osx-x64.zip"
copy(path.join(path.dirname(path.__file__), filename), tempfile.gettempdir())


async def handle(request):
    return web.Response(text="""<html>
<head><title>date</title></head>
<body>
{}</p>
<a href="/">get time</a">
</body>
</html>
""".format(datetime.today().isoformat()), content_type="text/html")

app = web.Application()
app.router.add_get('/', handle)

launch('http://localhost:9999', 'nw-app or firefox-app')
web.run_app(app, port=9999)