Преглед на файлове

text_print support `inline` parameter

wangweimin преди 5 години
родител
ревизия
a27641c605
променени са 2 файла, в които са добавени 7 реда и са изтрити 5 реда
  1. 3 2
      pywebio/html/js/form.js
  2. 4 3
      pywebio/output.py

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

@@ -141,7 +141,8 @@
 
 
     // OutputController.prototype.get_[output_type]_element return a jQuery obj
     // OutputController.prototype.get_[output_type]_element return a jQuery obj
     OutputController.prototype.get_text_element = function (spec) {
     OutputController.prototype.get_text_element = function (spec) {
-        var elem = $('<p></p>');
+        var elem = spec.inline ? $('<span></span>') : $('<p></p>');
+        spec.content = spec.content.replace(/ /g, '\u00A0');
         // make '\n' to <br/>
         // make '\n' to <br/>
         var lines = (spec.content || '').split('\n');
         var lines = (spec.content || '').split('\n');
         for (var idx = 0; idx < lines.length - 1; idx++)
         for (var idx = 0; idx < lines.length - 1; idx++)
@@ -190,7 +191,7 @@
         if (msg.spec.auto_scroll_bottom !== undefined)
         if (msg.spec.auto_scroll_bottom !== undefined)
             AutoScrollBottom = msg.spec.auto_scroll_bottom;
             AutoScrollBottom = msg.spec.auto_scroll_bottom;
         if (msg.spec.set_anchor !== undefined) {
         if (msg.spec.set_anchor !== undefined) {
-            this.container_elem.find(`#${msg.spec.set_anchor}`).attr('id','');
+            this.container_elem.find(`#${msg.spec.set_anchor}`).attr('id', '');
             this.container_elem.append(`<div id="${msg.spec.set_anchor}"></div>`);
             this.container_elem.append(`<div id="${msg.spec.set_anchor}"></div>`);
         }
         }
         if (msg.spec.clear_before !== undefined)
         if (msg.spec.clear_before !== undefined)

+ 4 - 3
pywebio/output.py

@@ -85,7 +85,7 @@ def _put_content(type, ws=None, anchor=None, before=None, after=None, **other_sp
     (ws or Global.active_ws).write_message(json.dumps(msg))
     (ws or Global.active_ws).write_message(json.dumps(msg))
 
 
 
 
-def text_print(text, *, ws=None, anchor=None, before=None, after=None):
+def text_print(text, inline=False, ws=None, anchor=None, before=None, after=None):
     """
     """
     输出文本内容
     输出文本内容
     :param text:
     :param text:
@@ -94,7 +94,7 @@ def text_print(text, *, ws=None, anchor=None, before=None, after=None):
     :param after:
     :param after:
     :return:
     :return:
     """
     """
-    _put_content('text', content=text, ws=ws, anchor=anchor, before=before, after=after)
+    _put_content('text', content=text, inline=inline, ws=ws, anchor=anchor, before=before, after=after)
 
 
 
 
 def put_html(html, anchor=None, before=None, after=None):
 def put_html(html, anchor=None, before=None, after=None):
@@ -210,7 +210,8 @@ def buttons(buttons, onclick, small=False, save=None, mutex_mode=False, anchor=N
     assert not (before and after), "Parameter 'before' and 'after' cannot be specified at the same time"
     assert not (before and after), "Parameter 'before' and 'after' cannot be specified at the same time"
     btns = _format_button(buttons)
     btns = _format_button(buttons)
     callback_id = register_callback(onclick, save, mutex_mode)
     callback_id = register_callback(onclick, save, mutex_mode)
-    _put_content('buttons', callback_id=callback_id, buttons=btns, small=small, anchor=anchor, before=before, after=after)
+    _put_content('buttons', callback_id=callback_id, buttons=btns, small=small, anchor=anchor, before=before,
+                 after=after)
 
 
 
 
 def put_file(name, content, anchor=None, before=None, after=None):
 def put_file(name, content, anchor=None, before=None, after=None):