def handle_request(self, request): handle_request_button = Button( 'Crash in handle_request()', _id='handle_request', ) handle_input_event_button = Button( 'Crash in handle_input_event()', _id='handle_input_event', ) handle_input_event_button.hide() html = HTML( H2('Crashing Event Handler'), Div(), Button('Start refresh loop', _id='refresh-loop'), Button('Stop view', _id='stop-view'), Br(), Br(), handle_request_button, Button( 'Crash in handle_input_event_root()', _id='handle_input_event_root', ), handle_input_event_button, CrashWidget(), ) input_event = self.await_input_event(html=html) if input_event.node_has_id('handle_request'): raise ValueError('Success! Crash in handle_request()') handle_request_button.hide() handle_input_event_button.show() if input_event.node_has_id('stop-view'): return html if input_event.node_has_id('refresh-loop'): while True: html[1].set_text(str((datetime.now()))) self.show(html) self.sleep(1)
def handle_request(self, request): widget = HTML() interval = Select(values=[ (1, '1s', False), (0.5, '0.5s', True), (0.25, '0.25s', False), (0.01, '0.01s', False), ], ) html = HTML( H2('Interactive View'), Strong('Interval: '), interval, Br(), Br(), widget, ) while True: widget.clear() for i in range(0, 5): widget.append(Div('Div {}'.format(i + 1))) self.show(html) self.sleep(float(interval.value)) for i in range(0, 5): widget[i].insert(i + 1, Div('Div {}.{}'.format(i + 1, i + 1))) self.show(html) self.sleep(float(interval.value)) for i in range(0, 5): widget[i].style = {'color': 'red'} self.show(html) self.sleep(float(interval.value)) moving_div = Div('Div 6', style={'color': 'blue'}) for i in range(0, 5): widget[i].append(moving_div) self.show(html) self.sleep(float(interval.value)) self.show(html)
def handle_request(self, request): request_data = { 'GET': request.GET, 'POST': request.POST, } message = Div() html = HTML( H2('Form View'), Pre(pformat(request_data)), Button('Interactive GET', _id='interactive-get'), Button('Interactive POST', _id='interactive-post'), Br(), Button('Non Interactive GET', _id='non-interactive-get'), Button('Non Interactive POST', _id='non-interactive-post'), ) input_event = self.await_click(html=html) action = '.' method = 'post' if (input_event.node_has_id('non-interactive-get') or input_event.node_has_id('interactive-get')): method = 'get' html = HTML( H2('Form View'), message, Form( TextInput(name='text'), Submit('Submit'), method=method, action=action, ), ) if (input_event.node_has_id('non-interactive-get') or input_event.node_has_id('non-interactive-post')): message.set_text('View stopped') return html else: message.set_text('View waits for input events') self.await_input_event(html=html)
def handle_request(self, request): self.message = Div('Nothing clicked yet') self.html = HTML( H2('Class Based View'), self.message, Br(), Button('handle_input_event_root()', _id='handle_input_event_root'), Button('handle_input_event()', _id='handle_input_event'), Button('handle_request()', _id='handle_request'), Br(), Button('Stop View', _id='stop_view')) while True: input_event = self.await_click( self.html[-3], self.html[-1], html=self.html, ) if input_event.node == self.html[-1]: self.message.set_text('View Stopped') self.show(self.html) return self.message.set_text('handled by handle_request()')
def handle_request(self, request): try: html = HTML( H2('Async View'), Div(), Br(), Button('Sleep forever', _id='sleep-forever'), Button('Await short running coroutine', _id='await-short-running-coroutine'), Button('Await long running coroutine', _id='await-long-running-coroutine'), Button('Show HTML', _id='show-html'), Button('Crash', _id='crash'), ) input_event = self.await_input_event(html=html) if input_event.node_has_id('sleep-forever'): html[1].set_text('Sleeping forever') self.show(html) self.sleep(300) elif input_event.node_has_id('await-short-running-coroutine'): return_value = self.await_sync(short_running_coroutine()) html[1].set_text( 'short_running_coroutine() returned {}'.format( repr(return_value))) self.show(html) elif input_event.node_has_id('await-long-running-coroutine'): html[1].set_text('running long_running_coroutine()') self.show(html) self.await_sync(long_running_coroutine()) elif input_event.node_has_id('show-html'): self.await_sync(show_html(self)) return html finally: print('>> async view stopped')
def handle_request(self, request): now = Span() self.message = Div('Button not clicked') self.button = Button('Button') self.html = Div( H2('HTML Tree Locking View'), Div(Strong('Now: '), now), Br(), self.message, self.button, ) while True: now.set_text(datetime.now()) self.show(self.html) self.sleep(1)
def handle_request(self, request): now = Span() self.message = Div('Button not clicked') self.button = Button('Button') self.html = Div( H2('Server State Locking View'), Div(Strong('Now: '), now), Br(), self.message, self.button, ) while True: self.server.state['now'] = str(datetime.now()) now.set_text(self.server.state['now']) self.show(self.html) self.sleep(1)
def handle_request(self, request): colors = ['navy', 'maroon', 'green', 'teal', 'grey', 'purple', 'aqua'] style = { 'float': 'left', 'margin': '3px', 'width': '50px', 'height': '50px', 'cursor': 'pointer', 'background-color': colors[0], } pre = Pre( '{}', style={ 'background-color': 'lightgrey', }, ) html = Div( H2('Click Events'), Div( Div( Div( A('Link', href='/', events=[CLICK]), Br(), Br(), ), Div(style=style, events=[CLICK]), Div(style=style, events=[CLICK]), Div(style=style, events=[CLICK]), Div(style=style, events=[CLICK]), Div(style=style, events=[CLICK]), style={ 'float': 'left', 'width': '50%', }, ), Div( pre, style={ 'float': 'left', 'width': '50%', }, ), ), ) while True: input_event = self.await_click(html=html) data = { 'event_id': input_event.event_id, 'node': input_event.node._id, 'tag_name': input_event.node.tag_name, 'event_data': input_event.data } pre.set_text(pformat(data)) if input_event.node.tag_name == 'div': next_color = colors[ colors.index(input_event.node.style['background-color']) - 1] input_event.node.style['background-color'] = next_color
def handle_request(self, request): widget = TestWidget() interval = Select(values=[ (1, '1s', False), (0.5, '0.5s', True), (0.25, '0.25s', False), (0.01, '0.01s', False), ], ) html = HTML( H2('Widget Data'), 'This view tests the encoding and decoding of abstract widget data.', # NOQA Br(), Br(), 'The first value is the state the server has, the second is the ' 'second is the client state.', Br(), 'Both values should be equal at all times.', Br(), Br(), Strong('Interval: '), interval, Br(), Br(), widget, ) self.show(html) while True: # list widget.data = {'list': []} for i in range(6): widget.data['list'].append(i) widget.update_state() self.show(html) self.sleep(float(interval.value)) widget.data['list'].remove(2) widget.update_state() self.show(html) self.sleep(float(interval.value)) widget.data['list'].insert(2, 2) widget.update_state() self.show(html) self.sleep(float(interval.value)) widget.data['list'].clear() widget.update_state() self.show(html) self.sleep(float(interval.value)) widget.data['list'] = [5, 4, 3, 2, 1] widget.update_state() self.show(html) self.sleep(float(interval.value)) # dict widget.data = [{}] for i in range(6): widget.data[0][i] = i widget.update_state() self.show(html) self.sleep(float(interval.value)) widget.data[0].pop(2) widget.update_state() self.show(html) self.sleep(float(interval.value)) widget.data[0].clear() widget.update_state() self.show(html) self.sleep(float(interval.value)) widget.data[0] = {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5} widget.update_state() self.show(html) self.sleep(float(interval.value))