def main(): # Must have at least one application app = WebApplication() # Generate index.html from index.enaml with open('index.html', 'wb') as f: f.write(Index().render())
def run(): # Needed to create enaml components enaml_app = WebApplication() # Start the tornado app app = tornado.web.Application([ (r'/', ViewerHandler), (r'/websocket/', ViewerWebSocket), (r'/static/(.*)', tornado.web.StaticFileHandler, { 'path': os.path.dirname(__file__) }), ]) app.listen(4040) tornado.ioloop.IOLoop.current().start()
async def __setstate__(self, state, scope=None): """ Restore an object from the a state from the database. This is async as it will lookup any referenced objects from the DB. """ unflatten = self.serializer.unflatten name = state.get('__model__') if name is None: raise ValueError("State must contain the __model__ key") if name != self.__model__: raise ValueError(f"Trying to use {name} state for " f"{self.__model__} object") scope = scope or {} ref = state.pop('__ref__', None) if ref is not None: scope[ref] = self members = self.members() for k, v in state.items(): # Don't use getattr because it triggers a default value lookup if members.get(k): try: obj = await unflatten(v, scope) setattr(self, k, obj) except Exception as e: exc = traceback.format_exc() WebApplication.instance().logger.error( f"Error setting state:" f"{self.__model__}.{k} = {pformat(obj)}:" f"\nSelf: {ref}: {scope.get(ref)}" f"\nValue: {pformat(v)}" f"\nScope: {pformat(scope)}" f"\nState: {pformat(state)}" f"\n{exc}" )
def run(): # Needed to create enaml components enaml_app = WebApplication() log.setLevel('DEBUG') # Start the tornado app app = tornado.web.Application([ (r'/', ViewerHandler), (r'/websocket/', ViewerWebSocket), (r'/static/(.*)', tornado.web.StaticFileHandler, { 'path': os.path.dirname(__file__) }), ]) app.listen(int(os.environ.get('PORT', 5000))) tornado.ioloop.IOLoop.current().start()
def run_web_app(): enaml_app = WebApplication() # Start the tornado app app = tornado.web.Application( [ (r"/", ViewerHandler), (r"/datas", DatasHandler), (r"/ws", WsHandler), (r"/static/(.*)", StaticFiles, { "path": "static/" }), ], debug=True, ) app.listen(8888) io_loop = tornado.ioloop.IOLoop.current() io_loop.start()
def run(): # Python3.8 win32; asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) enable_pretty_logging() # Needed to create enaml components enaml_app = WebApplication() # Start the tornado app app = tornado.web.Application([ (r'/', ViewerHandler), (r'/websocket/', ViewerWebSocket), (r'/static/(.*)', tornado.web.StaticFileHandler, { 'path': os.path.dirname(__file__) }), ], debug=True) app.listen(8888) tornado.ioloop.IOLoop.current().start()
def app(): from web.core.app import WebApplication app = WebApplication.instance() or WebApplication() yield app
def app(): app = WebApplication.instance() or WebApplication() yield app
def app(event_loop): client = AsyncIOMotorClient(io_loop=event_loop) app = WebApplication.instance() or WebApplication() db = client.enaml_web_test_db app.database = db yield app
def _get_database(self): db = WebApplication.instance().database if db is None: raise EnvironmentError("No database set!") return db
def app(event_loop): app = WebApplication.instance() or WebApplication() yield app