Browse Source

output fixed height mode option

wangweimin 5 years ago
parent
commit
909fffe89e
3 changed files with 45 additions and 3 deletions
  1. 32 1
      pywebio/html/index.html
  2. 9 2
      pywebio/html/js/form.js
  3. 4 0
      pywebio/output.py

+ 32 - 1
pywebio/html/index.html

@@ -35,13 +35,44 @@
             font-size: 13px
         }
 
+        .mditor {
+            height: 400px;
+            width: auto;
+        }
+
+        /*非固定行高模式*/
+        .no-fix-height {
+
+        }
+
+        .no-fix-height .mditor {
+            height: initial;
+            padding-top: 0;
+            border: 0;
+        }
+
+        .no-fix-height .mditor .body {
+            height: initial;
+            box-shadow: unset;
+        }
+
+        .no-fix-height .mditor .viewer {
+            height: initial;
+            padding-bottom: 10px;
+        }
+        .no-fix-height .mditor .head{
+            display: none;
+        }
+        .no-fix-height #input-container{
+            margin: 0 10px;
+        }
     </style>
 </head>
 
 <body>
 
 <div class="container">
-    <div tabindex="1" class="mditor preview" style="width:auto;height: 400px">
+    <div tabindex="1" class="mditor preview">
         <div class="head">
             <ul class="toolbar">
                 <span id="title">Interactive notebook</span>

+ 9 - 2
pywebio/html/js/form.js

@@ -124,8 +124,15 @@
                     this.handle_file(msg);
                 else
                     console.warn('Unknown output type:%s', msg.spec.type);
-            } else if (msg.command === 'output_ctl')
-                $('#title').text(msg.spec.title);  // todo 不规范
+            } else if (msg.command === 'output_ctl'){
+                if(msg.spec.title)
+                    $('#title').text(msg.spec.title);  // 直接使用#title不规范 todo
+                if(msg.spec.output_fixed_height!==undefined)
+                    if(msg.spec.output_fixed_height)
+                        $('.container').removeClass('no-fix-height');  // todo 不规范
+                    else
+                        $('.container').addClass('no-fix-height');  // todo 不规范
+            }
         }
     }
 

+ 4 - 0
pywebio/output.py

@@ -13,6 +13,10 @@ def set_title(title):
     send_msg('output_ctl', dict(title=title))
 
 
+def set_output_fixed_height(enabled=True):
+    send_msg('output_ctl', dict(output_fixed_height=enabled))
+
+
 def text_print(text, *, ws=None):
     if text is None:
         text = ''