wangweimin пре 3 година
родитељ
комит
434ebacac9

+ 1 - 0
pywebio/__init__.py

@@ -2,6 +2,7 @@ from . import input  # make PyCharm understand `pywebio.input.xxx` expression
 from . import output
 from . import platform
 from . import session
+from . import pin
 
 from .__version__ import __author__, __author_email__, __license__
 from .__version__ import __description__, __url__, __version__

+ 1 - 1
pywebio/io_ctrl.py

@@ -6,7 +6,7 @@ import json
 import logging
 from collections import UserList
 from functools import partial, wraps
-from collections.abc import Mapping
+
 from .session import chose_impl, next_client_event, get_current_task_id, get_current_session
 from .utils import random_str
 

+ 1 - 1
pywebio/output.py

@@ -1461,7 +1461,7 @@ def popup(title, content=None, size=PopupSize.NORMAL, implicit_close=True, closa
     """
     Show a popup.
 
-    ⚠️: In PyWebIO, you can't shoe multiple popup windows at the same time. Before displaying a new pop-up window, the existing popup on the page will be automatically closed. You can use `close_popup()` to close the popup manually.
+    ⚠️: In PyWebIO, you can't show multiple popup windows at the same time. Before displaying a new pop-up window, the existing popup on the page will be automatically closed. You can use `close_popup()` to close the popup manually.
 
     :param str title: The title of the popup.
     :type content: list/str/put_xxx()

+ 6 - 1
pywebio/pin.py

@@ -120,7 +120,6 @@ Pin utils
 
 import string
 
-from pywebio.input import *
 from pywebio.input import parse_input_update_spec
 from pywebio.output import Scope, OutputPosition, Output
 from pywebio.output import _get_output_spec
@@ -147,6 +146,7 @@ def _pin_output(single_input_return, scope, position):
 def put_input(name, type='text', *, label='', value=None, placeholder=None, readonly=None, datalist=None,
               help_text=None, scope=Scope.Current, position=OutputPosition.BOTTOM) -> Output:
     """Output an input widget. Refer to: `pywebio.input.input()`"""
+    from pywebio.input import input
     check_name(name)
     single_input_return = input(name=name, label=label, value=value, type=type, placeholder=placeholder,
                                 readonly=readonly, datalist=datalist, help_text=help_text)
@@ -156,6 +156,7 @@ def put_input(name, type='text', *, label='', value=None, placeholder=None, read
 def put_textarea(name, *, label='', rows=6, code=None, maxlength=None, minlength=None, value=None, placeholder=None,
                  readonly=None, help_text=None, scope=Scope.Current, position=OutputPosition.BOTTOM) -> Output:
     """Output a textarea widget. Refer to: `pywebio.input.textarea()`"""
+    from pywebio.input import textarea
     check_name(name)
     single_input_return = textarea(
         name=name, label=label, rows=rows, code=code, maxlength=maxlength,
@@ -166,6 +167,7 @@ def put_textarea(name, *, label='', rows=6, code=None, maxlength=None, minlength
 def put_select(name, options=None, *, label='', multiple=None, value=None, help_text=None,
                scope=Scope.Current, position=OutputPosition.BOTTOM) -> Output:
     """Output a select widget. Refer to: `pywebio.input.select()`"""
+    from pywebio.input import select
     check_name(name)
     single_input_return = select(name=name, options=options, label=label, multiple=multiple,
                                  value=value, help_text=help_text)
@@ -175,6 +177,7 @@ def put_select(name, options=None, *, label='', multiple=None, value=None, help_
 def put_checkbox(name, options=None, *, label='', inline=None, value=None, help_text=None,
                  scope=Scope.Current, position=OutputPosition.BOTTOM) -> Output:
     """Output a checkbox widget. Refer to: `pywebio.input.checkbox()`"""
+    from pywebio.input import checkbox
     check_name(name)
     single_input_return = checkbox(name=name, options=options, label=label, inline=inline, value=value,
                                    help_text=help_text)
@@ -184,6 +187,7 @@ def put_checkbox(name, options=None, *, label='', inline=None, value=None, help_
 def put_radio(name, options=None, *, label='', inline=None, value=None, help_text=None,
               scope=Scope.Current, position=OutputPosition.BOTTOM) -> Output:
     """Output a radio widget. Refer to: `pywebio.input.radio()`"""
+    from pywebio.input import radio
     check_name(name)
     single_input_return = radio(name=name, options=options, label=label, inline=inline, value=value,
                                 help_text=help_text)
@@ -193,6 +197,7 @@ def put_radio(name, options=None, *, label='', inline=None, value=None, help_tex
 def put_slider(name, *, label='', value=0, min_value=0, max_value=100, step=1, required=None, help_text=None,
                scope=Scope.Current, position=OutputPosition.BOTTOM) -> Output:
     """Output a slide widget. Refer to: `pywebio.input.slider()`"""
+    from pywebio.input import slider
     check_name(name)
     single_input_return = slider(name=name, label=label, value=value, min_value=min_value, max_value=max_value,
                                  step=step, required=required, help_text=help_text)

+ 1 - 0
webiojs/src/handlers/script.ts

@@ -41,6 +41,7 @@ export class ScriptHandler implements CommandHandler {
                     data: value === undefined ? null : value
                 });
             }).catch((error) => {
+                console.log('Exception occurred in user code of `run_script` command: \n%s', error);
                 state.CurrentSession.send_message({event: "js_yield", task_id: msg.task_id, data: null});
             });
         }

+ 2 - 2
webiojs/src/main.ts

@@ -1,8 +1,8 @@
 import {config as appConfig, state} from "./state";
-import {ClientEvent, Command, HttpSession, is_http_backend, pushData, Session, WebSocketSession} from "./session";
+import {Command, HttpSession, is_http_backend, Session, WebSocketSession} from "./session";
 import {InputHandler} from "./handlers/input"
 import {OutputHandler} from "./handlers/output"
-import {SessionCtrlHandler, CommandDispatcher} from "./handlers/base"
+import {CommandDispatcher, SessionCtrlHandler} from "./handlers/base"
 import {PopupHandler} from "./handlers/popup";
 import {openApp} from "./utils";
 import {ScriptHandler} from "./handlers/script";

+ 3 - 4
webiojs/src/models/pin.ts

@@ -1,6 +1,5 @@
 import {get_input_item_from_type} from "./input/index"
 import {InputItem} from "./input/base";
-import {error_alert} from "../utils";
 import {t} from "../i18n";
 
 let after_show_callbacks: (() => void) [] = [];
@@ -23,7 +22,7 @@ export function GetPinValue(name: string) {
 }
 
 export function PinUpdate(name: string, attributes: { [k: string]: any }) {
-    name2input[name].update_input({attributes:attributes});
+    name2input[name].update_input({attributes: attributes});
 }
 
 let onchange_callbacks: { [name: string]: ((val: any) => void)[] } = {}; // name->[]
@@ -53,7 +52,7 @@ export let PinWidget = {
     handle_type: 'pin',
     get_element: function (spec: any) {
         let input_spec = spec.input;
-        if(input_spec.name in name2input){
+        if (input_spec.name in name2input) {
             let tip = `<p style="color: grey; border:1px solid #ced4da; padding: .375rem .75rem;">${t("duplicated_pin_name")}</p>`;
             name2input[input_spec.name].element.replaceWith(tip);
         }
@@ -62,7 +61,7 @@ export let PinWidget = {
         input_spec.onblur = true;
         let InputClass = get_input_item_from_type(input_spec.type);
         let input_item = new InputClass(input_spec, null, (event, input_item) => {
-            if(event=='change')
+            if (event == 'change')
                 trigger_onchange_event(input_spec.name, input_item.get_value());
         });
 

+ 1 - 1
webiojs/src/session.ts

@@ -329,7 +329,7 @@ export function is_http_backend(backend_addr: string) {
 }
 
 
-// 向服务端发送数据
+// Send data to backend
 export function pushData(data: any, callback_id: string) {
     if (state.CurrentSession === null)
         return console.error("can't invoke PushData when WebIOController is not instantiated");

+ 3 - 3
webiojs/src/state.ts

@@ -1,6 +1,6 @@
 import {Session} from "./session";
 
-// 运行时状态
+// Runtime state
 export let state = {
     AutoScrollBottom: false,  // 是否有新内容时自动滚动到底部
     CurrentSession: null as Session,  // 当前正在活跃的会话
@@ -8,10 +8,10 @@ export let state = {
     InputPanelMinHeight: 300,  // 输入panel的最小高度
     InputPanelInitHeight: 300,  // 输入panel的初始高度
     FixedInputPanel:true,
-    AutoFocusOnInput:true
+    AutoFocusOnInput:true,
 };
 
-// 应用配置
+// App config
 export let config = {
     codeMirrorModeURL: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.52.2/mode/%N/%N.min.js",
     codeMirrorThemeURL: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.52.2/theme/%N.min.css",