Skip to content

Commit

Permalink
更新 v0.1.1 自动保存/加载用户配置选项 / Update v0.1.1 Automatically save/load user …
Browse files Browse the repository at this point in the history
…configuration options

- 将挂件名称更改为 `brython-editor` / Change the widget name to `brython-editor`.
- 自动保存用户设置 / Save user settings automatically.
- 自动加载用户设置 / Load user settings automatically.
  • Loading branch information
Zuoqiu-Yingyi committed Oct 26, 2021
1 parent 01a09d2 commit 271d920
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 120 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更改日志/CHANGE LOG

## v0.1.1/2021-10-26

- 将挂件名称更改为 `brython-editor` / Change the widget name to `brython-editor`.
- 自动保存用户设置 / Save user settings automatically.
- 自动加载用户设置 / Load user settings automatically.

## v0.1.0/2021-10-24

- 新建项目 / Create a new project
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ It is now on the shelves of the [Siyuan Notes Community Bazaar](https://github.c
- 输出面板 / Output panel
- 折叠/展开输出面板<br>
Fold/Unfold the output panel.
- 自动保存/加载用户设置<br>
Automatically save/load user settings.

# 开始 / START

Expand Down
31 changes: 11 additions & 20 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<script type="text/javascript" src="./brython/editor/ace/ace.js" charset="utf-8"></script>
<script type="text/javascript" src="./brython/editor/ace/ext-language_tools.js" charset="utf-8"></script>

<script type="text/python3" src="./main.py" id="tests_editor"></script>


<script>
function run_js() {
var cons = document.getElementById("console")
Expand All @@ -27,7 +26,7 @@
var t1 = (new Date()).getTime()
console.log("Javascript code run in " + (t1 - t0) + " ms")
}
</script>
</script>
</head>

<body onload="brython({debug:1})">
Expand All @@ -36,23 +35,15 @@
<span id="menu"></span>
<!-- <span class="logo"><a href="/index.html">brython</a></span> -->
<label id="debug">&nbsp;调试</label>
<input type="checkbox" id="set_debug" checked="">
<input type="checkbox" id="set_debug">
<label id="output">&nbsp;输出面板</label>
<input type="checkbox" id="set_output" checked="">
<!-- <label id="language">语言</label> -->
<!-- <span id="sel_lang"></span> -->
<!-- <label id="theme">主题</label> -->
<!-- <span id="sel_theme"></span> -->
<input type="checkbox" id="set_output">

<span id="version_label">&nbsp;Brython 版本: </span>
<span id="version"></span>
<!-- <button id="load_script">导入</button> -->
<!-- <button id="clear">清空</button> -->
<!-- <button id="run"> ▶ 运行</button> -->
<!-- <button id="show_console">Python</button> -->
<!-- <button id="show_js">Javascript</button> -->
<!-- <button id="share_code">分享</button> -->
</div>

</div>

<table id="container">
<tbody>
<tr>
Expand All @@ -64,7 +55,7 @@
<textarea id="console" autocomplete="off"></textarea>
</td>
</tr>

<tr>
<td>
Python code editor uses <a href="https://ace.c9.io/" target="_blank">Ace</a>.
Expand All @@ -76,9 +67,9 @@
</tr>
</tbody>
</table>



<script type="text/python3" src="./main.py" id="tests_editor"></script>
</body>

</html>
66 changes: 5 additions & 61 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from browser import document
from browser.widgets.menu import Menu
from package import editor

from package import editor, config

__BRYTHON__.language = 'zh-cn'

Expand Down Expand Up @@ -97,75 +98,18 @@ def init(language=None, theme=None):
},
}

themes = {
"ambiance": "ambiance",
"chaos": "chaos",
"chrome": "chrome",
"clouds": "clouds",
"clouds midnight": "clouds_midnight",
"cobalt": "cobalt",
"crimson editor": "crimson_editor",
"dawn": "dawn",
"dracula": "dracula",
"dreamweaver": "dreamweaver",
"eclipse": "eclipse",
"github": "github",
"gob": "gob",
"gruvbox": "gruvbox",
"idle fingers": "idle_fingers",
"iplastic": "iplastic",
"katzenmilch": "katzenmilch",
"kr theme": "kr_theme",
"kuroir": "kuroir",
"merbivore": "merbivore",
"merbivore soft": "merbivore_soft",
"monokai": "monokai",
"mono industrial": "mono_industrial",
"nord dark": "nord_dark",
"one dark": "one_dark",
"pastel on dark": "pastel_on_dark",
"solarized dark": "solarized_dark",
"solarized light": "solarized_light",
"sqlserver": "sqlserver",
"terminal": "terminal",
"textmate": "textmate",
"tomorrow": "tomorrow",
"tomorrow night": "tomorrow_night",
"tomorrow night blue": "tomorrow_night_blue",
"tomorrow night bright": "tomorrow_night_bright",
"tomorrow night eighties": "tomorrow_night_eighties",
"twilight": "twilight",
"vibrant ink": "vibrant_ink",
"xcode": "xcode",
}
themes = config.THEMES

for key in trans:
if key in document:
document[key].html = trans[key].get(language, trans[key]['zh-cn'])


def set_debug(ev):
if ev.target.checked:
__BRYTHON__.debug = 1
else:
__BRYTHON__.debug = 0


def set_output(ev):
if ev.target.checked:
document['left'].style.width = '50%'
document['right'].style.width = '50%'
else:
document['left'].style.width = '100%'
document['right'].style.width = '0%'
editor.refresh_warp()


__BRYTHON__.debug = int(document['set_debug'].checked)

# bindings
document['set_debug'].bind('change', set_debug)
document['set_output'].bind('change', set_output)
document['set_debug'].bind('change', editor.set_debug)
document['set_output'].bind('change', editor.set_output)

menu = Menu(document["menu"])
file_menu = menu.add_menu(trans['File'].get(language, trans['File']['zh-cn']))
Expand Down
51 changes: 51 additions & 0 deletions package/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,54 @@
'version': "/api/system/version",
'currentTime': "/api/system/currentTime",
}

DEFAULT_USER_CONFIG = {
'py_src': 'print(globals())\nprint(dir(__builtins__))',
'theme': 'one_dark',
'font_size': 16,
'wrap_flag': True,
'debug_flag': True,
'output_flag': True,
}

THEMES = {
"ambiance": "ambiance",
"chaos": "chaos",
"chrome": "chrome",
"clouds": "clouds",
"clouds midnight": "clouds_midnight",
"cobalt": "cobalt",
"crimson editor": "crimson_editor",
"dawn": "dawn",
"dracula": "dracula",
"dreamweaver": "dreamweaver",
"eclipse": "eclipse",
"github": "github",
"gob": "gob",
"gruvbox": "gruvbox",
"idle fingers": "idle_fingers",
"iplastic": "iplastic",
"katzenmilch": "katzenmilch",
"kr theme": "kr_theme",
"kuroir": "kuroir",
"merbivore": "merbivore",
"merbivore soft": "merbivore_soft",
"monokai": "monokai",
"mono industrial": "mono_industrial",
"nord dark": "nord_dark",
"one dark": "one_dark",
"pastel on dark": "pastel_on_dark",
"solarized dark": "solarized_dark",
"solarized light": "solarized_light",
"sqlserver": "sqlserver",
"terminal": "terminal",
"textmate": "textmate",
"tomorrow": "tomorrow",
"tomorrow night": "tomorrow_night",
"tomorrow night blue": "tomorrow_night_blue",
"tomorrow night bright": "tomorrow_night_bright",
"tomorrow night eighties": "tomorrow_night_eighties",
"twilight": "twilight",
"vibrant ink": "vibrant_ink",
"xcode": "xcode",
}
Loading

0 comments on commit 271d920

Please sign in to comment.