Browse Source

feat: session env `output_fixed_height` accept number as custom height

wangweimin 4 years ago
parent
commit
1741a000de
4 changed files with 15 additions and 5 deletions
  1. 7 0
      demos/set_env_demo.py
  2. 1 1
      docs/spec.rst
  3. 1 1
      pywebio/session/__init__.py
  4. 6 3
      webiojs/src/handlers/env.ts

+ 7 - 0
demos/set_env_demo.py

@@ -46,6 +46,13 @@ async def main():
             state['title'] = await input('请输入标题')
             set_env(title=state['title'])
             toast('已将标题设置为%r' % state['title'])
+        elif key == 'output_fixed_height':
+            act = await actions('选择要对output_fixed_height设置项进行的操作', ['设置为False', '自定义高度'])
+            if act == '自定义高度':
+                state['output_fixed_height'] = await input('请输入输出区高度(像素)', type=NUMBER)
+            else:
+                state['output_fixed_height'] = False
+            set_env(output_fixed_height=state['output_fixed_height'])
         elif key in state:
             state[key] = not (state[key])
             set_env(**{key: state[key]})

+ 1 - 1
docs/spec.rst

@@ -257,7 +257,7 @@ set_env
 
 * title (str): 设定标题
 * output_animation (bool): 是否在输出内容时,使用过渡动画
-* output_fixed_height (bool): 设置是否输出区固定高度
+* output_fixed_height (int/bool): 输出区高度(单位为css像素值),0或False表示不固定高度
 * auto_scroll_bottom (bool): 是否在内容输出时将页面自动滚动到底部
 * http_pull_interval (int): HTTP轮训后端消息的周期(单位为毫秒,默认1000ms),仅在使用HTTP的连接中可用
 

+ 1 - 1
pywebio/session/__init__.py

@@ -288,7 +288,7 @@ def set_env(**env_info):
     * ``output_animation`` (bool): 是否启用输出动画(在输出内容时,使用过渡动画),默认启用
     * ``auto_scroll_bottom`` (bool): 是否在内容输出时将页面自动滚动到底部,默认启用
     * ``http_pull_interval`` (int): HTTP轮训后端消息的周期(单位为毫秒,默认1000ms),仅在使用HTTP的连接中可用
-    * ``output_fixed_height`` (bool): 是否使用固定高度的输出区域(默认不启用)
+    * ``output_fixed_height`` (int/bool): 输出区高度(单位为css像素值),0或False表示不固定高度。默认不固定高度
 
     调用示例::
 

+ 6 - 3
webiojs/src/handlers/env.ts

@@ -16,11 +16,14 @@ export class EnvSettingHandler implements CommandHandler {
         }
 
         if (spec.output_fixed_height !== undefined) {
-            state.OutputFixedHeight = spec.output_fixed_height;
-            if (spec.output_fixed_height)
+            state.OutputFixedHeight = !!(spec.output_fixed_height);
+            if (spec.output_fixed_height) {
                 $('.container').removeClass('no-fix-height');  // todo 不规范
-            else
+                if (typeof spec.output_fixed_height == 'number')
+                    $('.mditor')[0].style.height = spec.output_fixed_height + 'px';
+            } else {
                 $('.container').addClass('no-fix-height');  // todo 不规范
+            }
         }
 
         if (spec.auto_scroll_bottom !== undefined)