diff --git a/README-ja.md b/README-ja.md index 385f46b..269f784 100644 --- a/README-ja.md +++ b/README-ja.md @@ -23,6 +23,8 @@ **辞書モード**:テキストの一行目に`#dict`と記入すると2行目以降をコロンを挟んで「表示テキスト: 出力されるテキスト」と解釈して処理します。長い文章を簡潔なタイトルで把握することができます。 +**セクションモード**:テキストの一行目に`#section`と記入すると2行目以降を「\[表示テキスト\](改行)出力されるテキスト」の連続と解釈して処理します。表示テキストの行全体を角括弧で囲み、次の行から出力されるテキストを記入します。出力されるテキストは改行を含めることができます。csvやテキストファイル群から整形済みテキストを生成する[Pythonスクリプトが付属しています](./tools/README-ja.md)。 +  diff --git a/assets/slp04.jpg b/assets/slp04.jpg new file mode 100644 index 0000000..8b5072b Binary files /dev/null and b/assets/slp04.jpg differ diff --git a/tools/README-ja.md b/tools/README-ja.md new file mode 100644 index 0000000..d4508cd --- /dev/null +++ b/tools/README-ja.md @@ -0,0 +1,47 @@ +
+ English | + 日本語 (Japanese) +
+ +# Tools +[Single Line Picker](https://github.com/hetima/ComfyUI-SingleLinePicker) の動作を補助するPythonスクリプトです。 + + +## slp_buld_csv.py + +csvやtsvを読み込んで、Single Line Pickerで使える形式に変換したテキストを書き出します。 + +``` +python path/to/slp_build_folder.py path/to/file.csv +``` + +と実行すると、.csvや.tsvを1列目を表示テキスト、2列目を出力されるテキストとしてパースし、`#section`形式のテキストファイルをファイル名.slp.txtの名前で保存します。 + +``` +python path/to/slp_build_folder.py path/to/folder +``` + +と実行すると、フォルダ内のすべての.csv、.tsvファイルをパースします。ファイル名を表示テキスト、前述の方法でパースした内容をbase64エンコードして出力されるテキストとして格納し、output.slp.txtの名前で保存します。`#section`形式の出力が`#section`形式となる二重の入れ子構造になっています。Single Line Pickerを2つ繋げて最初のノードに適用することで、カテゴリーを選んでから項目を選ぶようなことができるようになります。 + + + +書き出されたテキストファイルをファイルを読み込むノードでSingle Line Pickerに繋げるか、ノード情報パネルのParametersの`source_text`に内容をペーストすることで内容を適用できます。 + + +## slp_build_folder.py + +フォルダを読み込んで、その中の.txtファイルをまとめて、Single Line Pickerで使える形式に変換したテキストを書き出します。 + +``` +python path/to/slp_build_folder.py -d path/to/folder +``` + +と実行すると、フォルダ内のすべてのtxtファイルをパースします。ファイル名を表示テキスト、内容を出力されるテキストとして格納し、output.slp.txtの名前で保存します。 + +``` +python path/to/slp_build_folder.py -dd path/to/folder +``` + +`-dd`オプションを付けると、フォルダ内のすべてのサブフォルダに対して前述処理を行い、サブフォルダ名を表示テキスト、処理内容を出力されるテキストとして格納し、output.slp.txtの名前で保存します。入れ子構造になります。 + +書き出されたテキストファイルをファイルを読み込むノードでSingle Line Pickerに繋げるか、ノード情報パネルのParametersの`source_text`に内容をペーストすることで内容を適用できます。 diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 0000000..b95fefa --- /dev/null +++ b/tools/README.md @@ -0,0 +1,46 @@ ++ English | + 日本語 (Japanese) +
+ +# Tools +These are Python scripts that assist the operation of the [Single Line Picker](https://github.com/hetima/ComfyUI-SingleLinePicker). + + +## slp_buld_csv.py + +It reads CSV or TSV files and exports text converted into a format usable with the Single Line Picker. + +``` +python path/to/slp_build_folder.py path/to/file.csv +``` + +When executed, it parses .csv or .tsv with the first column as display text and the second column as output text, then saves the `#section` formatted text file as filename.slp.txt. + +``` +python path/to/slp_build_folder.py path/to/folder +``` + +When executed, it parses all .csv and .tsv files within the folder. The filename is displayed as text, and the content parsed using the above method is stored as text output after base64 encoding, then saved as output.slp.txt. The output format is structured as a two-level nested hierarchy. By connecting two Single Line Pickers and applying them to the first node, you can enable functionality like selecting a category before choosing an item. + + + +To apply this result, connect the exported text file to the Single Line Picker using a node that reads file contents, or paste the contents into `source_text` in the parameters of node info panel. + +## slp_build_folder.py + +Load the folder, gather all the .txt files within it, and output the text converted into a format usable by the Single Line Picker. + +``` +python path/to/slp_build_folder.py -d path/to/folder +``` + +When executed, it parses all .txt files within the folder. It stores the filename as display text and the contents as output text, saving the result as output.slp.txt. + +``` +python path/to/slp_build_folder.py -dd path/to/folder +``` + +When the `-dd` option is specified, the above processing is performed on all subfolders within the folder. Subfolder names are stored as display text, and processing results are stored as output text, saved under the filename `output.slp.txt`. This creates a nested structure. + +To apply this result, connect the exported text file to the Single Line Picker using a node that reads file contents, or paste the contents into `source_text` in the parameters of node info panel. diff --git a/tools/slp_build_folder.py b/tools/slp_build_folder.py index d7d95e2..a6b5a62 100644 --- a/tools/slp_build_folder.py +++ b/tools/slp_build_folder.py @@ -77,7 +77,7 @@ def merge_subfolder_files(target_dir): def main(): parser = argparse.ArgumentParser(description='Converts text files to SLP compatible text file.') - parser.add_argument('path', help='Path to the target file or directory') + parser.add_argument('path', help='Path to the target directory') group = parser.add_mutually_exclusive_group() group.add_argument('-d', action='store_true', help='Process text files in the folder') @@ -85,6 +85,11 @@ def main(): args = parser.parse_args() target_path = Path(args.path) + target_path = Path(target_path) + + if not target_path.is_dir(): + print(f"Error: {target_path} is not a directory.") + return if args.d: process_folder(target_path) diff --git a/tools/slp_buld_csv.py b/tools/slp_buld_csv.py index 5dcddc6..d9cb0f0 100644 --- a/tools/slp_buld_csv.py +++ b/tools/slp_buld_csv.py @@ -63,7 +63,8 @@ def merge_folder_files(target_dir): return "\n".join(final_results) def process_csv(target_path): - # 単体ファイル処理 + """単体ファイル処理""" + target_path = Path(target_path) if target_path.suffix.lower() not in ['.csv', '.tsv']: print("Error: Target path must be a .csv or .tsv file")