()
| 390 | |
| 391 | |
| 392 | def basic_input(): |
| 393 | js_res = yield eval_js('''(function(){ |
| 394 | for(var i=0;i<=limit;i++) |
| 395 | a += i; |
| 396 | return a; |
| 397 | })()''', a=0, limit=100) |
| 398 | assert js_res == 5050 |
| 399 | |
| 400 | age = yield input("How old are you?", type=NUMBER) |
| 401 | put_markdown(f'`{repr(age)}`') |
| 402 | |
| 403 | password = yield input("Input password", type=PASSWORD) |
| 404 | put_markdown(f'`{repr(password)}`') |
| 405 | |
| 406 | # 下拉选择框 |
| 407 | gift = yield select('Which gift you want?', ['keyboard', 'ipad']) |
| 408 | put_markdown(f'`{repr(gift)}`') |
| 409 | |
| 410 | # CheckBox |
| 411 | agree = yield checkbox("用户协议", options=['I agree to terms and conditions']) |
| 412 | put_markdown(f'`{repr(agree)}`') |
| 413 | |
| 414 | # Text Area |
| 415 | text = yield textarea('Text Area', rows=3, placeholder='Some text') |
| 416 | put_markdown(f'`{repr(text)}`') |
| 417 | |
| 418 | # 文件上传 |
| 419 | img = yield file_upload("Select a image:", accept="image/*", max_size=10 ** 7) |
| 420 | put_image(img['content'], title=img['filename']) |
| 421 | |
| 422 | # 输入参数 |
| 423 | res = yield input('This is label', type=TEXT, placeholder='This is placeholder,required=True', |
| 424 | help_text='This is help text', required=True) |
| 425 | put_markdown(f'`{repr(res)}`') |
| 426 | |
| 427 | # 取消表单 |
| 428 | res = yield input_group('cancel test', [input(name='cancel')], cancelable=True) |
| 429 | put_markdown(f'`{repr(res)}`') |
| 430 | |
| 431 | # 校验函数 |
| 432 | def check_age(p): # 检验函数校验通过时返回None,否则返回错误消息 |
| 433 | if p < 10: |
| 434 | return 'Too young!!' |
| 435 | if p > 60: |
| 436 | return 'Too old!!' |
| 437 | |
| 438 | age = yield input("How old are you?", type=NUMBER, validate=check_age, help_text='age in [10, 60]') |
| 439 | put_markdown(f'`{repr(age)}`') |
| 440 | |
| 441 | # Codemirror |
| 442 | code = yield textarea('Code Edit', code={ |
| 443 | 'mode': "python", # 编辑区代码语言 |
| 444 | 'theme': 'darcula', # 编辑区darcula主题, Visit https://codemirror.net/demo/theme.html#cobalt to get more themes |
| 445 | }, value='import something\n# Write your python code') |
| 446 | put_markdown(f'`{repr(code)}`') |
| 447 | |
| 448 | # 输入组 cancelable |
| 449 | info = yield input_group("Cancelable", [ |
nothing calls this directly
no test coverage detected
searching dependent graphs…