pomera-ai-commander 1.1.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +105 -680
- package/bin/pomera-ai-commander.js +62 -62
- package/core/__init__.py +65 -65
- package/core/app_context.py +482 -482
- package/core/async_text_processor.py +421 -421
- package/core/backup_manager.py +655 -655
- package/core/backup_recovery_manager.py +1199 -1033
- package/core/content_hash_cache.py +508 -508
- package/core/context_menu.py +313 -313
- package/core/data_directory.py +549 -0
- package/core/data_validator.py +1066 -1066
- package/core/database_connection_manager.py +744 -744
- package/core/database_curl_settings_manager.py +608 -608
- package/core/database_promera_ai_settings_manager.py +446 -446
- package/core/database_schema.py +411 -411
- package/core/database_schema_manager.py +395 -395
- package/core/database_settings_manager.py +1507 -1507
- package/core/database_settings_manager_interface.py +456 -456
- package/core/dialog_manager.py +734 -734
- package/core/diff_utils.py +239 -0
- package/core/efficient_line_numbers.py +540 -510
- package/core/error_handler.py +746 -746
- package/core/error_service.py +431 -431
- package/core/event_consolidator.py +511 -511
- package/core/mcp/__init__.py +43 -43
- package/core/mcp/find_replace_diff.py +334 -0
- package/core/mcp/protocol.py +288 -288
- package/core/mcp/schema.py +251 -251
- package/core/mcp/server_stdio.py +299 -299
- package/core/mcp/tool_registry.py +2699 -2345
- package/core/memento.py +275 -0
- package/core/memory_efficient_text_widget.py +711 -711
- package/core/migration_manager.py +914 -914
- package/core/migration_test_suite.py +1085 -1085
- package/core/migration_validator.py +1143 -1143
- package/core/optimized_find_replace.py +714 -714
- package/core/optimized_pattern_engine.py +424 -424
- package/core/optimized_search_highlighter.py +552 -552
- package/core/performance_monitor.py +674 -674
- package/core/persistence_manager.py +712 -712
- package/core/progressive_stats_calculator.py +632 -632
- package/core/regex_pattern_cache.py +529 -529
- package/core/regex_pattern_library.py +350 -350
- package/core/search_operation_manager.py +434 -434
- package/core/settings_defaults_registry.py +1087 -1087
- package/core/settings_integrity_validator.py +1111 -1111
- package/core/settings_serializer.py +557 -557
- package/core/settings_validator.py +1823 -1823
- package/core/smart_stats_calculator.py +709 -709
- package/core/statistics_update_manager.py +619 -619
- package/core/stats_config_manager.py +858 -858
- package/core/streaming_text_handler.py +723 -723
- package/core/task_scheduler.py +596 -596
- package/core/update_pattern_library.py +168 -168
- package/core/visibility_monitor.py +596 -596
- package/core/widget_cache.py +498 -498
- package/mcp.json +51 -61
- package/migrate_data.py +127 -0
- package/package.json +64 -57
- package/pomera.py +7883 -7482
- package/pomera_mcp_server.py +183 -144
- package/requirements.txt +33 -0
- package/scripts/Dockerfile.alpine +43 -0
- package/scripts/Dockerfile.gui-test +54 -0
- package/scripts/Dockerfile.linux +43 -0
- package/scripts/Dockerfile.test-linux +80 -0
- package/scripts/Dockerfile.ubuntu +39 -0
- package/scripts/README.md +53 -0
- package/scripts/build-all.bat +113 -0
- package/scripts/build-docker.bat +53 -0
- package/scripts/build-docker.sh +55 -0
- package/scripts/build-optimized.bat +101 -0
- package/scripts/build.sh +78 -0
- package/scripts/docker-compose.test.yml +27 -0
- package/scripts/docker-compose.yml +32 -0
- package/scripts/postinstall.js +62 -0
- package/scripts/requirements-minimal.txt +33 -0
- package/scripts/test-linux-simple.bat +28 -0
- package/scripts/validate-release-workflow.py +450 -0
- package/tools/__init__.py +4 -4
- package/tools/ai_tools.py +2891 -2891
- package/tools/ascii_art_generator.py +352 -352
- package/tools/base64_tools.py +183 -183
- package/tools/base_tool.py +511 -511
- package/tools/case_tool.py +308 -308
- package/tools/column_tools.py +395 -395
- package/tools/cron_tool.py +884 -884
- package/tools/curl_history.py +600 -600
- package/tools/curl_processor.py +1207 -1207
- package/tools/curl_settings.py +502 -502
- package/tools/curl_tool.py +5467 -5467
- package/tools/diff_viewer.py +1817 -1072
- package/tools/email_extraction_tool.py +248 -248
- package/tools/email_header_analyzer.py +425 -425
- package/tools/extraction_tools.py +250 -250
- package/tools/find_replace.py +2289 -1750
- package/tools/folder_file_reporter.py +1463 -1463
- package/tools/folder_file_reporter_adapter.py +480 -480
- package/tools/generator_tools.py +1216 -1216
- package/tools/hash_generator.py +255 -255
- package/tools/html_tool.py +656 -656
- package/tools/jsonxml_tool.py +729 -729
- package/tools/line_tools.py +419 -419
- package/tools/markdown_tools.py +561 -561
- package/tools/mcp_widget.py +1417 -1417
- package/tools/notes_widget.py +978 -973
- package/tools/number_base_converter.py +372 -372
- package/tools/regex_extractor.py +571 -571
- package/tools/slug_generator.py +310 -310
- package/tools/sorter_tools.py +458 -458
- package/tools/string_escape_tool.py +392 -392
- package/tools/text_statistics_tool.py +365 -365
- package/tools/text_wrapper.py +430 -430
- package/tools/timestamp_converter.py +421 -421
- package/tools/tool_loader.py +710 -710
- package/tools/translator_tools.py +522 -522
- package/tools/url_link_extractor.py +261 -261
- package/tools/url_parser.py +204 -204
- package/tools/whitespace_tools.py +355 -355
- package/tools/word_frequency_counter.py +146 -146
- package/core/__pycache__/__init__.cpython-313.pyc +0 -0
- package/core/__pycache__/app_context.cpython-313.pyc +0 -0
- package/core/__pycache__/async_text_processor.cpython-313.pyc +0 -0
- package/core/__pycache__/backup_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/backup_recovery_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/content_hash_cache.cpython-313.pyc +0 -0
- package/core/__pycache__/context_menu.cpython-313.pyc +0 -0
- package/core/__pycache__/data_validator.cpython-313.pyc +0 -0
- package/core/__pycache__/database_connection_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/database_curl_settings_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/database_promera_ai_settings_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/database_schema.cpython-313.pyc +0 -0
- package/core/__pycache__/database_schema_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/database_settings_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/database_settings_manager_interface.cpython-313.pyc +0 -0
- package/core/__pycache__/dialog_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/efficient_line_numbers.cpython-313.pyc +0 -0
- package/core/__pycache__/error_handler.cpython-313.pyc +0 -0
- package/core/__pycache__/error_service.cpython-313.pyc +0 -0
- package/core/__pycache__/event_consolidator.cpython-313.pyc +0 -0
- package/core/__pycache__/memory_efficient_text_widget.cpython-313.pyc +0 -0
- package/core/__pycache__/migration_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/migration_test_suite.cpython-313.pyc +0 -0
- package/core/__pycache__/migration_validator.cpython-313.pyc +0 -0
- package/core/__pycache__/optimized_find_replace.cpython-313.pyc +0 -0
- package/core/__pycache__/optimized_pattern_engine.cpython-313.pyc +0 -0
- package/core/__pycache__/optimized_search_highlighter.cpython-313.pyc +0 -0
- package/core/__pycache__/performance_monitor.cpython-313.pyc +0 -0
- package/core/__pycache__/persistence_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/progressive_stats_calculator.cpython-313.pyc +0 -0
- package/core/__pycache__/regex_pattern_cache.cpython-313.pyc +0 -0
- package/core/__pycache__/regex_pattern_library.cpython-313.pyc +0 -0
- package/core/__pycache__/search_operation_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/settings_defaults_registry.cpython-313.pyc +0 -0
- package/core/__pycache__/settings_integrity_validator.cpython-313.pyc +0 -0
- package/core/__pycache__/settings_serializer.cpython-313.pyc +0 -0
- package/core/__pycache__/settings_validator.cpython-313.pyc +0 -0
- package/core/__pycache__/smart_stats_calculator.cpython-313.pyc +0 -0
- package/core/__pycache__/statistics_update_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/stats_config_manager.cpython-313.pyc +0 -0
- package/core/__pycache__/streaming_text_handler.cpython-313.pyc +0 -0
- package/core/__pycache__/task_scheduler.cpython-313.pyc +0 -0
- package/core/__pycache__/visibility_monitor.cpython-313.pyc +0 -0
- package/core/__pycache__/widget_cache.cpython-313.pyc +0 -0
- package/core/mcp/__pycache__/__init__.cpython-313.pyc +0 -0
- package/core/mcp/__pycache__/protocol.cpython-313.pyc +0 -0
- package/core/mcp/__pycache__/schema.cpython-313.pyc +0 -0
- package/core/mcp/__pycache__/server_stdio.cpython-313.pyc +0 -0
- package/core/mcp/__pycache__/tool_registry.cpython-313.pyc +0 -0
- package/tools/__pycache__/__init__.cpython-313.pyc +0 -0
- package/tools/__pycache__/ai_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/ascii_art_generator.cpython-313.pyc +0 -0
- package/tools/__pycache__/base64_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/base_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/case_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/column_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/cron_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/curl_history.cpython-313.pyc +0 -0
- package/tools/__pycache__/curl_processor.cpython-313.pyc +0 -0
- package/tools/__pycache__/curl_settings.cpython-313.pyc +0 -0
- package/tools/__pycache__/curl_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/diff_viewer.cpython-313.pyc +0 -0
- package/tools/__pycache__/email_extraction_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/email_header_analyzer.cpython-313.pyc +0 -0
- package/tools/__pycache__/extraction_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/find_replace.cpython-313.pyc +0 -0
- package/tools/__pycache__/folder_file_reporter.cpython-313.pyc +0 -0
- package/tools/__pycache__/folder_file_reporter_adapter.cpython-313.pyc +0 -0
- package/tools/__pycache__/generator_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/hash_generator.cpython-313.pyc +0 -0
- package/tools/__pycache__/html_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/huggingface_helper.cpython-313.pyc +0 -0
- package/tools/__pycache__/jsonxml_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/line_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/list_comparator.cpython-313.pyc +0 -0
- package/tools/__pycache__/markdown_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/mcp_widget.cpython-313.pyc +0 -0
- package/tools/__pycache__/notes_widget.cpython-313.pyc +0 -0
- package/tools/__pycache__/number_base_converter.cpython-313.pyc +0 -0
- package/tools/__pycache__/regex_extractor.cpython-313.pyc +0 -0
- package/tools/__pycache__/slug_generator.cpython-313.pyc +0 -0
- package/tools/__pycache__/sorter_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/string_escape_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/text_statistics_tool.cpython-313.pyc +0 -0
- package/tools/__pycache__/text_wrapper.cpython-313.pyc +0 -0
- package/tools/__pycache__/timestamp_converter.cpython-313.pyc +0 -0
- package/tools/__pycache__/tool_loader.cpython-313.pyc +0 -0
- package/tools/__pycache__/translator_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/url_link_extractor.cpython-313.pyc +0 -0
- package/tools/__pycache__/url_parser.cpython-313.pyc +0 -0
- package/tools/__pycache__/whitespace_tools.cpython-313.pyc +0 -0
- package/tools/__pycache__/word_frequency_counter.cpython-313.pyc +0 -0
package/tools/text_wrapper.py
CHANGED
|
@@ -1,431 +1,431 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Text Wrapper/Formatter Module - Text formatting utilities
|
|
3
|
-
|
|
4
|
-
This module provides text wrapping and formatting functionality
|
|
5
|
-
for the Pomera AI Commander application.
|
|
6
|
-
|
|
7
|
-
Features:
|
|
8
|
-
- Word Wrap: Wrap text at specified column width
|
|
9
|
-
- Justify Text: Left, right, center, full justify
|
|
10
|
-
- Add Prefix/Suffix: Add text to start/end of each line
|
|
11
|
-
- Indent/Dedent: Add or remove indentation
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
import tkinter as tk
|
|
15
|
-
from tkinter import ttk
|
|
16
|
-
import textwrap
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class TextWrapperProcessor:
|
|
20
|
-
"""Text wrapper processor with various formatting capabilities."""
|
|
21
|
-
|
|
22
|
-
@staticmethod
|
|
23
|
-
def word_wrap(text, width=80, break_long_words=True, break_on_hyphens=True):
|
|
24
|
-
"""Wrap text at specified column width."""
|
|
25
|
-
lines = text.split('\n')
|
|
26
|
-
wrapped_lines = []
|
|
27
|
-
|
|
28
|
-
for line in lines:
|
|
29
|
-
if line.strip():
|
|
30
|
-
wrapped = textwrap.fill(
|
|
31
|
-
line,
|
|
32
|
-
width=width,
|
|
33
|
-
break_long_words=break_long_words,
|
|
34
|
-
break_on_hyphens=break_on_hyphens
|
|
35
|
-
)
|
|
36
|
-
wrapped_lines.append(wrapped)
|
|
37
|
-
else:
|
|
38
|
-
wrapped_lines.append('')
|
|
39
|
-
|
|
40
|
-
return '\n'.join(wrapped_lines)
|
|
41
|
-
|
|
42
|
-
@staticmethod
|
|
43
|
-
def justify_text(text, width=80, mode="left"):
|
|
44
|
-
"""Justify text to specified width."""
|
|
45
|
-
lines = text.split('\n')
|
|
46
|
-
result = []
|
|
47
|
-
|
|
48
|
-
for line in lines:
|
|
49
|
-
line = line.strip()
|
|
50
|
-
if not line:
|
|
51
|
-
result.append('')
|
|
52
|
-
continue
|
|
53
|
-
|
|
54
|
-
if mode == "left":
|
|
55
|
-
result.append(line.ljust(width))
|
|
56
|
-
elif mode == "right":
|
|
57
|
-
result.append(line.rjust(width))
|
|
58
|
-
elif mode == "center":
|
|
59
|
-
result.append(line.center(width))
|
|
60
|
-
elif mode == "full":
|
|
61
|
-
# Full justify - distribute spaces evenly
|
|
62
|
-
words = line.split()
|
|
63
|
-
if len(words) == 1:
|
|
64
|
-
result.append(line.ljust(width))
|
|
65
|
-
else:
|
|
66
|
-
total_spaces = width - sum(len(w) for w in words)
|
|
67
|
-
gaps = len(words) - 1
|
|
68
|
-
if gaps > 0:
|
|
69
|
-
space_per_gap = total_spaces // gaps
|
|
70
|
-
extra_spaces = total_spaces % gaps
|
|
71
|
-
justified = words[0]
|
|
72
|
-
for i, word in enumerate(words[1:]):
|
|
73
|
-
spaces = space_per_gap + (1 if i < extra_spaces else 0)
|
|
74
|
-
justified += ' ' * spaces + word
|
|
75
|
-
result.append(justified)
|
|
76
|
-
else:
|
|
77
|
-
result.append(line)
|
|
78
|
-
else:
|
|
79
|
-
result.append(line)
|
|
80
|
-
|
|
81
|
-
return '\n'.join(result)
|
|
82
|
-
|
|
83
|
-
@staticmethod
|
|
84
|
-
def add_prefix_suffix(text, prefix="", suffix="", skip_empty=True):
|
|
85
|
-
"""Add prefix and/or suffix to each line."""
|
|
86
|
-
lines = text.split('\n')
|
|
87
|
-
result = []
|
|
88
|
-
|
|
89
|
-
for line in lines:
|
|
90
|
-
if skip_empty and not line.strip():
|
|
91
|
-
result.append(line)
|
|
92
|
-
else:
|
|
93
|
-
result.append(f"{prefix}{line}{suffix}")
|
|
94
|
-
|
|
95
|
-
return '\n'.join(result)
|
|
96
|
-
|
|
97
|
-
@staticmethod
|
|
98
|
-
def indent(text, size=4, char="space"):
|
|
99
|
-
"""Add indentation to each line."""
|
|
100
|
-
indent_char = '\t' if char == "tab" else ' '
|
|
101
|
-
indent_str = indent_char * size if char == "space" else indent_char * size
|
|
102
|
-
|
|
103
|
-
lines = text.split('\n')
|
|
104
|
-
result = [indent_str + line if line.strip() else line for line in lines]
|
|
105
|
-
|
|
106
|
-
return '\n'.join(result)
|
|
107
|
-
|
|
108
|
-
@staticmethod
|
|
109
|
-
def dedent(text, size=4):
|
|
110
|
-
"""Remove indentation from each line."""
|
|
111
|
-
lines = text.split('\n')
|
|
112
|
-
result = []
|
|
113
|
-
|
|
114
|
-
for line in lines:
|
|
115
|
-
# Count leading whitespace
|
|
116
|
-
stripped = line.lstrip()
|
|
117
|
-
leading = len(line) - len(stripped)
|
|
118
|
-
|
|
119
|
-
# Remove up to 'size' characters of indentation
|
|
120
|
-
remove = min(leading, size)
|
|
121
|
-
result.append(line[remove:])
|
|
122
|
-
|
|
123
|
-
return '\n'.join(result)
|
|
124
|
-
|
|
125
|
-
@staticmethod
|
|
126
|
-
def quote_text(text, style="double"):
|
|
127
|
-
"""Wrap text in quotes or code blocks."""
|
|
128
|
-
if style == "double":
|
|
129
|
-
return f'"{text}"'
|
|
130
|
-
elif style == "single":
|
|
131
|
-
return f"'{text}'"
|
|
132
|
-
elif style == "backtick":
|
|
133
|
-
return f"`{text}`"
|
|
134
|
-
elif style == "code_block":
|
|
135
|
-
return f"```\n{text}\n```"
|
|
136
|
-
elif style == "blockquote":
|
|
137
|
-
lines = text.split('\n')
|
|
138
|
-
return '\n'.join(f"> {line}" for line in lines)
|
|
139
|
-
else:
|
|
140
|
-
return text
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
class TextWrapperWidget(ttk.Frame):
|
|
144
|
-
"""Tabbed interface widget for text wrapper tools."""
|
|
145
|
-
|
|
146
|
-
def __init__(self, parent, app):
|
|
147
|
-
super().__init__(parent)
|
|
148
|
-
self.app = app
|
|
149
|
-
self.processor = TextWrapperProcessor()
|
|
150
|
-
|
|
151
|
-
self.wrap_width = tk.IntVar(value=80)
|
|
152
|
-
self.justify_mode = tk.StringVar(value="left")
|
|
153
|
-
self.justify_width = tk.IntVar(value=80)
|
|
154
|
-
self.prefix = tk.StringVar(value="")
|
|
155
|
-
self.suffix = tk.StringVar(value="")
|
|
156
|
-
self.skip_empty = tk.BooleanVar(value=True)
|
|
157
|
-
self.indent_size = tk.IntVar(value=4)
|
|
158
|
-
self.indent_char = tk.StringVar(value="space")
|
|
159
|
-
self.quote_style = tk.StringVar(value="double")
|
|
160
|
-
|
|
161
|
-
self.create_widgets()
|
|
162
|
-
self.load_settings()
|
|
163
|
-
|
|
164
|
-
def create_widgets(self):
|
|
165
|
-
"""Creates the tabbed interface for text wrapper tools."""
|
|
166
|
-
self.notebook = ttk.Notebook(self)
|
|
167
|
-
self.notebook.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
|
168
|
-
|
|
169
|
-
self.create_wrap_tab()
|
|
170
|
-
self.create_justify_tab()
|
|
171
|
-
self.create_prefix_suffix_tab()
|
|
172
|
-
self.create_indent_tab()
|
|
173
|
-
self.create_quote_tab()
|
|
174
|
-
|
|
175
|
-
def create_wrap_tab(self):
|
|
176
|
-
"""Creates the Word Wrap tab."""
|
|
177
|
-
frame = ttk.Frame(self.notebook)
|
|
178
|
-
self.notebook.add(frame, text="Word Wrap")
|
|
179
|
-
|
|
180
|
-
width_frame = ttk.Frame(frame)
|
|
181
|
-
width_frame.pack(fill=tk.X, padx=5, pady=10)
|
|
182
|
-
|
|
183
|
-
ttk.Label(width_frame, text="Line Width:").pack(side=tk.LEFT)
|
|
184
|
-
ttk.Spinbox(width_frame, from_=20, to=200, width=5,
|
|
185
|
-
textvariable=self.wrap_width,
|
|
186
|
-
command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
|
|
187
|
-
ttk.Label(width_frame, text="characters").pack(side=tk.LEFT)
|
|
188
|
-
|
|
189
|
-
ttk.Button(frame, text="Wrap Text",
|
|
190
|
-
command=lambda: self.process("wrap")).pack(pady=10)
|
|
191
|
-
|
|
192
|
-
def create_justify_tab(self):
|
|
193
|
-
"""Creates the Justify Text tab."""
|
|
194
|
-
frame = ttk.Frame(self.notebook)
|
|
195
|
-
self.notebook.add(frame, text="Justify")
|
|
196
|
-
|
|
197
|
-
mode_frame = ttk.LabelFrame(frame, text="Alignment", padding=10)
|
|
198
|
-
mode_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
199
|
-
|
|
200
|
-
modes = [("Left", "left"), ("Right", "right"),
|
|
201
|
-
("Center", "center"), ("Full", "full")]
|
|
202
|
-
for text, value in modes:
|
|
203
|
-
ttk.Radiobutton(mode_frame, text=text,
|
|
204
|
-
variable=self.justify_mode, value=value,
|
|
205
|
-
command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
|
|
206
|
-
|
|
207
|
-
width_frame = ttk.Frame(frame)
|
|
208
|
-
width_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
209
|
-
|
|
210
|
-
ttk.Label(width_frame, text="Width:").pack(side=tk.LEFT)
|
|
211
|
-
ttk.Spinbox(width_frame, from_=20, to=200, width=5,
|
|
212
|
-
textvariable=self.justify_width,
|
|
213
|
-
command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
|
|
214
|
-
|
|
215
|
-
ttk.Button(frame, text="Justify Text",
|
|
216
|
-
command=lambda: self.process("justify")).pack(pady=10)
|
|
217
|
-
|
|
218
|
-
def create_prefix_suffix_tab(self):
|
|
219
|
-
"""Creates the Prefix/Suffix tab."""
|
|
220
|
-
frame = ttk.Frame(self.notebook)
|
|
221
|
-
self.notebook.add(frame, text="Prefix/Suffix")
|
|
222
|
-
|
|
223
|
-
prefix_frame = ttk.Frame(frame)
|
|
224
|
-
prefix_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
225
|
-
ttk.Label(prefix_frame, text="Prefix:").pack(side=tk.LEFT)
|
|
226
|
-
ttk.Entry(prefix_frame, textvariable=self.prefix, width=20).pack(side=tk.LEFT, padx=5)
|
|
227
|
-
|
|
228
|
-
suffix_frame = ttk.Frame(frame)
|
|
229
|
-
suffix_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
230
|
-
ttk.Label(suffix_frame, text="Suffix:").pack(side=tk.LEFT)
|
|
231
|
-
ttk.Entry(suffix_frame, textvariable=self.suffix, width=20).pack(side=tk.LEFT, padx=5)
|
|
232
|
-
|
|
233
|
-
ttk.Checkbutton(frame, text="Skip Empty Lines",
|
|
234
|
-
variable=self.skip_empty,
|
|
235
|
-
command=self.on_setting_change).pack(anchor=tk.W, padx=5, pady=5)
|
|
236
|
-
|
|
237
|
-
ttk.Button(frame, text="Add Prefix/Suffix",
|
|
238
|
-
command=lambda: self.process("prefix_suffix")).pack(pady=10)
|
|
239
|
-
|
|
240
|
-
def create_indent_tab(self):
|
|
241
|
-
"""Creates the Indent/Dedent tab."""
|
|
242
|
-
frame = ttk.Frame(self.notebook)
|
|
243
|
-
self.notebook.add(frame, text="Indent")
|
|
244
|
-
|
|
245
|
-
size_frame = ttk.Frame(frame)
|
|
246
|
-
size_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
247
|
-
ttk.Label(size_frame, text="Indent Size:").pack(side=tk.LEFT)
|
|
248
|
-
ttk.Spinbox(size_frame, from_=1, to=16, width=4,
|
|
249
|
-
textvariable=self.indent_size,
|
|
250
|
-
command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
|
|
251
|
-
|
|
252
|
-
char_frame = ttk.LabelFrame(frame, text="Indent Character", padding=10)
|
|
253
|
-
char_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
254
|
-
|
|
255
|
-
ttk.Radiobutton(char_frame, text="Spaces",
|
|
256
|
-
variable=self.indent_char, value="space",
|
|
257
|
-
command=self.on_setting_change).pack(side=tk.LEFT, padx=10)
|
|
258
|
-
ttk.Radiobutton(char_frame, text="Tabs",
|
|
259
|
-
variable=self.indent_char, value="tab",
|
|
260
|
-
command=self.on_setting_change).pack(side=tk.LEFT, padx=10)
|
|
261
|
-
|
|
262
|
-
buttons_frame = ttk.Frame(frame)
|
|
263
|
-
buttons_frame.pack(pady=10)
|
|
264
|
-
|
|
265
|
-
ttk.Button(buttons_frame, text="Indent",
|
|
266
|
-
command=lambda: self.process("indent")).pack(side=tk.LEFT, padx=5)
|
|
267
|
-
ttk.Button(buttons_frame, text="Dedent",
|
|
268
|
-
command=lambda: self.process("dedent")).pack(side=tk.LEFT, padx=5)
|
|
269
|
-
|
|
270
|
-
def create_quote_tab(self):
|
|
271
|
-
"""Creates the Quote Text tab."""
|
|
272
|
-
frame = ttk.Frame(self.notebook)
|
|
273
|
-
self.notebook.add(frame, text="Quote")
|
|
274
|
-
|
|
275
|
-
style_frame = ttk.LabelFrame(frame, text="Quote Style", padding=10)
|
|
276
|
-
style_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
277
|
-
|
|
278
|
-
styles = [
|
|
279
|
-
('Double Quotes ("...")', "double"),
|
|
280
|
-
("Single Quotes ('...')", "single"),
|
|
281
|
-
("Backticks (`...`)", "backtick"),
|
|
282
|
-
("Code Block (```...```)", "code_block"),
|
|
283
|
-
("Blockquote (> ...)", "blockquote"),
|
|
284
|
-
]
|
|
285
|
-
|
|
286
|
-
for text, value in styles:
|
|
287
|
-
ttk.Radiobutton(style_frame, text=text,
|
|
288
|
-
variable=self.quote_style, value=value,
|
|
289
|
-
command=self.on_setting_change).pack(anchor=tk.W)
|
|
290
|
-
|
|
291
|
-
ttk.Button(frame, text="Quote Text",
|
|
292
|
-
command=lambda: self.process("quote")).pack(pady=10)
|
|
293
|
-
|
|
294
|
-
def load_settings(self):
|
|
295
|
-
"""Load settings from the application."""
|
|
296
|
-
settings = self.app.settings.get("tool_settings", {}).get("Text Wrapper", {})
|
|
297
|
-
|
|
298
|
-
self.wrap_width.set(settings.get("wrap_width", 80))
|
|
299
|
-
self.justify_mode.set(settings.get("justify_mode", "left"))
|
|
300
|
-
self.justify_width.set(settings.get("justify_width", 80))
|
|
301
|
-
self.prefix.set(settings.get("prefix", ""))
|
|
302
|
-
self.suffix.set(settings.get("suffix", ""))
|
|
303
|
-
self.skip_empty.set(settings.get("skip_empty", True))
|
|
304
|
-
self.indent_size.set(settings.get("indent_size", 4))
|
|
305
|
-
self.indent_char.set(settings.get("indent_char", "space"))
|
|
306
|
-
self.quote_style.set(settings.get("quote_style", "double"))
|
|
307
|
-
|
|
308
|
-
def save_settings(self):
|
|
309
|
-
"""Save current settings to the application."""
|
|
310
|
-
if "Text Wrapper" not in self.app.settings["tool_settings"]:
|
|
311
|
-
self.app.settings["tool_settings"]["Text Wrapper"] = {}
|
|
312
|
-
|
|
313
|
-
self.app.settings["tool_settings"]["Text Wrapper"].update({
|
|
314
|
-
"wrap_width": self.wrap_width.get(),
|
|
315
|
-
"justify_mode": self.justify_mode.get(),
|
|
316
|
-
"justify_width": self.justify_width.get(),
|
|
317
|
-
"prefix": self.prefix.get(),
|
|
318
|
-
"suffix": self.suffix.get(),
|
|
319
|
-
"skip_empty": self.skip_empty.get(),
|
|
320
|
-
"indent_size": self.indent_size.get(),
|
|
321
|
-
"indent_char": self.indent_char.get(),
|
|
322
|
-
"quote_style": self.quote_style.get()
|
|
323
|
-
})
|
|
324
|
-
|
|
325
|
-
self.app.save_settings()
|
|
326
|
-
|
|
327
|
-
def on_setting_change(self, *args):
|
|
328
|
-
"""Handle setting changes."""
|
|
329
|
-
self.save_settings()
|
|
330
|
-
|
|
331
|
-
def process(self, operation):
|
|
332
|
-
"""Process the input text."""
|
|
333
|
-
active_input_tab = self.app.input_tabs[self.app.input_notebook.index(self.app.input_notebook.select())]
|
|
334
|
-
input_text = active_input_tab.text.get("1.0", tk.END).rstrip('\n')
|
|
335
|
-
|
|
336
|
-
if not input_text:
|
|
337
|
-
return
|
|
338
|
-
|
|
339
|
-
if operation == "wrap":
|
|
340
|
-
result = TextWrapperProcessor.word_wrap(input_text, self.wrap_width.get())
|
|
341
|
-
elif operation == "justify":
|
|
342
|
-
result = TextWrapperProcessor.justify_text(
|
|
343
|
-
input_text, self.justify_width.get(), self.justify_mode.get())
|
|
344
|
-
elif operation == "prefix_suffix":
|
|
345
|
-
result = TextWrapperProcessor.add_prefix_suffix(
|
|
346
|
-
input_text, self.prefix.get(), self.suffix.get(), self.skip_empty.get())
|
|
347
|
-
elif operation == "indent":
|
|
348
|
-
result = TextWrapperProcessor.indent(
|
|
349
|
-
input_text, self.indent_size.get(), self.indent_char.get())
|
|
350
|
-
elif operation == "dedent":
|
|
351
|
-
result = TextWrapperProcessor.dedent(input_text, self.indent_size.get())
|
|
352
|
-
elif operation == "quote":
|
|
353
|
-
result = TextWrapperProcessor.quote_text(input_text, self.quote_style.get())
|
|
354
|
-
else:
|
|
355
|
-
result = input_text
|
|
356
|
-
|
|
357
|
-
active_output_tab = self.app.output_tabs[self.app.output_notebook.index(self.app.output_notebook.select())]
|
|
358
|
-
active_output_tab.text.config(state="normal")
|
|
359
|
-
active_output_tab.text.delete("1.0", tk.END)
|
|
360
|
-
active_output_tab.text.insert("1.0", result)
|
|
361
|
-
active_output_tab.text.config(state="disabled")
|
|
362
|
-
|
|
363
|
-
self.app.update_all_stats()
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
class TextWrapper:
|
|
367
|
-
"""Main class for Text Wrapper integration."""
|
|
368
|
-
|
|
369
|
-
def __init__(self):
|
|
370
|
-
self.processor = TextWrapperProcessor()
|
|
371
|
-
|
|
372
|
-
def create_widget(self, parent, app):
|
|
373
|
-
"""Create and return the Text Wrapper widget."""
|
|
374
|
-
return TextWrapperWidget(parent, app)
|
|
375
|
-
|
|
376
|
-
def get_default_settings(self):
|
|
377
|
-
"""Return default settings for Text Wrapper."""
|
|
378
|
-
return {
|
|
379
|
-
"wrap_width": 80,
|
|
380
|
-
"justify_mode": "left",
|
|
381
|
-
"justify_width": 80,
|
|
382
|
-
"prefix": "",
|
|
383
|
-
"suffix": "",
|
|
384
|
-
"skip_empty": True,
|
|
385
|
-
"indent_size": 4,
|
|
386
|
-
"indent_char": "space",
|
|
387
|
-
"quote_style": "double"
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
# BaseTool-compatible wrapper
|
|
392
|
-
try:
|
|
393
|
-
from tools.base_tool import BaseTool
|
|
394
|
-
from typing import Dict, Any, Optional, Callable
|
|
395
|
-
|
|
396
|
-
class TextWrapperV2(BaseTool):
|
|
397
|
-
"""
|
|
398
|
-
BaseTool-compatible version of TextWrapper.
|
|
399
|
-
"""
|
|
400
|
-
|
|
401
|
-
TOOL_NAME = "Text Wrapper"
|
|
402
|
-
TOOL_DESCRIPTION = "Wrap text to specified width"
|
|
403
|
-
TOOL_VERSION = "2.0.0"
|
|
404
|
-
|
|
405
|
-
def __init__(self):
|
|
406
|
-
super().__init__()
|
|
407
|
-
self._processor = TextWrapperProcessor()
|
|
408
|
-
|
|
409
|
-
def process_text(self, input_text: str, settings: Dict[str, Any]) -> str:
|
|
410
|
-
"""Wrap text to specified width."""
|
|
411
|
-
width = settings.get("width", 80)
|
|
412
|
-
return TextWrapperProcessor.word_wrap(input_text, width)
|
|
413
|
-
|
|
414
|
-
def create_ui(self,
|
|
415
|
-
parent,
|
|
416
|
-
settings: Dict[str, Any],
|
|
417
|
-
on_setting_change_callback: Optional[Callable] = None,
|
|
418
|
-
apply_tool_callback: Optional[Callable] = None):
|
|
419
|
-
"""Create minimal UI - full widget used separately."""
|
|
420
|
-
self._settings = settings.copy()
|
|
421
|
-
self._on_setting_change = on_setting_change_callback
|
|
422
|
-
self._apply_callback = apply_tool_callback
|
|
423
|
-
return None
|
|
424
|
-
|
|
425
|
-
@classmethod
|
|
426
|
-
def get_default_settings(cls) -> Dict[str, Any]:
|
|
427
|
-
"""Return default settings."""
|
|
428
|
-
return {"width": 80}
|
|
429
|
-
|
|
430
|
-
except ImportError:
|
|
1
|
+
"""
|
|
2
|
+
Text Wrapper/Formatter Module - Text formatting utilities
|
|
3
|
+
|
|
4
|
+
This module provides text wrapping and formatting functionality
|
|
5
|
+
for the Pomera AI Commander application.
|
|
6
|
+
|
|
7
|
+
Features:
|
|
8
|
+
- Word Wrap: Wrap text at specified column width
|
|
9
|
+
- Justify Text: Left, right, center, full justify
|
|
10
|
+
- Add Prefix/Suffix: Add text to start/end of each line
|
|
11
|
+
- Indent/Dedent: Add or remove indentation
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import tkinter as tk
|
|
15
|
+
from tkinter import ttk
|
|
16
|
+
import textwrap
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TextWrapperProcessor:
|
|
20
|
+
"""Text wrapper processor with various formatting capabilities."""
|
|
21
|
+
|
|
22
|
+
@staticmethod
|
|
23
|
+
def word_wrap(text, width=80, break_long_words=True, break_on_hyphens=True):
|
|
24
|
+
"""Wrap text at specified column width."""
|
|
25
|
+
lines = text.split('\n')
|
|
26
|
+
wrapped_lines = []
|
|
27
|
+
|
|
28
|
+
for line in lines:
|
|
29
|
+
if line.strip():
|
|
30
|
+
wrapped = textwrap.fill(
|
|
31
|
+
line,
|
|
32
|
+
width=width,
|
|
33
|
+
break_long_words=break_long_words,
|
|
34
|
+
break_on_hyphens=break_on_hyphens
|
|
35
|
+
)
|
|
36
|
+
wrapped_lines.append(wrapped)
|
|
37
|
+
else:
|
|
38
|
+
wrapped_lines.append('')
|
|
39
|
+
|
|
40
|
+
return '\n'.join(wrapped_lines)
|
|
41
|
+
|
|
42
|
+
@staticmethod
|
|
43
|
+
def justify_text(text, width=80, mode="left"):
|
|
44
|
+
"""Justify text to specified width."""
|
|
45
|
+
lines = text.split('\n')
|
|
46
|
+
result = []
|
|
47
|
+
|
|
48
|
+
for line in lines:
|
|
49
|
+
line = line.strip()
|
|
50
|
+
if not line:
|
|
51
|
+
result.append('')
|
|
52
|
+
continue
|
|
53
|
+
|
|
54
|
+
if mode == "left":
|
|
55
|
+
result.append(line.ljust(width))
|
|
56
|
+
elif mode == "right":
|
|
57
|
+
result.append(line.rjust(width))
|
|
58
|
+
elif mode == "center":
|
|
59
|
+
result.append(line.center(width))
|
|
60
|
+
elif mode == "full":
|
|
61
|
+
# Full justify - distribute spaces evenly
|
|
62
|
+
words = line.split()
|
|
63
|
+
if len(words) == 1:
|
|
64
|
+
result.append(line.ljust(width))
|
|
65
|
+
else:
|
|
66
|
+
total_spaces = width - sum(len(w) for w in words)
|
|
67
|
+
gaps = len(words) - 1
|
|
68
|
+
if gaps > 0:
|
|
69
|
+
space_per_gap = total_spaces // gaps
|
|
70
|
+
extra_spaces = total_spaces % gaps
|
|
71
|
+
justified = words[0]
|
|
72
|
+
for i, word in enumerate(words[1:]):
|
|
73
|
+
spaces = space_per_gap + (1 if i < extra_spaces else 0)
|
|
74
|
+
justified += ' ' * spaces + word
|
|
75
|
+
result.append(justified)
|
|
76
|
+
else:
|
|
77
|
+
result.append(line)
|
|
78
|
+
else:
|
|
79
|
+
result.append(line)
|
|
80
|
+
|
|
81
|
+
return '\n'.join(result)
|
|
82
|
+
|
|
83
|
+
@staticmethod
|
|
84
|
+
def add_prefix_suffix(text, prefix="", suffix="", skip_empty=True):
|
|
85
|
+
"""Add prefix and/or suffix to each line."""
|
|
86
|
+
lines = text.split('\n')
|
|
87
|
+
result = []
|
|
88
|
+
|
|
89
|
+
for line in lines:
|
|
90
|
+
if skip_empty and not line.strip():
|
|
91
|
+
result.append(line)
|
|
92
|
+
else:
|
|
93
|
+
result.append(f"{prefix}{line}{suffix}")
|
|
94
|
+
|
|
95
|
+
return '\n'.join(result)
|
|
96
|
+
|
|
97
|
+
@staticmethod
|
|
98
|
+
def indent(text, size=4, char="space"):
|
|
99
|
+
"""Add indentation to each line."""
|
|
100
|
+
indent_char = '\t' if char == "tab" else ' '
|
|
101
|
+
indent_str = indent_char * size if char == "space" else indent_char * size
|
|
102
|
+
|
|
103
|
+
lines = text.split('\n')
|
|
104
|
+
result = [indent_str + line if line.strip() else line for line in lines]
|
|
105
|
+
|
|
106
|
+
return '\n'.join(result)
|
|
107
|
+
|
|
108
|
+
@staticmethod
|
|
109
|
+
def dedent(text, size=4):
|
|
110
|
+
"""Remove indentation from each line."""
|
|
111
|
+
lines = text.split('\n')
|
|
112
|
+
result = []
|
|
113
|
+
|
|
114
|
+
for line in lines:
|
|
115
|
+
# Count leading whitespace
|
|
116
|
+
stripped = line.lstrip()
|
|
117
|
+
leading = len(line) - len(stripped)
|
|
118
|
+
|
|
119
|
+
# Remove up to 'size' characters of indentation
|
|
120
|
+
remove = min(leading, size)
|
|
121
|
+
result.append(line[remove:])
|
|
122
|
+
|
|
123
|
+
return '\n'.join(result)
|
|
124
|
+
|
|
125
|
+
@staticmethod
|
|
126
|
+
def quote_text(text, style="double"):
|
|
127
|
+
"""Wrap text in quotes or code blocks."""
|
|
128
|
+
if style == "double":
|
|
129
|
+
return f'"{text}"'
|
|
130
|
+
elif style == "single":
|
|
131
|
+
return f"'{text}'"
|
|
132
|
+
elif style == "backtick":
|
|
133
|
+
return f"`{text}`"
|
|
134
|
+
elif style == "code_block":
|
|
135
|
+
return f"```\n{text}\n```"
|
|
136
|
+
elif style == "blockquote":
|
|
137
|
+
lines = text.split('\n')
|
|
138
|
+
return '\n'.join(f"> {line}" for line in lines)
|
|
139
|
+
else:
|
|
140
|
+
return text
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class TextWrapperWidget(ttk.Frame):
|
|
144
|
+
"""Tabbed interface widget for text wrapper tools."""
|
|
145
|
+
|
|
146
|
+
def __init__(self, parent, app):
|
|
147
|
+
super().__init__(parent)
|
|
148
|
+
self.app = app
|
|
149
|
+
self.processor = TextWrapperProcessor()
|
|
150
|
+
|
|
151
|
+
self.wrap_width = tk.IntVar(value=80)
|
|
152
|
+
self.justify_mode = tk.StringVar(value="left")
|
|
153
|
+
self.justify_width = tk.IntVar(value=80)
|
|
154
|
+
self.prefix = tk.StringVar(value="")
|
|
155
|
+
self.suffix = tk.StringVar(value="")
|
|
156
|
+
self.skip_empty = tk.BooleanVar(value=True)
|
|
157
|
+
self.indent_size = tk.IntVar(value=4)
|
|
158
|
+
self.indent_char = tk.StringVar(value="space")
|
|
159
|
+
self.quote_style = tk.StringVar(value="double")
|
|
160
|
+
|
|
161
|
+
self.create_widgets()
|
|
162
|
+
self.load_settings()
|
|
163
|
+
|
|
164
|
+
def create_widgets(self):
|
|
165
|
+
"""Creates the tabbed interface for text wrapper tools."""
|
|
166
|
+
self.notebook = ttk.Notebook(self)
|
|
167
|
+
self.notebook.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
|
168
|
+
|
|
169
|
+
self.create_wrap_tab()
|
|
170
|
+
self.create_justify_tab()
|
|
171
|
+
self.create_prefix_suffix_tab()
|
|
172
|
+
self.create_indent_tab()
|
|
173
|
+
self.create_quote_tab()
|
|
174
|
+
|
|
175
|
+
def create_wrap_tab(self):
|
|
176
|
+
"""Creates the Word Wrap tab."""
|
|
177
|
+
frame = ttk.Frame(self.notebook)
|
|
178
|
+
self.notebook.add(frame, text="Word Wrap")
|
|
179
|
+
|
|
180
|
+
width_frame = ttk.Frame(frame)
|
|
181
|
+
width_frame.pack(fill=tk.X, padx=5, pady=10)
|
|
182
|
+
|
|
183
|
+
ttk.Label(width_frame, text="Line Width:").pack(side=tk.LEFT)
|
|
184
|
+
ttk.Spinbox(width_frame, from_=20, to=200, width=5,
|
|
185
|
+
textvariable=self.wrap_width,
|
|
186
|
+
command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
|
|
187
|
+
ttk.Label(width_frame, text="characters").pack(side=tk.LEFT)
|
|
188
|
+
|
|
189
|
+
ttk.Button(frame, text="Wrap Text",
|
|
190
|
+
command=lambda: self.process("wrap")).pack(pady=10)
|
|
191
|
+
|
|
192
|
+
def create_justify_tab(self):
|
|
193
|
+
"""Creates the Justify Text tab."""
|
|
194
|
+
frame = ttk.Frame(self.notebook)
|
|
195
|
+
self.notebook.add(frame, text="Justify")
|
|
196
|
+
|
|
197
|
+
mode_frame = ttk.LabelFrame(frame, text="Alignment", padding=10)
|
|
198
|
+
mode_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
199
|
+
|
|
200
|
+
modes = [("Left", "left"), ("Right", "right"),
|
|
201
|
+
("Center", "center"), ("Full", "full")]
|
|
202
|
+
for text, value in modes:
|
|
203
|
+
ttk.Radiobutton(mode_frame, text=text,
|
|
204
|
+
variable=self.justify_mode, value=value,
|
|
205
|
+
command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
|
|
206
|
+
|
|
207
|
+
width_frame = ttk.Frame(frame)
|
|
208
|
+
width_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
209
|
+
|
|
210
|
+
ttk.Label(width_frame, text="Width:").pack(side=tk.LEFT)
|
|
211
|
+
ttk.Spinbox(width_frame, from_=20, to=200, width=5,
|
|
212
|
+
textvariable=self.justify_width,
|
|
213
|
+
command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
|
|
214
|
+
|
|
215
|
+
ttk.Button(frame, text="Justify Text",
|
|
216
|
+
command=lambda: self.process("justify")).pack(pady=10)
|
|
217
|
+
|
|
218
|
+
def create_prefix_suffix_tab(self):
|
|
219
|
+
"""Creates the Prefix/Suffix tab."""
|
|
220
|
+
frame = ttk.Frame(self.notebook)
|
|
221
|
+
self.notebook.add(frame, text="Prefix/Suffix")
|
|
222
|
+
|
|
223
|
+
prefix_frame = ttk.Frame(frame)
|
|
224
|
+
prefix_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
225
|
+
ttk.Label(prefix_frame, text="Prefix:").pack(side=tk.LEFT)
|
|
226
|
+
ttk.Entry(prefix_frame, textvariable=self.prefix, width=20).pack(side=tk.LEFT, padx=5)
|
|
227
|
+
|
|
228
|
+
suffix_frame = ttk.Frame(frame)
|
|
229
|
+
suffix_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
230
|
+
ttk.Label(suffix_frame, text="Suffix:").pack(side=tk.LEFT)
|
|
231
|
+
ttk.Entry(suffix_frame, textvariable=self.suffix, width=20).pack(side=tk.LEFT, padx=5)
|
|
232
|
+
|
|
233
|
+
ttk.Checkbutton(frame, text="Skip Empty Lines",
|
|
234
|
+
variable=self.skip_empty,
|
|
235
|
+
command=self.on_setting_change).pack(anchor=tk.W, padx=5, pady=5)
|
|
236
|
+
|
|
237
|
+
ttk.Button(frame, text="Add Prefix/Suffix",
|
|
238
|
+
command=lambda: self.process("prefix_suffix")).pack(pady=10)
|
|
239
|
+
|
|
240
|
+
def create_indent_tab(self):
|
|
241
|
+
"""Creates the Indent/Dedent tab."""
|
|
242
|
+
frame = ttk.Frame(self.notebook)
|
|
243
|
+
self.notebook.add(frame, text="Indent")
|
|
244
|
+
|
|
245
|
+
size_frame = ttk.Frame(frame)
|
|
246
|
+
size_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
247
|
+
ttk.Label(size_frame, text="Indent Size:").pack(side=tk.LEFT)
|
|
248
|
+
ttk.Spinbox(size_frame, from_=1, to=16, width=4,
|
|
249
|
+
textvariable=self.indent_size,
|
|
250
|
+
command=self.on_setting_change).pack(side=tk.LEFT, padx=5)
|
|
251
|
+
|
|
252
|
+
char_frame = ttk.LabelFrame(frame, text="Indent Character", padding=10)
|
|
253
|
+
char_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
254
|
+
|
|
255
|
+
ttk.Radiobutton(char_frame, text="Spaces",
|
|
256
|
+
variable=self.indent_char, value="space",
|
|
257
|
+
command=self.on_setting_change).pack(side=tk.LEFT, padx=10)
|
|
258
|
+
ttk.Radiobutton(char_frame, text="Tabs",
|
|
259
|
+
variable=self.indent_char, value="tab",
|
|
260
|
+
command=self.on_setting_change).pack(side=tk.LEFT, padx=10)
|
|
261
|
+
|
|
262
|
+
buttons_frame = ttk.Frame(frame)
|
|
263
|
+
buttons_frame.pack(pady=10)
|
|
264
|
+
|
|
265
|
+
ttk.Button(buttons_frame, text="Indent",
|
|
266
|
+
command=lambda: self.process("indent")).pack(side=tk.LEFT, padx=5)
|
|
267
|
+
ttk.Button(buttons_frame, text="Dedent",
|
|
268
|
+
command=lambda: self.process("dedent")).pack(side=tk.LEFT, padx=5)
|
|
269
|
+
|
|
270
|
+
def create_quote_tab(self):
|
|
271
|
+
"""Creates the Quote Text tab."""
|
|
272
|
+
frame = ttk.Frame(self.notebook)
|
|
273
|
+
self.notebook.add(frame, text="Quote")
|
|
274
|
+
|
|
275
|
+
style_frame = ttk.LabelFrame(frame, text="Quote Style", padding=10)
|
|
276
|
+
style_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
277
|
+
|
|
278
|
+
styles = [
|
|
279
|
+
('Double Quotes ("...")', "double"),
|
|
280
|
+
("Single Quotes ('...')", "single"),
|
|
281
|
+
("Backticks (`...`)", "backtick"),
|
|
282
|
+
("Code Block (```...```)", "code_block"),
|
|
283
|
+
("Blockquote (> ...)", "blockquote"),
|
|
284
|
+
]
|
|
285
|
+
|
|
286
|
+
for text, value in styles:
|
|
287
|
+
ttk.Radiobutton(style_frame, text=text,
|
|
288
|
+
variable=self.quote_style, value=value,
|
|
289
|
+
command=self.on_setting_change).pack(anchor=tk.W)
|
|
290
|
+
|
|
291
|
+
ttk.Button(frame, text="Quote Text",
|
|
292
|
+
command=lambda: self.process("quote")).pack(pady=10)
|
|
293
|
+
|
|
294
|
+
def load_settings(self):
|
|
295
|
+
"""Load settings from the application."""
|
|
296
|
+
settings = self.app.settings.get("tool_settings", {}).get("Text Wrapper", {})
|
|
297
|
+
|
|
298
|
+
self.wrap_width.set(settings.get("wrap_width", 80))
|
|
299
|
+
self.justify_mode.set(settings.get("justify_mode", "left"))
|
|
300
|
+
self.justify_width.set(settings.get("justify_width", 80))
|
|
301
|
+
self.prefix.set(settings.get("prefix", ""))
|
|
302
|
+
self.suffix.set(settings.get("suffix", ""))
|
|
303
|
+
self.skip_empty.set(settings.get("skip_empty", True))
|
|
304
|
+
self.indent_size.set(settings.get("indent_size", 4))
|
|
305
|
+
self.indent_char.set(settings.get("indent_char", "space"))
|
|
306
|
+
self.quote_style.set(settings.get("quote_style", "double"))
|
|
307
|
+
|
|
308
|
+
def save_settings(self):
|
|
309
|
+
"""Save current settings to the application."""
|
|
310
|
+
if "Text Wrapper" not in self.app.settings["tool_settings"]:
|
|
311
|
+
self.app.settings["tool_settings"]["Text Wrapper"] = {}
|
|
312
|
+
|
|
313
|
+
self.app.settings["tool_settings"]["Text Wrapper"].update({
|
|
314
|
+
"wrap_width": self.wrap_width.get(),
|
|
315
|
+
"justify_mode": self.justify_mode.get(),
|
|
316
|
+
"justify_width": self.justify_width.get(),
|
|
317
|
+
"prefix": self.prefix.get(),
|
|
318
|
+
"suffix": self.suffix.get(),
|
|
319
|
+
"skip_empty": self.skip_empty.get(),
|
|
320
|
+
"indent_size": self.indent_size.get(),
|
|
321
|
+
"indent_char": self.indent_char.get(),
|
|
322
|
+
"quote_style": self.quote_style.get()
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
self.app.save_settings()
|
|
326
|
+
|
|
327
|
+
def on_setting_change(self, *args):
|
|
328
|
+
"""Handle setting changes."""
|
|
329
|
+
self.save_settings()
|
|
330
|
+
|
|
331
|
+
def process(self, operation):
|
|
332
|
+
"""Process the input text."""
|
|
333
|
+
active_input_tab = self.app.input_tabs[self.app.input_notebook.index(self.app.input_notebook.select())]
|
|
334
|
+
input_text = active_input_tab.text.get("1.0", tk.END).rstrip('\n')
|
|
335
|
+
|
|
336
|
+
if not input_text:
|
|
337
|
+
return
|
|
338
|
+
|
|
339
|
+
if operation == "wrap":
|
|
340
|
+
result = TextWrapperProcessor.word_wrap(input_text, self.wrap_width.get())
|
|
341
|
+
elif operation == "justify":
|
|
342
|
+
result = TextWrapperProcessor.justify_text(
|
|
343
|
+
input_text, self.justify_width.get(), self.justify_mode.get())
|
|
344
|
+
elif operation == "prefix_suffix":
|
|
345
|
+
result = TextWrapperProcessor.add_prefix_suffix(
|
|
346
|
+
input_text, self.prefix.get(), self.suffix.get(), self.skip_empty.get())
|
|
347
|
+
elif operation == "indent":
|
|
348
|
+
result = TextWrapperProcessor.indent(
|
|
349
|
+
input_text, self.indent_size.get(), self.indent_char.get())
|
|
350
|
+
elif operation == "dedent":
|
|
351
|
+
result = TextWrapperProcessor.dedent(input_text, self.indent_size.get())
|
|
352
|
+
elif operation == "quote":
|
|
353
|
+
result = TextWrapperProcessor.quote_text(input_text, self.quote_style.get())
|
|
354
|
+
else:
|
|
355
|
+
result = input_text
|
|
356
|
+
|
|
357
|
+
active_output_tab = self.app.output_tabs[self.app.output_notebook.index(self.app.output_notebook.select())]
|
|
358
|
+
active_output_tab.text.config(state="normal")
|
|
359
|
+
active_output_tab.text.delete("1.0", tk.END)
|
|
360
|
+
active_output_tab.text.insert("1.0", result)
|
|
361
|
+
active_output_tab.text.config(state="disabled")
|
|
362
|
+
|
|
363
|
+
self.app.update_all_stats()
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
class TextWrapper:
|
|
367
|
+
"""Main class for Text Wrapper integration."""
|
|
368
|
+
|
|
369
|
+
def __init__(self):
|
|
370
|
+
self.processor = TextWrapperProcessor()
|
|
371
|
+
|
|
372
|
+
def create_widget(self, parent, app):
|
|
373
|
+
"""Create and return the Text Wrapper widget."""
|
|
374
|
+
return TextWrapperWidget(parent, app)
|
|
375
|
+
|
|
376
|
+
def get_default_settings(self):
|
|
377
|
+
"""Return default settings for Text Wrapper."""
|
|
378
|
+
return {
|
|
379
|
+
"wrap_width": 80,
|
|
380
|
+
"justify_mode": "left",
|
|
381
|
+
"justify_width": 80,
|
|
382
|
+
"prefix": "",
|
|
383
|
+
"suffix": "",
|
|
384
|
+
"skip_empty": True,
|
|
385
|
+
"indent_size": 4,
|
|
386
|
+
"indent_char": "space",
|
|
387
|
+
"quote_style": "double"
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
# BaseTool-compatible wrapper
|
|
392
|
+
try:
|
|
393
|
+
from tools.base_tool import BaseTool
|
|
394
|
+
from typing import Dict, Any, Optional, Callable
|
|
395
|
+
|
|
396
|
+
class TextWrapperV2(BaseTool):
|
|
397
|
+
"""
|
|
398
|
+
BaseTool-compatible version of TextWrapper.
|
|
399
|
+
"""
|
|
400
|
+
|
|
401
|
+
TOOL_NAME = "Text Wrapper"
|
|
402
|
+
TOOL_DESCRIPTION = "Wrap text to specified width"
|
|
403
|
+
TOOL_VERSION = "2.0.0"
|
|
404
|
+
|
|
405
|
+
def __init__(self):
|
|
406
|
+
super().__init__()
|
|
407
|
+
self._processor = TextWrapperProcessor()
|
|
408
|
+
|
|
409
|
+
def process_text(self, input_text: str, settings: Dict[str, Any]) -> str:
|
|
410
|
+
"""Wrap text to specified width."""
|
|
411
|
+
width = settings.get("width", 80)
|
|
412
|
+
return TextWrapperProcessor.word_wrap(input_text, width)
|
|
413
|
+
|
|
414
|
+
def create_ui(self,
|
|
415
|
+
parent,
|
|
416
|
+
settings: Dict[str, Any],
|
|
417
|
+
on_setting_change_callback: Optional[Callable] = None,
|
|
418
|
+
apply_tool_callback: Optional[Callable] = None):
|
|
419
|
+
"""Create minimal UI - full widget used separately."""
|
|
420
|
+
self._settings = settings.copy()
|
|
421
|
+
self._on_setting_change = on_setting_change_callback
|
|
422
|
+
self._apply_callback = apply_tool_callback
|
|
423
|
+
return None
|
|
424
|
+
|
|
425
|
+
@classmethod
|
|
426
|
+
def get_default_settings(cls) -> Dict[str, Any]:
|
|
427
|
+
"""Return default settings."""
|
|
428
|
+
return {"width": 80}
|
|
429
|
+
|
|
430
|
+
except ImportError:
|
|
431
431
|
pass
|