# Path: webalchemy/server.py
# def _generate_session_id():
# def async_delay(secs):
# def _dreload(module, dreload_blacklist_starting_with, just_visit=False):
#     def __dreload(mdl):
#     def initialize(self, **kwargs):
#     def get(self, *varargs):
# def async_delay(secs):
#     def on_open(self, info):
#     def handle_binary_message(self, message):
#     def on_close(self):
#     def on_message(self, message):
#     def send_data(self, text, data):
#     def flush_dom(self):
#     def please_reload(self):
#     def msg_to_sessions(self, msg, send_to_self=False, to_session_ids=None):
#     def prepare_session_for_general_reload(self):
#     def handle_binary_message(self, message):
#     def send_heartbeat(self):
#     def init_localdocument(self, message):
#     def handle_js_to_py_rpc_message(self, msg):
#     def rpc(self, f, *varargs, send_to_self=False, to_session_ids=None, **kwargs):
#     def __init__(self, app, kwa, router, cls, shared_wshandlers, dreload_blacklist_starting_with, shared_data,
#                  additional_monitored_files):
#     def set_additional_monitored_files(self, fns):
#     def update_app(self):
#     def __init__(self):
#     def get_store(self, uid):
#     def remove_store(self, uid):
# def run(app=None, **kwargs):
# def generate_static(app):
# class _MainHandler(tornado.web.RequestHandler):
# class WebSocketHandler(SockJSConnection):
# class _AppUpdater:
# class PrivateDataStore:


from webalchemy import server
    from hello_world_example import HellowWorldApp

class HellowWorldApp:
    def initialize(self, **kwargs):
        self.rdoc = kwargs['remote_document']
        self.print_hi = self.rdoc.translate(self.print_hi)
        self.rdoc.body.element(h1='Hello World!').events.add(click=self.clicked, translate=True)
        self.rdoc.body.element(h2='--------------')
        self.rdoc.stylesheet.rule('h1').style(
            color='#FF0000',
            marginLeft='75px',
            marginTop='75px',
            background='#00FF00'
        )

    def clicked(self):
        self.textContent = self.textContent[1:]
        rpc(self.handle_click_on_backend, 'some message', 'just so you see how to pass paramaters')
        srv(self.print_hi)()

    def handle_click_on_backend(self, sender_id, m1, m2):
        self.rdoc.body.element(h1=m1+m2)

    def print_hi(self):
        print('hi!')

if __name__ == '__main__':
    # this import is necessary because of the live editing. Everything else works OK without it

# Path: webalchemy/server.py
# def _generate_session_id():
# def async_delay(secs):
# def _dreload(module, dreload_blacklist_starting_with, just_visit=False):
#     def __dreload(mdl):
#     def initialize(self, **kwargs):
#     def get(self, *varargs):
# def async_delay(secs):
#     def on_open(self, info):
#     def handle_binary_message(self, message):
#     def on_close(self):
#     def on_message(self, message):
#     def send_data(self, text, data):
#     def flush_dom(self):
#     def please_reload(self):
#     def msg_to_sessions(self, msg, send_to_self=False, to_session_ids=None):
#     def prepare_session_for_general_reload(self):
#     def handle_binary_message(self, message):
#     def send_heartbeat(self):
#     def init_localdocument(self, message):
#     def handle_js_to_py_rpc_message(self, msg):
#     def rpc(self, f, *varargs, send_to_self=False, to_session_ids=None, **kwargs):
#     def __init__(self, app, kwa, router, cls, shared_wshandlers, dreload_blacklist_starting_with, shared_data,
#                  additional_monitored_files):
#     def set_additional_monitored_files(self, fns):
#     def update_app(self):
#     def __init__(self):
#     def get_store(self, uid):
#     def remove_store(self, uid):
# def run(app=None, **kwargs):
# def generate_static(app):
# class _MainHandler(tornado.web.RequestHandler):
# class WebSocketHandler(SockJSConnection):
# class _AppUpdater:
# class PrivateDataStore:


# Path: examples/hello_world/hello_world_example.py
from webalchemy import server
    from hello_world_example import HellowWorldApp


class HellowWorldApp:
    def initialize(self, **kwargs):
        self.rdoc = kwargs['remote_document']
        self.print_hi = self.rdoc.translate(self.print_hi)
        self.rdoc.body.element(h1='Hello World!').events.add(click=self.clicked, translate=True)
        self.rdoc.body.element(h2='--------------')
        self.rdoc.stylesheet.rule('h1').style(
            color='#FF0000',
            marginLeft='75px',
            marginTop='75px',
            background='#00FF00'
        )

    def clicked(self):
        self.textContent = self.textContent[1:]
        rpc(self.handle_click_on_backend, 'some message', 'just so you see how to pass paramaters')
        srv(self.print_hi)()

    def handle_click_on_backend(self, sender_id, m1, m2):
        self.rdoc.body.element(h1=m1+m2)

    def print_hi(self):
        print('hi!')

if __name__ == '__main__':
    # this import is necessary because of the live editing. Everything else works OK without it

    server.run(HellowWorldApp)