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/sorter_tools.py
CHANGED
|
@@ -1,459 +1,459 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Sorter Tools Module - Number and Alphabetical sorting utilities
|
|
3
|
-
|
|
4
|
-
This module provides comprehensive sorting functionality with a tabbed UI interface
|
|
5
|
-
for the Promera AI Commander application.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import tkinter as tk
|
|
9
|
-
from tkinter import ttk
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class SorterToolsProcessor:
|
|
13
|
-
"""Sorter tools processor with number and alphabetical sorting capabilities."""
|
|
14
|
-
|
|
15
|
-
@staticmethod
|
|
16
|
-
def number_sorter(text, order):
|
|
17
|
-
"""Sorts a list of numbers numerically."""
|
|
18
|
-
try:
|
|
19
|
-
numbers = [float(line.strip()) for line in text.splitlines() if line.strip()]
|
|
20
|
-
numbers.sort(reverse=(order == "descending"))
|
|
21
|
-
return '\n'.join(map(lambda n: '%g' % n, numbers))
|
|
22
|
-
except ValueError:
|
|
23
|
-
return "Error: Input contains non-numeric values."
|
|
24
|
-
|
|
25
|
-
@staticmethod
|
|
26
|
-
def alphabetical_sorter(text, order, unique_only=False, trim=False):
|
|
27
|
-
"""Sorts a list of lines alphabetically, with options for unique values and trimming."""
|
|
28
|
-
lines = text.splitlines()
|
|
29
|
-
if trim:
|
|
30
|
-
lines = [line.strip() for line in lines]
|
|
31
|
-
if unique_only:
|
|
32
|
-
# Using dict.fromkeys to get unique lines while preserving order before sorting
|
|
33
|
-
lines = list(dict.fromkeys(lines))
|
|
34
|
-
lines.sort(key=str.lower, reverse=(order == "descending"))
|
|
35
|
-
return '\n'.join(lines)
|
|
36
|
-
|
|
37
|
-
@staticmethod
|
|
38
|
-
def process_text(input_text, tool_type, settings):
|
|
39
|
-
"""Process text using the specified sorter tool and settings."""
|
|
40
|
-
if tool_type == "Number Sorter":
|
|
41
|
-
return SorterToolsProcessor.number_sorter(
|
|
42
|
-
input_text,
|
|
43
|
-
settings.get("order", "ascending")
|
|
44
|
-
)
|
|
45
|
-
elif tool_type == "Alphabetical Sorter":
|
|
46
|
-
return SorterToolsProcessor.alphabetical_sorter(
|
|
47
|
-
input_text,
|
|
48
|
-
settings.get("order", "ascending"),
|
|
49
|
-
settings.get("unique_only", False),
|
|
50
|
-
settings.get("trim", False)
|
|
51
|
-
)
|
|
52
|
-
else:
|
|
53
|
-
return f"Unknown sorter tool: {tool_type}"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
class SorterToolsWidget(ttk.Frame):
|
|
57
|
-
"""Tabbed interface widget for sorter tools, similar to AI Tools."""
|
|
58
|
-
|
|
59
|
-
def __init__(self, parent, app):
|
|
60
|
-
super().__init__(parent)
|
|
61
|
-
self.app = app
|
|
62
|
-
self.processor = SorterToolsProcessor()
|
|
63
|
-
|
|
64
|
-
# Initialize UI variables for Number Sorter
|
|
65
|
-
self.number_order = tk.StringVar(value="ascending")
|
|
66
|
-
|
|
67
|
-
# Initialize UI variables for Alphabetical Sorter
|
|
68
|
-
self.alpha_order = tk.StringVar(value="ascending")
|
|
69
|
-
self.alpha_trim = tk.BooleanVar(value=False)
|
|
70
|
-
self.alpha_unique_only = tk.BooleanVar(value=False)
|
|
71
|
-
|
|
72
|
-
self.create_widgets()
|
|
73
|
-
self.load_settings()
|
|
74
|
-
|
|
75
|
-
def create_widgets(self):
|
|
76
|
-
"""Creates the tabbed interface for sorter tools."""
|
|
77
|
-
# Create notebook for tabs
|
|
78
|
-
self.notebook = ttk.Notebook(self)
|
|
79
|
-
self.notebook.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
|
80
|
-
|
|
81
|
-
# Create Number Sorter tab
|
|
82
|
-
self.number_frame = ttk.Frame(self.notebook)
|
|
83
|
-
self.notebook.add(self.number_frame, text="Number Sorter")
|
|
84
|
-
self.create_number_sorter_widgets()
|
|
85
|
-
|
|
86
|
-
# Create Alphabetical Sorter tab
|
|
87
|
-
self.alpha_frame = ttk.Frame(self.notebook)
|
|
88
|
-
self.notebook.add(self.alpha_frame, text="Alphabetical Sorter")
|
|
89
|
-
self.create_alphabetical_sorter_widgets()
|
|
90
|
-
|
|
91
|
-
def create_number_sorter_widgets(self):
|
|
92
|
-
"""Creates widgets for the Number Sorter tab."""
|
|
93
|
-
# Order selection
|
|
94
|
-
order_frame = ttk.LabelFrame(self.number_frame, text="Sort Order", padding=10)
|
|
95
|
-
order_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
96
|
-
|
|
97
|
-
ttk.Radiobutton(
|
|
98
|
-
order_frame,
|
|
99
|
-
text="Ascending",
|
|
100
|
-
variable=self.number_order,
|
|
101
|
-
value="ascending",
|
|
102
|
-
command=self._on_setting_change
|
|
103
|
-
).pack(side=tk.LEFT, padx=5)
|
|
104
|
-
|
|
105
|
-
ttk.Radiobutton(
|
|
106
|
-
order_frame,
|
|
107
|
-
text="Descending",
|
|
108
|
-
variable=self.number_order,
|
|
109
|
-
value="descending",
|
|
110
|
-
command=self._on_setting_change
|
|
111
|
-
).pack(side=tk.LEFT, padx=5)
|
|
112
|
-
|
|
113
|
-
# Sort button
|
|
114
|
-
button_frame = ttk.Frame(self.number_frame)
|
|
115
|
-
button_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
116
|
-
|
|
117
|
-
sort_button = ttk.Button(
|
|
118
|
-
button_frame,
|
|
119
|
-
text="Sort Numbers",
|
|
120
|
-
command=self._apply_number_sorter
|
|
121
|
-
)
|
|
122
|
-
sort_button.pack(side=tk.LEFT, padx=5)
|
|
123
|
-
|
|
124
|
-
def create_alphabetical_sorter_widgets(self):
|
|
125
|
-
"""Creates widgets for the Alphabetical Sorter tab."""
|
|
126
|
-
# Order selection
|
|
127
|
-
order_frame = ttk.LabelFrame(self.alpha_frame, text="Sort Order", padding=10)
|
|
128
|
-
order_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
129
|
-
|
|
130
|
-
ttk.Radiobutton(
|
|
131
|
-
order_frame,
|
|
132
|
-
text="Ascending (A-Z)",
|
|
133
|
-
variable=self.alpha_order,
|
|
134
|
-
value="ascending",
|
|
135
|
-
command=self._on_setting_change
|
|
136
|
-
).pack(side=tk.LEFT, padx=5)
|
|
137
|
-
|
|
138
|
-
ttk.Radiobutton(
|
|
139
|
-
order_frame,
|
|
140
|
-
text="Descending (Z-A)",
|
|
141
|
-
variable=self.alpha_order,
|
|
142
|
-
value="descending",
|
|
143
|
-
command=self._on_setting_change
|
|
144
|
-
).pack(side=tk.LEFT, padx=5)
|
|
145
|
-
|
|
146
|
-
# Options
|
|
147
|
-
options_frame = ttk.LabelFrame(self.alpha_frame, text="Options", padding=10)
|
|
148
|
-
options_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
149
|
-
|
|
150
|
-
ttk.Checkbutton(
|
|
151
|
-
options_frame,
|
|
152
|
-
text="Trim whitespace",
|
|
153
|
-
variable=self.alpha_trim,
|
|
154
|
-
command=self._on_setting_change
|
|
155
|
-
).pack(side=tk.LEFT, padx=5)
|
|
156
|
-
|
|
157
|
-
ttk.Checkbutton(
|
|
158
|
-
options_frame,
|
|
159
|
-
text="Only unique values",
|
|
160
|
-
variable=self.alpha_unique_only,
|
|
161
|
-
command=self._on_setting_change
|
|
162
|
-
).pack(side=tk.LEFT, padx=5)
|
|
163
|
-
|
|
164
|
-
# Sort button
|
|
165
|
-
button_frame = ttk.Frame(self.alpha_frame)
|
|
166
|
-
button_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
167
|
-
|
|
168
|
-
sort_button = ttk.Button(
|
|
169
|
-
button_frame,
|
|
170
|
-
text="Sort Alphabetically",
|
|
171
|
-
command=self._apply_alphabetical_sorter
|
|
172
|
-
)
|
|
173
|
-
sort_button.pack(side=tk.LEFT, padx=5)
|
|
174
|
-
|
|
175
|
-
def _on_setting_change(self):
|
|
176
|
-
"""Handle setting changes."""
|
|
177
|
-
self.save_settings()
|
|
178
|
-
if hasattr(self.app, 'on_tool_setting_change'):
|
|
179
|
-
self.app.on_tool_setting_change()
|
|
180
|
-
|
|
181
|
-
def _apply_number_sorter(self):
|
|
182
|
-
"""Apply the Number Sorter tool."""
|
|
183
|
-
self._apply_tool("Number Sorter")
|
|
184
|
-
|
|
185
|
-
def _apply_alphabetical_sorter(self):
|
|
186
|
-
"""Apply the Alphabetical Sorter tool."""
|
|
187
|
-
self._apply_tool("Alphabetical Sorter")
|
|
188
|
-
|
|
189
|
-
def _apply_tool(self, tool_type):
|
|
190
|
-
"""Apply the specified sorter tool."""
|
|
191
|
-
try:
|
|
192
|
-
# Get input text from the active input tab
|
|
193
|
-
active_input_tab = self.app.input_tabs[self.app.input_notebook.index(self.app.input_notebook.select())]
|
|
194
|
-
input_text = active_input_tab.text.get("1.0", tk.END).strip()
|
|
195
|
-
|
|
196
|
-
if not input_text:
|
|
197
|
-
# Show a message if no input text
|
|
198
|
-
active_output_tab = self.app.output_tabs[self.app.output_notebook.index(self.app.output_notebook.select())]
|
|
199
|
-
active_output_tab.text.config(state="normal")
|
|
200
|
-
active_output_tab.text.delete("1.0", tk.END)
|
|
201
|
-
active_output_tab.text.insert("1.0", f"Please enter text to sort in the input area.\n\nFor {tool_type}:\n" +
|
|
202
|
-
("- Enter numbers, one per line" if tool_type == "Number Sorter" else "- Enter text lines to sort alphabetically"))
|
|
203
|
-
active_output_tab.text.config(state="disabled")
|
|
204
|
-
return
|
|
205
|
-
|
|
206
|
-
# Get settings for the tool
|
|
207
|
-
settings = self.get_tool_settings(tool_type)
|
|
208
|
-
|
|
209
|
-
# Process the text
|
|
210
|
-
result = self.processor.process_text(input_text, tool_type, settings)
|
|
211
|
-
|
|
212
|
-
# Update output
|
|
213
|
-
active_output_tab = self.app.output_tabs[self.app.output_notebook.index(self.app.output_notebook.select())]
|
|
214
|
-
active_output_tab.text.config(state="normal")
|
|
215
|
-
active_output_tab.text.delete("1.0", tk.END)
|
|
216
|
-
active_output_tab.text.insert("1.0", result)
|
|
217
|
-
active_output_tab.text.config(state="disabled")
|
|
218
|
-
|
|
219
|
-
# Update statistics
|
|
220
|
-
if hasattr(self.app, 'update_all_stats'):
|
|
221
|
-
self.app.after(10, self.app.update_all_stats)
|
|
222
|
-
|
|
223
|
-
except Exception as e:
|
|
224
|
-
# Show error in output if something goes wrong
|
|
225
|
-
try:
|
|
226
|
-
active_output_tab = self.app.output_tabs[self.app.output_notebook.index(self.app.output_notebook.select())]
|
|
227
|
-
active_output_tab.text.config(state="normal")
|
|
228
|
-
active_output_tab.text.delete("1.0", tk.END)
|
|
229
|
-
active_output_tab.text.insert("1.0", f"Error: {str(e)}")
|
|
230
|
-
active_output_tab.text.config(state="disabled")
|
|
231
|
-
except:
|
|
232
|
-
print(f"Sorter Tools Error: {str(e)}") # Fallback to console
|
|
233
|
-
|
|
234
|
-
def get_tool_settings(self, tool_type):
|
|
235
|
-
"""Get settings for the specified tool."""
|
|
236
|
-
if tool_type == "Number Sorter":
|
|
237
|
-
return {
|
|
238
|
-
"order": self.number_order.get()
|
|
239
|
-
}
|
|
240
|
-
elif tool_type == "Alphabetical Sorter":
|
|
241
|
-
return {
|
|
242
|
-
"order": self.alpha_order.get(),
|
|
243
|
-
"unique_only": self.alpha_unique_only.get(),
|
|
244
|
-
"trim": self.alpha_trim.get()
|
|
245
|
-
}
|
|
246
|
-
return {}
|
|
247
|
-
|
|
248
|
-
def get_all_settings(self):
|
|
249
|
-
"""Get all settings for both sorter tools."""
|
|
250
|
-
return {
|
|
251
|
-
"Number Sorter": self.get_tool_settings("Number Sorter"),
|
|
252
|
-
"Alphabetical Sorter": self.get_tool_settings("Alphabetical Sorter")
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
def load_settings(self):
|
|
256
|
-
"""Load settings from the main application."""
|
|
257
|
-
if not hasattr(self.app, 'settings'):
|
|
258
|
-
return
|
|
259
|
-
|
|
260
|
-
# Load Number Sorter settings
|
|
261
|
-
number_settings = self.app.settings.get("tool_settings", {}).get("Number Sorter", {})
|
|
262
|
-
self.number_order.set(number_settings.get("order", "ascending"))
|
|
263
|
-
|
|
264
|
-
# Load Alphabetical Sorter settings
|
|
265
|
-
alpha_settings = self.app.settings.get("tool_settings", {}).get("Alphabetical Sorter", {})
|
|
266
|
-
self.alpha_order.set(alpha_settings.get("order", "ascending"))
|
|
267
|
-
self.alpha_trim.set(alpha_settings.get("trim", False))
|
|
268
|
-
self.alpha_unique_only.set(alpha_settings.get("unique_only", False))
|
|
269
|
-
|
|
270
|
-
def save_settings(self):
|
|
271
|
-
"""Save settings to the main application."""
|
|
272
|
-
if not hasattr(self.app, 'settings'):
|
|
273
|
-
return
|
|
274
|
-
|
|
275
|
-
# Save Number Sorter settings
|
|
276
|
-
if "Number Sorter" not in self.app.settings["tool_settings"]:
|
|
277
|
-
self.app.settings["tool_settings"]["Number Sorter"] = {}
|
|
278
|
-
self.app.settings["tool_settings"]["Number Sorter"]["order"] = self.number_order.get()
|
|
279
|
-
|
|
280
|
-
# Save Alphabetical Sorter settings
|
|
281
|
-
if "Alphabetical Sorter" not in self.app.settings["tool_settings"]:
|
|
282
|
-
self.app.settings["tool_settings"]["Alphabetical Sorter"] = {}
|
|
283
|
-
self.app.settings["tool_settings"]["Alphabetical Sorter"]["order"] = self.alpha_order.get()
|
|
284
|
-
self.app.settings["tool_settings"]["Alphabetical Sorter"]["unique_only"] = self.alpha_unique_only.get()
|
|
285
|
-
self.app.settings["tool_settings"]["Alphabetical Sorter"]["trim"] = self.alpha_trim.get()
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
class SorterTools:
|
|
289
|
-
"""Main Sorter Tools class that provides the interface for the main application."""
|
|
290
|
-
|
|
291
|
-
def __init__(self):
|
|
292
|
-
self.processor = SorterToolsProcessor()
|
|
293
|
-
self.widget = None
|
|
294
|
-
|
|
295
|
-
def create_widget(self, parent, app):
|
|
296
|
-
"""Create and return the tabbed widget component."""
|
|
297
|
-
self.widget = SorterToolsWidget(parent, app)
|
|
298
|
-
return self.widget
|
|
299
|
-
|
|
300
|
-
def process_text(self, input_text, tool_type, settings):
|
|
301
|
-
"""Process text using the specified sorter tool and settings."""
|
|
302
|
-
return self.processor.process_text(input_text, tool_type, settings)
|
|
303
|
-
|
|
304
|
-
def get_default_settings(self):
|
|
305
|
-
"""Get default settings for both sorter tools."""
|
|
306
|
-
return {
|
|
307
|
-
"Number Sorter": {"order": "ascending"},
|
|
308
|
-
"Alphabetical Sorter": {"order": "ascending", "unique_only": False, "trim": False}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
# Convenience functions for backward compatibility
|
|
313
|
-
def number_sorter(text, order):
|
|
314
|
-
"""Sort numbers with specified order."""
|
|
315
|
-
return SorterToolsProcessor.number_sorter(text, order)
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
def alphabetical_sorter(text, order, unique_only=False, trim=False):
|
|
319
|
-
"""Sort text alphabetically with specified options."""
|
|
320
|
-
return SorterToolsProcessor.alphabetical_sorter(text, order, unique_only, trim)
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
# BaseTool-compatible wrapper
|
|
324
|
-
try:
|
|
325
|
-
from tools.base_tool import BaseTool
|
|
326
|
-
from typing import Dict, Any, Optional, Callable
|
|
327
|
-
import tkinter as tk
|
|
328
|
-
from tkinter import ttk
|
|
329
|
-
|
|
330
|
-
class SorterToolsV2(BaseTool):
|
|
331
|
-
"""
|
|
332
|
-
BaseTool-compatible version of SorterTools.
|
|
333
|
-
|
|
334
|
-
Provides both number and alphabetical sorting with a unified interface.
|
|
335
|
-
"""
|
|
336
|
-
|
|
337
|
-
TOOL_NAME = "Sorter Tools"
|
|
338
|
-
TOOL_DESCRIPTION = "Sort lines numerically or alphabetically"
|
|
339
|
-
TOOL_VERSION = "2.0.0"
|
|
340
|
-
|
|
341
|
-
def __init__(self):
|
|
342
|
-
super().__init__()
|
|
343
|
-
self._processor = SorterToolsProcessor()
|
|
344
|
-
self._sort_type_var: Optional[tk.StringVar] = None
|
|
345
|
-
self._order_var: Optional[tk.StringVar] = None
|
|
346
|
-
self._unique_var: Optional[tk.BooleanVar] = None
|
|
347
|
-
self._trim_var: Optional[tk.BooleanVar] = None
|
|
348
|
-
|
|
349
|
-
def process_text(self, input_text: str, settings: Dict[str, Any]) -> str:
|
|
350
|
-
"""Process text using the specified sorter settings."""
|
|
351
|
-
sort_type = settings.get("sort_type", "alphabetical")
|
|
352
|
-
|
|
353
|
-
if sort_type == "number":
|
|
354
|
-
return SorterToolsProcessor.number_sorter(
|
|
355
|
-
input_text,
|
|
356
|
-
settings.get("order", "ascending")
|
|
357
|
-
)
|
|
358
|
-
else:
|
|
359
|
-
return SorterToolsProcessor.alphabetical_sorter(
|
|
360
|
-
input_text,
|
|
361
|
-
settings.get("order", "ascending"),
|
|
362
|
-
settings.get("unique_only", False),
|
|
363
|
-
settings.get("trim", False)
|
|
364
|
-
)
|
|
365
|
-
|
|
366
|
-
def create_ui(self,
|
|
367
|
-
parent: tk.Frame,
|
|
368
|
-
settings: Dict[str, Any],
|
|
369
|
-
on_setting_change_callback: Optional[Callable] = None,
|
|
370
|
-
apply_tool_callback: Optional[Callable] = None) -> tk.Frame:
|
|
371
|
-
"""Create the Sorter Tools UI."""
|
|
372
|
-
self._settings = settings.copy()
|
|
373
|
-
self._on_setting_change = on_setting_change_callback
|
|
374
|
-
self._apply_callback = apply_tool_callback
|
|
375
|
-
self._initializing = True
|
|
376
|
-
|
|
377
|
-
frame = ttk.Frame(parent)
|
|
378
|
-
frame.pack(fill=tk.BOTH, expand=True)
|
|
379
|
-
|
|
380
|
-
# Sort type selection
|
|
381
|
-
type_frame = ttk.LabelFrame(frame, text="Sort Type", padding=5)
|
|
382
|
-
type_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
383
|
-
|
|
384
|
-
self._sort_type_var = tk.StringVar(value=settings.get("sort_type", "alphabetical"))
|
|
385
|
-
ttk.Radiobutton(type_frame, text="Alphabetical", variable=self._sort_type_var,
|
|
386
|
-
value="alphabetical", command=self._on_type_change).pack(side=tk.LEFT, padx=5)
|
|
387
|
-
ttk.Radiobutton(type_frame, text="Numeric", variable=self._sort_type_var,
|
|
388
|
-
value="number", command=self._on_type_change).pack(side=tk.LEFT, padx=5)
|
|
389
|
-
|
|
390
|
-
# Order selection
|
|
391
|
-
order_frame = ttk.LabelFrame(frame, text="Order", padding=5)
|
|
392
|
-
order_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
393
|
-
|
|
394
|
-
self._order_var = tk.StringVar(value=settings.get("order", "ascending"))
|
|
395
|
-
ttk.Radiobutton(order_frame, text="Ascending", variable=self._order_var,
|
|
396
|
-
value="ascending", command=self._on_change).pack(side=tk.LEFT, padx=5)
|
|
397
|
-
ttk.Radiobutton(order_frame, text="Descending", variable=self._order_var,
|
|
398
|
-
value="descending", command=self._on_change).pack(side=tk.LEFT, padx=5)
|
|
399
|
-
|
|
400
|
-
# Options (for alphabetical)
|
|
401
|
-
self._options_frame = ttk.LabelFrame(frame, text="Options", padding=5)
|
|
402
|
-
self._options_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
403
|
-
|
|
404
|
-
self._trim_var = tk.BooleanVar(value=settings.get("trim", False))
|
|
405
|
-
ttk.Checkbutton(self._options_frame, text="Trim whitespace",
|
|
406
|
-
variable=self._trim_var, command=self._on_change).pack(anchor=tk.W)
|
|
407
|
-
|
|
408
|
-
self._unique_var = tk.BooleanVar(value=settings.get("unique_only", False))
|
|
409
|
-
ttk.Checkbutton(self._options_frame, text="Unique only",
|
|
410
|
-
variable=self._unique_var, command=self._on_change).pack(anchor=tk.W)
|
|
411
|
-
|
|
412
|
-
# Apply button
|
|
413
|
-
if apply_tool_callback:
|
|
414
|
-
ttk.Button(frame, text="Sort", command=apply_tool_callback).pack(pady=10)
|
|
415
|
-
|
|
416
|
-
self._ui_frame = frame
|
|
417
|
-
self._initializing = False
|
|
418
|
-
self._update_options_visibility()
|
|
419
|
-
return frame
|
|
420
|
-
|
|
421
|
-
def _on_type_change(self):
|
|
422
|
-
"""Handle sort type change."""
|
|
423
|
-
self._update_options_visibility()
|
|
424
|
-
self._on_change()
|
|
425
|
-
|
|
426
|
-
def _update_options_visibility(self):
|
|
427
|
-
"""Show/hide options based on sort type."""
|
|
428
|
-
if self._sort_type_var and self._sort_type_var.get() == "number":
|
|
429
|
-
self._options_frame.pack_forget()
|
|
430
|
-
else:
|
|
431
|
-
self._options_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
432
|
-
|
|
433
|
-
def _on_change(self):
|
|
434
|
-
"""Handle setting change."""
|
|
435
|
-
if not self._initializing and self._on_setting_change:
|
|
436
|
-
self._on_setting_change()
|
|
437
|
-
|
|
438
|
-
def get_current_settings(self) -> Dict[str, Any]:
|
|
439
|
-
"""Get current settings from UI."""
|
|
440
|
-
return {
|
|
441
|
-
"sort_type": self._sort_type_var.get() if self._sort_type_var else "alphabetical",
|
|
442
|
-
"order": self._order_var.get() if self._order_var else "ascending",
|
|
443
|
-
"trim": self._trim_var.get() if self._trim_var else False,
|
|
444
|
-
"unique_only": self._unique_var.get() if self._unique_var else False,
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
@classmethod
|
|
448
|
-
def get_default_settings(cls) -> Dict[str, Any]:
|
|
449
|
-
"""Get default settings."""
|
|
450
|
-
return {
|
|
451
|
-
"sort_type": "alphabetical",
|
|
452
|
-
"order": "ascending",
|
|
453
|
-
"trim": False,
|
|
454
|
-
"unique_only": False
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
except ImportError:
|
|
458
|
-
# BaseTool not available
|
|
1
|
+
"""
|
|
2
|
+
Sorter Tools Module - Number and Alphabetical sorting utilities
|
|
3
|
+
|
|
4
|
+
This module provides comprehensive sorting functionality with a tabbed UI interface
|
|
5
|
+
for the Promera AI Commander application.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import tkinter as tk
|
|
9
|
+
from tkinter import ttk
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SorterToolsProcessor:
|
|
13
|
+
"""Sorter tools processor with number and alphabetical sorting capabilities."""
|
|
14
|
+
|
|
15
|
+
@staticmethod
|
|
16
|
+
def number_sorter(text, order):
|
|
17
|
+
"""Sorts a list of numbers numerically."""
|
|
18
|
+
try:
|
|
19
|
+
numbers = [float(line.strip()) for line in text.splitlines() if line.strip()]
|
|
20
|
+
numbers.sort(reverse=(order == "descending"))
|
|
21
|
+
return '\n'.join(map(lambda n: '%g' % n, numbers))
|
|
22
|
+
except ValueError:
|
|
23
|
+
return "Error: Input contains non-numeric values."
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def alphabetical_sorter(text, order, unique_only=False, trim=False):
|
|
27
|
+
"""Sorts a list of lines alphabetically, with options for unique values and trimming."""
|
|
28
|
+
lines = text.splitlines()
|
|
29
|
+
if trim:
|
|
30
|
+
lines = [line.strip() for line in lines]
|
|
31
|
+
if unique_only:
|
|
32
|
+
# Using dict.fromkeys to get unique lines while preserving order before sorting
|
|
33
|
+
lines = list(dict.fromkeys(lines))
|
|
34
|
+
lines.sort(key=str.lower, reverse=(order == "descending"))
|
|
35
|
+
return '\n'.join(lines)
|
|
36
|
+
|
|
37
|
+
@staticmethod
|
|
38
|
+
def process_text(input_text, tool_type, settings):
|
|
39
|
+
"""Process text using the specified sorter tool and settings."""
|
|
40
|
+
if tool_type == "Number Sorter":
|
|
41
|
+
return SorterToolsProcessor.number_sorter(
|
|
42
|
+
input_text,
|
|
43
|
+
settings.get("order", "ascending")
|
|
44
|
+
)
|
|
45
|
+
elif tool_type == "Alphabetical Sorter":
|
|
46
|
+
return SorterToolsProcessor.alphabetical_sorter(
|
|
47
|
+
input_text,
|
|
48
|
+
settings.get("order", "ascending"),
|
|
49
|
+
settings.get("unique_only", False),
|
|
50
|
+
settings.get("trim", False)
|
|
51
|
+
)
|
|
52
|
+
else:
|
|
53
|
+
return f"Unknown sorter tool: {tool_type}"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class SorterToolsWidget(ttk.Frame):
|
|
57
|
+
"""Tabbed interface widget for sorter tools, similar to AI Tools."""
|
|
58
|
+
|
|
59
|
+
def __init__(self, parent, app):
|
|
60
|
+
super().__init__(parent)
|
|
61
|
+
self.app = app
|
|
62
|
+
self.processor = SorterToolsProcessor()
|
|
63
|
+
|
|
64
|
+
# Initialize UI variables for Number Sorter
|
|
65
|
+
self.number_order = tk.StringVar(value="ascending")
|
|
66
|
+
|
|
67
|
+
# Initialize UI variables for Alphabetical Sorter
|
|
68
|
+
self.alpha_order = tk.StringVar(value="ascending")
|
|
69
|
+
self.alpha_trim = tk.BooleanVar(value=False)
|
|
70
|
+
self.alpha_unique_only = tk.BooleanVar(value=False)
|
|
71
|
+
|
|
72
|
+
self.create_widgets()
|
|
73
|
+
self.load_settings()
|
|
74
|
+
|
|
75
|
+
def create_widgets(self):
|
|
76
|
+
"""Creates the tabbed interface for sorter tools."""
|
|
77
|
+
# Create notebook for tabs
|
|
78
|
+
self.notebook = ttk.Notebook(self)
|
|
79
|
+
self.notebook.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
|
80
|
+
|
|
81
|
+
# Create Number Sorter tab
|
|
82
|
+
self.number_frame = ttk.Frame(self.notebook)
|
|
83
|
+
self.notebook.add(self.number_frame, text="Number Sorter")
|
|
84
|
+
self.create_number_sorter_widgets()
|
|
85
|
+
|
|
86
|
+
# Create Alphabetical Sorter tab
|
|
87
|
+
self.alpha_frame = ttk.Frame(self.notebook)
|
|
88
|
+
self.notebook.add(self.alpha_frame, text="Alphabetical Sorter")
|
|
89
|
+
self.create_alphabetical_sorter_widgets()
|
|
90
|
+
|
|
91
|
+
def create_number_sorter_widgets(self):
|
|
92
|
+
"""Creates widgets for the Number Sorter tab."""
|
|
93
|
+
# Order selection
|
|
94
|
+
order_frame = ttk.LabelFrame(self.number_frame, text="Sort Order", padding=10)
|
|
95
|
+
order_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
96
|
+
|
|
97
|
+
ttk.Radiobutton(
|
|
98
|
+
order_frame,
|
|
99
|
+
text="Ascending",
|
|
100
|
+
variable=self.number_order,
|
|
101
|
+
value="ascending",
|
|
102
|
+
command=self._on_setting_change
|
|
103
|
+
).pack(side=tk.LEFT, padx=5)
|
|
104
|
+
|
|
105
|
+
ttk.Radiobutton(
|
|
106
|
+
order_frame,
|
|
107
|
+
text="Descending",
|
|
108
|
+
variable=self.number_order,
|
|
109
|
+
value="descending",
|
|
110
|
+
command=self._on_setting_change
|
|
111
|
+
).pack(side=tk.LEFT, padx=5)
|
|
112
|
+
|
|
113
|
+
# Sort button
|
|
114
|
+
button_frame = ttk.Frame(self.number_frame)
|
|
115
|
+
button_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
116
|
+
|
|
117
|
+
sort_button = ttk.Button(
|
|
118
|
+
button_frame,
|
|
119
|
+
text="Sort Numbers",
|
|
120
|
+
command=self._apply_number_sorter
|
|
121
|
+
)
|
|
122
|
+
sort_button.pack(side=tk.LEFT, padx=5)
|
|
123
|
+
|
|
124
|
+
def create_alphabetical_sorter_widgets(self):
|
|
125
|
+
"""Creates widgets for the Alphabetical Sorter tab."""
|
|
126
|
+
# Order selection
|
|
127
|
+
order_frame = ttk.LabelFrame(self.alpha_frame, text="Sort Order", padding=10)
|
|
128
|
+
order_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
129
|
+
|
|
130
|
+
ttk.Radiobutton(
|
|
131
|
+
order_frame,
|
|
132
|
+
text="Ascending (A-Z)",
|
|
133
|
+
variable=self.alpha_order,
|
|
134
|
+
value="ascending",
|
|
135
|
+
command=self._on_setting_change
|
|
136
|
+
).pack(side=tk.LEFT, padx=5)
|
|
137
|
+
|
|
138
|
+
ttk.Radiobutton(
|
|
139
|
+
order_frame,
|
|
140
|
+
text="Descending (Z-A)",
|
|
141
|
+
variable=self.alpha_order,
|
|
142
|
+
value="descending",
|
|
143
|
+
command=self._on_setting_change
|
|
144
|
+
).pack(side=tk.LEFT, padx=5)
|
|
145
|
+
|
|
146
|
+
# Options
|
|
147
|
+
options_frame = ttk.LabelFrame(self.alpha_frame, text="Options", padding=10)
|
|
148
|
+
options_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
149
|
+
|
|
150
|
+
ttk.Checkbutton(
|
|
151
|
+
options_frame,
|
|
152
|
+
text="Trim whitespace",
|
|
153
|
+
variable=self.alpha_trim,
|
|
154
|
+
command=self._on_setting_change
|
|
155
|
+
).pack(side=tk.LEFT, padx=5)
|
|
156
|
+
|
|
157
|
+
ttk.Checkbutton(
|
|
158
|
+
options_frame,
|
|
159
|
+
text="Only unique values",
|
|
160
|
+
variable=self.alpha_unique_only,
|
|
161
|
+
command=self._on_setting_change
|
|
162
|
+
).pack(side=tk.LEFT, padx=5)
|
|
163
|
+
|
|
164
|
+
# Sort button
|
|
165
|
+
button_frame = ttk.Frame(self.alpha_frame)
|
|
166
|
+
button_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
167
|
+
|
|
168
|
+
sort_button = ttk.Button(
|
|
169
|
+
button_frame,
|
|
170
|
+
text="Sort Alphabetically",
|
|
171
|
+
command=self._apply_alphabetical_sorter
|
|
172
|
+
)
|
|
173
|
+
sort_button.pack(side=tk.LEFT, padx=5)
|
|
174
|
+
|
|
175
|
+
def _on_setting_change(self):
|
|
176
|
+
"""Handle setting changes."""
|
|
177
|
+
self.save_settings()
|
|
178
|
+
if hasattr(self.app, 'on_tool_setting_change'):
|
|
179
|
+
self.app.on_tool_setting_change()
|
|
180
|
+
|
|
181
|
+
def _apply_number_sorter(self):
|
|
182
|
+
"""Apply the Number Sorter tool."""
|
|
183
|
+
self._apply_tool("Number Sorter")
|
|
184
|
+
|
|
185
|
+
def _apply_alphabetical_sorter(self):
|
|
186
|
+
"""Apply the Alphabetical Sorter tool."""
|
|
187
|
+
self._apply_tool("Alphabetical Sorter")
|
|
188
|
+
|
|
189
|
+
def _apply_tool(self, tool_type):
|
|
190
|
+
"""Apply the specified sorter tool."""
|
|
191
|
+
try:
|
|
192
|
+
# Get input text from the active input tab
|
|
193
|
+
active_input_tab = self.app.input_tabs[self.app.input_notebook.index(self.app.input_notebook.select())]
|
|
194
|
+
input_text = active_input_tab.text.get("1.0", tk.END).strip()
|
|
195
|
+
|
|
196
|
+
if not input_text:
|
|
197
|
+
# Show a message if no input text
|
|
198
|
+
active_output_tab = self.app.output_tabs[self.app.output_notebook.index(self.app.output_notebook.select())]
|
|
199
|
+
active_output_tab.text.config(state="normal")
|
|
200
|
+
active_output_tab.text.delete("1.0", tk.END)
|
|
201
|
+
active_output_tab.text.insert("1.0", f"Please enter text to sort in the input area.\n\nFor {tool_type}:\n" +
|
|
202
|
+
("- Enter numbers, one per line" if tool_type == "Number Sorter" else "- Enter text lines to sort alphabetically"))
|
|
203
|
+
active_output_tab.text.config(state="disabled")
|
|
204
|
+
return
|
|
205
|
+
|
|
206
|
+
# Get settings for the tool
|
|
207
|
+
settings = self.get_tool_settings(tool_type)
|
|
208
|
+
|
|
209
|
+
# Process the text
|
|
210
|
+
result = self.processor.process_text(input_text, tool_type, settings)
|
|
211
|
+
|
|
212
|
+
# Update output
|
|
213
|
+
active_output_tab = self.app.output_tabs[self.app.output_notebook.index(self.app.output_notebook.select())]
|
|
214
|
+
active_output_tab.text.config(state="normal")
|
|
215
|
+
active_output_tab.text.delete("1.0", tk.END)
|
|
216
|
+
active_output_tab.text.insert("1.0", result)
|
|
217
|
+
active_output_tab.text.config(state="disabled")
|
|
218
|
+
|
|
219
|
+
# Update statistics
|
|
220
|
+
if hasattr(self.app, 'update_all_stats'):
|
|
221
|
+
self.app.after(10, self.app.update_all_stats)
|
|
222
|
+
|
|
223
|
+
except Exception as e:
|
|
224
|
+
# Show error in output if something goes wrong
|
|
225
|
+
try:
|
|
226
|
+
active_output_tab = self.app.output_tabs[self.app.output_notebook.index(self.app.output_notebook.select())]
|
|
227
|
+
active_output_tab.text.config(state="normal")
|
|
228
|
+
active_output_tab.text.delete("1.0", tk.END)
|
|
229
|
+
active_output_tab.text.insert("1.0", f"Error: {str(e)}")
|
|
230
|
+
active_output_tab.text.config(state="disabled")
|
|
231
|
+
except:
|
|
232
|
+
print(f"Sorter Tools Error: {str(e)}") # Fallback to console
|
|
233
|
+
|
|
234
|
+
def get_tool_settings(self, tool_type):
|
|
235
|
+
"""Get settings for the specified tool."""
|
|
236
|
+
if tool_type == "Number Sorter":
|
|
237
|
+
return {
|
|
238
|
+
"order": self.number_order.get()
|
|
239
|
+
}
|
|
240
|
+
elif tool_type == "Alphabetical Sorter":
|
|
241
|
+
return {
|
|
242
|
+
"order": self.alpha_order.get(),
|
|
243
|
+
"unique_only": self.alpha_unique_only.get(),
|
|
244
|
+
"trim": self.alpha_trim.get()
|
|
245
|
+
}
|
|
246
|
+
return {}
|
|
247
|
+
|
|
248
|
+
def get_all_settings(self):
|
|
249
|
+
"""Get all settings for both sorter tools."""
|
|
250
|
+
return {
|
|
251
|
+
"Number Sorter": self.get_tool_settings("Number Sorter"),
|
|
252
|
+
"Alphabetical Sorter": self.get_tool_settings("Alphabetical Sorter")
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
def load_settings(self):
|
|
256
|
+
"""Load settings from the main application."""
|
|
257
|
+
if not hasattr(self.app, 'settings'):
|
|
258
|
+
return
|
|
259
|
+
|
|
260
|
+
# Load Number Sorter settings
|
|
261
|
+
number_settings = self.app.settings.get("tool_settings", {}).get("Number Sorter", {})
|
|
262
|
+
self.number_order.set(number_settings.get("order", "ascending"))
|
|
263
|
+
|
|
264
|
+
# Load Alphabetical Sorter settings
|
|
265
|
+
alpha_settings = self.app.settings.get("tool_settings", {}).get("Alphabetical Sorter", {})
|
|
266
|
+
self.alpha_order.set(alpha_settings.get("order", "ascending"))
|
|
267
|
+
self.alpha_trim.set(alpha_settings.get("trim", False))
|
|
268
|
+
self.alpha_unique_only.set(alpha_settings.get("unique_only", False))
|
|
269
|
+
|
|
270
|
+
def save_settings(self):
|
|
271
|
+
"""Save settings to the main application."""
|
|
272
|
+
if not hasattr(self.app, 'settings'):
|
|
273
|
+
return
|
|
274
|
+
|
|
275
|
+
# Save Number Sorter settings
|
|
276
|
+
if "Number Sorter" not in self.app.settings["tool_settings"]:
|
|
277
|
+
self.app.settings["tool_settings"]["Number Sorter"] = {}
|
|
278
|
+
self.app.settings["tool_settings"]["Number Sorter"]["order"] = self.number_order.get()
|
|
279
|
+
|
|
280
|
+
# Save Alphabetical Sorter settings
|
|
281
|
+
if "Alphabetical Sorter" not in self.app.settings["tool_settings"]:
|
|
282
|
+
self.app.settings["tool_settings"]["Alphabetical Sorter"] = {}
|
|
283
|
+
self.app.settings["tool_settings"]["Alphabetical Sorter"]["order"] = self.alpha_order.get()
|
|
284
|
+
self.app.settings["tool_settings"]["Alphabetical Sorter"]["unique_only"] = self.alpha_unique_only.get()
|
|
285
|
+
self.app.settings["tool_settings"]["Alphabetical Sorter"]["trim"] = self.alpha_trim.get()
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
class SorterTools:
|
|
289
|
+
"""Main Sorter Tools class that provides the interface for the main application."""
|
|
290
|
+
|
|
291
|
+
def __init__(self):
|
|
292
|
+
self.processor = SorterToolsProcessor()
|
|
293
|
+
self.widget = None
|
|
294
|
+
|
|
295
|
+
def create_widget(self, parent, app):
|
|
296
|
+
"""Create and return the tabbed widget component."""
|
|
297
|
+
self.widget = SorterToolsWidget(parent, app)
|
|
298
|
+
return self.widget
|
|
299
|
+
|
|
300
|
+
def process_text(self, input_text, tool_type, settings):
|
|
301
|
+
"""Process text using the specified sorter tool and settings."""
|
|
302
|
+
return self.processor.process_text(input_text, tool_type, settings)
|
|
303
|
+
|
|
304
|
+
def get_default_settings(self):
|
|
305
|
+
"""Get default settings for both sorter tools."""
|
|
306
|
+
return {
|
|
307
|
+
"Number Sorter": {"order": "ascending"},
|
|
308
|
+
"Alphabetical Sorter": {"order": "ascending", "unique_only": False, "trim": False}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
# Convenience functions for backward compatibility
|
|
313
|
+
def number_sorter(text, order):
|
|
314
|
+
"""Sort numbers with specified order."""
|
|
315
|
+
return SorterToolsProcessor.number_sorter(text, order)
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def alphabetical_sorter(text, order, unique_only=False, trim=False):
|
|
319
|
+
"""Sort text alphabetically with specified options."""
|
|
320
|
+
return SorterToolsProcessor.alphabetical_sorter(text, order, unique_only, trim)
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
# BaseTool-compatible wrapper
|
|
324
|
+
try:
|
|
325
|
+
from tools.base_tool import BaseTool
|
|
326
|
+
from typing import Dict, Any, Optional, Callable
|
|
327
|
+
import tkinter as tk
|
|
328
|
+
from tkinter import ttk
|
|
329
|
+
|
|
330
|
+
class SorterToolsV2(BaseTool):
|
|
331
|
+
"""
|
|
332
|
+
BaseTool-compatible version of SorterTools.
|
|
333
|
+
|
|
334
|
+
Provides both number and alphabetical sorting with a unified interface.
|
|
335
|
+
"""
|
|
336
|
+
|
|
337
|
+
TOOL_NAME = "Sorter Tools"
|
|
338
|
+
TOOL_DESCRIPTION = "Sort lines numerically or alphabetically"
|
|
339
|
+
TOOL_VERSION = "2.0.0"
|
|
340
|
+
|
|
341
|
+
def __init__(self):
|
|
342
|
+
super().__init__()
|
|
343
|
+
self._processor = SorterToolsProcessor()
|
|
344
|
+
self._sort_type_var: Optional[tk.StringVar] = None
|
|
345
|
+
self._order_var: Optional[tk.StringVar] = None
|
|
346
|
+
self._unique_var: Optional[tk.BooleanVar] = None
|
|
347
|
+
self._trim_var: Optional[tk.BooleanVar] = None
|
|
348
|
+
|
|
349
|
+
def process_text(self, input_text: str, settings: Dict[str, Any]) -> str:
|
|
350
|
+
"""Process text using the specified sorter settings."""
|
|
351
|
+
sort_type = settings.get("sort_type", "alphabetical")
|
|
352
|
+
|
|
353
|
+
if sort_type == "number":
|
|
354
|
+
return SorterToolsProcessor.number_sorter(
|
|
355
|
+
input_text,
|
|
356
|
+
settings.get("order", "ascending")
|
|
357
|
+
)
|
|
358
|
+
else:
|
|
359
|
+
return SorterToolsProcessor.alphabetical_sorter(
|
|
360
|
+
input_text,
|
|
361
|
+
settings.get("order", "ascending"),
|
|
362
|
+
settings.get("unique_only", False),
|
|
363
|
+
settings.get("trim", False)
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
def create_ui(self,
|
|
367
|
+
parent: tk.Frame,
|
|
368
|
+
settings: Dict[str, Any],
|
|
369
|
+
on_setting_change_callback: Optional[Callable] = None,
|
|
370
|
+
apply_tool_callback: Optional[Callable] = None) -> tk.Frame:
|
|
371
|
+
"""Create the Sorter Tools UI."""
|
|
372
|
+
self._settings = settings.copy()
|
|
373
|
+
self._on_setting_change = on_setting_change_callback
|
|
374
|
+
self._apply_callback = apply_tool_callback
|
|
375
|
+
self._initializing = True
|
|
376
|
+
|
|
377
|
+
frame = ttk.Frame(parent)
|
|
378
|
+
frame.pack(fill=tk.BOTH, expand=True)
|
|
379
|
+
|
|
380
|
+
# Sort type selection
|
|
381
|
+
type_frame = ttk.LabelFrame(frame, text="Sort Type", padding=5)
|
|
382
|
+
type_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
383
|
+
|
|
384
|
+
self._sort_type_var = tk.StringVar(value=settings.get("sort_type", "alphabetical"))
|
|
385
|
+
ttk.Radiobutton(type_frame, text="Alphabetical", variable=self._sort_type_var,
|
|
386
|
+
value="alphabetical", command=self._on_type_change).pack(side=tk.LEFT, padx=5)
|
|
387
|
+
ttk.Radiobutton(type_frame, text="Numeric", variable=self._sort_type_var,
|
|
388
|
+
value="number", command=self._on_type_change).pack(side=tk.LEFT, padx=5)
|
|
389
|
+
|
|
390
|
+
# Order selection
|
|
391
|
+
order_frame = ttk.LabelFrame(frame, text="Order", padding=5)
|
|
392
|
+
order_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
393
|
+
|
|
394
|
+
self._order_var = tk.StringVar(value=settings.get("order", "ascending"))
|
|
395
|
+
ttk.Radiobutton(order_frame, text="Ascending", variable=self._order_var,
|
|
396
|
+
value="ascending", command=self._on_change).pack(side=tk.LEFT, padx=5)
|
|
397
|
+
ttk.Radiobutton(order_frame, text="Descending", variable=self._order_var,
|
|
398
|
+
value="descending", command=self._on_change).pack(side=tk.LEFT, padx=5)
|
|
399
|
+
|
|
400
|
+
# Options (for alphabetical)
|
|
401
|
+
self._options_frame = ttk.LabelFrame(frame, text="Options", padding=5)
|
|
402
|
+
self._options_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
403
|
+
|
|
404
|
+
self._trim_var = tk.BooleanVar(value=settings.get("trim", False))
|
|
405
|
+
ttk.Checkbutton(self._options_frame, text="Trim whitespace",
|
|
406
|
+
variable=self._trim_var, command=self._on_change).pack(anchor=tk.W)
|
|
407
|
+
|
|
408
|
+
self._unique_var = tk.BooleanVar(value=settings.get("unique_only", False))
|
|
409
|
+
ttk.Checkbutton(self._options_frame, text="Unique only",
|
|
410
|
+
variable=self._unique_var, command=self._on_change).pack(anchor=tk.W)
|
|
411
|
+
|
|
412
|
+
# Apply button
|
|
413
|
+
if apply_tool_callback:
|
|
414
|
+
ttk.Button(frame, text="Sort", command=apply_tool_callback).pack(pady=10)
|
|
415
|
+
|
|
416
|
+
self._ui_frame = frame
|
|
417
|
+
self._initializing = False
|
|
418
|
+
self._update_options_visibility()
|
|
419
|
+
return frame
|
|
420
|
+
|
|
421
|
+
def _on_type_change(self):
|
|
422
|
+
"""Handle sort type change."""
|
|
423
|
+
self._update_options_visibility()
|
|
424
|
+
self._on_change()
|
|
425
|
+
|
|
426
|
+
def _update_options_visibility(self):
|
|
427
|
+
"""Show/hide options based on sort type."""
|
|
428
|
+
if self._sort_type_var and self._sort_type_var.get() == "number":
|
|
429
|
+
self._options_frame.pack_forget()
|
|
430
|
+
else:
|
|
431
|
+
self._options_frame.pack(fill=tk.X, padx=5, pady=5)
|
|
432
|
+
|
|
433
|
+
def _on_change(self):
|
|
434
|
+
"""Handle setting change."""
|
|
435
|
+
if not self._initializing and self._on_setting_change:
|
|
436
|
+
self._on_setting_change()
|
|
437
|
+
|
|
438
|
+
def get_current_settings(self) -> Dict[str, Any]:
|
|
439
|
+
"""Get current settings from UI."""
|
|
440
|
+
return {
|
|
441
|
+
"sort_type": self._sort_type_var.get() if self._sort_type_var else "alphabetical",
|
|
442
|
+
"order": self._order_var.get() if self._order_var else "ascending",
|
|
443
|
+
"trim": self._trim_var.get() if self._trim_var else False,
|
|
444
|
+
"unique_only": self._unique_var.get() if self._unique_var else False,
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
@classmethod
|
|
448
|
+
def get_default_settings(cls) -> Dict[str, Any]:
|
|
449
|
+
"""Get default settings."""
|
|
450
|
+
return {
|
|
451
|
+
"sort_type": "alphabetical",
|
|
452
|
+
"order": "ascending",
|
|
453
|
+
"trim": False,
|
|
454
|
+
"unique_only": False
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
except ImportError:
|
|
458
|
+
# BaseTool not available
|
|
459
459
|
pass
|