def test_variables(): page = Page() input1 = page.new_input(id='input1') page.start(open_browser=False) output = subprocess.check_output(['awe', '-l', 'ls-variables']) parsed_output = json.loads(output) assert parsed_output[input1.id] == { 'id': input1.id, 'value': '', 'version': 0 } output = subprocess.check_output( ['awe', '-l', 'get-variable', '-v', input1.id]) parsed_output = json.loads(output) assert parsed_output == {'id': input1.id, 'value': '', 'version': 0} subprocess.check_call( ['awe', 'new-variable', '-d', 'initial-value', '-v', 'variable1']) assert page._registry.variables['variable1'].get_variable() == { 'id': 'variable1', 'value': 'initial-value', 'version': 0 } subprocess.check_call( ['awe', 'update-variable', '-d', 'new-value', '-v', 'variable1']) assert page._registry.variables['variable1'].get_variable() == { 'id': 'variable1', 'value': 'new-value', 'version': 1 }
def main(): now = time.time() page = Page('Showcase') grid = page.new_grid(columns=3, props={'gutter': 12}) grid.new_card('Card 1') card = grid.new_card() tabs = grid.new_tabs() collapse = grid.new_collapse() grid.new_chart([(now + i, -i) for i in range(100)], transform='numbers') grid.new_table(['Header 1', 'Header 2', 'Header 3'], page_size=4).extend([[ 'Value {}'.format(i), 'Value {}'.format(i + 1), 'Value {}'.format(i + 2) ] for i in range(1, 20, 3)]) grid.new_divider() grid.new_button(lambda: None, 'Button 1', block=True) grid.new_input() grid.new_icon('heart', theme='twoTone', two_tone_color='red') inline = grid.new_inline() card.new_text('Card Text 1') card.new_text('Card Text 2') tabs.new_tab('Tab 1').new_text('Tab 1 Text') tabs.new_tab('Tab 2').new_text('Tab 2 Text') tabs.new_tab('Tab 3').new_text('Tab 3 Text') tabs.new_tab('Tab 4').new_text('Tab 4 Text') collapse.new_panel('Panel 1', active=True).new_text('Panel 1 Text') collapse.new_panel('Panel 2').new_text('Panel 2 Text') collapse.new_panel('Panel 3').new_text('Panel 3 Text') collapse.new_panel('Panel 4').new_text('Panel 4 Text') collapse.new_panel('Panel 5').new_text('Panel 5 Text') inline.new_inline('inline 1') inline.new_inline('inline 2') inline.new_inline('inline 3') page.start(True)
def main(): title = 'Awe Examples' page = Page(title, width=900) page.register(HighlightJS) page.new('h1').new_text(title) page.new_text('Examples page was created with awe.\n') collapse = page.new_collapse() for example in examples.examples_order: config = examples.exported_examples[example] this_dir = os.path.dirname(__file__) py_file = os.path.join(this_dir, '{}.py'.format(example)) md_file = os.path.join(this_dir, '{}.md'.format(example)) github_link = 'https://github.com/dankilman/awe/blob/master/examples/{}.py'.format( example) static_url = 'https://s3.amazonaws.com/awe-static-files/examples/{}.html'.format( example) image_url = 'https://s3.amazonaws.com/awe-static-files/examples/{}.{}'.format( example, config['extension']) panel = collapse.new_panel('examples/{}.py'.format(example), active=True) (panel.new('h2').s.new_link(github_link).new_inline( 'examples/{}.py'.format(example)).n.new_inline(' ').new_link( static_url).new_inline(' [static demo]').p) with open(md_file) as f: panel.new_markdown(f.read()) panel.new('img', props={'src': image_url}, style={'maxWidth': '100%'}) panel.new_divider() with open(py_file) as f: panel.new('pre').new('code').new_inline( f.read(), style={'borderRadius': '2px'}, props={'className': 'python'}, ) page.start(block=True)
def test_element_creation_modification_and_call(): page = Page() page.start(open_browser=False) subprocess.check_call([ 'awe', 'new', '-o', 'Text: Hello World', '-p', 'props: {key1: value1}' ]) text1 = page.children[0] assert isinstance(text1, view.Text) assert text1.text == 'Hello World' assert text1.props['key1'] == 'value1' subprocess.check_call(['awe', 'new-prop', '-e', text1.id, '-n', 'prop1']) assert 'prop1' in text1._prop_children subprocess.check_call( ['awe', 'update-data', '-e', text1.id, '-d', 'text: New Text']) assert text1.text == 'New Text' subprocess.check_call( ['awe', 'update-props', '-e', text1.id, '-p', 'key1: value11']) assert text1.props['key1'] == 'value11' subprocess.check_call( ['awe', 'update-prop', '-e', text1.id, '-p', 'key1', '-v', 'value12']) assert text1.props['key1'] == 'value12' subprocess.check_call([ 'awe', 'call', '-e', text1.id, '-m', 'update_props', '-k', 'props: {key1: value13}' ]) assert text1.props['key1'] == 'value13' subprocess.check_call(['awe', 'remove', '-e', text1.id]) assert page.children == []
def main(): page = Page() page.new_text('single line') page.new_text() page.new_text('line 1\nline 2\nline3\n') page.new_text('other single line') page.start(block=True)
def main(): page = Page() page.start() for i in range(3): time.sleep(1) page.new_text('1') page.new_text('2') page.block()
def main(): page = Page() data = generate_random_data(1) chart = page.new_chart(data=data, transform='2to31', moving_window=3 * 60) page.start() while True: time.sleep(5) chart.add(generate_random_data(1))
def main(): page = Page() popover = page.new(Popover, title='Some Title') popover.new_button(lambda: None, 'Hover Me!') content = popover.new_prop('content') content.new_text('line 1') content.new(Moment) page.start(block=True)
def main(): page = Page() page.start() page.new_text('Header', style={'fontSize': '1.5em', 'color': '#ff0000'}) for i in range(20): page.new_text('{} hello {}'.format(i, i), style={'color': 'blue'}) time.sleep(2) page.block()
def main(): page = Page() b = page.new_button(do_stuff, id='button1') b.count = 0 page.new_input(id='input1') page.new_input(placeholder='Input 2, write anything!', on_enter=do_stuff, id='input2') page.start(block=True)
def main(): args = (1, 3) page = Page() data = generate_random_data(*args) chart = page.new_chart(data=data, transform='numbers') page.start() while True: time.sleep(1) chart.add(generate_random_data(*args))
def main(): page = Page() collapse = page.new_collapse() panel1 = collapse.new_panel('Panel 1', active=True) panel1.new_text('Hello From Panel 1') panel2 = collapse.new_panel('Panel 2', active=False) panel2.new_text('Hello From Panel2') panel3 = collapse.new_panel('Panel 3') panel3.new_text('Hello From Panel3') page.start(block=True)
def main(): page = Page() kitchen = Kitchen(page) page.start() try: for i in range(1000): kitchen.update(i) time.sleep(5) except KeyboardInterrupt: pass
def wrapper(fn): page = Page(**page_kwargs) page.start(open_browser=False) @retry() def result(): driver.get('http://localhost:{}'.format(page._port)) fn() return result
def test_ls_and_get(): page = Page() text1 = page.new_text() page.start(open_browser=False) output = subprocess.check_output(['awe', '-l', 'ls']) parsed_output = json.loads(output) assert parsed_output[text1.id]['id'] == text1.id output = subprocess.check_output(['awe', '-l', 'get', '-e', text1.id]) parsed_output = json.loads(output) assert parsed_output['id'] == text1.id
def main(): page = Page() collapse = page.new_collapse() panel1 = collapse.new_panel('Panel 1', active=True) panel1.new_text('Hello From Panel 1') panel2 = collapse.new_panel(active=False) panel2.header.new_icon('pie-chart') panel2.header.new_inline(' Panel 2') panel2.new_text('Hello From Panel2') panel3 = collapse.new_panel('Panel 3') panel3.new_text('Hello From Panel3') page.start(block=True)
def test_call_function(): state = {} def fn(**kwargs): state.update(kwargs) page = Page() page.new_button(fn, 'function', id='button1') page.start(open_browser=False) subprocess.check_call( ['awe', 'call-function', '-f', 'button1', '-k', 'key1: value1']) assert state == {'key1': 'value1'}
def main(): page = Page() page.new_markdown(''' # Hello There This is a markdown document. Thanks react-markdown! ## Let's try a list 1. Item 1 1. Item 2 1. Item 3 ''') page.start(block=True)
def main(): page = Page() data = generate_random_data() chart = page.new_chart(data=data, transform={ 'type': 'flat', 'chart_mapping': ['color', 'fruit'], 'series_mapping': ['temp', 'city'], 'value_key': 'value' }, moving_window=3 * 60) page.start() while True: time.sleep(0.7) chart.add(generate_random_data())
def run(): page = Page() content = page.new(page_layout) ref = content.ref page.start() for i in range(1000): ref.table1.append([i, i**2, i**3]) ref.table2.prepend([-i, -i * 12]) ref.table3.append([-i, -i**2, -i**3]) ref.table4.append([i, i * 12]) ref.text1.text = '4 Text: {}'.format(i * 3) ref.text2.text = '4 Text {}'.format(i * 4) ref.card1.children[0].text = '{} Time: {}'.format(i, time.time()) ref.divider1.update_prop('dashed', not ref.divider1.props.get('dashed')) time.sleep(5)
def main(): chart_id = 'chart1' # normally, when using the API client, the page is started elsewhere. # for the sake of keeping this example simple, the page is started here. page = Page() page.new_chart(data=[[0]], transform='numbers', id=chart_id) page.start() # create an API client instance client = APIClient() # add points to the chart in a loop for i in range(10): # data is a list of entries. in this case, because we are using the numbers transformer, # each entry is a list of numbers itself. client.call_method(chart_id, 'add', {'data': [[i]]}) time.sleep(1)
def main(): page = Page() b = page.element_builder page.new('h1').new_text('Simple Report') page.new_text('''Things weren't always so good for Foxy Fox. There were days when Fox had to do {thing}, which was hard and not very satisfying. '''.format(thing='documentation')) page.new('div').s.new_inline('But things are ').n.new('em').new_inline( 'better').n.new_inline(' now.') page.new_text() table = page.new_table(['Day', 'Number Of Emotions']) for i in range(5): number = random.randint(0, 1000) url = 'https://www.google.com/search?q={}'.format(number) table.append([ 'Day {}'.format(i), b.link(url).s.new('em').new_inline( str(number)).n.new_inline(' Emotions') ]) page.start(block=True)
def start(ctx, title, width, open_browser, obj, params, style, host, port, websocket_port): """ Start a new page. """ try: page = Page(title=title, width=width, host=host, port=port, websocket_port=websocket_port, style=ctx.parse_object(style)) page.start(open_browser=open_browser) if obj: obj = ctx.parse_object(obj) params = ctx.parse_object(params) page.new(obj, **params) page.block() except Exception: if ctx.quiet: sys.exit(1) else: raise
def test_offline(): page = Page(offline=True) # shouldn't block page.start(block=True) page.block()
def page(): result = Page() result.start(open_browser=False) return result
def test_status(): with pytest.raises(subprocess.CalledProcessError): subprocess.check_call(['awe', 'status']) page = Page() page.start(open_browser=False) subprocess.check_call(['awe', 'status'])
def main(): page = Page('Page Properties', width=600, style={'backgroundColor': 'red'}) page.new_card('hello') page.start(block=True)
def main(): page = Page() grid = page.new_grid(columns=3) for _ in range(3): grid.new_card(updater=updater) page.start(block=True)
def main(): page = Page() page.new_input(id='query', on_enter=run_query) page.new_table(headers=['one', 'two', 'three'], id='table') page.start(block=True)
def main(): page = Page() page.new_text('Hello World!') page.start(block=True)