From b7b9c07ca507765c0c15183c42c5e2df3ada51b1 Mon Sep 17 00:00:00 2001 From: Haoming Date: Mon, 22 Jan 2024 10:19:28 +0800 Subject: [PATCH] add init settings Addressing #7 --- README.md | 9 +++++---- README_ZH.md | 7 ++++--- javascript/prompt_format.js | 28 ++++++++++++++++++++++------ scripts/pf_settings.py | 5 ++++- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 707334b..1fad397 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,12 @@ Sometimes, when you type too fast or copy prompts from all over the places, you - [x] Toggle between auto formatting and manual formatting - In `Auto`: The process is ran whenever you press **Generate** - In `Manual`: The process is only ran when you press the **Format** button -- [x] **[New]** Use `Shift + ScrollWheel` to quickly move the hovered tag *(determined by **commas**)* around the prompt +- [x] Use `Shift + ScrollWheel` to quickly move the hovered tag *(determined by **commas**)* around the prompt +- [x] **[New]** You can now toggle which features to enable/disable by default in `System` section of the **Settings** tab ## Note -1. Since the auto formatting is triggered at the same time as the generation, -the immediate image will not have its metadata updated unless you already did manual formatting beforehand. +1. Since the formatting in `Auto` mode is triggered at the same time as the generation, +the immediate image will not have its metadata updated (unless you already did manual formatting beforehand). 2. Some Extensions *(**eg.** [tagcomplete](https://github.com/DominikDoom/a1111-sd-webui-tagcomplete))* listen to the text editing event, -meaning the formatting will cause them to trigger. You can disable updating the actual prompts in the **System** section of the **Settings** tab. +meaning the formatting will cause them to trigger. You can disable updating the actual prompts in the `System` section of the **Settings** tab. diff --git a/README_ZH.md b/README_ZH.md index c27ef43..f04c753 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -24,10 +24,11 @@ - [x] 按下`Auto Format`以在手動與自動間切換 - `自動`: 每次按下 **生成 (Generate)** 時處裡 - `手動`: 手動按下 **Format** 時才處裡 -- [x] **[New]** 使用`Shift + 滾輪`來橫移目前游標所在的單字 *(由**逗點**決定)* +- [x] 使用`Shift + 滾輪`來橫移目前游標所在的單字 *(由**逗點**決定)* +- [x] **[New]** 可以在 **Settings** 頁面的 `System` 區開啟/關閉某些預設功能 ## 注意 -1. 由於自動校正和生成是同時觸發,除非你有用手動校正,不然當下所產的圖片之內部資料並不會被更新。 +1. 由於`自動`校正和生成是同時觸發,除非有先用過`手動`校正,不然當下所產的第一章圖片之內部資料並不會被更新。 2. 有些擴充 *(如. [tagcomplete](https://github.com/DominikDoom/a1111-sd-webui-tagcomplete))* 追蹤文字的編輯事件,意即文字校正會導致它們啟動。 -你可以到 **Settings** 的 **System** 頁面關閉咒語的自動編輯。 +你可以到 **Settings** 頁面的 `System` 區關閉咒語的自動編輯。 diff --git a/javascript/prompt_format.js b/javascript/prompt_format.js index 14c5a31..96f33c2 100644 --- a/javascript/prompt_format.js +++ b/javascript/prompt_format.js @@ -76,6 +76,9 @@ class LeFormatter { if (!remove) return tag; + if (this.cachedCards == null) + this.cache_Cards(); + // [start:end:step] OR const chucks = tag.split(':').map(c => c.trim()); @@ -282,14 +285,29 @@ class LeFormatter { const config = gradioApp().getElementById('setting_pf_disableupdateinput').querySelector('input[type=checkbox]'); return !config.checked; } + + static defaultAuto() { + const config = gradioApp().getElementById('setting_pf_startinauto').querySelector('input[type=checkbox]'); + return config.checked; + } + + static defaultDedupe() { + const config = gradioApp().getElementById('setting_pf_startwithdedupe').querySelector('input[type=checkbox]'); + return config.checked; + } + + static defaultRemoveUnderscore() { + const config = gradioApp().getElementById('setting_pf_startwithrmudscr').querySelector('input[type=checkbox]'); + return config.checked; + } } onUiLoaded(async () => { const Modes = ['txt', 'img']; - var autoRun = true; - var dedupe = true; - var removeUnderscore = false; + var autoRun = LeFormatter.defaultAuto(); + var dedupe = LeFormatter.defaultDedupe(); + var removeUnderscore = LeFormatter.defaultRemoveUnderscore(); const manualBtn = LeFormatter.manualButton({ onClick: () => { @@ -298,7 +316,7 @@ onUiLoaded(async () => { } }); - manualBtn.style.display = 'none'; + manualBtn.style.display = autoRun ? 'none' : 'block'; const autoCB = LeFormatter.checkbox('Auto Format', autoRun, { onChange: (checked) => { @@ -314,8 +332,6 @@ onUiLoaded(async () => { const underlineCB = LeFormatter.checkbox('Remove Underscores', removeUnderscore, { onChange: (checked) => { removeUnderscore = checked; - if (LeFormatter.cachedCards == null) - LeFormatter.cache_Cards(); } }); diff --git a/scripts/pf_settings.py b/scripts/pf_settings.py index 0eb0cb9..0764bd9 100644 --- a/scripts/pf_settings.py +++ b/scripts/pf_settings.py @@ -1,6 +1,9 @@ from modules import script_callbacks, shared def on_ui_settings(): - shared.opts.add_option("pf_disableupdateinput", shared.OptionInfo(False, "Prompt Format - Disable Update Input", section=("system", "System"))) + shared.opts.add_option("pf_disableupdateinput", shared.OptionInfo(False, "Prompt Format - Disable Update Input", section=("system", "System")).info("Enable this if you have Extensions, such as [tagcomplete], that subscribe to text editing event.")) + shared.opts.add_option("pf_startinauto", shared.OptionInfo(True, "Prompt Format - Start in Auto Mode", section=("system", "System"))) + shared.opts.add_option("pf_startwithdedupe", shared.OptionInfo(True, "Prompt Format - Start with Remove Duplicates", section=("system", "System"))) + shared.opts.add_option("pf_startwithrmudscr", shared.OptionInfo(False, "Prompt Format - Start with Remove Underscores", section=("system", "System"))) script_callbacks.on_ui_settings(on_ui_settings)