wangweimin 5 роки тому
батько
коміт
4e9aba778f
6 змінених файлів з 50 додано та 26 видалено
  1. 22 0
      setup.py
  2. 4 6
      test.py
  3. 11 0
      wsrepl/__init__.py
  4. 11 3
      wsrepl/html/js/form.js
  5. 0 14
      wsrepl/interact.py
  6. 2 3
      wsrepl/ioloop.py

+ 22 - 0
setup.py

@@ -0,0 +1,22 @@
+from setuptools import setup, find_packages
+
+setup(
+    name='webio',
+    version='1.0.0',
+    description='Spider utils lib',
+    url='',
+    author='WangWeimin',
+    author_email='wangweimin@buaa.edu.com',
+    license='MIT',
+    packages=find_packages(),
+    include_package_data=True,
+    classifiers=[
+        "Programming Language :: Python :: 3",
+        "Programming Language :: Python :: 3.5",
+        "Programming Language :: Python :: 3.6",
+        "Programming Language :: Python :: 3.7",
+    ],
+    install_requires=[
+        'tornado>=4.2.0',
+    ]
+)

+ 4 - 6
test.py

@@ -5,6 +5,7 @@ import json
 
 from wsrepl.ioloop import start_ioloop
 from wsrepl.interact import *
+from wsrepl.output import *
 from tornado.gen import sleep
 
 
@@ -18,13 +19,10 @@ async def say_hello():
     # 向用户输出文字
     text_print("Welcome!!!")
 
-    res = await textarea('Text area', codemirror={
+    put_table([[str(i)] * 4 for i in range(5)])
+
+    res = await textarea('Text area', value='value',codemirror={
         'mode': "python",
-        'lineNumbers': True,  # 显示行数
-        'indentUnit': 4,  # 缩进单位为4
-        'styleActiveLine': True,  # 当前行背景高亮
-        'matchBrackets': True,  # 括号匹配
-        'lineWrapping': True,  # 自动换行
         'theme': 'darcula',  # 使用monokai模版 ,darcula:IDEA,
     })
     text_print(res)

+ 11 - 0
wsrepl/__init__.py

@@ -0,0 +1,11 @@
+"""The WebIO"""
+
+# version is a human-readable version number.
+
+# version_info is a four-tuple for programmatic comparison. The first
+# three numbers are the components of the version number.  The fourth
+# is zero for an official release, positive for a development branch,
+# or negative for a release candidate or beta (after the base version
+# number has been incremented)
+version = "0.1.0"
+version_info = (0, 1, 0, 0)

+ 11 - 3
wsrepl/html/js/form.js

@@ -436,7 +436,7 @@
     const textarea_input_tpl = `
 <div class="form-group">
     <label for="{{id_name}}">{{label}}</label>
-    <textarea id="{{id_name}}" aria-describedby="{{id_name}}_help" rows="{{rows}}" class="form-control" ></textarea>
+    <textarea id="{{id_name}}" aria-describedby="{{id_name}}_help" rows="{{rows}}" class="form-control" >{{value}}</textarea>
     <div class="invalid-feedback">{{invalid_feedback}}</div>  <!-- input 添加 is-invalid 类 -->
     <div class="valid-feedback">{{valid_feedback}}</div> <!-- input 添加 is-valid 类 -->
     <small id="{{id_name}}_help" class="form-text text-muted">{{help_text}}</small>
@@ -453,7 +453,7 @@
         // input_elem.on('blur', this.send_value_listener);
 
         // 将额外的html参数加到input标签上
-        const ignore_keys = make_set(['type', 'label', 'invalid_feedback', 'valid_feedback', 'help_text', 'rows', 'codemirror']);
+        const ignore_keys = make_set(['value','type', 'label', 'invalid_feedback', 'valid_feedback', 'help_text', 'rows', 'codemirror']);
         for (var key in this.spec) {
             if (key in ignore_keys) continue;
             input_elem.attr(key, this.spec[key]);
@@ -461,7 +461,15 @@
         if (spec.codemirror) {
             var that = this;
             setTimeout(function () {
-                that.code_mirror = CodeMirror.fromTextArea(that.element.find('textarea')[0], that.spec.codemirror);
+                var config = {
+                    'lineNumbers': true,  // 显示行数
+                    'indentUnit': 4,  //缩进单位为4
+                    'styleActiveLine': true,  // 当前行背景高亮
+                    'matchBrackets': true,  //括号匹配
+                    'lineWrapping': true,  //自动换行
+                };
+                for (var k in that.spec.codemirror) config[k] = that.spec.codemirror[k];
+                that.code_mirror = CodeMirror.fromTextArea(that.element.find('textarea')[0], config);
                 CodeMirror.autoLoadMode(that.code_mirror, that.spec.codemirror.mode);
             }, ShowDuration + 100);
         }

+ 0 - 14
wsrepl/interact.py

@@ -165,22 +165,8 @@ def actions(label, buttons, name='data'):
     return single_input(item_spec, valid_func, lambda d: d)
 
 
-def set_title(title):
-    send_msg('output_ctl', dict(title=title))
 
 
-def text_print(text, *, ws=None):
-    msg = dict(command="output", spec=dict(content=text, type='text'))
-    (ws or Global.active_ws).write_message(json.dumps(msg))
-
-
-def json_print(obj):
-    text = "```\n%s\n```" % json.dumps(obj, indent=4, ensure_ascii=False)
-    text_print(text)
-
-
-put_markdown = text_print
-
 
 def input_group(label, inputs, valid_func=None):
     """

+ 2 - 3
wsrepl/ioloop.py

@@ -83,9 +83,8 @@ def ws_handler(coro_func):
 
 def start_ioloop(coro_func, port=8080, debug=True, tornado_app_args=None):
     handlers = [(r"/test", ws_handler(coro_func)),
-                (r"/(.*)", StaticFileHandler,
-                 {"path": '%s/html/' % project_dir,
-                  'default_filename': 'index.html'})]
+                (r"/(.*)", StaticFileHandler, {"path": '%s/html/' % project_dir,
+                                               'default_filename': 'index.html'})]
 
     gen_log.setLevel(logging.DEBUG)
     tornado_app_args = tornado_app_args or {}