SafePDF 1.0.11__py3-none-any.whl
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.
- SafePDF/__init__.py +10 -0
- SafePDF/ctrl/__init__.py +0 -0
- SafePDF/ctrl/language_manager.py +69 -0
- SafePDF/ctrl/safe_pdf_controller.py +469 -0
- SafePDF/logger/__init__.py +0 -0
- SafePDF/logger/logging_config.py +94 -0
- SafePDF/ops/__init__.py +0 -0
- SafePDF/ops/license_manager.py +247 -0
- SafePDF/ops/pdf2docx.py +157 -0
- SafePDF/ops/pdf2jpeg.py +116 -0
- SafePDF/ops/pdf_compress.py +282 -0
- SafePDF/ops/pdf_merge.py +104 -0
- SafePDF/ops/pdf_operations.py +563 -0
- SafePDF/ops/pdf_rotate.py +102 -0
- SafePDF/ops/pdf_split.py +178 -0
- SafePDF/ops/updates.py +308 -0
- SafePDF/safe_pdf_app.py +121 -0
- SafePDF/test/__init__.py +0 -0
- SafePDF/test/test_compression.py +79 -0
- SafePDF/test/test_pro_dialog.py +45 -0
- SafePDF/text/de/help_content.txt +58 -0
- SafePDF/text/de/pro_features.txt +9 -0
- SafePDF/text/de/ui.json +260 -0
- SafePDF/text/de/welcome_content.txt +24 -0
- SafePDF/text/en/help_content.txt +42 -0
- SafePDF/text/en/pro_features.txt +8 -0
- SafePDF/text/en/ui.json +260 -0
- SafePDF/text/en/welcome_content.txt +25 -0
- SafePDF/text/tr/help_content.txt +53 -0
- SafePDF/text/tr/pro_features.txt +8 -0
- SafePDF/text/tr/ui.json +260 -0
- SafePDF/text/tr/welcome_content.txt +24 -0
- SafePDF/ui/__init__.py +11 -0
- SafePDF/ui/common_elements.py +40 -0
- SafePDF/ui/help_ui.py +233 -0
- SafePDF/ui/language_elements.py +9 -0
- SafePDF/ui/operation_settings.py +377 -0
- SafePDF/ui/safe_pdf_ui.py +3497 -0
- SafePDF/ui/settings_ui.py +394 -0
- SafePDF/ui/tabs_manager.py +235 -0
- SafePDF/ui/update_ui.py +717 -0
- SafePDF/version.txt +34 -0
- safepdf-1.0.11.dist-info/METADATA +162 -0
- safepdf-1.0.11.dist-info/RECORD +48 -0
- safepdf-1.0.11.dist-info/WHEEL +5 -0
- safepdf-1.0.11.dist-info/entry_points.txt +2 -0
- safepdf-1.0.11.dist-info/licenses/LICENSE +674 -0
- safepdf-1.0.11.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,3497 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SafePDF UI - Optimized User Interface Components
|
|
3
|
+
This module contains the SafePDFUI class which manages the user interface.
|
|
4
|
+
|
|
5
|
+
@author: Mehmet Cagri Aksoy
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import sys
|
|
11
|
+
import tkinter as tk
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from platform import system as platform_system
|
|
14
|
+
from subprocess import run as subprocess_run
|
|
15
|
+
from tkinter import filedialog, messagebox, ttk
|
|
16
|
+
from urllib.parse import urlparse
|
|
17
|
+
from webbrowser import open as webbrowser_open
|
|
18
|
+
|
|
19
|
+
from SafePDF import __version__ as SAFEPDF_VERSION
|
|
20
|
+
from SafePDF.ctrl.language_manager import LanguageManager
|
|
21
|
+
from SafePDF.logger.logging_config import setup_logging, get_logger
|
|
22
|
+
|
|
23
|
+
from .common_elements import CommonElements # Common UI elements
|
|
24
|
+
from .help_ui import HelpUI # Delegated Help UI module
|
|
25
|
+
from .settings_ui import SettingsUI # Delegated Settings UI module
|
|
26
|
+
from .update_ui import UpdateUI # Import the new UpdateUI class
|
|
27
|
+
|
|
28
|
+
SIZE_STR = CommonElements.SIZE_STR
|
|
29
|
+
SIZE_LIST = CommonElements.SIZE_LIST
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def resource_path(relative_path: str) -> Path:
|
|
33
|
+
"""
|
|
34
|
+
Resolve a resource path that works both during development and when
|
|
35
|
+
packaged with PyInstaller. When frozen (PyInstaller), files are extracted
|
|
36
|
+
to `sys._MEIPASS`.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
relative_path: relative path inside the project (e.g., "assets/icon.ico")
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
Path: absolute Path to the resource
|
|
43
|
+
"""
|
|
44
|
+
try:
|
|
45
|
+
if getattr(sys, "frozen", False):
|
|
46
|
+
base = Path(sys._MEIPASS)
|
|
47
|
+
else:
|
|
48
|
+
base = Path(__file__).parent.parent
|
|
49
|
+
except Exception:
|
|
50
|
+
base = Path(__file__).parent.parent
|
|
51
|
+
|
|
52
|
+
return base / Path(relative_path)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# Initialize logging and get log file path
|
|
56
|
+
LOG_FILE_PATH = setup_logging()
|
|
57
|
+
logger = get_logger("SafePDF.UI")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def safe_open_file_or_folder(path):
|
|
61
|
+
"""
|
|
62
|
+
Safely open a file or folder using the system's default application.
|
|
63
|
+
Validates the path to prevent execution of untrusted input.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
path: The file or folder path to open
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
bool: True if successful, False otherwise
|
|
70
|
+
"""
|
|
71
|
+
try:
|
|
72
|
+
# Validate that path exists and is absolute
|
|
73
|
+
path = Path(path).resolve()
|
|
74
|
+
if not path.exists():
|
|
75
|
+
logger.warning(f"Attempted to open non-existent path: {path}")
|
|
76
|
+
return False
|
|
77
|
+
|
|
78
|
+
# Convert to string for subprocess
|
|
79
|
+
path_str = str(path)
|
|
80
|
+
|
|
81
|
+
# Use platform-specific safe methods
|
|
82
|
+
if platform_system() == "Windows":
|
|
83
|
+
os.startfile(path_str)
|
|
84
|
+
elif platform_system() == "Darwin": # macOS
|
|
85
|
+
# Use hardcoded command path and validate file path
|
|
86
|
+
subprocess_run(["/usr/bin/open", path_str], check=False) # nosec B603
|
|
87
|
+
else: # Linux
|
|
88
|
+
# Use hardcoded command path and validate file path
|
|
89
|
+
subprocess_run(["/usr/bin/xdg-open", path_str], check=False) # nosec B603
|
|
90
|
+
|
|
91
|
+
logger.info(f"Opened path: {path_str}")
|
|
92
|
+
return True
|
|
93
|
+
except Exception as e:
|
|
94
|
+
logger.error(f"Error opening path {path}: {e}", exc_info=True)
|
|
95
|
+
return False
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def open_url(url: str) -> bool:
|
|
99
|
+
"""
|
|
100
|
+
Safely open a URL in the default browser.
|
|
101
|
+
Only allows HTTP and HTTPS schemes to prevent security issues.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
url: The URL to open
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
True if URL was opened, False otherwise
|
|
108
|
+
"""
|
|
109
|
+
try:
|
|
110
|
+
parsed = urlparse(url)
|
|
111
|
+
# Only allow http and https schemes
|
|
112
|
+
if parsed.scheme.lower() not in ("http", "https"):
|
|
113
|
+
logger.warning(f"Security: Blocked attempt to open non-HTTP(S) URL: {url}")
|
|
114
|
+
return False
|
|
115
|
+
webbrowser_open(url)
|
|
116
|
+
logger.info(f"Opened URL: {url}")
|
|
117
|
+
return True
|
|
118
|
+
except Exception as e:
|
|
119
|
+
logger.error(f"Error opening URL {url}: {e}", exc_info=True)
|
|
120
|
+
return False
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
# Lazy imports for optional components
|
|
124
|
+
def _get_tkinterdnd():
|
|
125
|
+
"""Lazy load tkinterdnd2 only when needed"""
|
|
126
|
+
try:
|
|
127
|
+
from tkinterdnd2 import DND_FILES
|
|
128
|
+
|
|
129
|
+
return DND_FILES
|
|
130
|
+
except ImportError:
|
|
131
|
+
return None
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _get_pil():
|
|
135
|
+
"""Lazy load PIL only when needed"""
|
|
136
|
+
try:
|
|
137
|
+
from PIL import Image, ImageTk
|
|
138
|
+
|
|
139
|
+
return Image, ImageTk
|
|
140
|
+
except ImportError:
|
|
141
|
+
return None, None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class SafePDFUI:
|
|
145
|
+
"""Optimized UI class with minimal memory footprint"""
|
|
146
|
+
|
|
147
|
+
def __init__(self, root, controller):
|
|
148
|
+
self.root = root
|
|
149
|
+
self.controller = controller
|
|
150
|
+
|
|
151
|
+
# Lazy loaded components
|
|
152
|
+
self._pil_loaded = False
|
|
153
|
+
self._dnd_loaded = False
|
|
154
|
+
|
|
155
|
+
# Essential UI components only
|
|
156
|
+
self.notebook = None
|
|
157
|
+
self.progress = None
|
|
158
|
+
self.results_text = None
|
|
159
|
+
self.file_label = None
|
|
160
|
+
self.drop_label = None
|
|
161
|
+
|
|
162
|
+
# Tab frames
|
|
163
|
+
self.welcome_frame = None
|
|
164
|
+
self.file_frame = None
|
|
165
|
+
self.operation_frame = None
|
|
166
|
+
self.settings_frame = None
|
|
167
|
+
self.results_frame = None
|
|
168
|
+
|
|
169
|
+
# Navigation buttons
|
|
170
|
+
self.back_btn = None
|
|
171
|
+
self.next_btn = None
|
|
172
|
+
self.cancel_btn = None
|
|
173
|
+
|
|
174
|
+
# Operation selection
|
|
175
|
+
self.operation_buttons = []
|
|
176
|
+
self.operation_images = []
|
|
177
|
+
|
|
178
|
+
# Settings variables
|
|
179
|
+
self.quality_var = tk.StringVar(value="medium")
|
|
180
|
+
self.rotation_var = tk.StringVar(value="90")
|
|
181
|
+
self.img_quality_var = tk.StringVar(value="medium")
|
|
182
|
+
self.split_var = tk.StringVar(value="pages")
|
|
183
|
+
self.page_range_var = tk.StringVar()
|
|
184
|
+
self.repair_var = tk.BooleanVar(value=True)
|
|
185
|
+
self.merge_var = tk.BooleanVar(value=True)
|
|
186
|
+
# Merge-specific UI state: second file path and order (end/beginning)
|
|
187
|
+
self.merge_second_file_var = tk.StringVar(value="")
|
|
188
|
+
self.merge_order_var = tk.StringVar(value="end") # 'end' or 'beginning'
|
|
189
|
+
self.use_default_output = tk.BooleanVar(value=True)
|
|
190
|
+
self.output_path_var = tk.StringVar()
|
|
191
|
+
# Single shared output selection UI guard
|
|
192
|
+
self.output_selection_created = False
|
|
193
|
+
self.output_selection_is_directory = False
|
|
194
|
+
self.output_frame = None
|
|
195
|
+
# Application-level settings
|
|
196
|
+
self.language_var = tk.StringVar(value=self._load_language_preference())
|
|
197
|
+
self.theme_var = tk.StringVar(value="system") # options: system, light, dark
|
|
198
|
+
# Update the global language setting with loaded preference
|
|
199
|
+
CommonElements.SELECTED_LANGUAGE = str(self.language_var.get())
|
|
200
|
+
# Language manager to provide localized UI strings and content
|
|
201
|
+
self.lang_manager = LanguageManager(str(self.language_var.get()))
|
|
202
|
+
|
|
203
|
+
# Window dragging variables
|
|
204
|
+
self.drag_data = {"x": 0, "y": 0}
|
|
205
|
+
|
|
206
|
+
# Window state management
|
|
207
|
+
self.is_minimized = False
|
|
208
|
+
self.is_fullscreen = False
|
|
209
|
+
self.restore_geometry = None
|
|
210
|
+
|
|
211
|
+
# Previous tab for reverting disabled tab selection
|
|
212
|
+
self._previous_tab = 0
|
|
213
|
+
|
|
214
|
+
# Current tooltip index to prevent flickering
|
|
215
|
+
self.current_tooltip_index = None
|
|
216
|
+
|
|
217
|
+
# Store icon for taskbar window
|
|
218
|
+
self.icon_path = None
|
|
219
|
+
self._find_icon()
|
|
220
|
+
|
|
221
|
+
# Set up callbacks
|
|
222
|
+
self.controller.set_ui_callbacks(
|
|
223
|
+
update_ui_callback=self.update_ui,
|
|
224
|
+
completion_callback=self.operation_completed,
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
# Instantiate UpdateUI with root and controller
|
|
228
|
+
self.update_ui = UpdateUI(
|
|
229
|
+
root, controller, CommonElements.FONT, language_manager=self.lang_manager
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
# Instantiate delegated UI helpers
|
|
233
|
+
self.help_ui = HelpUI(root, controller, CommonElements.FONT, lang_manager=self.lang_manager)
|
|
234
|
+
self.settings_ui = SettingsUI(
|
|
235
|
+
root,
|
|
236
|
+
controller,
|
|
237
|
+
self.theme_var,
|
|
238
|
+
self.language_var,
|
|
239
|
+
LOG_FILE_PATH,
|
|
240
|
+
language_manager=self.lang_manager,
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
# Ensure language changes update UI (language_var stores language code, e.g. 'en')
|
|
244
|
+
try:
|
|
245
|
+
self.language_var.trace("w", lambda *args: self._on_language_change())
|
|
246
|
+
except Exception:
|
|
247
|
+
pass
|
|
248
|
+
|
|
249
|
+
# Initialize UI
|
|
250
|
+
self.setup_main_window()
|
|
251
|
+
self.create_ui_components()
|
|
252
|
+
|
|
253
|
+
def setup_main_window(self):
|
|
254
|
+
"""Configure the main application window with modern design and custom title bar"""
|
|
255
|
+
self.root.title("SafePDF - A tool for PDF Manipulation")
|
|
256
|
+
|
|
257
|
+
# Set window size based on screen resolution
|
|
258
|
+
screen_width = self.root.winfo_screenwidth()
|
|
259
|
+
screen_height = self.root.winfo_screenheight()
|
|
260
|
+
|
|
261
|
+
# Use default size but ensure it fits on screen (80% max)
|
|
262
|
+
window_width = min(SIZE_LIST[0], int(screen_width * 0.8))
|
|
263
|
+
window_height = min(SIZE_LIST[1], int(screen_height * 0.8))
|
|
264
|
+
|
|
265
|
+
self.root.geometry(f"{window_width}x{window_height}")
|
|
266
|
+
self.root.minsize(900, 650) # Set absolute minimum size
|
|
267
|
+
self.root.configure(bg=CommonElements.BG_MAIN)
|
|
268
|
+
|
|
269
|
+
# IMPORTANT: First update the window to ensure it's created properly
|
|
270
|
+
self.root.update_idletasks()
|
|
271
|
+
|
|
272
|
+
# NOW remove the default title bar FIRST
|
|
273
|
+
self.root.overrideredirect(True)
|
|
274
|
+
|
|
275
|
+
# Force window update
|
|
276
|
+
self.root.update_idletasks()
|
|
277
|
+
|
|
278
|
+
# Ensure window appears in taskbar AFTER overrideredirect
|
|
279
|
+
try:
|
|
280
|
+
# Force taskbar visibility on Windows
|
|
281
|
+
if platform_system() == "Windows":
|
|
282
|
+
# Use GWL_EXSTYLE to add WS_EX_APPWINDOW flag
|
|
283
|
+
import ctypes
|
|
284
|
+
|
|
285
|
+
GWL_EXSTYLE = -20
|
|
286
|
+
WS_EX_APPWINDOW = 0x00040000
|
|
287
|
+
WS_EX_TOOLWINDOW = 0x00000080
|
|
288
|
+
|
|
289
|
+
# Get the actual window handle
|
|
290
|
+
hwnd = ctypes.windll.user32.GetParent(self.root.winfo_id())
|
|
291
|
+
if hwnd == 0:
|
|
292
|
+
hwnd = self.root.winfo_id()
|
|
293
|
+
|
|
294
|
+
# Get current style
|
|
295
|
+
style = ctypes.windll.user32.GetWindowLongW(hwnd, GWL_EXSTYLE)
|
|
296
|
+
# Add APPWINDOW, remove TOOLWINDOW
|
|
297
|
+
style = (style | WS_EX_APPWINDOW) & ~WS_EX_TOOLWINDOW
|
|
298
|
+
ctypes.windll.user32.SetWindowLongW(hwnd, GWL_EXSTYLE, style)
|
|
299
|
+
|
|
300
|
+
# Force window to show in taskbar
|
|
301
|
+
SWP_FRAMECHANGED = 0x0020
|
|
302
|
+
SWP_NOMOVE = 0x0002
|
|
303
|
+
SWP_NOSIZE = 0x0001
|
|
304
|
+
SWP_NOZORDER = 0x0004
|
|
305
|
+
ctypes.windll.user32.SetWindowPos(
|
|
306
|
+
hwnd,
|
|
307
|
+
0,
|
|
308
|
+
0,
|
|
309
|
+
0,
|
|
310
|
+
0,
|
|
311
|
+
0,
|
|
312
|
+
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER,
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
except Exception as e:
|
|
316
|
+
logger.warning(
|
|
317
|
+
f"Could not set taskbar visibility: {e}"
|
|
318
|
+
) # Final update to apply changes
|
|
319
|
+
self.root.update_idletasks()
|
|
320
|
+
|
|
321
|
+
# Apply ttk theme for modern look
|
|
322
|
+
style = ttk.Style()
|
|
323
|
+
try:
|
|
324
|
+
style.theme_use("winnative")
|
|
325
|
+
except Exception as e:
|
|
326
|
+
logger.debug(f"Theme application failed: {e}, continuing with system theme")
|
|
327
|
+
pass
|
|
328
|
+
|
|
329
|
+
# Modern rounded style with red theme
|
|
330
|
+
style.configure("TNotebook", background="#f4f6fb", borderwidth=0, relief="flat")
|
|
331
|
+
style.configure(
|
|
332
|
+
"TNotebook.Tab",
|
|
333
|
+
background="#e9ecef",
|
|
334
|
+
padding=[15, 10],
|
|
335
|
+
font=(CommonElements.FONT, CommonElements.FONT_SIZE),
|
|
336
|
+
borderwidth=0,
|
|
337
|
+
relief="flat",
|
|
338
|
+
)
|
|
339
|
+
style.map(
|
|
340
|
+
"TNotebook.Tab",
|
|
341
|
+
background=[("selected", "#ffffff"), ("active", "#f8f9fa")],
|
|
342
|
+
foreground=[
|
|
343
|
+
("selected", CommonElements.RED_COLOR),
|
|
344
|
+
("active", CommonElements.RED_COLOR),
|
|
345
|
+
],
|
|
346
|
+
expand=[("selected", [1, 1, 1, 0])],
|
|
347
|
+
)
|
|
348
|
+
style.configure("TFrame", background="#ffffff")
|
|
349
|
+
style.configure(
|
|
350
|
+
"TLabel",
|
|
351
|
+
background="#ffffff",
|
|
352
|
+
font=(CommonElements.FONT, CommonElements.FONT_SIZE),
|
|
353
|
+
)
|
|
354
|
+
style.configure(
|
|
355
|
+
"TButton",
|
|
356
|
+
font=(CommonElements.FONT, CommonElements.FONT_SIZE),
|
|
357
|
+
padding=10,
|
|
358
|
+
background="#e9ecef",
|
|
359
|
+
foreground="#000000",
|
|
360
|
+
borderwidth=0,
|
|
361
|
+
relief="flat",
|
|
362
|
+
)
|
|
363
|
+
style.map(
|
|
364
|
+
"TButton",
|
|
365
|
+
background=[("active", "#d6d8db"), ("!active", "#e9ecef")],
|
|
366
|
+
foreground=[("active", "#000000"), ("!active", "#000000")],
|
|
367
|
+
relief=[("pressed", "flat"), ("!pressed", "flat")],
|
|
368
|
+
)
|
|
369
|
+
style.configure(
|
|
370
|
+
"Accent.TButton",
|
|
371
|
+
background="#00b386",
|
|
372
|
+
foreground="#000000",
|
|
373
|
+
font=(CommonElements.FONT, 10, "bold"),
|
|
374
|
+
padding=12,
|
|
375
|
+
borderwidth=0,
|
|
376
|
+
relief="flat",
|
|
377
|
+
)
|
|
378
|
+
style.map(
|
|
379
|
+
"Accent.TButton",
|
|
380
|
+
background=[("active", "#009970"), ("!active", "#00b386")],
|
|
381
|
+
foreground=[("active", "#000000"), ("!active", "#000000")],
|
|
382
|
+
relief=[("pressed", "flat"), ("!pressed", "flat")],
|
|
383
|
+
)
|
|
384
|
+
style.configure("Gray.TLabel", foreground="#888", background="#ffffff")
|
|
385
|
+
|
|
386
|
+
# Center the window
|
|
387
|
+
self.center_window()
|
|
388
|
+
|
|
389
|
+
def _find_icon(self):
|
|
390
|
+
"""Find and store the application icon path"""
|
|
391
|
+
try:
|
|
392
|
+
candidates = [
|
|
393
|
+
resource_path("assets/icon.ico"),
|
|
394
|
+
resource_path("assets/icon.png"),
|
|
395
|
+
]
|
|
396
|
+
for c in candidates:
|
|
397
|
+
if c and c.exists():
|
|
398
|
+
self.icon_path = str(c)
|
|
399
|
+
break
|
|
400
|
+
except Exception:
|
|
401
|
+
logger.debug("Icon not found or error occurred while finding icon")
|
|
402
|
+
pass
|
|
403
|
+
|
|
404
|
+
def _ensure_taskbar_visibility(self):
|
|
405
|
+
"""Force taskbar icon to appear after window is fully initialized"""
|
|
406
|
+
try:
|
|
407
|
+
if platform_system() == "Windows":
|
|
408
|
+
import ctypes
|
|
409
|
+
|
|
410
|
+
# Get window handle
|
|
411
|
+
hwnd = ctypes.windll.user32.GetParent(self.root.winfo_id())
|
|
412
|
+
if hwnd == 0:
|
|
413
|
+
hwnd = self.root.winfo_id()
|
|
414
|
+
|
|
415
|
+
# Windows API constants
|
|
416
|
+
GWL_EXSTYLE = -20
|
|
417
|
+
WS_EX_APPWINDOW = 0x00040000
|
|
418
|
+
WS_EX_TOOLWINDOW = 0x00000080
|
|
419
|
+
# SW_HIDE = 0
|
|
420
|
+
# SW_SHOW = 5
|
|
421
|
+
|
|
422
|
+
# Get current style
|
|
423
|
+
style = ctypes.windll.user32.GetWindowLongW(hwnd, GWL_EXSTYLE)
|
|
424
|
+
|
|
425
|
+
# Add APPWINDOW, remove TOOLWINDOW
|
|
426
|
+
new_style = (style | WS_EX_APPWINDOW) & ~WS_EX_TOOLWINDOW
|
|
427
|
+
ctypes.windll.user32.SetWindowLongW(hwnd, GWL_EXSTYLE, new_style)
|
|
428
|
+
|
|
429
|
+
# Force window position update to refresh taskbar
|
|
430
|
+
SWP_FRAMECHANGED = 0x0020
|
|
431
|
+
SWP_NOMOVE = 0x0002
|
|
432
|
+
SWP_NOSIZE = 0x0001
|
|
433
|
+
SWP_NOZORDER = 0x0004
|
|
434
|
+
SWP_SHOWWINDOW = 0x0040
|
|
435
|
+
ctypes.windll.user32.SetWindowPos(
|
|
436
|
+
hwnd,
|
|
437
|
+
0,
|
|
438
|
+
0,
|
|
439
|
+
0,
|
|
440
|
+
0,
|
|
441
|
+
0,
|
|
442
|
+
SWP_FRAMECHANGED
|
|
443
|
+
| SWP_NOMOVE
|
|
444
|
+
| SWP_NOSIZE
|
|
445
|
+
| SWP_NOZORDER
|
|
446
|
+
| SWP_SHOWWINDOW,
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
# Final update
|
|
450
|
+
self.root.update()
|
|
451
|
+
|
|
452
|
+
except Exception as e:
|
|
453
|
+
logger.warning(f"Could not ensure taskbar visibility: {e}")
|
|
454
|
+
|
|
455
|
+
def center_window(self):
|
|
456
|
+
"""Center the window on screen"""
|
|
457
|
+
self.root.update_idletasks()
|
|
458
|
+
width = self.root.winfo_width()
|
|
459
|
+
height = self.root.winfo_height()
|
|
460
|
+
screen_width = self.root.winfo_screenwidth()
|
|
461
|
+
screen_height = self.root.winfo_screenheight()
|
|
462
|
+
|
|
463
|
+
# Ensure window fits on screen with some padding
|
|
464
|
+
if width > screen_width - 100:
|
|
465
|
+
width = screen_width - 100
|
|
466
|
+
if height > screen_height - 100:
|
|
467
|
+
height = screen_height - 100
|
|
468
|
+
|
|
469
|
+
x = (screen_width // 2) - (width // 2)
|
|
470
|
+
y = (screen_height // 2) - (height // 2)
|
|
471
|
+
|
|
472
|
+
# Ensure window is not positioned off-screen
|
|
473
|
+
x = max(0, min(x, screen_width - width))
|
|
474
|
+
y = max(0, min(y, screen_height - height))
|
|
475
|
+
|
|
476
|
+
self.root.geometry(f"{width}x{height}+{x}+{y}")
|
|
477
|
+
|
|
478
|
+
def create_ui_components(self):
|
|
479
|
+
"""Create all UI components"""
|
|
480
|
+
# Add modern header
|
|
481
|
+
self.create_header()
|
|
482
|
+
|
|
483
|
+
# Create main card area
|
|
484
|
+
self.create_main_card()
|
|
485
|
+
|
|
486
|
+
# Create tabbed interface
|
|
487
|
+
self.create_notebook()
|
|
488
|
+
|
|
489
|
+
# Create all tabs
|
|
490
|
+
self.create_tabs()
|
|
491
|
+
|
|
492
|
+
# Create bottom controls
|
|
493
|
+
self.create_bottom_controls()
|
|
494
|
+
|
|
495
|
+
# Bind events
|
|
496
|
+
self.bind_events()
|
|
497
|
+
|
|
498
|
+
# Update UI to reflect loaded pro status
|
|
499
|
+
self.update_pro_features()
|
|
500
|
+
|
|
501
|
+
def create_header(self):
|
|
502
|
+
"""Create the application header with custom title bar controls"""
|
|
503
|
+
self.header_frame = tk.Frame(self.root, bg=CommonElements.RED_COLOR, height=56)
|
|
504
|
+
self.header_frame.pack(fill="x", side="top")
|
|
505
|
+
self.header_frame.pack_propagate(False)
|
|
506
|
+
|
|
507
|
+
# Left side - App title (draggable area)
|
|
508
|
+
self.title_frame = tk.Frame(self.header_frame, bg=CommonElements.RED_COLOR)
|
|
509
|
+
self.title_frame.pack(side="left", fill="both", expand=True)
|
|
510
|
+
|
|
511
|
+
self.header_label = tk.Label(
|
|
512
|
+
self.title_frame,
|
|
513
|
+
text=self.lang_manager.get("app_title", "SafePDF™"),
|
|
514
|
+
font=(CommonElements.FONT, 18, "bold"),
|
|
515
|
+
bg=CommonElements.RED_COLOR,
|
|
516
|
+
fg="#fff",
|
|
517
|
+
pady=10,
|
|
518
|
+
)
|
|
519
|
+
self.header_label.pack(side="left", padx=(24, 8))
|
|
520
|
+
|
|
521
|
+
# Pro status badge in title bar with rounded appearance
|
|
522
|
+
pro_badge_color = CommonElements.URL_COLOR if self.controller.is_pro_activated else "#888888"
|
|
523
|
+
pro_badge_text = (
|
|
524
|
+
self.lang_manager.get("pro_badge_pro", "PRO")
|
|
525
|
+
if self.controller.is_pro_activated
|
|
526
|
+
else self.lang_manager.get("pro_badge_free", "FREE")
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
self.pro_badge_label = tk.Label(
|
|
530
|
+
self.title_frame,
|
|
531
|
+
text=pro_badge_text,
|
|
532
|
+
font=(CommonElements.FONT, 8, "bold"),
|
|
533
|
+
bg=pro_badge_color,
|
|
534
|
+
fg="white",
|
|
535
|
+
padx=8,
|
|
536
|
+
pady=3,
|
|
537
|
+
cursor="hand2",
|
|
538
|
+
relief="flat",
|
|
539
|
+
bd=0,
|
|
540
|
+
)
|
|
541
|
+
self.pro_badge_label.pack(side="left", padx=(4, 0))
|
|
542
|
+
self.pro_badge_label.bind(
|
|
543
|
+
"<Button-1>", lambda e: self.update_ui.show_pro_dialog(self)
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
# Make the title area draggable
|
|
547
|
+
self.bind_drag_events(self.title_frame)
|
|
548
|
+
self.bind_drag_events(self.header_label)
|
|
549
|
+
self.bind_drag_events(self.pro_badge_label)
|
|
550
|
+
|
|
551
|
+
# Right side - Window controls
|
|
552
|
+
self.controls_frame = tk.Frame(self.header_frame, bg=CommonElements.RED_COLOR)
|
|
553
|
+
self.controls_frame.pack(side="right", fill="y")
|
|
554
|
+
|
|
555
|
+
# Minimize button
|
|
556
|
+
self.minimize_btn = tk.Button(
|
|
557
|
+
self.controls_frame,
|
|
558
|
+
text="−",
|
|
559
|
+
font=(CommonElements.FONT, 16, "bold"),
|
|
560
|
+
bg=CommonElements.RED_COLOR,
|
|
561
|
+
fg="#fff",
|
|
562
|
+
bd=0,
|
|
563
|
+
width=3,
|
|
564
|
+
height=1,
|
|
565
|
+
cursor="hand2",
|
|
566
|
+
activebackground="#a01818",
|
|
567
|
+
activeforeground="#fff",
|
|
568
|
+
relief=tk.FLAT,
|
|
569
|
+
command=self.minimize_window,
|
|
570
|
+
)
|
|
571
|
+
self.minimize_btn.pack(side="left", fill="y")
|
|
572
|
+
|
|
573
|
+
# Fullscreen/Maximize button
|
|
574
|
+
self.maximize_btn = tk.Button(
|
|
575
|
+
self.controls_frame,
|
|
576
|
+
text="□",
|
|
577
|
+
font=(CommonElements.FONT, 14, "bold"),
|
|
578
|
+
bg=CommonElements.RED_COLOR,
|
|
579
|
+
fg="#fff",
|
|
580
|
+
bd=0,
|
|
581
|
+
width=3,
|
|
582
|
+
height=1,
|
|
583
|
+
cursor="hand2",
|
|
584
|
+
activebackground="#a01818",
|
|
585
|
+
activeforeground="#fff",
|
|
586
|
+
relief=tk.FLAT,
|
|
587
|
+
command=self.toggle_fullscreen,
|
|
588
|
+
)
|
|
589
|
+
self.maximize_btn.pack(side="left", fill="y")
|
|
590
|
+
|
|
591
|
+
# Close button
|
|
592
|
+
self.close_btn = tk.Button(
|
|
593
|
+
self.controls_frame,
|
|
594
|
+
text="×",
|
|
595
|
+
font=(CommonElements.FONT, 20, "bold"),
|
|
596
|
+
bg=CommonElements.RED_COLOR,
|
|
597
|
+
fg="#fff",
|
|
598
|
+
bd=0,
|
|
599
|
+
width=3,
|
|
600
|
+
height=1,
|
|
601
|
+
cursor="hand2",
|
|
602
|
+
activebackground="#d32f2f",
|
|
603
|
+
activeforeground="#fff",
|
|
604
|
+
relief=tk.FLAT,
|
|
605
|
+
command=self.close_window,
|
|
606
|
+
)
|
|
607
|
+
self.close_btn.pack(side="right", fill="y")
|
|
608
|
+
|
|
609
|
+
# Add hover effects for window control buttons
|
|
610
|
+
self.setup_button_hover_effects()
|
|
611
|
+
|
|
612
|
+
def bind_drag_events(self, widget):
|
|
613
|
+
"""Bind drag events to a widget for window dragging"""
|
|
614
|
+
widget.bind("<Button-1>", self.start_drag)
|
|
615
|
+
widget.bind("<B1-Motion>", self.on_drag)
|
|
616
|
+
widget.bind("<ButtonRelease-1>", self.stop_drag)
|
|
617
|
+
|
|
618
|
+
def start_drag(self, event):
|
|
619
|
+
"""Start window dragging"""
|
|
620
|
+
self.drag_data["x"] = event.x_root
|
|
621
|
+
self.drag_data["y"] = event.y_root
|
|
622
|
+
|
|
623
|
+
def on_drag(self, event):
|
|
624
|
+
"""Handle window dragging"""
|
|
625
|
+
delta_x = event.x_root - self.drag_data["x"]
|
|
626
|
+
delta_y = event.y_root - self.drag_data["y"]
|
|
627
|
+
x = self.root.winfo_x() + delta_x
|
|
628
|
+
y = self.root.winfo_y() + delta_y
|
|
629
|
+
self.root.geometry(f"+{x}+{y}")
|
|
630
|
+
self.drag_data["x"] = event.x_root
|
|
631
|
+
self.drag_data["y"] = event.y_root
|
|
632
|
+
|
|
633
|
+
def stop_drag(self, event):
|
|
634
|
+
"""Stop window dragging"""
|
|
635
|
+
self.drag_data["x"] = 0
|
|
636
|
+
self.drag_data["y"] = 0
|
|
637
|
+
|
|
638
|
+
def setup_button_hover_effects(self):
|
|
639
|
+
"""Setup hover effects for window control buttons"""
|
|
640
|
+
|
|
641
|
+
def on_minimize_enter(event):
|
|
642
|
+
self.minimize_btn.config(bg="#a01818")
|
|
643
|
+
|
|
644
|
+
def on_minimize_leave(event):
|
|
645
|
+
self.minimize_btn.config(bg=CommonElements.RED_COLOR)
|
|
646
|
+
|
|
647
|
+
def on_maximize_enter(event):
|
|
648
|
+
self.maximize_btn.config(bg="#a01818")
|
|
649
|
+
|
|
650
|
+
def on_maximize_leave(event):
|
|
651
|
+
self.maximize_btn.config(bg=CommonElements.RED_COLOR)
|
|
652
|
+
|
|
653
|
+
def on_close_enter(event):
|
|
654
|
+
self.close_btn.config(bg="#d32f2f")
|
|
655
|
+
|
|
656
|
+
def on_close_leave(event):
|
|
657
|
+
self.close_btn.config(bg=CommonElements.RED_COLOR)
|
|
658
|
+
|
|
659
|
+
self.minimize_btn.bind("<Enter>", on_minimize_enter)
|
|
660
|
+
self.minimize_btn.bind("<Leave>", on_minimize_leave)
|
|
661
|
+
self.maximize_btn.bind("<Enter>", on_maximize_enter)
|
|
662
|
+
self.maximize_btn.bind("<Leave>", on_maximize_leave)
|
|
663
|
+
self.close_btn.bind("<Enter>", on_close_enter)
|
|
664
|
+
self.close_btn.bind("<Leave>", on_close_leave)
|
|
665
|
+
|
|
666
|
+
def minimize_window(self):
|
|
667
|
+
"""Minimize the window by hiding it and creating a taskbar entry"""
|
|
668
|
+
if not self.is_minimized:
|
|
669
|
+
try:
|
|
670
|
+
# Store current geometry
|
|
671
|
+
self.restore_geometry = self.root.geometry()
|
|
672
|
+
|
|
673
|
+
# Mark as minimized first
|
|
674
|
+
self.is_minimized = True
|
|
675
|
+
|
|
676
|
+
# Create taskbar window BEFORE hiding main window
|
|
677
|
+
self.create_taskbar_window()
|
|
678
|
+
|
|
679
|
+
# Now hide the main window
|
|
680
|
+
self.root.withdraw()
|
|
681
|
+
|
|
682
|
+
except Exception as e:
|
|
683
|
+
print(f"Error minimizing window: {e}")
|
|
684
|
+
self.is_minimized = False
|
|
685
|
+
|
|
686
|
+
def create_taskbar_window(self):
|
|
687
|
+
"""Create a minimal window to maintain taskbar presence"""
|
|
688
|
+
try:
|
|
689
|
+
self.taskbar_window = tk.Toplevel(self.root)
|
|
690
|
+
self.taskbar_window.title("SafePDF")
|
|
691
|
+
self.taskbar_window.withdraw() # Hide initially
|
|
692
|
+
|
|
693
|
+
# Apply icon to taskbar window BEFORE iconifying
|
|
694
|
+
if self.icon_path:
|
|
695
|
+
try:
|
|
696
|
+
icon_path = Path(self.icon_path)
|
|
697
|
+
if icon_path.suffix.lower() == ".ico":
|
|
698
|
+
self.taskbar_window.iconbitmap(str(icon_path))
|
|
699
|
+
else:
|
|
700
|
+
img = tk.PhotoImage(file=str(icon_path))
|
|
701
|
+
self.taskbar_window.iconphoto(False, img)
|
|
702
|
+
except Exception:
|
|
703
|
+
logger.debug("Icon could not be set for taskbar window")
|
|
704
|
+
pass # Icon setting failed, not critical
|
|
705
|
+
|
|
706
|
+
# Set window size and position offscreen
|
|
707
|
+
self.taskbar_window.geometry("200x50+-32000+-32000")
|
|
708
|
+
|
|
709
|
+
# Bind close event
|
|
710
|
+
self.taskbar_window.protocol("WM_DELETE_WINDOW", self.close_window)
|
|
711
|
+
|
|
712
|
+
# Update to ensure window is ready
|
|
713
|
+
self.taskbar_window.update_idletasks()
|
|
714
|
+
|
|
715
|
+
# Make it appear minimized in taskbar
|
|
716
|
+
self.taskbar_window.iconify()
|
|
717
|
+
|
|
718
|
+
# NOW bind the restore event AFTER iconifying to avoid immediate trigger
|
|
719
|
+
# Use after() to delay binding slightly
|
|
720
|
+
self.taskbar_window.after(
|
|
721
|
+
100, lambda: self.taskbar_window.bind("<Map>", self.on_taskbar_restore)
|
|
722
|
+
)
|
|
723
|
+
|
|
724
|
+
except Exception as e:
|
|
725
|
+
print(f"Error creating taskbar window: {e}")
|
|
726
|
+
import traceback
|
|
727
|
+
|
|
728
|
+
traceback.print_exc()
|
|
729
|
+
self.is_minimized = False
|
|
730
|
+
|
|
731
|
+
def on_taskbar_restore(self, event):
|
|
732
|
+
"""Handle when user clicks on minimized taskbar icon"""
|
|
733
|
+
# Check if the window is being deiconified (restored from minimized state)
|
|
734
|
+
if self.is_minimized and hasattr(self, "taskbar_window"):
|
|
735
|
+
try:
|
|
736
|
+
state = self.taskbar_window.state()
|
|
737
|
+
if state == "normal": # Window is being restored
|
|
738
|
+
self.restore_window()
|
|
739
|
+
except Exception:
|
|
740
|
+
logger.debug("Error in on_taskbar_restore event handler", exc_info=True)
|
|
741
|
+
pass
|
|
742
|
+
|
|
743
|
+
def restore_window(self, event=None):
|
|
744
|
+
"""Restore the minimized window"""
|
|
745
|
+
if self.is_minimized:
|
|
746
|
+
# Prevent multiple triggers
|
|
747
|
+
self.is_minimized = False
|
|
748
|
+
|
|
749
|
+
# Destroy taskbar window first
|
|
750
|
+
if hasattr(self, "taskbar_window") and self.taskbar_window.winfo_exists():
|
|
751
|
+
try:
|
|
752
|
+
self.taskbar_window.destroy()
|
|
753
|
+
except Exception:
|
|
754
|
+
logger.debug("Error destroying taskbar window", exc_info=True)
|
|
755
|
+
pass
|
|
756
|
+
|
|
757
|
+
# Restore main window
|
|
758
|
+
self.root.deiconify()
|
|
759
|
+
if self.restore_geometry:
|
|
760
|
+
self.root.geometry(self.restore_geometry)
|
|
761
|
+
|
|
762
|
+
# Bring to front
|
|
763
|
+
self.root.lift()
|
|
764
|
+
self.root.focus_force()
|
|
765
|
+
self.root.update_idletasks()
|
|
766
|
+
|
|
767
|
+
def close_window(self):
|
|
768
|
+
"""Close the window with confirmation"""
|
|
769
|
+
self.controller.cancel_operation()
|
|
770
|
+
self.root.quit()
|
|
771
|
+
|
|
772
|
+
def create_main_card(self):
|
|
773
|
+
"""Create the main card-like container with rounded appearance"""
|
|
774
|
+
# Create outer frame for shadow effect
|
|
775
|
+
shadow_frame = tk.Frame(self.root, bg="#e2e8f0")
|
|
776
|
+
shadow_frame.pack(fill="both", expand=True, padx=10, pady=(6, 10))
|
|
777
|
+
|
|
778
|
+
# Create inner card frame with offset for shadow
|
|
779
|
+
self.card_frame = tk.Frame(
|
|
780
|
+
shadow_frame, bg="#ffffff", bd=0, highlightthickness=0
|
|
781
|
+
)
|
|
782
|
+
self.card_frame.place(x=2, y=2, relwidth=1, relheight=1, width=-4, height=-4)
|
|
783
|
+
self.card_frame.grid_propagate(False)
|
|
784
|
+
self.card_frame.update_idletasks()
|
|
785
|
+
|
|
786
|
+
def create_notebook(self):
|
|
787
|
+
"""Create the tabbed notebook interface"""
|
|
788
|
+
self.notebook = ttk.Notebook(self.card_frame)
|
|
789
|
+
self.notebook.pack(fill="both", expand=True, padx=0, pady=0)
|
|
790
|
+
|
|
791
|
+
def create_tabs(self):
|
|
792
|
+
"""Create all application tabs with content"""
|
|
793
|
+
# Create tab frames
|
|
794
|
+
self.welcome_frame = ttk.Frame(self.notebook)
|
|
795
|
+
self.notebook.add(
|
|
796
|
+
self.welcome_frame, text=self.lang_manager.get("tab_welcome", "1. Welcome")
|
|
797
|
+
)
|
|
798
|
+
self.create_welcome_tab()
|
|
799
|
+
|
|
800
|
+
# Tab 2: Select Operation
|
|
801
|
+
self.operation_frame = ttk.Frame(self.notebook)
|
|
802
|
+
self.notebook.add(
|
|
803
|
+
self.operation_frame,
|
|
804
|
+
text=self.lang_manager.get("tab_operation", "2. Select Operation"),
|
|
805
|
+
)
|
|
806
|
+
self.create_operation_tab()
|
|
807
|
+
|
|
808
|
+
# Tab 3: Select File
|
|
809
|
+
self.file_frame = ttk.Frame(self.notebook)
|
|
810
|
+
self.notebook.add(
|
|
811
|
+
self.file_frame, text=self.lang_manager.get("tab_file", "3. Select File")
|
|
812
|
+
)
|
|
813
|
+
self.create_file_tab()
|
|
814
|
+
|
|
815
|
+
# Tab 4: Adjust Settings
|
|
816
|
+
self.settings_frame = ttk.Frame(self.notebook)
|
|
817
|
+
self.notebook.add(
|
|
818
|
+
self.settings_frame,
|
|
819
|
+
text=self.lang_manager.get("tab_settings", "4. Adjust Settings"),
|
|
820
|
+
)
|
|
821
|
+
self.create_settings_tab()
|
|
822
|
+
|
|
823
|
+
# Tab 5: Results
|
|
824
|
+
self.results_frame = ttk.Frame(self.notebook)
|
|
825
|
+
self.notebook.add(
|
|
826
|
+
self.results_frame, text=self.lang_manager.get("tab_results", "5. Results")
|
|
827
|
+
)
|
|
828
|
+
self.create_results_tab()
|
|
829
|
+
|
|
830
|
+
# Settings
|
|
831
|
+
self.app_settings_frame = ttk.Frame(self.notebook)
|
|
832
|
+
self.notebook.add(
|
|
833
|
+
self.app_settings_frame,
|
|
834
|
+
text=self.lang_manager.get("tab_app_settings", "Settings"),
|
|
835
|
+
)
|
|
836
|
+
self.create_app_settings_tab()
|
|
837
|
+
|
|
838
|
+
# Help
|
|
839
|
+
self.help_frame = ttk.Frame(self.notebook)
|
|
840
|
+
self.notebook.add(
|
|
841
|
+
self.help_frame, text=self.lang_manager.get("tab_help", "Help")
|
|
842
|
+
)
|
|
843
|
+
self.create_help_tab()
|
|
844
|
+
|
|
845
|
+
# Disable workflow tabs that require prerequisites
|
|
846
|
+
self.notebook.tab(2, state="disabled") # Select File
|
|
847
|
+
self.notebook.tab(3, state="disabled") # Adjust Settings
|
|
848
|
+
self.notebook.tab(4, state="disabled") # Results
|
|
849
|
+
|
|
850
|
+
# Add tooltips to tabs
|
|
851
|
+
self.setup_tab_tooltips()
|
|
852
|
+
|
|
853
|
+
def setup_tab_tooltips(self):
|
|
854
|
+
"""Setup tooltips for notebook tabs"""
|
|
855
|
+
# Define tooltips for each tab
|
|
856
|
+
tooltips = {
|
|
857
|
+
0: self.lang_manager.get(
|
|
858
|
+
"tooltip_welcome", "Start here - Welcome and introduction to SafePDF"
|
|
859
|
+
) or "",
|
|
860
|
+
1: self.lang_manager.get(
|
|
861
|
+
"tooltip_operation", "Choose the PDF operation you want to perform"
|
|
862
|
+
) or "",
|
|
863
|
+
2: self.lang_manager.get(
|
|
864
|
+
"tooltip_file", "Select the PDF file(s) you want to process"
|
|
865
|
+
) or "",
|
|
866
|
+
3: self.lang_manager.get(
|
|
867
|
+
"tooltip_settings", "Configure operation-specific settings"
|
|
868
|
+
) or "",
|
|
869
|
+
4: self.lang_manager.get(
|
|
870
|
+
"tooltip_results", "View the results of your PDF operation"
|
|
871
|
+
) or "",
|
|
872
|
+
5: self.lang_manager.get(
|
|
873
|
+
"tooltip_app_settings", "Application settings and preferences"
|
|
874
|
+
) or "",
|
|
875
|
+
6: self.lang_manager.get("tooltip_help", "Help and documentation") or "",
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
# Create tooltip window
|
|
879
|
+
self.tooltip_window = None
|
|
880
|
+
|
|
881
|
+
def show_tooltip(event, text):
|
|
882
|
+
"""Show tooltip on hover"""
|
|
883
|
+
if text is None:
|
|
884
|
+
text = ""
|
|
885
|
+
|
|
886
|
+
if not self.tooltip_window:
|
|
887
|
+
self.tooltip_window = tk.Toplevel(self.root)
|
|
888
|
+
self.tooltip_window.wm_overrideredirect(True)
|
|
889
|
+
self.tooltip_window.wm_attributes("-topmost", True)
|
|
890
|
+
|
|
891
|
+
self.tooltip_label = tk.Label(
|
|
892
|
+
self.tooltip_window,
|
|
893
|
+
text=text,
|
|
894
|
+
background=CommonElements.BG_COLOR,
|
|
895
|
+
foreground=CommonElements.FG_COLOR,
|
|
896
|
+
relief=tk.FLAT,
|
|
897
|
+
bd=0,
|
|
898
|
+
font=(CommonElements.FONT, 9),
|
|
899
|
+
padx=10,
|
|
900
|
+
pady=5,
|
|
901
|
+
)
|
|
902
|
+
self.tooltip_label.pack()
|
|
903
|
+
else:
|
|
904
|
+
self.tooltip_label.config(text=text)
|
|
905
|
+
|
|
906
|
+
x = event.x_root + 15
|
|
907
|
+
y = event.y_root + 10
|
|
908
|
+
self.tooltip_window.wm_geometry(f"+{x}+{y}")
|
|
909
|
+
|
|
910
|
+
def hide_tooltip(event):
|
|
911
|
+
"""Hide tooltip"""
|
|
912
|
+
if self.tooltip_window:
|
|
913
|
+
self.tooltip_window.destroy()
|
|
914
|
+
self.tooltip_window = None
|
|
915
|
+
self.current_tooltip_index = None
|
|
916
|
+
|
|
917
|
+
def move_tooltip(event):
|
|
918
|
+
"""Move tooltip to follow cursor"""
|
|
919
|
+
if self.tooltip_window:
|
|
920
|
+
x = event.x_root + 15
|
|
921
|
+
y = event.y_root + 10
|
|
922
|
+
self.tooltip_window.wm_geometry(f"+{x}+{y}")
|
|
923
|
+
|
|
924
|
+
# Bind mouse events to notebook tabs
|
|
925
|
+
try:
|
|
926
|
+
self.notebook.bind(
|
|
927
|
+
"<Motion>",
|
|
928
|
+
lambda e: self.check_tab_hover(
|
|
929
|
+
e, tooltips, show_tooltip, hide_tooltip, move_tooltip
|
|
930
|
+
),
|
|
931
|
+
)
|
|
932
|
+
self.notebook.bind("<Leave>", hide_tooltip)
|
|
933
|
+
except Exception as e:
|
|
934
|
+
logger.debug(f"Could not setup tab tooltips: {e}")
|
|
935
|
+
|
|
936
|
+
def check_tab_hover(self, event, tooltips, show_func, hide_func, move_func):
|
|
937
|
+
"""Check which tab is being hovered"""
|
|
938
|
+
try:
|
|
939
|
+
tab_id = self.notebook.identify(event.x, event.y)
|
|
940
|
+
if tab_id:
|
|
941
|
+
tab_index = self.notebook.index("@%d,%d" % (event.x, event.y))
|
|
942
|
+
if tab_index in tooltips:
|
|
943
|
+
if tab_index != self.current_tooltip_index:
|
|
944
|
+
self.current_tooltip_index = tab_index
|
|
945
|
+
show_func(event, tooltips[tab_index])
|
|
946
|
+
else:
|
|
947
|
+
move_func(event)
|
|
948
|
+
return
|
|
949
|
+
hide_func(event)
|
|
950
|
+
except Exception:
|
|
951
|
+
hide_func(event)
|
|
952
|
+
|
|
953
|
+
def create_welcome_tab(self):
|
|
954
|
+
"""Create the welcome tab content"""
|
|
955
|
+
# Create a frame for the HTML content
|
|
956
|
+
html_frame = tk.Frame(self.welcome_frame, bg="#ffffff")
|
|
957
|
+
html_frame.pack(fill="both", expand=True, padx=10, pady=10)
|
|
958
|
+
|
|
959
|
+
try:
|
|
960
|
+
# Try to load HTML content using tkhtml or webview
|
|
961
|
+
from tkinter import html
|
|
962
|
+
|
|
963
|
+
html_widget = html.HTMLWidget(html_frame)
|
|
964
|
+
html_widget.pack(fill="both", expand=True)
|
|
965
|
+
|
|
966
|
+
html_widget.config(state="disabled")
|
|
967
|
+
|
|
968
|
+
# Load the HTML file from the moved `text/` folder, prefer localized version
|
|
969
|
+
lang_code = CommonElements.SELECTED_LANGUAGE or "en"
|
|
970
|
+
try:
|
|
971
|
+
# Allow controller override if it exposes a language_var with a code-like value
|
|
972
|
+
lang_var = getattr(self.controller, "language_var", None)
|
|
973
|
+
if lang_var and hasattr(lang_var, "get"):
|
|
974
|
+
v = lang_var.get()
|
|
975
|
+
if v and isinstance(v, str) and len(v) <= 5:
|
|
976
|
+
lang_code = v
|
|
977
|
+
except Exception:
|
|
978
|
+
lang_code = CommonElements.SELECTED_LANGUAGE or "en"
|
|
979
|
+
|
|
980
|
+
candidates = [
|
|
981
|
+
resource_path(f"text/{lang_code}/welcome_content.html"),
|
|
982
|
+
resource_path("text/welcome_content.html"),
|
|
983
|
+
]
|
|
984
|
+
html_content = None
|
|
985
|
+
for p in candidates:
|
|
986
|
+
try:
|
|
987
|
+
if p.exists():
|
|
988
|
+
with open(str(p), "r", encoding="utf-8") as f:
|
|
989
|
+
html_content = f.read()
|
|
990
|
+
break
|
|
991
|
+
except Exception:
|
|
992
|
+
html_content = None
|
|
993
|
+
|
|
994
|
+
if html_content:
|
|
995
|
+
html_widget.set_html(html_content)
|
|
996
|
+
else:
|
|
997
|
+
raise FileNotFoundError("No welcome HTML content available")
|
|
998
|
+
|
|
999
|
+
except ImportError:
|
|
1000
|
+
# Fallback to text-based content if HTML widget is not available
|
|
1001
|
+
self.create_fallback_welcome_content(html_frame)
|
|
1002
|
+
|
|
1003
|
+
def create_fallback_welcome_content(self, parent_frame):
|
|
1004
|
+
"""Create fallback text-based welcome content with formatting"""
|
|
1005
|
+
# Use tk.Text instead of ScrolledText to avoid scrollbar
|
|
1006
|
+
welcome_text = tk.Text(
|
|
1007
|
+
parent_frame,
|
|
1008
|
+
wrap=tk.WORD,
|
|
1009
|
+
width=60,
|
|
1010
|
+
height=15,
|
|
1011
|
+
state=tk.DISABLED,
|
|
1012
|
+
font=(CommonElements.FONT, CommonElements.FONT_SIZE),
|
|
1013
|
+
bg=CommonElements.TEXT_BG,
|
|
1014
|
+
fg=CommonElements.TEXT_FG,
|
|
1015
|
+
borderwidth=0,
|
|
1016
|
+
highlightthickness=0,
|
|
1017
|
+
)
|
|
1018
|
+
welcome_text.pack(fill="both", expand=True)
|
|
1019
|
+
|
|
1020
|
+
# Enable text insertion
|
|
1021
|
+
welcome_text.config(state=tk.NORMAL)
|
|
1022
|
+
|
|
1023
|
+
# Load and format welcome content
|
|
1024
|
+
welcome_content = self.load_welcome_content()
|
|
1025
|
+
welcome_text.insert("1.0", welcome_content)
|
|
1026
|
+
|
|
1027
|
+
# Add text formatting
|
|
1028
|
+
self.format_welcome_text(welcome_text)
|
|
1029
|
+
|
|
1030
|
+
# Make text read-only
|
|
1031
|
+
welcome_text.config(state=tk.DISABLED)
|
|
1032
|
+
|
|
1033
|
+
def load_welcome_content(self):
|
|
1034
|
+
"""Load welcome content from text file or use fallback"""
|
|
1035
|
+
try:
|
|
1036
|
+
# Prefer localized welcome text under text/<lang>/welcome_content.txt
|
|
1037
|
+
lang_code = CommonElements.SELECTED_LANGUAGE or "en"
|
|
1038
|
+
try:
|
|
1039
|
+
lang_var = getattr(self.controller, "language_var", None)
|
|
1040
|
+
if lang_var and hasattr(lang_var, "get"):
|
|
1041
|
+
v = lang_var.get()
|
|
1042
|
+
if v and isinstance(v, str) and len(v) <= 5:
|
|
1043
|
+
lang_code = v
|
|
1044
|
+
except Exception:
|
|
1045
|
+
lang_code = CommonElements.SELECTED_LANGUAGE or "en"
|
|
1046
|
+
|
|
1047
|
+
candidates = [
|
|
1048
|
+
resource_path(f"text/{lang_code}/welcome_content.txt"),
|
|
1049
|
+
resource_path("text/welcome_content.txt"),
|
|
1050
|
+
]
|
|
1051
|
+
for welcome_txt_path in candidates:
|
|
1052
|
+
try:
|
|
1053
|
+
if welcome_txt_path.exists():
|
|
1054
|
+
with open(str(welcome_txt_path), "r", encoding="utf-8") as f:
|
|
1055
|
+
content = f.read()
|
|
1056
|
+
# Replace {VERSION} placeholder with actual version
|
|
1057
|
+
content = content.replace("{VERSION}", f"v{SAFEPDF_VERSION}")
|
|
1058
|
+
return content
|
|
1059
|
+
except Exception:
|
|
1060
|
+
logger.debug(
|
|
1061
|
+
f"Error reading welcome file {welcome_txt_path}", exc_info=True
|
|
1062
|
+
)
|
|
1063
|
+
continue
|
|
1064
|
+
except Exception:
|
|
1065
|
+
logger.debug("Error loading welcome content from file", exc_info=True)
|
|
1066
|
+
pass # File not found, use fallback
|
|
1067
|
+
|
|
1068
|
+
# Fallback content if file doesn't exist
|
|
1069
|
+
return "Welcome to SafePDF!\n\nThis application helps you perform various PDF operations."
|
|
1070
|
+
|
|
1071
|
+
def format_welcome_text(self, text_widget):
|
|
1072
|
+
"""Apply formatting to the welcome text"""
|
|
1073
|
+
# Configure text tags for formatting
|
|
1074
|
+
text_widget.tag_configure(
|
|
1075
|
+
"title",
|
|
1076
|
+
foreground=CommonElements.RED_COLOR,
|
|
1077
|
+
font=(CommonElements.FONT, 14, "bold"),
|
|
1078
|
+
justify="center",
|
|
1079
|
+
)
|
|
1080
|
+
text_widget.tag_configure(
|
|
1081
|
+
"step", foreground=CommonElements.URL_COLOR, font=(CommonElements.FONT, 10, "bold")
|
|
1082
|
+
)
|
|
1083
|
+
text_widget.tag_configure(
|
|
1084
|
+
"update_link",
|
|
1085
|
+
foreground= CommonElements.URL_COLOR,
|
|
1086
|
+
underline=True,
|
|
1087
|
+
font=(CommonElements.FONT, 10, "bold"),
|
|
1088
|
+
)
|
|
1089
|
+
text_widget.tag_configure(
|
|
1090
|
+
"contact_link",
|
|
1091
|
+
foreground=CommonElements.URL_COLOR,
|
|
1092
|
+
underline=True,
|
|
1093
|
+
font=(CommonElements.FONT, 10, "bold"),
|
|
1094
|
+
)
|
|
1095
|
+
text_widget.tag_configure(
|
|
1096
|
+
"info",
|
|
1097
|
+
foreground=CommonElements.RED_COLOR,
|
|
1098
|
+
font=(CommonElements.FONT, 11, "bold"),
|
|
1099
|
+
)
|
|
1100
|
+
text_widget.tag_configure(
|
|
1101
|
+
"version", foreground=CommonElements.URL_COLOR, font=(CommonElements.FONT, 10, "bold")
|
|
1102
|
+
)
|
|
1103
|
+
|
|
1104
|
+
# Apply formatting to specific parts
|
|
1105
|
+
content = text_widget.get("1.0", "end-1c")
|
|
1106
|
+
|
|
1107
|
+
# Title formatting (first line, language-agnostic)
|
|
1108
|
+
try:
|
|
1109
|
+
first_line = content.splitlines()[0] if content else ""
|
|
1110
|
+
if first_line:
|
|
1111
|
+
text_widget.tag_add("title", "1.0", f"1.0+{len(first_line)}c")
|
|
1112
|
+
except Exception:
|
|
1113
|
+
pass
|
|
1114
|
+
|
|
1115
|
+
# Update link formatting (language-agnostic: the line starting with 🔗)
|
|
1116
|
+
try:
|
|
1117
|
+
update_line_start = content.find("🔗")
|
|
1118
|
+
if update_line_start != -1:
|
|
1119
|
+
line_end = content.find("\n", update_line_start)
|
|
1120
|
+
if line_end == -1:
|
|
1121
|
+
line_end = len(content)
|
|
1122
|
+
text_widget.tag_add(
|
|
1123
|
+
"update_link",
|
|
1124
|
+
f"1.0+{update_line_start}c",
|
|
1125
|
+
f"1.0+{line_end}c",
|
|
1126
|
+
)
|
|
1127
|
+
text_widget.tag_bind(
|
|
1128
|
+
"update_link", "<Button-1>", self.update_ui.check_for_updates
|
|
1129
|
+
)
|
|
1130
|
+
text_widget.tag_bind(
|
|
1131
|
+
"update_link",
|
|
1132
|
+
"<Enter>",
|
|
1133
|
+
lambda e: text_widget.config(cursor="hand2"),
|
|
1134
|
+
)
|
|
1135
|
+
text_widget.tag_bind(
|
|
1136
|
+
"update_link", "<Leave>", lambda e: text_widget.config(cursor="")
|
|
1137
|
+
)
|
|
1138
|
+
except Exception:
|
|
1139
|
+
pass
|
|
1140
|
+
|
|
1141
|
+
# Contact us link formatting (best-effort; avoid overriding the update link)
|
|
1142
|
+
try:
|
|
1143
|
+
# Prefer i18n marker(s) from LanguageManager.
|
|
1144
|
+
# This should match the phrase used in localized welcome_content.txt.
|
|
1145
|
+
contact_markers = [
|
|
1146
|
+
self.lang_manager.get("contact_us", "contact us"),
|
|
1147
|
+
]
|
|
1148
|
+
lower_content = content.lower()
|
|
1149
|
+
for marker in contact_markers:
|
|
1150
|
+
if not marker:
|
|
1151
|
+
continue
|
|
1152
|
+
idx = lower_content.find(str(marker).lower())
|
|
1153
|
+
if idx != -1:
|
|
1154
|
+
# Adjust for Turkish formatting offset
|
|
1155
|
+
if CommonElements.SELECTED_LANGUAGE == "tr":
|
|
1156
|
+
adjusted_idx = idx - 3
|
|
1157
|
+
else:
|
|
1158
|
+
adjusted_idx = idx
|
|
1159
|
+
if adjusted_idx < 0:
|
|
1160
|
+
adjusted_idx = 0
|
|
1161
|
+
text_widget.tag_add(
|
|
1162
|
+
"contact_link",
|
|
1163
|
+
f"1.0+{adjusted_idx}c",
|
|
1164
|
+
f"1.0+{adjusted_idx + len(marker)}c",
|
|
1165
|
+
)
|
|
1166
|
+
text_widget.tag_bind(
|
|
1167
|
+
"contact_link", "<Button-1>", lambda e: self.open_contact_us()
|
|
1168
|
+
)
|
|
1169
|
+
text_widget.tag_bind(
|
|
1170
|
+
"contact_link",
|
|
1171
|
+
"<Enter>",
|
|
1172
|
+
lambda e: text_widget.config(cursor="hand2"),
|
|
1173
|
+
)
|
|
1174
|
+
text_widget.tag_bind(
|
|
1175
|
+
"contact_link",
|
|
1176
|
+
"<Leave>",
|
|
1177
|
+
lambda e: text_widget.config(cursor=""),
|
|
1178
|
+
)
|
|
1179
|
+
break
|
|
1180
|
+
except Exception:
|
|
1181
|
+
pass
|
|
1182
|
+
|
|
1183
|
+
# Info sections
|
|
1184
|
+
info_sections = ["💻 Software Information", "📋 Process Steps:"]
|
|
1185
|
+
for section in info_sections:
|
|
1186
|
+
if section in content:
|
|
1187
|
+
start = content.find(section)
|
|
1188
|
+
if start != -1:
|
|
1189
|
+
text_widget.tag_add(
|
|
1190
|
+
"info", f"1.0+{start}c", f"1.0+{start + len(section)}c"
|
|
1191
|
+
)
|
|
1192
|
+
|
|
1193
|
+
def create_file_tab(self):
|
|
1194
|
+
"""Create the file selection tab with modern design and PDF preview"""
|
|
1195
|
+
main_frame = ttk.Frame(self.file_frame, style="TFrame")
|
|
1196
|
+
main_frame.pack(fill="both", expand=True, padx=20, pady=20)
|
|
1197
|
+
|
|
1198
|
+
# Horizontal layout for drop zone and preview
|
|
1199
|
+
file_tab_container = tk.Frame(main_frame, bg=CommonElements.TEXT_BG)
|
|
1200
|
+
file_tab_container.pack(fill="both", expand=True)
|
|
1201
|
+
|
|
1202
|
+
# Left: Drop zone
|
|
1203
|
+
drop_frame = tk.Frame(
|
|
1204
|
+
file_tab_container, bg=CommonElements.TEXT_BG, relief=tk.FLAT, bd=0
|
|
1205
|
+
)
|
|
1206
|
+
drop_frame.pack(side="left", fill="both", expand=True, pady=(0, 12))
|
|
1207
|
+
|
|
1208
|
+
self.drop_canvas = tk.Canvas(
|
|
1209
|
+
drop_frame, bg=CommonElements.TEXT_BG, highlightthickness=0, relief=tk.FLAT
|
|
1210
|
+
)
|
|
1211
|
+
self.drop_canvas.pack(fill="both", expand=True)
|
|
1212
|
+
|
|
1213
|
+
self.drop_label = tk.Label(
|
|
1214
|
+
self.drop_canvas,
|
|
1215
|
+
text=self.lang_manager.get(
|
|
1216
|
+
"drop_pdf_file", "📄 Drop PDF File Here\n\nClick to browse"
|
|
1217
|
+
) or "",
|
|
1218
|
+
relief=tk.FLAT,
|
|
1219
|
+
bd=0,
|
|
1220
|
+
bg=CommonElements.TEXT_BG,
|
|
1221
|
+
font=(CommonElements.FONT, 12, "bold"),
|
|
1222
|
+
height=10,
|
|
1223
|
+
cursor="hand2",
|
|
1224
|
+
fg=CommonElements.RED_COLOR,
|
|
1225
|
+
)
|
|
1226
|
+
self.drop_label.bind("<Button-1>", self.browse_file)
|
|
1227
|
+
self._draw_dashed_border()
|
|
1228
|
+
drop_frame.bind("<Configure>", lambda e: self._draw_dashed_border())
|
|
1229
|
+
self.setup_drag_drop()
|
|
1230
|
+
|
|
1231
|
+
# Right: PDF preview area
|
|
1232
|
+
preview_frame = tk.Frame(
|
|
1233
|
+
file_tab_container, bg=CommonElements.TEXT_BG, relief=tk.FLAT, bd=0
|
|
1234
|
+
)
|
|
1235
|
+
preview_frame.pack(side="right", fill="y", padx=(16, 0), pady=(0, 12))
|
|
1236
|
+
self.preview_label = tk.Label(
|
|
1237
|
+
preview_frame,
|
|
1238
|
+
text=self.lang_manager.get("preview", "Preview:"),
|
|
1239
|
+
font=(CommonElements.FONT, 11, "bold"),
|
|
1240
|
+
bg=CommonElements.TEXT_BG,
|
|
1241
|
+
fg="#333",
|
|
1242
|
+
)
|
|
1243
|
+
self.preview_label.pack(anchor="nw", pady=(0, 4))
|
|
1244
|
+
self.pdf_preview_canvas = tk.Canvas(
|
|
1245
|
+
preview_frame,
|
|
1246
|
+
width=180,
|
|
1247
|
+
height=240,
|
|
1248
|
+
bg=CommonElements.BG_FRAME,
|
|
1249
|
+
bd=1,
|
|
1250
|
+
relief=tk.SOLID,
|
|
1251
|
+
highlightthickness=1,
|
|
1252
|
+
highlightbackground="#acb2bb",
|
|
1253
|
+
)
|
|
1254
|
+
self.pdf_preview_canvas.pack(anchor="n", pady=(0, 8))
|
|
1255
|
+
self.pdf_preview_image = None
|
|
1256
|
+
|
|
1257
|
+
# Or label and browse button below
|
|
1258
|
+
self.or_label = ttk.Label(
|
|
1259
|
+
main_frame, text=self.lang_manager.get("or_label", "or"), style="TLabel"
|
|
1260
|
+
)
|
|
1261
|
+
self.or_label.pack(pady=4)
|
|
1262
|
+
self.browse_btn = ttk.Button(
|
|
1263
|
+
main_frame,
|
|
1264
|
+
text=self.lang_manager.get("btn_load_file", "Load File from Disk"),
|
|
1265
|
+
command=self.browse_file,
|
|
1266
|
+
style="Accent.TButton",
|
|
1267
|
+
)
|
|
1268
|
+
self.browse_btn.pack(pady=(8, 0))
|
|
1269
|
+
|
|
1270
|
+
self.update_file_tab_ui()
|
|
1271
|
+
|
|
1272
|
+
def show_pdf_preview(self, pdf_path):
|
|
1273
|
+
"""Render and show the first page of the selected PDF in the preview canvas."""
|
|
1274
|
+
if not hasattr(self, "pdf_preview_canvas") or not self.pdf_preview_canvas:
|
|
1275
|
+
return
|
|
1276
|
+
|
|
1277
|
+
canvas_w, canvas_h = 180, 240
|
|
1278
|
+
self.pdf_preview_canvas.delete("all")
|
|
1279
|
+
|
|
1280
|
+
if not pdf_path:
|
|
1281
|
+
self.pdf_preview_canvas.create_text(
|
|
1282
|
+
canvas_w // 2,
|
|
1283
|
+
canvas_h // 2,
|
|
1284
|
+
text=self.lang_manager.get(
|
|
1285
|
+
"preview_no_file_selected", "No file\nselected"
|
|
1286
|
+
),
|
|
1287
|
+
fill="#888",
|
|
1288
|
+
font=(CommonElements.FONT, 10),
|
|
1289
|
+
)
|
|
1290
|
+
return
|
|
1291
|
+
|
|
1292
|
+
try:
|
|
1293
|
+
pdf_path = str(Path(pdf_path))
|
|
1294
|
+
if not Path(pdf_path).exists():
|
|
1295
|
+
raise FileNotFoundError(pdf_path)
|
|
1296
|
+
|
|
1297
|
+
Image, ImageTk = _get_pil()
|
|
1298
|
+
if not Image or not ImageTk:
|
|
1299
|
+
raise ImportError("Pillow is not available")
|
|
1300
|
+
|
|
1301
|
+
# Use pypdfium2 for rendering (no external dependencies)
|
|
1302
|
+
import pypdfium2 as pdfium
|
|
1303
|
+
|
|
1304
|
+
# Open PDF and render first page
|
|
1305
|
+
pdf = pdfium.PdfDocument(pdf_path)
|
|
1306
|
+
if len(pdf) < 1:
|
|
1307
|
+
pdf.close()
|
|
1308
|
+
raise ValueError("Empty PDF")
|
|
1309
|
+
|
|
1310
|
+
page = pdf[0]
|
|
1311
|
+
# Calculate scale to fit canvas
|
|
1312
|
+
scale = min(canvas_w / page.get_width(), canvas_h / page.get_height()) * 0.8
|
|
1313
|
+
img = page.render(scale=scale).to_pil()
|
|
1314
|
+
pdf.close()
|
|
1315
|
+
|
|
1316
|
+
img.thumbnail((canvas_w, canvas_h), Image.LANCZOS)
|
|
1317
|
+
|
|
1318
|
+
self.pdf_preview_image = ImageTk.PhotoImage(img)
|
|
1319
|
+
self.pdf_preview_canvas.create_image(
|
|
1320
|
+
canvas_w // 2, canvas_h // 2, image=self.pdf_preview_image
|
|
1321
|
+
)
|
|
1322
|
+
except Exception:
|
|
1323
|
+
self.pdf_preview_canvas.delete("all")
|
|
1324
|
+
self.pdf_preview_canvas.create_text(
|
|
1325
|
+
canvas_w // 2,
|
|
1326
|
+
canvas_h // 2,
|
|
1327
|
+
text=self.lang_manager.get(
|
|
1328
|
+
"preview_unavailable", "Preview\nUnavailable"
|
|
1329
|
+
),
|
|
1330
|
+
fill="#888",
|
|
1331
|
+
font=(CommonElements.FONT, 10),
|
|
1332
|
+
)
|
|
1333
|
+
|
|
1334
|
+
def update_file_tab_ui(self):
|
|
1335
|
+
"""Update file tab UI based on selected operation"""
|
|
1336
|
+
if not hasattr(self, "drop_label") or not self.drop_label:
|
|
1337
|
+
return
|
|
1338
|
+
|
|
1339
|
+
if self.controller.selected_operation == "merge":
|
|
1340
|
+
self.drop_label.config(
|
|
1341
|
+
text=self.lang_manager.get("drop_pdf_files", "📄 Drop PDF Files Here!")
|
|
1342
|
+
)
|
|
1343
|
+
else:
|
|
1344
|
+
self.drop_label.config(
|
|
1345
|
+
text=self.lang_manager.get(
|
|
1346
|
+
"drop_pdf_file", "📄 Drop PDF File Here\n\nClick to browse"
|
|
1347
|
+
)
|
|
1348
|
+
)
|
|
1349
|
+
|
|
1350
|
+
def setup_drag_drop(self):
|
|
1351
|
+
"""Setup drag and drop with lazy loading"""
|
|
1352
|
+
if self._dnd_loaded:
|
|
1353
|
+
return
|
|
1354
|
+
|
|
1355
|
+
DND_FILES = _get_tkinterdnd()
|
|
1356
|
+
if DND_FILES and hasattr(self, "drop_canvas") and self.drop_canvas:
|
|
1357
|
+
try:
|
|
1358
|
+
self.drop_canvas.drop_target_register(DND_FILES)
|
|
1359
|
+
self.drop_canvas.dnd_bind("<<Drop>>", self.handle_drop)
|
|
1360
|
+
self.drop_canvas.dnd_bind("<<DragEnter>>", self.on_drag_enter)
|
|
1361
|
+
self.drop_canvas.dnd_bind("<<DragLeave>>", self.on_drag_leave)
|
|
1362
|
+
self._dnd_loaded = True
|
|
1363
|
+
except Exception:
|
|
1364
|
+
logger.debug("Error setting up drag and drop", exc_info=True)
|
|
1365
|
+
pass
|
|
1366
|
+
|
|
1367
|
+
def _load_operation_image(self, img_path: str):
|
|
1368
|
+
"""Load operation images with lazy PIL loading"""
|
|
1369
|
+
if not self._pil_loaded:
|
|
1370
|
+
Image, ImageTk = _get_pil()
|
|
1371
|
+
if not Image or not ImageTk:
|
|
1372
|
+
return None
|
|
1373
|
+
self._pil_loaded = True
|
|
1374
|
+
else:
|
|
1375
|
+
Image, ImageTk = _get_pil()
|
|
1376
|
+
|
|
1377
|
+
abs_img_path = resource_path(img_path)
|
|
1378
|
+
try:
|
|
1379
|
+
if abs_img_path.exists():
|
|
1380
|
+
# Optimize image loading
|
|
1381
|
+
img = Image.open(str(abs_img_path))
|
|
1382
|
+
# Reduce size for memory efficiency
|
|
1383
|
+
max_size = 80 # Reduced from 100
|
|
1384
|
+
img.thumbnail((max_size, max_size), Image.LANCZOS)
|
|
1385
|
+
return ImageTk.PhotoImage(img)
|
|
1386
|
+
except Exception:
|
|
1387
|
+
logger.debug(f"Error loading operation image: {img_path}", exc_info=True)
|
|
1388
|
+
pass
|
|
1389
|
+
return None
|
|
1390
|
+
|
|
1391
|
+
def _draw_dashed_border(self):
|
|
1392
|
+
"""Draw a dashed border around the drop zone using canvas"""
|
|
1393
|
+
try:
|
|
1394
|
+
if not hasattr(self, "drop_canvas") or not self.drop_canvas:
|
|
1395
|
+
return
|
|
1396
|
+
|
|
1397
|
+
# Clear existing border
|
|
1398
|
+
self.drop_canvas.delete("border")
|
|
1399
|
+
|
|
1400
|
+
# Get canvas dimensions
|
|
1401
|
+
width = self.drop_canvas.winfo_width()
|
|
1402
|
+
height = self.drop_canvas.winfo_height()
|
|
1403
|
+
|
|
1404
|
+
if width <= 1 or height <= 1:
|
|
1405
|
+
# Canvas not yet sized, schedule redraw
|
|
1406
|
+
self.drop_canvas.after(10, self._draw_dashed_border)
|
|
1407
|
+
return
|
|
1408
|
+
|
|
1409
|
+
# Border parameters
|
|
1410
|
+
border_width = 3
|
|
1411
|
+
dash_length = 8
|
|
1412
|
+
gap_length = 4
|
|
1413
|
+
border_color = "#acb2bb"
|
|
1414
|
+
|
|
1415
|
+
# Calculate border segments
|
|
1416
|
+
# Top border
|
|
1417
|
+
x = border_width // 2
|
|
1418
|
+
while x < width:
|
|
1419
|
+
end_x = min(x + dash_length, width - border_width // 2)
|
|
1420
|
+
self.drop_canvas.create_line(
|
|
1421
|
+
x,
|
|
1422
|
+
border_width // 2,
|
|
1423
|
+
end_x,
|
|
1424
|
+
border_width // 2,
|
|
1425
|
+
fill=border_color,
|
|
1426
|
+
width=border_width,
|
|
1427
|
+
tags="border",
|
|
1428
|
+
)
|
|
1429
|
+
x += dash_length + gap_length
|
|
1430
|
+
|
|
1431
|
+
# Right border
|
|
1432
|
+
y = border_width // 2
|
|
1433
|
+
while y < height:
|
|
1434
|
+
end_y = min(y + dash_length, height - border_width // 2)
|
|
1435
|
+
self.drop_canvas.create_line(
|
|
1436
|
+
width - border_width // 2,
|
|
1437
|
+
y,
|
|
1438
|
+
width - border_width // 2,
|
|
1439
|
+
end_y,
|
|
1440
|
+
fill=border_color,
|
|
1441
|
+
width=border_width,
|
|
1442
|
+
tags="border",
|
|
1443
|
+
)
|
|
1444
|
+
y += dash_length + gap_length
|
|
1445
|
+
|
|
1446
|
+
# Bottom border
|
|
1447
|
+
x = width - border_width // 2
|
|
1448
|
+
while x > 0:
|
|
1449
|
+
start_x = max(x - dash_length, border_width // 2)
|
|
1450
|
+
self.drop_canvas.create_line(
|
|
1451
|
+
x,
|
|
1452
|
+
height - border_width // 2,
|
|
1453
|
+
start_x,
|
|
1454
|
+
height - border_width // 2,
|
|
1455
|
+
fill=border_color,
|
|
1456
|
+
width=border_width,
|
|
1457
|
+
tags="border",
|
|
1458
|
+
)
|
|
1459
|
+
x -= dash_length + gap_length
|
|
1460
|
+
|
|
1461
|
+
# Left border
|
|
1462
|
+
y = height - border_width // 2
|
|
1463
|
+
while y > 0:
|
|
1464
|
+
start_y = max(y - dash_length, border_width // 2)
|
|
1465
|
+
self.drop_canvas.create_line(
|
|
1466
|
+
border_width // 2,
|
|
1467
|
+
y,
|
|
1468
|
+
border_width // 2,
|
|
1469
|
+
start_y,
|
|
1470
|
+
fill=border_color,
|
|
1471
|
+
width=border_width,
|
|
1472
|
+
tags="border",
|
|
1473
|
+
)
|
|
1474
|
+
y -= dash_length + gap_length
|
|
1475
|
+
|
|
1476
|
+
# Position the label in the center
|
|
1477
|
+
if hasattr(self, "drop_label") and self.drop_label:
|
|
1478
|
+
self.drop_canvas.create_window(
|
|
1479
|
+
width // 2, height // 2, window=self.drop_label, tags="label"
|
|
1480
|
+
)
|
|
1481
|
+
|
|
1482
|
+
except Exception as e:
|
|
1483
|
+
logger.debug(f"Error drawing dashed border: {e}", exc_info=True)
|
|
1484
|
+
|
|
1485
|
+
def _update_canvas_border_color(self, color):
|
|
1486
|
+
"""Update the color of the dashed border on the canvas"""
|
|
1487
|
+
try:
|
|
1488
|
+
if hasattr(self, "drop_canvas") and self.drop_canvas:
|
|
1489
|
+
# Update all border lines
|
|
1490
|
+
self.drop_canvas.itemconfig("border", fill=color)
|
|
1491
|
+
except Exception as e:
|
|
1492
|
+
logger.debug(f"Error updating canvas border color: {e}", exc_info=True)
|
|
1493
|
+
|
|
1494
|
+
def create_operation_tab(self):
|
|
1495
|
+
"""Optimized operation tab with smaller images"""
|
|
1496
|
+
# Modern group frame optimized for larger image buttons
|
|
1497
|
+
group_frame = tk.Frame(self.operation_frame, bg="#f9f9fa", relief=tk.FLAT)
|
|
1498
|
+
group_frame.pack(fill="both", expand=True, padx=0, pady=0)
|
|
1499
|
+
|
|
1500
|
+
# Create container for the operation buttons
|
|
1501
|
+
operations_container = tk.Frame(group_frame, bg="#f9f9fa")
|
|
1502
|
+
operations_container.pack(fill="both", expand=True)
|
|
1503
|
+
|
|
1504
|
+
# Operations with smaller, optimized images
|
|
1505
|
+
operations = [
|
|
1506
|
+
(
|
|
1507
|
+
self.lang_manager.get("op_compress", "PDF Compress"),
|
|
1508
|
+
self.lang_manager.get("op_compress_desc", "Reduce file size"),
|
|
1509
|
+
self.select_compress,
|
|
1510
|
+
"assets/compress.png",
|
|
1511
|
+
),
|
|
1512
|
+
(
|
|
1513
|
+
self.lang_manager.get("op_split", "PDF Split"),
|
|
1514
|
+
self.lang_manager.get("op_split_desc", "Separate pages"),
|
|
1515
|
+
self.select_split,
|
|
1516
|
+
"assets/split.png",
|
|
1517
|
+
),
|
|
1518
|
+
(
|
|
1519
|
+
self.lang_manager.get("op_merge", "PDF Merge"),
|
|
1520
|
+
self.lang_manager.get("op_merge_desc", "Combine files"),
|
|
1521
|
+
self.select_merge,
|
|
1522
|
+
"assets/merge.png",
|
|
1523
|
+
),
|
|
1524
|
+
(
|
|
1525
|
+
self.lang_manager.get("op_to_jpg", "PDF to JPG"),
|
|
1526
|
+
self.lang_manager.get("op_to_jpg_desc", "Convert to images"),
|
|
1527
|
+
self.select_to_jpg,
|
|
1528
|
+
"assets/pdf2jpg.png",
|
|
1529
|
+
),
|
|
1530
|
+
(
|
|
1531
|
+
self.lang_manager.get("op_rotate", "PDF Rotate"),
|
|
1532
|
+
self.lang_manager.get("op_rotate_desc", "Rotate pages"),
|
|
1533
|
+
self.select_rotate,
|
|
1534
|
+
"assets/rotate.png",
|
|
1535
|
+
),
|
|
1536
|
+
(
|
|
1537
|
+
self.lang_manager.get("op_repair", "PDF Repair"),
|
|
1538
|
+
self.lang_manager.get("op_repair_desc", "Fix corrupted files"),
|
|
1539
|
+
self.select_repair,
|
|
1540
|
+
"assets/repair.png",
|
|
1541
|
+
),
|
|
1542
|
+
(
|
|
1543
|
+
self.lang_manager.get("op_to_word", "PDF to Word"),
|
|
1544
|
+
self.lang_manager.get("op_to_word_desc", "Convert to document"),
|
|
1545
|
+
self.select_to_word,
|
|
1546
|
+
"assets/pdf2word.png",
|
|
1547
|
+
),
|
|
1548
|
+
(
|
|
1549
|
+
self.lang_manager.get("op_to_txt", "PDF to TXT"),
|
|
1550
|
+
self.lang_manager.get("op_to_txt_desc", "Extract text"),
|
|
1551
|
+
self.select_to_txt,
|
|
1552
|
+
"assets/pdf2txt.png",
|
|
1553
|
+
),
|
|
1554
|
+
(
|
|
1555
|
+
self.lang_manager.get("op_extract", "Extract Info"),
|
|
1556
|
+
self.lang_manager.get("op_extract_desc", "Hidden PDF data"),
|
|
1557
|
+
self.select_extract_info,
|
|
1558
|
+
"assets/extract.png",
|
|
1559
|
+
),
|
|
1560
|
+
]
|
|
1561
|
+
|
|
1562
|
+
self.operation_buttons = []
|
|
1563
|
+
self.operation_images = []
|
|
1564
|
+
|
|
1565
|
+
for i, (text, description, command, img_path) in enumerate(operations):
|
|
1566
|
+
row = i // 3
|
|
1567
|
+
col = i % 3
|
|
1568
|
+
tk_img = None
|
|
1569
|
+
|
|
1570
|
+
# Load image with optimization
|
|
1571
|
+
tk_img = self._load_operation_image(img_path)
|
|
1572
|
+
self.operation_images.append(tk_img)
|
|
1573
|
+
|
|
1574
|
+
# Create clickable image button frame with modern rounded shadow effect
|
|
1575
|
+
shadow_frame = tk.Frame(operations_container, bg="#e2e8f0", relief=tk.FLAT)
|
|
1576
|
+
shadow_frame.grid(row=row, column=col, padx=12, pady=12, sticky="nsew")
|
|
1577
|
+
|
|
1578
|
+
op_frame = tk.Frame(
|
|
1579
|
+
shadow_frame,
|
|
1580
|
+
relief=tk.FLAT,
|
|
1581
|
+
bd=0,
|
|
1582
|
+
bg="#ffffff",
|
|
1583
|
+
cursor="hand2",
|
|
1584
|
+
highlightbackground="#cbd5e1",
|
|
1585
|
+
highlightthickness=2,
|
|
1586
|
+
)
|
|
1587
|
+
op_frame.place(x=3, y=3, relwidth=1, relheight=1, width=-6, height=-6)
|
|
1588
|
+
|
|
1589
|
+
# Configure grid weights for centered content
|
|
1590
|
+
operations_container.grid_columnconfigure(col, weight=1)
|
|
1591
|
+
operations_container.grid_rowconfigure(row, weight=1)
|
|
1592
|
+
|
|
1593
|
+
# Create the clickable image button with description
|
|
1594
|
+
if tk_img:
|
|
1595
|
+
# Create a container for image and text
|
|
1596
|
+
button_container = tk.Frame(op_frame, bg="#ffffff")
|
|
1597
|
+
button_container.pack(expand=True, fill="both", padx=5, pady=5)
|
|
1598
|
+
|
|
1599
|
+
# Image button (clickable)
|
|
1600
|
+
img_button = tk.Button(
|
|
1601
|
+
button_container,
|
|
1602
|
+
image=tk_img,
|
|
1603
|
+
relief=tk.FLAT,
|
|
1604
|
+
bd=0,
|
|
1605
|
+
bg="#ffffff",
|
|
1606
|
+
cursor="hand2",
|
|
1607
|
+
pady=5,
|
|
1608
|
+
)
|
|
1609
|
+
img_button.image = tk_img # Keep a reference
|
|
1610
|
+
img_button.pack()
|
|
1611
|
+
|
|
1612
|
+
# Title label
|
|
1613
|
+
title_label = tk.Label(
|
|
1614
|
+
button_container,
|
|
1615
|
+
text=text,
|
|
1616
|
+
font=(CommonElements.FONT, 12, "bold"),
|
|
1617
|
+
bg=CommonElements.BG_FRAME,
|
|
1618
|
+
fg=CommonElements.FG_TEXT,
|
|
1619
|
+
cursor="hand2",
|
|
1620
|
+
)
|
|
1621
|
+
title_label.pack(pady=(5, 2))
|
|
1622
|
+
|
|
1623
|
+
# Description label
|
|
1624
|
+
desc_label = tk.Label(
|
|
1625
|
+
button_container,
|
|
1626
|
+
text=description,
|
|
1627
|
+
font=(CommonElements.FONT, 9),
|
|
1628
|
+
bg=CommonElements.BG_FRAME,
|
|
1629
|
+
fg=CommonElements.FG_SECONDARY,
|
|
1630
|
+
cursor="hand2",
|
|
1631
|
+
)
|
|
1632
|
+
desc_label.pack()
|
|
1633
|
+
|
|
1634
|
+
# Make the entire frame clickable
|
|
1635
|
+
op_frame.bind("<Button-1>", lambda e, cmd=command: cmd())
|
|
1636
|
+
button_container.bind("<Button-1>", lambda e, cmd=command: cmd())
|
|
1637
|
+
img_button.bind("<Button-1>", lambda e, cmd=command: cmd())
|
|
1638
|
+
title_label.bind("<Button-1>", lambda e, cmd=command: cmd())
|
|
1639
|
+
desc_label.bind("<Button-1>", lambda e, cmd=command: cmd())
|
|
1640
|
+
|
|
1641
|
+
clickable_widgets = [
|
|
1642
|
+
button_container,
|
|
1643
|
+
img_button,
|
|
1644
|
+
title_label,
|
|
1645
|
+
desc_label,
|
|
1646
|
+
]
|
|
1647
|
+
|
|
1648
|
+
else:
|
|
1649
|
+
# Fallback button without image
|
|
1650
|
+
img_button = tk.Button(
|
|
1651
|
+
op_frame,
|
|
1652
|
+
text=f"{text}\n{description}",
|
|
1653
|
+
command=command,
|
|
1654
|
+
relief=tk.FLAT,
|
|
1655
|
+
bd=0,
|
|
1656
|
+
bg=CommonElements.BG_FRAME,
|
|
1657
|
+
fg=CommonElements.FG_TEXT,
|
|
1658
|
+
font=(CommonElements.FONT, 11, "bold"),
|
|
1659
|
+
cursor="hand2",
|
|
1660
|
+
padx=15,
|
|
1661
|
+
pady=30,
|
|
1662
|
+
width=15,
|
|
1663
|
+
height=8,
|
|
1664
|
+
)
|
|
1665
|
+
img_button.pack(expand=True, fill="both")
|
|
1666
|
+
clickable_widgets = [img_button]
|
|
1667
|
+
|
|
1668
|
+
# Enhanced hover effects for the frame and all clickable elements
|
|
1669
|
+
def create_hover_effect(frame, widgets):
|
|
1670
|
+
def on_enter(event):
|
|
1671
|
+
frame.config(
|
|
1672
|
+
relief=tk.FLAT,
|
|
1673
|
+
bg=CommonElements.HIGHLIGHT_COLOR,
|
|
1674
|
+
highlightbackground=CommonElements.RED_COLOR,
|
|
1675
|
+
highlightthickness=2,
|
|
1676
|
+
)
|
|
1677
|
+
for widget in widgets:
|
|
1678
|
+
if hasattr(widget, "config"):
|
|
1679
|
+
try:
|
|
1680
|
+
widget.config(bg=CommonElements.HIGHLIGHT_COLOR)
|
|
1681
|
+
except Exception:
|
|
1682
|
+
pass
|
|
1683
|
+
|
|
1684
|
+
def on_leave(event):
|
|
1685
|
+
frame.config(
|
|
1686
|
+
relief=tk.FLAT,
|
|
1687
|
+
bg=CommonElements.BG_FRAME,
|
|
1688
|
+
highlightbackground="#cbd5e1",
|
|
1689
|
+
highlightthickness=2,
|
|
1690
|
+
)
|
|
1691
|
+
for widget in widgets:
|
|
1692
|
+
if hasattr(widget, "config"):
|
|
1693
|
+
try:
|
|
1694
|
+
widget.config(bg=CommonElements.BG_FRAME)
|
|
1695
|
+
except Exception:
|
|
1696
|
+
pass
|
|
1697
|
+
|
|
1698
|
+
# Bind hover events to frame and all widgets
|
|
1699
|
+
frame.bind("<Enter>", on_enter)
|
|
1700
|
+
frame.bind("<Leave>", on_leave)
|
|
1701
|
+
for widget in widgets:
|
|
1702
|
+
widget.bind("<Enter>", on_enter)
|
|
1703
|
+
widget.bind("<Leave>", on_leave)
|
|
1704
|
+
|
|
1705
|
+
create_hover_effect(op_frame, clickable_widgets)
|
|
1706
|
+
# Store the main clickable element for reference
|
|
1707
|
+
self.operation_buttons.append(
|
|
1708
|
+
clickable_widgets[0] if clickable_widgets else op_frame
|
|
1709
|
+
)
|
|
1710
|
+
|
|
1711
|
+
# Configure grid weights for 3-column layout (3 rows for 9 operations)
|
|
1712
|
+
for i in range(3): # 3 columns
|
|
1713
|
+
operations_container.grid_columnconfigure(i, weight=1)
|
|
1714
|
+
for i in range(3): # 3 rows
|
|
1715
|
+
operations_container.grid_rowconfigure(i, weight=1)
|
|
1716
|
+
|
|
1717
|
+
# Apply ttk style for modern look
|
|
1718
|
+
style = ttk.Style()
|
|
1719
|
+
style.configure(
|
|
1720
|
+
"Modern.TLabelframe", background="#f9f9fa", borderwidth=2, relief="groove"
|
|
1721
|
+
)
|
|
1722
|
+
style.configure("Modern.TFrame", background="#f9f9fa", borderwidth=0)
|
|
1723
|
+
|
|
1724
|
+
def create_settings_tab(self):
|
|
1725
|
+
"""Create the settings adjustment tab with modern design"""
|
|
1726
|
+
main_frame = ttk.Frame(self.settings_frame, style="TFrame")
|
|
1727
|
+
main_frame.pack(fill="both", expand=True, padx=20, pady=20)
|
|
1728
|
+
|
|
1729
|
+
# Settings will be populated based on selected operation
|
|
1730
|
+
self.settings_label = ttk.Label(
|
|
1731
|
+
main_frame,
|
|
1732
|
+
text=self.lang_manager.get(
|
|
1733
|
+
"select_settings", "Select an operation first to see available settings"
|
|
1734
|
+
),
|
|
1735
|
+
style="TLabel",
|
|
1736
|
+
font=(CommonElements.FONT, 12, "bold"),
|
|
1737
|
+
foreground=CommonElements.RED_COLOR,
|
|
1738
|
+
)
|
|
1739
|
+
self.settings_label.pack(expand=True, pady=(0, 8))
|
|
1740
|
+
|
|
1741
|
+
# Settings container
|
|
1742
|
+
self.settings_container = ttk.Frame(main_frame, style="TFrame")
|
|
1743
|
+
self.settings_container.pack(fill="both", expand=True)
|
|
1744
|
+
|
|
1745
|
+
def create_results_tab(self):
|
|
1746
|
+
"""Create the results display tab with modern design"""
|
|
1747
|
+
main_frame = ttk.Frame(self.results_frame, style="TFrame")
|
|
1748
|
+
main_frame.pack(fill="both", expand=True, padx=20, pady=20)
|
|
1749
|
+
|
|
1750
|
+
# Use tk.Text instead of ScrolledText to avoid scrollbar
|
|
1751
|
+
self.results_text = tk.Text(
|
|
1752
|
+
main_frame,
|
|
1753
|
+
wrap=tk.WORD,
|
|
1754
|
+
height=15,
|
|
1755
|
+
font=(CommonElements.FONT, CommonElements.FONT_SIZE),
|
|
1756
|
+
background=CommonElements.TEXT_BG,
|
|
1757
|
+
foreground=CommonElements.TEXT_FG,
|
|
1758
|
+
borderwidth=1,
|
|
1759
|
+
relief=tk.FLAT,
|
|
1760
|
+
)
|
|
1761
|
+
self.results_text.config(state=tk.DISABLED)
|
|
1762
|
+
|
|
1763
|
+
# Insert informational message
|
|
1764
|
+
self.results_text.config(state=tk.NORMAL)
|
|
1765
|
+
self.results_text.insert(
|
|
1766
|
+
"1.0",
|
|
1767
|
+
self.lang_manager.get(
|
|
1768
|
+
"results_placeholder",
|
|
1769
|
+
"When selected operation finishes, the results will be displayed here.\nPlease go back and select the operation.",
|
|
1770
|
+
),
|
|
1771
|
+
)
|
|
1772
|
+
self.results_text.config(state=tk.DISABLED)
|
|
1773
|
+
|
|
1774
|
+
# Progress bar - initialize to 0
|
|
1775
|
+
self.progress = ttk.Progressbar(
|
|
1776
|
+
main_frame, mode="determinate", style="TProgressbar", value=0
|
|
1777
|
+
)
|
|
1778
|
+
|
|
1779
|
+
self.progress.pack(fill="x", pady=(0, 10))
|
|
1780
|
+
self.results_text.pack(fill="both", expand=True, pady=(0, 10))
|
|
1781
|
+
|
|
1782
|
+
# Start new operation button
|
|
1783
|
+
self.start_new_btn = ttk.Button(
|
|
1784
|
+
main_frame,
|
|
1785
|
+
text=self.lang_manager.get("btn_start_new", "Start New Operation"),
|
|
1786
|
+
command=self.start_new_operation,
|
|
1787
|
+
)
|
|
1788
|
+
self.start_new_btn.pack(pady=(10, 0))
|
|
1789
|
+
|
|
1790
|
+
def create_help_tab(self):
|
|
1791
|
+
"""Delegate the help tab construction to HelpUI"""
|
|
1792
|
+
try:
|
|
1793
|
+
self.help_ui.build_help_tab(self.help_frame)
|
|
1794
|
+
except Exception:
|
|
1795
|
+
# Fallback: create very small placeholder content
|
|
1796
|
+
main_frame = ttk.Frame(self.help_frame, style="TFrame")
|
|
1797
|
+
main_frame.pack(fill="both", expand=True, padx=24, pady=24)
|
|
1798
|
+
ttk.Label(
|
|
1799
|
+
main_frame,
|
|
1800
|
+
text=self.lang_manager.get(
|
|
1801
|
+
"help_unavailable", "Help content is unavailable."
|
|
1802
|
+
),
|
|
1803
|
+
font=(CommonElements.FONT, CommonElements.FONT_SIZE),
|
|
1804
|
+
).pack(fill="both", expand=True)
|
|
1805
|
+
|
|
1806
|
+
def create_app_settings_tab(self):
|
|
1807
|
+
"""Delegate the app settings tab to SettingsUI"""
|
|
1808
|
+
try:
|
|
1809
|
+
# Replace the app settings tab content with the delegated implementation
|
|
1810
|
+
self.settings_ui.create_settings_tab_content(self.app_settings_frame)
|
|
1811
|
+
# Ensure the theme radio buttons trigger the main UI apply_theme callback
|
|
1812
|
+
|
|
1813
|
+
except Exception:
|
|
1814
|
+
main_frame = ttk.Frame(self.app_settings_frame, style="TFrame")
|
|
1815
|
+
main_frame.pack(fill="both", expand=True, padx=24, pady=24)
|
|
1816
|
+
ttk.Label(
|
|
1817
|
+
main_frame,
|
|
1818
|
+
text=self.lang_manager.get(
|
|
1819
|
+
"settings_unavailable", "Settings are unavailable."
|
|
1820
|
+
),
|
|
1821
|
+
font=(CommonElements.FONT, CommonElements.FONT_SIZE),
|
|
1822
|
+
).pack(fill="both", expand=True)
|
|
1823
|
+
|
|
1824
|
+
def _on_language_change(self):
|
|
1825
|
+
"""Internal trace callback when `language_var` changes."""
|
|
1826
|
+
try:
|
|
1827
|
+
code = str(self.language_var.get())
|
|
1828
|
+
CommonElements.SELECTED_LANGUAGE = code
|
|
1829
|
+
# Save the language preference
|
|
1830
|
+
self._save_language_preference(code)
|
|
1831
|
+
try:
|
|
1832
|
+
if hasattr(self, "lang_manager") and self.lang_manager:
|
|
1833
|
+
self.lang_manager.load(code)
|
|
1834
|
+
except Exception:
|
|
1835
|
+
pass
|
|
1836
|
+
self.apply_language()
|
|
1837
|
+
except Exception:
|
|
1838
|
+
logger.debug("Error handling language change", exc_info=True)
|
|
1839
|
+
|
|
1840
|
+
def apply_language(self):
|
|
1841
|
+
"""Refresh UI parts that depend on language selection.
|
|
1842
|
+
|
|
1843
|
+
This will recreate localized content in welcome/help/settings tabs.
|
|
1844
|
+
"""
|
|
1845
|
+
try:
|
|
1846
|
+
# Unbind existing tooltip events to prevent multiple bindings
|
|
1847
|
+
try:
|
|
1848
|
+
self.notebook.unbind("<Motion>")
|
|
1849
|
+
self.notebook.unbind("<Leave>")
|
|
1850
|
+
except Exception:
|
|
1851
|
+
pass
|
|
1852
|
+
# Recreate welcome content
|
|
1853
|
+
if getattr(self, "welcome_frame", None):
|
|
1854
|
+
for w in self.welcome_frame.winfo_children():
|
|
1855
|
+
try:
|
|
1856
|
+
w.destroy()
|
|
1857
|
+
except Exception:
|
|
1858
|
+
pass
|
|
1859
|
+
try:
|
|
1860
|
+
self.create_welcome_tab()
|
|
1861
|
+
except Exception:
|
|
1862
|
+
pass
|
|
1863
|
+
|
|
1864
|
+
# Recreate help content
|
|
1865
|
+
if getattr(self, "help_frame", None):
|
|
1866
|
+
for w in self.help_frame.winfo_children():
|
|
1867
|
+
try:
|
|
1868
|
+
w.destroy()
|
|
1869
|
+
except Exception:
|
|
1870
|
+
pass
|
|
1871
|
+
try:
|
|
1872
|
+
self.create_help_tab()
|
|
1873
|
+
except Exception:
|
|
1874
|
+
pass
|
|
1875
|
+
|
|
1876
|
+
# Recreate app settings tab content
|
|
1877
|
+
if getattr(self, "app_settings_frame", None):
|
|
1878
|
+
for w in self.app_settings_frame.winfo_children():
|
|
1879
|
+
try:
|
|
1880
|
+
w.destroy()
|
|
1881
|
+
except Exception:
|
|
1882
|
+
pass
|
|
1883
|
+
try:
|
|
1884
|
+
self.create_app_settings_tab()
|
|
1885
|
+
except Exception:
|
|
1886
|
+
pass
|
|
1887
|
+
|
|
1888
|
+
# Let UpdateUI refresh any localized strings it manages
|
|
1889
|
+
try:
|
|
1890
|
+
self.update_ui.update_pro_ui(self)
|
|
1891
|
+
except Exception:
|
|
1892
|
+
pass
|
|
1893
|
+
|
|
1894
|
+
# Update header and top-level UI elements
|
|
1895
|
+
try:
|
|
1896
|
+
if hasattr(self, "header_label") and self.header_label:
|
|
1897
|
+
self.header_label.config(
|
|
1898
|
+
text=self.lang_manager.get("app_title", "SafePDF™")
|
|
1899
|
+
)
|
|
1900
|
+
except Exception:
|
|
1901
|
+
pass
|
|
1902
|
+
|
|
1903
|
+
# Update tab labels
|
|
1904
|
+
try:
|
|
1905
|
+
self.notebook.tab(
|
|
1906
|
+
self.welcome_frame,
|
|
1907
|
+
text=self.lang_manager.get("tab_welcome", "1. Welcome"),
|
|
1908
|
+
)
|
|
1909
|
+
self.notebook.tab(
|
|
1910
|
+
self.operation_frame,
|
|
1911
|
+
text=self.lang_manager.get("tab_operation", "2. Select Operation"),
|
|
1912
|
+
)
|
|
1913
|
+
self.notebook.tab(
|
|
1914
|
+
self.file_frame,
|
|
1915
|
+
text=self.lang_manager.get("tab_file", "3. Select File"),
|
|
1916
|
+
)
|
|
1917
|
+
self.notebook.tab(
|
|
1918
|
+
self.settings_frame,
|
|
1919
|
+
text=self.lang_manager.get("tab_settings", "4. Adjust Settings"),
|
|
1920
|
+
)
|
|
1921
|
+
self.notebook.tab(
|
|
1922
|
+
self.results_frame,
|
|
1923
|
+
text=self.lang_manager.get("tab_results", "5. Results"),
|
|
1924
|
+
)
|
|
1925
|
+
self.notebook.tab(
|
|
1926
|
+
self.app_settings_frame,
|
|
1927
|
+
text=self.lang_manager.get("tab_app_settings", "Settings"),
|
|
1928
|
+
)
|
|
1929
|
+
self.notebook.tab(
|
|
1930
|
+
self.help_frame, text=self.lang_manager.get("tab_help", "Help")
|
|
1931
|
+
)
|
|
1932
|
+
except Exception:
|
|
1933
|
+
pass
|
|
1934
|
+
|
|
1935
|
+
# Update pro badge and status button
|
|
1936
|
+
try:
|
|
1937
|
+
if hasattr(self, "pro_badge_label") and self.pro_badge_label:
|
|
1938
|
+
badge_text = (
|
|
1939
|
+
self.lang_manager.get("pro_badge_pro", "PRO")
|
|
1940
|
+
if self.controller.is_pro_activated
|
|
1941
|
+
else self.lang_manager.get("pro_badge_free", "FREE")
|
|
1942
|
+
)
|
|
1943
|
+
self.pro_badge_label.config(text=badge_text)
|
|
1944
|
+
if hasattr(self, "pro_status_btn") and self.pro_status_btn:
|
|
1945
|
+
status_text = (
|
|
1946
|
+
self.lang_manager.get("status_pro", "✓ PRO Version")
|
|
1947
|
+
if self.controller.is_pro_activated
|
|
1948
|
+
else self.lang_manager.get(
|
|
1949
|
+
"status_free", "FREE Version - Upgrade now!"
|
|
1950
|
+
)
|
|
1951
|
+
)
|
|
1952
|
+
self.pro_status_btn.config(text=status_text)
|
|
1953
|
+
except Exception:
|
|
1954
|
+
pass
|
|
1955
|
+
|
|
1956
|
+
# Refresh operation tab content so operation labels localize
|
|
1957
|
+
try:
|
|
1958
|
+
if getattr(self, "operation_frame", None):
|
|
1959
|
+
for w in self.operation_frame.winfo_children():
|
|
1960
|
+
try:
|
|
1961
|
+
w.destroy()
|
|
1962
|
+
except Exception:
|
|
1963
|
+
pass
|
|
1964
|
+
self.create_operation_tab()
|
|
1965
|
+
|
|
1966
|
+
# Restore highlight if an operation is already selected
|
|
1967
|
+
op_to_index = {
|
|
1968
|
+
"compress": 0,
|
|
1969
|
+
"split": 1,
|
|
1970
|
+
"merge": 2,
|
|
1971
|
+
"to_jpg": 3,
|
|
1972
|
+
"rotate": 4,
|
|
1973
|
+
"repair": 5,
|
|
1974
|
+
"to_word": 6,
|
|
1975
|
+
"to_txt": 7,
|
|
1976
|
+
"extract_info": 8,
|
|
1977
|
+
}
|
|
1978
|
+
idx = op_to_index.get(
|
|
1979
|
+
getattr(self.controller, "selected_operation", None)
|
|
1980
|
+
)
|
|
1981
|
+
if idx is not None:
|
|
1982
|
+
try:
|
|
1983
|
+
self.highlight_selected_operation(idx)
|
|
1984
|
+
except Exception:
|
|
1985
|
+
pass
|
|
1986
|
+
except Exception:
|
|
1987
|
+
pass
|
|
1988
|
+
|
|
1989
|
+
# Refresh settings tab content (labels, radio texts, etc.)
|
|
1990
|
+
try:
|
|
1991
|
+
if getattr(self, "settings_frame", None):
|
|
1992
|
+
for w in self.settings_frame.winfo_children():
|
|
1993
|
+
try:
|
|
1994
|
+
w.destroy()
|
|
1995
|
+
except Exception:
|
|
1996
|
+
pass
|
|
1997
|
+
self.create_settings_tab()
|
|
1998
|
+
try:
|
|
1999
|
+
self.update_settings_for_operation()
|
|
2000
|
+
except Exception:
|
|
2001
|
+
pass
|
|
2002
|
+
except Exception:
|
|
2003
|
+
pass
|
|
2004
|
+
|
|
2005
|
+
# Update file tab labels/buttons without recreating the tab (keeps DnD bindings intact)
|
|
2006
|
+
try:
|
|
2007
|
+
if hasattr(self, "preview_label") and self.preview_label:
|
|
2008
|
+
self.preview_label.config(
|
|
2009
|
+
text=self.lang_manager.get("preview", "Preview:")
|
|
2010
|
+
)
|
|
2011
|
+
if hasattr(self, "or_label") and self.or_label:
|
|
2012
|
+
self.or_label.config(text=self.lang_manager.get("or_label", "or"))
|
|
2013
|
+
if hasattr(self, "browse_btn") and self.browse_btn:
|
|
2014
|
+
self.browse_btn.config(
|
|
2015
|
+
text=self.lang_manager.get(
|
|
2016
|
+
"btn_load_file", "Load File from Disk"
|
|
2017
|
+
)
|
|
2018
|
+
)
|
|
2019
|
+
self.update_file_tab_ui()
|
|
2020
|
+
self.update_file_display()
|
|
2021
|
+
except Exception:
|
|
2022
|
+
pass
|
|
2023
|
+
|
|
2024
|
+
# Update results tab static strings (avoid clobbering existing results)
|
|
2025
|
+
try:
|
|
2026
|
+
if hasattr(self, "start_new_btn") and self.start_new_btn:
|
|
2027
|
+
self.start_new_btn.config(
|
|
2028
|
+
text=self.lang_manager.get(
|
|
2029
|
+
"btn_start_new", "Start New Operation"
|
|
2030
|
+
)
|
|
2031
|
+
)
|
|
2032
|
+
except Exception:
|
|
2033
|
+
pass
|
|
2034
|
+
|
|
2035
|
+
# Update navigation buttons
|
|
2036
|
+
try:
|
|
2037
|
+
if hasattr(self, "back_btn") and self.back_btn:
|
|
2038
|
+
self.back_btn.config(
|
|
2039
|
+
text=self.lang_manager.get("nav_back", "← Back")
|
|
2040
|
+
)
|
|
2041
|
+
if hasattr(self, "next_btn") and self.next_btn:
|
|
2042
|
+
self.next_btn.config(
|
|
2043
|
+
text=self.lang_manager.get("nav_next", "Next →")
|
|
2044
|
+
)
|
|
2045
|
+
if hasattr(self, "cancel_btn") and self.cancel_btn:
|
|
2046
|
+
self.cancel_btn.config(
|
|
2047
|
+
text=self.lang_manager.get("nav_cancel", "Cancel")
|
|
2048
|
+
)
|
|
2049
|
+
except Exception:
|
|
2050
|
+
pass
|
|
2051
|
+
|
|
2052
|
+
# Re-setup tooltips with new language
|
|
2053
|
+
try:
|
|
2054
|
+
self.setup_tab_tooltips()
|
|
2055
|
+
except Exception:
|
|
2056
|
+
pass
|
|
2057
|
+
except Exception:
|
|
2058
|
+
logger.debug("Error applying language to UI", exc_info=True)
|
|
2059
|
+
|
|
2060
|
+
def _update_widget_colors(self, widget, bg_color, fg_color, text_bg, text_fg):
|
|
2061
|
+
"""Recursively update colors for all widgets"""
|
|
2062
|
+
try:
|
|
2063
|
+
widget_class = widget.winfo_class()
|
|
2064
|
+
|
|
2065
|
+
# Update based on widget type
|
|
2066
|
+
if widget_class == "Text":
|
|
2067
|
+
try:
|
|
2068
|
+
widget.configure(background=text_bg, foreground=text_fg)
|
|
2069
|
+
except Exception:
|
|
2070
|
+
pass
|
|
2071
|
+
elif widget_class == "Label" and not isinstance(widget, ttk.Label):
|
|
2072
|
+
try:
|
|
2073
|
+
# Don't update header labels (with RED_COLOR bg)
|
|
2074
|
+
current_bg = widget.cget("bg")
|
|
2075
|
+
if current_bg != CommonElements.RED_COLOR and current_bg not in [
|
|
2076
|
+
CommonElements.RED_COLOR
|
|
2077
|
+
]:
|
|
2078
|
+
widget.configure(background=bg_color, foreground=fg_color)
|
|
2079
|
+
except Exception:
|
|
2080
|
+
pass
|
|
2081
|
+
elif widget_class == "Frame" and not isinstance(widget, ttk.Frame):
|
|
2082
|
+
try:
|
|
2083
|
+
# Don't update header frame
|
|
2084
|
+
current_bg = widget.cget("bg")
|
|
2085
|
+
if current_bg != CommonElements.RED_COLOR and current_bg not in [
|
|
2086
|
+
CommonElements.RED_COLOR,
|
|
2087
|
+
"#e2e8f0",
|
|
2088
|
+
]:
|
|
2089
|
+
widget.configure(background=bg_color)
|
|
2090
|
+
except Exception:
|
|
2091
|
+
pass
|
|
2092
|
+
|
|
2093
|
+
# Recursively update children
|
|
2094
|
+
for child in widget.winfo_children():
|
|
2095
|
+
self._update_widget_colors(child, bg_color, fg_color, text_bg, text_fg)
|
|
2096
|
+
|
|
2097
|
+
except Exception:
|
|
2098
|
+
pass
|
|
2099
|
+
|
|
2100
|
+
def create_bottom_controls(self):
|
|
2101
|
+
"""Create bottom navigation and control buttons"""
|
|
2102
|
+
control_frame = ttk.Frame(self.root)
|
|
2103
|
+
control_frame.pack(fill="x", padx=10, pady=10)
|
|
2104
|
+
|
|
2105
|
+
# Left side buttons
|
|
2106
|
+
left_frame = ttk.Frame(control_frame)
|
|
2107
|
+
left_frame.pack(side="left")
|
|
2108
|
+
|
|
2109
|
+
# Center spacer
|
|
2110
|
+
center_frame = ttk.Frame(control_frame)
|
|
2111
|
+
center_frame.pack(side="left", expand=True, fill="x")
|
|
2112
|
+
|
|
2113
|
+
# Pro version status - more prominent design
|
|
2114
|
+
pro_frame = ttk.Frame(center_frame, style="TFrame")
|
|
2115
|
+
pro_frame.pack(side="left")
|
|
2116
|
+
|
|
2117
|
+
# Pro status indicator with modern styling
|
|
2118
|
+
status_color = "#00b386" if self.controller.is_pro_activated else "#888888"
|
|
2119
|
+
status_text = (
|
|
2120
|
+
self.lang_manager.get("status_pro", "✓ PRO Version")
|
|
2121
|
+
if self.controller.is_pro_activated
|
|
2122
|
+
else self.lang_manager.get("status_free", "FREE Version - Upgrade now!")
|
|
2123
|
+
)
|
|
2124
|
+
|
|
2125
|
+
self.pro_status_btn = tk.Button(
|
|
2126
|
+
pro_frame,
|
|
2127
|
+
text=status_text,
|
|
2128
|
+
command=lambda: self.update_ui.show_pro_dialog(self),
|
|
2129
|
+
font=(CommonElements.FONT, 9, "bold"),
|
|
2130
|
+
fg="white",
|
|
2131
|
+
bg=status_color,
|
|
2132
|
+
bd=0,
|
|
2133
|
+
padx=16,
|
|
2134
|
+
pady=8,
|
|
2135
|
+
cursor="hand2",
|
|
2136
|
+
relief=tk.FLAT,
|
|
2137
|
+
highlightthickness=0,
|
|
2138
|
+
)
|
|
2139
|
+
self.pro_status_btn.pack()
|
|
2140
|
+
|
|
2141
|
+
# Add a subtle border/shadow effect
|
|
2142
|
+
self.pro_status_btn.config(
|
|
2143
|
+
highlightbackground=status_color, highlightcolor=status_color
|
|
2144
|
+
)
|
|
2145
|
+
|
|
2146
|
+
# Hover effect for pro status button
|
|
2147
|
+
def on_pro_enter(event):
|
|
2148
|
+
try:
|
|
2149
|
+
if self.controller.is_pro_activated:
|
|
2150
|
+
self.pro_status_btn.config(bg="#009970") # Darker green
|
|
2151
|
+
else:
|
|
2152
|
+
self.pro_status_btn.config(bg="#666666") # Darker gray
|
|
2153
|
+
except Exception:
|
|
2154
|
+
pass
|
|
2155
|
+
|
|
2156
|
+
def on_pro_leave(event):
|
|
2157
|
+
try:
|
|
2158
|
+
status_color = (
|
|
2159
|
+
"#00b386" if self.controller.is_pro_activated else "#888888"
|
|
2160
|
+
)
|
|
2161
|
+
self.pro_status_btn.config(bg=status_color)
|
|
2162
|
+
except Exception:
|
|
2163
|
+
pass
|
|
2164
|
+
|
|
2165
|
+
self.pro_status_btn.bind("<Enter>", on_pro_enter)
|
|
2166
|
+
self.pro_status_btn.bind("<Leave>", on_pro_leave)
|
|
2167
|
+
|
|
2168
|
+
# Right side buttons - Navigation and Cancel
|
|
2169
|
+
right_frame = ttk.Frame(control_frame)
|
|
2170
|
+
right_frame.pack(side="right")
|
|
2171
|
+
|
|
2172
|
+
# Deactivited for now.
|
|
2173
|
+
# settings_btn = ttk.Button(right_frame, text="Settings", command=lambda: self.notebook.select(self.app_settings_frame), width=10)
|
|
2174
|
+
# settings_btn.pack(side='left', padx=(0, 2))
|
|
2175
|
+
# help_btn = ttk.Button(right_frame, text="Help", command=lambda: self.notebook.select(self.help_frame), width=10)
|
|
2176
|
+
# help_btn.pack(side='left', padx=(0, 50))
|
|
2177
|
+
|
|
2178
|
+
# Navigation buttons frame
|
|
2179
|
+
nav_frame = ttk.Frame(right_frame)
|
|
2180
|
+
nav_frame.pack(side="left")
|
|
2181
|
+
|
|
2182
|
+
self.back_btn = ttk.Button(
|
|
2183
|
+
nav_frame,
|
|
2184
|
+
text=self.lang_manager.get("nav_back", "← Back"),
|
|
2185
|
+
command=self.previous_tab,
|
|
2186
|
+
width=10,
|
|
2187
|
+
state="disabled",
|
|
2188
|
+
)
|
|
2189
|
+
self.back_btn.pack(side="left", padx=(0, 2))
|
|
2190
|
+
|
|
2191
|
+
self.next_btn = ttk.Button(
|
|
2192
|
+
nav_frame,
|
|
2193
|
+
text=self.lang_manager.get("nav_next", "Next →"),
|
|
2194
|
+
command=self.next_tab,
|
|
2195
|
+
width=10,
|
|
2196
|
+
)
|
|
2197
|
+
self.next_btn.pack(side="left", padx=2)
|
|
2198
|
+
|
|
2199
|
+
self.cancel_btn = ttk.Button(
|
|
2200
|
+
right_frame,
|
|
2201
|
+
text=self.lang_manager.get("nav_cancel", "Cancel"),
|
|
2202
|
+
command=self.cancel_operation,
|
|
2203
|
+
width=10,
|
|
2204
|
+
)
|
|
2205
|
+
self.cancel_btn.pack(side="left", padx=(10, 0))
|
|
2206
|
+
|
|
2207
|
+
# Initialize previous tab tracker and update button states
|
|
2208
|
+
self._previous_tab = 0
|
|
2209
|
+
self.update_navigation_buttons()
|
|
2210
|
+
|
|
2211
|
+
def bind_events(self):
|
|
2212
|
+
"""Bind UI events"""
|
|
2213
|
+
# Bind tab change event
|
|
2214
|
+
self.notebook.bind("<<NotebookTabChanged>>", self.on_tab_changed)
|
|
2215
|
+
|
|
2216
|
+
def animate_tab_change(self):
|
|
2217
|
+
"""Simple animation for tab change"""
|
|
2218
|
+
original_bg = self.card_frame.cget("bg")
|
|
2219
|
+
self.card_frame.config(bg="#f0f0f0")
|
|
2220
|
+
self.root.after(200, lambda: self.card_frame.config(bg=original_bg))
|
|
2221
|
+
|
|
2222
|
+
# Event handlers
|
|
2223
|
+
def on_tab_changed(self, event):
|
|
2224
|
+
"""Handle tab change event"""
|
|
2225
|
+
if self.notebook is None:
|
|
2226
|
+
return
|
|
2227
|
+
new_tab = self.notebook.index(self.notebook.select())
|
|
2228
|
+
if self.notebook.tab(new_tab, "state") == "disabled":
|
|
2229
|
+
messagebox.showinfo(
|
|
2230
|
+
self.lang_manager.get("tab_locked", "Tab Locked"),
|
|
2231
|
+
self.lang_manager.get(
|
|
2232
|
+
"tab_locked_msg", "Please select an operation and file first."
|
|
2233
|
+
),
|
|
2234
|
+
)
|
|
2235
|
+
# fall back to the last valid tab index
|
|
2236
|
+
try:
|
|
2237
|
+
self.notebook.select(self._previous_tab)
|
|
2238
|
+
except Exception:
|
|
2239
|
+
self.notebook.select(0)
|
|
2240
|
+
else:
|
|
2241
|
+
# store last selected tab index (avoid name collision with method)
|
|
2242
|
+
self._previous_tab = new_tab
|
|
2243
|
+
self.controller.current_tab = new_tab
|
|
2244
|
+
self.update_navigation_buttons()
|
|
2245
|
+
self.animate_tab_change()
|
|
2246
|
+
|
|
2247
|
+
def on_drag_enter(self, event):
|
|
2248
|
+
"""Handle drag enter event - provide visual feedback"""
|
|
2249
|
+
self.drop_label.config(
|
|
2250
|
+
bg="#e8f5e8",
|
|
2251
|
+
relief=tk.FLAT,
|
|
2252
|
+
highlightbackground="#00b386",
|
|
2253
|
+
highlightthickness=4,
|
|
2254
|
+
)
|
|
2255
|
+
|
|
2256
|
+
def on_drag_leave(self, event):
|
|
2257
|
+
"""Handle drag leave event - restore original appearance"""
|
|
2258
|
+
if not self.controller.selected_file: # Only restore if no file is selected
|
|
2259
|
+
self.drop_label.config(
|
|
2260
|
+
bg="#f8f9fa",
|
|
2261
|
+
relief=tk.FLAT,
|
|
2262
|
+
highlightbackground="#d1d5db",
|
|
2263
|
+
highlightthickness=3,
|
|
2264
|
+
)
|
|
2265
|
+
|
|
2266
|
+
def handle_drop(self, event):
|
|
2267
|
+
"""Handle file drop event"""
|
|
2268
|
+
try:
|
|
2269
|
+
files = self.root.tk.splitlist(event.data)
|
|
2270
|
+
if files:
|
|
2271
|
+
# For merge operation, allow multiple files
|
|
2272
|
+
if self.controller.selected_operation == "merge":
|
|
2273
|
+
file_paths = [f.strip('"{}') for f in files]
|
|
2274
|
+
if len(file_paths) < 2:
|
|
2275
|
+
messagebox.showwarning(
|
|
2276
|
+
self.lang_manager.get(
|
|
2277
|
+
"not_enough_files", "Not enough files"
|
|
2278
|
+
),
|
|
2279
|
+
self.lang_manager.get(
|
|
2280
|
+
"not_enough_merge",
|
|
2281
|
+
"Please drop at least 2 PDF files to merge.",
|
|
2282
|
+
),
|
|
2283
|
+
)
|
|
2284
|
+
if hasattr(self, "drop_label") and self.drop_label:
|
|
2285
|
+
self.on_drag_leave(None)
|
|
2286
|
+
return
|
|
2287
|
+
else:
|
|
2288
|
+
# For other operations, take only the first file
|
|
2289
|
+
file_paths = [files[0].strip('"{}')]
|
|
2290
|
+
|
|
2291
|
+
success, message = self.controller.select_file(file_paths)
|
|
2292
|
+
|
|
2293
|
+
if success:
|
|
2294
|
+
if self.controller.selected_operation == "merge":
|
|
2295
|
+
filenames = [os.path.basename(f) for f in file_paths]
|
|
2296
|
+
if hasattr(self, "file_label") and self.file_label:
|
|
2297
|
+
self.file_label.config(
|
|
2298
|
+
text=f"Selected files: {', '.join(filenames)}",
|
|
2299
|
+
foreground="green",
|
|
2300
|
+
)
|
|
2301
|
+
if hasattr(self, "drop_label") and self.drop_label:
|
|
2302
|
+
self.drop_label.config(
|
|
2303
|
+
text=f"✅ Selected {len(filenames)} files for merge",
|
|
2304
|
+
bg="#e8f5e8",
|
|
2305
|
+
fg="#28a745",
|
|
2306
|
+
relief=tk.FLAT,
|
|
2307
|
+
highlightbackground="#28a745",
|
|
2308
|
+
highlightthickness=3,
|
|
2309
|
+
)
|
|
2310
|
+
else:
|
|
2311
|
+
filename = os.path.basename(file_paths[0])
|
|
2312
|
+
if hasattr(self, "file_label") and self.file_label:
|
|
2313
|
+
self.file_label.config(text=message, foreground="green")
|
|
2314
|
+
if hasattr(self, "drop_label") and self.drop_label:
|
|
2315
|
+
self.drop_label.config(
|
|
2316
|
+
text=f"✅ Selected: {filename}",
|
|
2317
|
+
bg="#e8f5e8",
|
|
2318
|
+
fg="#28a745",
|
|
2319
|
+
relief=tk.FLAT,
|
|
2320
|
+
highlightbackground="#28a745",
|
|
2321
|
+
highlightthickness=3,
|
|
2322
|
+
)
|
|
2323
|
+
|
|
2324
|
+
# Show PDF info for the first file
|
|
2325
|
+
self.show_pdf_info()
|
|
2326
|
+
|
|
2327
|
+
# Show preview of the first selected file
|
|
2328
|
+
try:
|
|
2329
|
+
self.show_pdf_preview(file_paths[0])
|
|
2330
|
+
except Exception:
|
|
2331
|
+
pass
|
|
2332
|
+
|
|
2333
|
+
# Enable settings tab
|
|
2334
|
+
self.notebook.tab(3, state="normal")
|
|
2335
|
+
else:
|
|
2336
|
+
messagebox.showwarning(
|
|
2337
|
+
self.lang_manager.get("invalid_file", "Invalid File"), message
|
|
2338
|
+
)
|
|
2339
|
+
if hasattr(self, "drop_label") and self.drop_label:
|
|
2340
|
+
self.on_drag_leave(None) # Restore original appearance
|
|
2341
|
+
else:
|
|
2342
|
+
messagebox.showwarning(
|
|
2343
|
+
self.lang_manager.get("no_file", "No File"),
|
|
2344
|
+
self.lang_manager.get("no_file_msg", "No file was dropped."),
|
|
2345
|
+
)
|
|
2346
|
+
if hasattr(self, "drop_label") and self.drop_label:
|
|
2347
|
+
self.on_drag_leave(None) # Restore original appearance
|
|
2348
|
+
except Exception as e:
|
|
2349
|
+
messagebox.showerror(
|
|
2350
|
+
self.lang_manager.get("drop_error", "Drop Error"),
|
|
2351
|
+
f"{self.lang_manager.get('drop_error_msg', 'An error occurred while processing the dropped file:')} {str(e)}",
|
|
2352
|
+
)
|
|
2353
|
+
if hasattr(self, "drop_label") and self.drop_label:
|
|
2354
|
+
self.on_drag_leave(None) # Restore original appearance
|
|
2355
|
+
|
|
2356
|
+
def browse_file(self, event=None):
|
|
2357
|
+
"""Browse for PDF file"""
|
|
2358
|
+
if not self.controller.selected_operation:
|
|
2359
|
+
messagebox.showwarning(
|
|
2360
|
+
self.lang_manager.get("no_operation", "No Operation Selected"),
|
|
2361
|
+
self.lang_manager.get(
|
|
2362
|
+
"no_operation_msg",
|
|
2363
|
+
"Please select an operation first from the 'Select Operation' tab.",
|
|
2364
|
+
),
|
|
2365
|
+
)
|
|
2366
|
+
return
|
|
2367
|
+
|
|
2368
|
+
if self.controller.selected_operation == "merge":
|
|
2369
|
+
file_paths = filedialog.askopenfilenames(
|
|
2370
|
+
title=self.lang_manager.get(
|
|
2371
|
+
"select_merge_files",
|
|
2372
|
+
"Select PDF Files to Merge (Select multiple files)",
|
|
2373
|
+
),
|
|
2374
|
+
filetypes=[("PDF files", "*.pdf"), ("All files", "*.*")],
|
|
2375
|
+
)
|
|
2376
|
+
if file_paths:
|
|
2377
|
+
if len(file_paths) < 2:
|
|
2378
|
+
messagebox.showwarning(
|
|
2379
|
+
self.lang_manager.get("not_enough_files", "Not enough files"),
|
|
2380
|
+
self.lang_manager.get(
|
|
2381
|
+
"not_enough_merge_select",
|
|
2382
|
+
"Please select at least 2 PDF files to merge.",
|
|
2383
|
+
),
|
|
2384
|
+
)
|
|
2385
|
+
return
|
|
2386
|
+
success, message = self.controller.select_file(list(file_paths))
|
|
2387
|
+
if success:
|
|
2388
|
+
self.update_file_display()
|
|
2389
|
+
self.notebook.tab(3, state="normal")
|
|
2390
|
+
# Show preview of first file
|
|
2391
|
+
self.show_pdf_preview(file_paths[0])
|
|
2392
|
+
else:
|
|
2393
|
+
messagebox.showerror(
|
|
2394
|
+
self.lang_manager.get("error", "Error"), message
|
|
2395
|
+
)
|
|
2396
|
+
else:
|
|
2397
|
+
file_path = filedialog.askopenfilename(
|
|
2398
|
+
title=self.lang_manager.get("select_pdf", "Select PDF File"),
|
|
2399
|
+
filetypes=[("PDF files", "*.pdf"), ("All files", "*.*")],
|
|
2400
|
+
defaultextension=".pdf",
|
|
2401
|
+
)
|
|
2402
|
+
|
|
2403
|
+
if file_path:
|
|
2404
|
+
success, message = self.controller.select_file(file_path)
|
|
2405
|
+
|
|
2406
|
+
if success:
|
|
2407
|
+
filename = os.path.basename(file_path)
|
|
2408
|
+
# Update UI with consistent styling - check if widgets exist first
|
|
2409
|
+
if hasattr(self, "file_label") and self.file_label:
|
|
2410
|
+
self.file_label.config(text=message, foreground="green")
|
|
2411
|
+
if hasattr(self, "drop_label") and self.drop_label:
|
|
2412
|
+
self.drop_label.config(
|
|
2413
|
+
text=f"✅ Selected: {filename}",
|
|
2414
|
+
bg="#e8f5e8",
|
|
2415
|
+
fg="#28a745",
|
|
2416
|
+
relief=tk.FLAT,
|
|
2417
|
+
highlightbackground="#28a745",
|
|
2418
|
+
highlightthickness=3,
|
|
2419
|
+
)
|
|
2420
|
+
# Show PDF info
|
|
2421
|
+
self.show_pdf_info()
|
|
2422
|
+
# Show PDF preview
|
|
2423
|
+
self.show_pdf_preview(file_path)
|
|
2424
|
+
# Enable settings tab
|
|
2425
|
+
self.notebook.tab(3, state="normal")
|
|
2426
|
+
else:
|
|
2427
|
+
messagebox.showerror(
|
|
2428
|
+
self.lang_manager.get("error", "Error"), message
|
|
2429
|
+
)
|
|
2430
|
+
|
|
2431
|
+
def browse_merge_second_file(self):
|
|
2432
|
+
"""Browse for the second PDF to merge"""
|
|
2433
|
+
file_path = filedialog.askopenfilename(
|
|
2434
|
+
title=self.lang_manager.get(
|
|
2435
|
+
"select_second_merge_pdf", "Select Second PDF File to Merge"
|
|
2436
|
+
),
|
|
2437
|
+
filetypes=[("PDF files", "*.pdf"), ("All files", "*.*")],
|
|
2438
|
+
defaultextension=".pdf",
|
|
2439
|
+
)
|
|
2440
|
+
|
|
2441
|
+
if file_path:
|
|
2442
|
+
# Basic validation: ensure it's a PDF
|
|
2443
|
+
if not file_path.lower().endswith(".pdf"):
|
|
2444
|
+
messagebox.showwarning(
|
|
2445
|
+
self.lang_manager.get("invalid_file", "Invalid File"),
|
|
2446
|
+
self.lang_manager.get(
|
|
2447
|
+
"invalid_pdf", "Please select a .pdf file for merging."
|
|
2448
|
+
),
|
|
2449
|
+
)
|
|
2450
|
+
return
|
|
2451
|
+
|
|
2452
|
+
# Update UI and internal variable
|
|
2453
|
+
self.merge_second_file_var.set(file_path)
|
|
2454
|
+
self.merge_second_label.config(
|
|
2455
|
+
text=os.path.basename(file_path), foreground="green"
|
|
2456
|
+
)
|
|
2457
|
+
|
|
2458
|
+
def show_pdf_info(self):
|
|
2459
|
+
"""Show information about the selected PDF"""
|
|
2460
|
+
info = self.controller.get_pdf_info()
|
|
2461
|
+
if info and "error" not in info:
|
|
2462
|
+
info_text = self.lang_manager.get(
|
|
2463
|
+
"pdf_info_pages", "Pages: {pages}"
|
|
2464
|
+
).format(pages=info.get("pages", "Unknown"))
|
|
2465
|
+
info_text += "\n" + self.lang_manager.get(
|
|
2466
|
+
"pdf_info_size", "Size: {size} KB"
|
|
2467
|
+
).format(size=f"{info.get('file_size', 0) / 1024:.1f}")
|
|
2468
|
+
if hasattr(self, "file_label") and self.file_label:
|
|
2469
|
+
current_text = self.file_label.cget("text")
|
|
2470
|
+
self.file_label.config(
|
|
2471
|
+
text=self.lang_manager.get(
|
|
2472
|
+
"file_info_format", "{current}\n{info}"
|
|
2473
|
+
).format(current=current_text, info=info_text)
|
|
2474
|
+
)
|
|
2475
|
+
elif info and "error" in info:
|
|
2476
|
+
messagebox.showerror(
|
|
2477
|
+
self.lang_manager.get("error", "Error"),
|
|
2478
|
+
f"{self.lang_manager.get('could_not_read_pdf', 'Could not read PDF:')} {info['error']}",
|
|
2479
|
+
)
|
|
2480
|
+
|
|
2481
|
+
# Operation selection methods
|
|
2482
|
+
def select_compress(self):
|
|
2483
|
+
self.controller.select_operation("compress")
|
|
2484
|
+
self.highlight_selected_operation(0)
|
|
2485
|
+
self.update_settings_for_operation()
|
|
2486
|
+
self.update_file_tab_ui()
|
|
2487
|
+
if self.notebook is not None:
|
|
2488
|
+
self.notebook.tab(2, state="normal")
|
|
2489
|
+
self.notebook.select(2) # Go to file tab
|
|
2490
|
+
|
|
2491
|
+
def select_split(self):
|
|
2492
|
+
self.controller.select_operation("split")
|
|
2493
|
+
self.highlight_selected_operation(1)
|
|
2494
|
+
self.update_settings_for_operation()
|
|
2495
|
+
self.update_file_tab_ui()
|
|
2496
|
+
if self.notebook is not None:
|
|
2497
|
+
self.notebook.tab(2, state="normal")
|
|
2498
|
+
self.notebook.select(2)
|
|
2499
|
+
|
|
2500
|
+
def select_merge(self):
|
|
2501
|
+
self.controller.select_operation("merge")
|
|
2502
|
+
self.highlight_selected_operation(2)
|
|
2503
|
+
self.update_settings_for_operation()
|
|
2504
|
+
self.update_file_tab_ui()
|
|
2505
|
+
if self.notebook is not None:
|
|
2506
|
+
self.notebook.tab(2, state="normal")
|
|
2507
|
+
self.notebook.select(2)
|
|
2508
|
+
|
|
2509
|
+
def select_to_jpg(self):
|
|
2510
|
+
self.controller.select_operation("to_jpg")
|
|
2511
|
+
self.highlight_selected_operation(3)
|
|
2512
|
+
self.update_settings_for_operation()
|
|
2513
|
+
self.update_file_tab_ui()
|
|
2514
|
+
if self.notebook is not None:
|
|
2515
|
+
self.notebook.tab(2, state="normal")
|
|
2516
|
+
self.notebook.select(2)
|
|
2517
|
+
|
|
2518
|
+
def select_rotate(self):
|
|
2519
|
+
self.controller.select_operation("rotate")
|
|
2520
|
+
self.highlight_selected_operation(4)
|
|
2521
|
+
self.update_settings_for_operation()
|
|
2522
|
+
self.update_file_tab_ui()
|
|
2523
|
+
if self.notebook is not None:
|
|
2524
|
+
self.notebook.tab(2, state="normal")
|
|
2525
|
+
self.notebook.select(2)
|
|
2526
|
+
|
|
2527
|
+
def select_repair(self):
|
|
2528
|
+
self.controller.select_operation("repair")
|
|
2529
|
+
self.highlight_selected_operation(5)
|
|
2530
|
+
self.update_settings_for_operation()
|
|
2531
|
+
self.update_file_tab_ui()
|
|
2532
|
+
if self.notebook is not None:
|
|
2533
|
+
self.notebook.tab(2, state="normal")
|
|
2534
|
+
self.notebook.select(2)
|
|
2535
|
+
|
|
2536
|
+
def highlight_selected_operation(self, selected_index):
|
|
2537
|
+
"""Highlight the selected operation button"""
|
|
2538
|
+
for i, btn in enumerate(self.operation_buttons):
|
|
2539
|
+
if i == selected_index:
|
|
2540
|
+
btn.config(relief=tk.SUNKEN, bg="#e8f5e8")
|
|
2541
|
+
else:
|
|
2542
|
+
btn.config(relief=tk.RAISED, bg="SystemButtonFace")
|
|
2543
|
+
|
|
2544
|
+
def update_settings_for_operation(self):
|
|
2545
|
+
"""Update settings tab based on selected operation - delegated to OperationSettingsUI"""
|
|
2546
|
+
from .operation_settings import OperationSettingsUI
|
|
2547
|
+
|
|
2548
|
+
# Clear existing settings
|
|
2549
|
+
for widget in self.settings_container.winfo_children():
|
|
2550
|
+
widget.destroy()
|
|
2551
|
+
|
|
2552
|
+
# Create operation settings manager
|
|
2553
|
+
ops_ui = OperationSettingsUI(self.settings_container, self.lang_manager, self.controller)
|
|
2554
|
+
|
|
2555
|
+
# Assign variables to the manager
|
|
2556
|
+
ops_ui.quality_var = self.quality_var
|
|
2557
|
+
ops_ui.rotation_var = self.rotation_var
|
|
2558
|
+
ops_ui.img_quality_var = self.img_quality_var
|
|
2559
|
+
ops_ui.split_var = self.split_var
|
|
2560
|
+
ops_ui.page_range_var = self.page_range_var
|
|
2561
|
+
ops_ui.repair_var = self.repair_var
|
|
2562
|
+
ops_ui.merge_var = self.merge_var
|
|
2563
|
+
ops_ui.use_default_output = self.use_default_output
|
|
2564
|
+
ops_ui.output_path_var = self.output_path_var
|
|
2565
|
+
|
|
2566
|
+
# Create appropriate settings based on operation
|
|
2567
|
+
if self.controller.selected_operation == "compress":
|
|
2568
|
+
ops_ui.create_compress_settings(
|
|
2569
|
+
self.quality_var,
|
|
2570
|
+
lambda: ops_ui.update_compression_visual(self.quality_var)
|
|
2571
|
+
)
|
|
2572
|
+
ops_ui.create_output_path_selection(
|
|
2573
|
+
False, self.use_default_output, self.output_path_var,
|
|
2574
|
+
self._on_browse_output
|
|
2575
|
+
)
|
|
2576
|
+
elif self.controller.selected_operation == "rotate":
|
|
2577
|
+
ops_ui.create_rotate_settings(self.rotation_var)
|
|
2578
|
+
ops_ui.create_output_path_selection(
|
|
2579
|
+
False, self.use_default_output, self.output_path_var,
|
|
2580
|
+
self._on_browse_output
|
|
2581
|
+
)
|
|
2582
|
+
elif self.controller.selected_operation == "split":
|
|
2583
|
+
ops_ui.create_split_settings(self.split_var, self.page_range_var)
|
|
2584
|
+
ops_ui.create_output_path_selection(
|
|
2585
|
+
True, self.use_default_output, self.output_path_var,
|
|
2586
|
+
self._on_browse_output
|
|
2587
|
+
)
|
|
2588
|
+
elif self.controller.selected_operation == "to_jpg":
|
|
2589
|
+
ops_ui.create_to_jpg_settings(self.img_quality_var)
|
|
2590
|
+
ops_ui.create_output_path_selection(
|
|
2591
|
+
True, self.use_default_output, self.output_path_var,
|
|
2592
|
+
self._on_browse_output
|
|
2593
|
+
)
|
|
2594
|
+
elif self.controller.selected_operation == "repair":
|
|
2595
|
+
ops_ui.create_repair_settings(self.repair_var)
|
|
2596
|
+
ops_ui.create_output_path_selection(
|
|
2597
|
+
False, self.use_default_output, self.output_path_var,
|
|
2598
|
+
self._on_browse_output
|
|
2599
|
+
)
|
|
2600
|
+
elif self.controller.selected_operation == "merge":
|
|
2601
|
+
ops_ui.create_merge_settings(self.merge_var, self.controller.selected_files)
|
|
2602
|
+
ops_ui.create_output_path_selection(
|
|
2603
|
+
False, self.use_default_output, self.output_path_var,
|
|
2604
|
+
self._on_browse_output
|
|
2605
|
+
)
|
|
2606
|
+
elif self.controller.selected_operation == "to_word":
|
|
2607
|
+
ops_ui.create_to_word_settings()
|
|
2608
|
+
ops_ui.create_output_path_selection(
|
|
2609
|
+
False, self.use_default_output, self.output_path_var,
|
|
2610
|
+
self._on_browse_output
|
|
2611
|
+
)
|
|
2612
|
+
elif self.controller.selected_operation == "to_txt":
|
|
2613
|
+
ops_ui.create_to_txt_settings()
|
|
2614
|
+
ops_ui.create_output_path_selection(
|
|
2615
|
+
False, self.use_default_output, self.output_path_var,
|
|
2616
|
+
self._on_browse_output
|
|
2617
|
+
)
|
|
2618
|
+
elif self.controller.selected_operation == "extract_info":
|
|
2619
|
+
ops_ui.create_extract_info_settings()
|
|
2620
|
+
ops_ui.create_output_path_selection(
|
|
2621
|
+
False, self.use_default_output, self.output_path_var,
|
|
2622
|
+
self._on_browse_output
|
|
2623
|
+
)
|
|
2624
|
+
|
|
2625
|
+
operation_name = self.controller.selected_operation.replace("_", " ").title()
|
|
2626
|
+
self.settings_label.config(text=f"Settings for {operation_name}")
|
|
2627
|
+
# Update Execute/Next button state based on current operation settings
|
|
2628
|
+
self._update_execute_button_state()
|
|
2629
|
+
|
|
2630
|
+
# If merge operation, ensure we react to second-file selection changes
|
|
2631
|
+
try:
|
|
2632
|
+
# Remove any existing trace to avoid duplicate traces. Only attempt
|
|
2633
|
+
# removal when we actually have a stored trace id.
|
|
2634
|
+
trace_id = getattr(self, "_merge_trace_id", None)
|
|
2635
|
+
if trace_id:
|
|
2636
|
+
try:
|
|
2637
|
+
# Prefer the modern API if available, otherwise fall back
|
|
2638
|
+
# to older trace_vdelete semantics. We avoid calling
|
|
2639
|
+
# trace_vdelete with a None id which raises TclError.
|
|
2640
|
+
if hasattr(self.merge_second_file_var, "trace_remove"):
|
|
2641
|
+
# trace_remove expects the ops name like 'write'
|
|
2642
|
+
self.merge_second_file_var.trace_remove("write", trace_id)
|
|
2643
|
+
else:
|
|
2644
|
+
# Older tkinter uses trace_vdelete(mode, callbackname)
|
|
2645
|
+
self.merge_second_file_var.trace_vdelete("w", trace_id)
|
|
2646
|
+
except Exception:
|
|
2647
|
+
logger.debug(
|
|
2648
|
+
"Error removing existing trace for merge second file variable",
|
|
2649
|
+
exc_info=True,
|
|
2650
|
+
)
|
|
2651
|
+
|
|
2652
|
+
# Add trace to update the execute button when second file is chosen.
|
|
2653
|
+
# Prefer trace_add if available (modern tkinter), otherwise use trace.
|
|
2654
|
+
try:
|
|
2655
|
+
if hasattr(self.merge_second_file_var, "trace_add"):
|
|
2656
|
+
self._merge_trace_id = self.merge_second_file_var.trace_add(
|
|
2657
|
+
"write", lambda *args: self._update_execute_button_state()
|
|
2658
|
+
)
|
|
2659
|
+
else:
|
|
2660
|
+
self._merge_trace_id = self.merge_second_file_var.trace(
|
|
2661
|
+
"w", lambda *args: self._update_execute_button_state()
|
|
2662
|
+
)
|
|
2663
|
+
except Exception:
|
|
2664
|
+
logger.debug(
|
|
2665
|
+
"Error setting trace for merge second file variable", exc_info=True
|
|
2666
|
+
)
|
|
2667
|
+
except Exception:
|
|
2668
|
+
logger.debug(
|
|
2669
|
+
"Unexpected error handling merge second file trace", exc_info=True
|
|
2670
|
+
)
|
|
2671
|
+
|
|
2672
|
+
def _on_browse_output(self):
|
|
2673
|
+
"""Unified browse handler that picks file or directory depending on operation."""
|
|
2674
|
+
try:
|
|
2675
|
+
# If split or PDF->JPG operations, prefer directory
|
|
2676
|
+
op = getattr(self.controller, "selected_operation", None)
|
|
2677
|
+
if op in ("split", "to_jpg"):
|
|
2678
|
+
self.browse_output_directory()
|
|
2679
|
+
else:
|
|
2680
|
+
self.browse_output_file()
|
|
2681
|
+
except Exception:
|
|
2682
|
+
# Fallback to file browser if controller state is unavailable
|
|
2683
|
+
self.browse_output_file()
|
|
2684
|
+
|
|
2685
|
+
def browse_output_file(self):
|
|
2686
|
+
"""Browse for output file location"""
|
|
2687
|
+
if self.controller.selected_file:
|
|
2688
|
+
initial_dir = os.path.dirname(self.controller.selected_file)
|
|
2689
|
+
base_name = os.path.splitext(
|
|
2690
|
+
os.path.basename(self.controller.selected_file)
|
|
2691
|
+
)[0]
|
|
2692
|
+
else:
|
|
2693
|
+
initial_dir = os.path.expanduser("~")
|
|
2694
|
+
base_name = "output"
|
|
2695
|
+
|
|
2696
|
+
file_path = filedialog.asksaveasfilename(
|
|
2697
|
+
title="Select Output File",
|
|
2698
|
+
initialdir=initial_dir,
|
|
2699
|
+
initialfile=f"{base_name}_{self.controller.selected_operation}.pdf",
|
|
2700
|
+
filetypes=[("PDF files", "*.pdf"), ("All files", "*.*")],
|
|
2701
|
+
)
|
|
2702
|
+
if file_path:
|
|
2703
|
+
self.output_path_var.set(file_path)
|
|
2704
|
+
|
|
2705
|
+
def browse_output_directory(self):
|
|
2706
|
+
"""Browse for output directory location"""
|
|
2707
|
+
if self.controller.selected_file:
|
|
2708
|
+
initial_dir = os.path.dirname(self.controller.selected_file)
|
|
2709
|
+
else:
|
|
2710
|
+
initial_dir = os.path.expanduser("~")
|
|
2711
|
+
|
|
2712
|
+
dir_path = filedialog.askdirectory(
|
|
2713
|
+
title=self.lang_manager.get("select_output_dir", "Select Output Directory"),
|
|
2714
|
+
initialdir=initial_dir,
|
|
2715
|
+
)
|
|
2716
|
+
|
|
2717
|
+
if dir_path:
|
|
2718
|
+
self.output_path_var.set(dir_path)
|
|
2719
|
+
|
|
2720
|
+
|
|
2721
|
+
|
|
2722
|
+
|
|
2723
|
+
# Navigation methods
|
|
2724
|
+
def next_tab(self):
|
|
2725
|
+
"""Move to next tab, execute operation, or open output file"""
|
|
2726
|
+
current_tab = self.controller.current_tab
|
|
2727
|
+
|
|
2728
|
+
# If on settings tab (tab 3, index 3), execute operation
|
|
2729
|
+
if current_tab == 3:
|
|
2730
|
+
if self.can_proceed_to_next():
|
|
2731
|
+
self.execute_operation()
|
|
2732
|
+
# If on results tab (tab 4, index 4), open output file/folder
|
|
2733
|
+
elif current_tab == 4 and self.controller.current_output:
|
|
2734
|
+
self.open_output_file()
|
|
2735
|
+
elif current_tab < 4:
|
|
2736
|
+
if self.can_proceed_to_next():
|
|
2737
|
+
self.notebook.select(current_tab + 1)
|
|
2738
|
+
|
|
2739
|
+
def previous_tab(self):
|
|
2740
|
+
"""Move to previous tab"""
|
|
2741
|
+
current_tab = getattr(self.controller, "current_tab", None)
|
|
2742
|
+
if current_tab is None:
|
|
2743
|
+
# fallback to notebook current index
|
|
2744
|
+
try:
|
|
2745
|
+
current_tab = self.notebook.index(self.notebook.select())
|
|
2746
|
+
except Exception:
|
|
2747
|
+
current_tab = 0
|
|
2748
|
+
|
|
2749
|
+
if current_tab > 0:
|
|
2750
|
+
target = current_tab - 1
|
|
2751
|
+
try:
|
|
2752
|
+
self.notebook.tab(target, state="normal")
|
|
2753
|
+
self.notebook.select(target)
|
|
2754
|
+
except Exception:
|
|
2755
|
+
# fallback to first tab
|
|
2756
|
+
self.notebook.select(0)
|
|
2757
|
+
|
|
2758
|
+
def can_proceed_to_next(self):
|
|
2759
|
+
"""Check if user can proceed to next tab"""
|
|
2760
|
+
current_tab = self.controller.current_tab
|
|
2761
|
+
can_proceed, message = self.controller.can_proceed_to_tab(current_tab + 1)
|
|
2762
|
+
|
|
2763
|
+
if not can_proceed:
|
|
2764
|
+
messagebox.showwarning(self.lang_manager.get("warning", "Warning"), message)
|
|
2765
|
+
|
|
2766
|
+
return can_proceed
|
|
2767
|
+
|
|
2768
|
+
def open_output_file(self):
|
|
2769
|
+
"""Open the output file or folder"""
|
|
2770
|
+
if self.controller.current_output:
|
|
2771
|
+
try:
|
|
2772
|
+
output_path = self.controller.current_output
|
|
2773
|
+
|
|
2774
|
+
if os.path.isfile(output_path) or os.path.isdir(output_path):
|
|
2775
|
+
if not safe_open_file_or_folder(output_path):
|
|
2776
|
+
messagebox.showerror(
|
|
2777
|
+
self.lang_manager.get("error", "Error"),
|
|
2778
|
+
self.lang_manager.get(
|
|
2779
|
+
"could_not_open", "Could not open output file/folder."
|
|
2780
|
+
),
|
|
2781
|
+
)
|
|
2782
|
+
else:
|
|
2783
|
+
messagebox.showwarning(
|
|
2784
|
+
self.lang_manager.get("file_not_found", "File Not Found"),
|
|
2785
|
+
f"{self.lang_manager.get('output_not_found', 'Output file/folder not found:')} {output_path}",
|
|
2786
|
+
)
|
|
2787
|
+
except Exception as e:
|
|
2788
|
+
logger.error(f"Error opening output: {e}", exc_info=True)
|
|
2789
|
+
messagebox.showerror(
|
|
2790
|
+
self.lang_manager.get("error", "Error"),
|
|
2791
|
+
f"{self.lang_manager.get('could_not_open_output', 'Could not open output:')} {str(e)}",
|
|
2792
|
+
)
|
|
2793
|
+
else:
|
|
2794
|
+
messagebox.showwarning(
|
|
2795
|
+
self.lang_manager.get("no_output", "No Output"),
|
|
2796
|
+
self.lang_manager.get(
|
|
2797
|
+
"no_output_msg", "No output file available to open."
|
|
2798
|
+
),
|
|
2799
|
+
)
|
|
2800
|
+
|
|
2801
|
+
def update_navigation_buttons(self):
|
|
2802
|
+
"""Update navigation button states and label"""
|
|
2803
|
+
current_tab = self.controller.current_tab
|
|
2804
|
+
|
|
2805
|
+
# Hide/show back button based on current tab
|
|
2806
|
+
if current_tab == 0:
|
|
2807
|
+
self.back_btn.pack_forget()
|
|
2808
|
+
else:
|
|
2809
|
+
# Show back button if it's not already visible
|
|
2810
|
+
if not self.back_btn.winfo_ismapped():
|
|
2811
|
+
self.back_btn.pack(side="left", padx=(0, 2), before=self.next_btn)
|
|
2812
|
+
self.back_btn.config(state="normal")
|
|
2813
|
+
|
|
2814
|
+
# If on settings tab, change Next to Execute
|
|
2815
|
+
if current_tab == 3:
|
|
2816
|
+
self.next_btn.config(
|
|
2817
|
+
text=self.lang_manager.get("nav_execute", "Execute"), state="normal"
|
|
2818
|
+
)
|
|
2819
|
+
# If on results tab with successful output, change to "Open Output"
|
|
2820
|
+
elif current_tab == 4 and self.controller.current_output:
|
|
2821
|
+
self.next_btn.config(
|
|
2822
|
+
text=self.lang_manager.get("nav_open_output", "📂 Open"), state="normal"
|
|
2823
|
+
)
|
|
2824
|
+
elif current_tab == 0:
|
|
2825
|
+
self.next_btn.config(
|
|
2826
|
+
text=self.lang_manager.get("nav_next", "Next →"), state="normal"
|
|
2827
|
+
)
|
|
2828
|
+
elif current_tab == 1:
|
|
2829
|
+
if self.controller.selected_operation:
|
|
2830
|
+
self.next_btn.config(
|
|
2831
|
+
text=self.lang_manager.get("nav_next", "Next →"), state="normal"
|
|
2832
|
+
)
|
|
2833
|
+
else:
|
|
2834
|
+
self.next_btn.config(
|
|
2835
|
+
text=self.lang_manager.get("nav_next", "Next →"), state="disabled"
|
|
2836
|
+
)
|
|
2837
|
+
elif current_tab == 2:
|
|
2838
|
+
self.next_btn.config(
|
|
2839
|
+
text=self.lang_manager.get("nav_next", "Next →"), state="normal"
|
|
2840
|
+
)
|
|
2841
|
+
else:
|
|
2842
|
+
self.next_btn.config(state="disabled")
|
|
2843
|
+
|
|
2844
|
+
def start_new_operation(self):
|
|
2845
|
+
"""Reset for a new operation"""
|
|
2846
|
+
# Reset controller state
|
|
2847
|
+
self.controller.selected_operation = None
|
|
2848
|
+
self.controller.selected_file = None
|
|
2849
|
+
self.controller.current_output = None
|
|
2850
|
+
|
|
2851
|
+
# Reset UI state
|
|
2852
|
+
self.update_file_display()
|
|
2853
|
+
self.update_navigation_buttons()
|
|
2854
|
+
|
|
2855
|
+
# Clear PDF preview
|
|
2856
|
+
if hasattr(self, "pdf_preview_canvas") and self.pdf_preview_canvas:
|
|
2857
|
+
self.show_pdf_preview(None)
|
|
2858
|
+
if hasattr(self, "pdf_preview_image"):
|
|
2859
|
+
self.pdf_preview_image = None
|
|
2860
|
+
|
|
2861
|
+
# Clear results
|
|
2862
|
+
self.results_text.config(state=tk.NORMAL)
|
|
2863
|
+
self.results_text.delete("1.0", tk.END)
|
|
2864
|
+
self.results_text.insert(
|
|
2865
|
+
"1.0",
|
|
2866
|
+
self.lang_manager.get(
|
|
2867
|
+
"results_placeholder",
|
|
2868
|
+
"When selected operation finishes, the results will be displayed here.\nPlease go back and select the operation.",
|
|
2869
|
+
),
|
|
2870
|
+
)
|
|
2871
|
+
self.results_text.config(state=tk.DISABLED)
|
|
2872
|
+
|
|
2873
|
+
# Disable workflow tabs
|
|
2874
|
+
self.notebook.tab(2, state="disabled")
|
|
2875
|
+
self.notebook.tab(3, state="disabled")
|
|
2876
|
+
self.notebook.tab(4, state="disabled")
|
|
2877
|
+
|
|
2878
|
+
# Go to operation selection tab
|
|
2879
|
+
self.notebook.select(1)
|
|
2880
|
+
|
|
2881
|
+
def execute_operation(self):
|
|
2882
|
+
"""Execute the selected PDF operation"""
|
|
2883
|
+
if not self.controller.selected_file or not self.controller.selected_operation:
|
|
2884
|
+
messagebox.showwarning(
|
|
2885
|
+
self.lang_manager.get("warning", "Warning"),
|
|
2886
|
+
self.lang_manager.get(
|
|
2887
|
+
"select_first", "Please select a file and operation first!"
|
|
2888
|
+
),
|
|
2889
|
+
)
|
|
2890
|
+
return
|
|
2891
|
+
|
|
2892
|
+
if self.controller.operation_running:
|
|
2893
|
+
messagebox.showinfo(
|
|
2894
|
+
self.lang_manager.get("info", "Info"),
|
|
2895
|
+
self.lang_manager.get(
|
|
2896
|
+
"already_running", "Operation is already running!"
|
|
2897
|
+
),
|
|
2898
|
+
)
|
|
2899
|
+
return
|
|
2900
|
+
|
|
2901
|
+
# Move to results tab
|
|
2902
|
+
self.notebook.tab(4, state="normal")
|
|
2903
|
+
self.notebook.select(4) # Results tab
|
|
2904
|
+
|
|
2905
|
+
# Clear previous results and reset progress
|
|
2906
|
+
self.progress.config(mode="determinate", value=0)
|
|
2907
|
+
self.results_text.config(state=tk.NORMAL)
|
|
2908
|
+
self.results_text.delete("1.0", tk.END)
|
|
2909
|
+
self.results_text.insert(
|
|
2910
|
+
"1.0", self.lang_manager.get("results_starting", "Starting operation...\n")
|
|
2911
|
+
)
|
|
2912
|
+
self.results_text.config(state=tk.DISABLED)
|
|
2913
|
+
|
|
2914
|
+
# Start progress animation
|
|
2915
|
+
self.progress.config(mode="indeterminate")
|
|
2916
|
+
self.progress.start()
|
|
2917
|
+
|
|
2918
|
+
# Collect settings from UI
|
|
2919
|
+
self.collect_operation_settings()
|
|
2920
|
+
|
|
2921
|
+
# Prepare output paths
|
|
2922
|
+
use_default = self.use_default_output.get()
|
|
2923
|
+
custom_path = self.output_path_var.get().strip() if not use_default else None
|
|
2924
|
+
output_path, output_dir = self.controller.prepare_output_paths(
|
|
2925
|
+
custom_path, use_default
|
|
2926
|
+
)
|
|
2927
|
+
|
|
2928
|
+
# Start operation
|
|
2929
|
+
success, message = self.controller.execute_operation_async(
|
|
2930
|
+
output_path, output_dir
|
|
2931
|
+
)
|
|
2932
|
+
|
|
2933
|
+
if not success:
|
|
2934
|
+
messagebox.showerror(self.lang_manager.get("error", "Error"), message)
|
|
2935
|
+
self.progress.stop()
|
|
2936
|
+
|
|
2937
|
+
def collect_operation_settings(self):
|
|
2938
|
+
"""Collect operation settings from UI and pass to controller"""
|
|
2939
|
+
settings = {}
|
|
2940
|
+
|
|
2941
|
+
if self.controller.selected_operation == "compress":
|
|
2942
|
+
settings["quality"] = self.quality_var.get()
|
|
2943
|
+
elif self.controller.selected_operation == "rotate":
|
|
2944
|
+
settings["angle"] = self.rotation_var.get()
|
|
2945
|
+
elif self.controller.selected_operation == "split":
|
|
2946
|
+
settings["method"] = self.split_var.get()
|
|
2947
|
+
settings["page_range"] = self.page_range_var.get()
|
|
2948
|
+
elif self.controller.selected_operation == "to_jpg":
|
|
2949
|
+
settings["quality"] = self.img_quality_var.get()
|
|
2950
|
+
# Map quality to DPI
|
|
2951
|
+
dpi_map = {"low": 150, "medium": 200, "high": 300}
|
|
2952
|
+
settings["dpi"] = dpi_map.get(settings["quality"], 200)
|
|
2953
|
+
elif self.controller.selected_operation == "repair":
|
|
2954
|
+
settings["recover_structure"] = self.repair_var.get()
|
|
2955
|
+
elif self.controller.selected_operation == "merge":
|
|
2956
|
+
settings["add_page_numbers"] = self.merge_var.get()
|
|
2957
|
+
# Include second file and order for merge operation
|
|
2958
|
+
second = self.merge_second_file_var.get().strip()
|
|
2959
|
+
settings["second_file"] = second if second else None
|
|
2960
|
+
settings["merge_order"] = self.merge_order_var.get() # 'end' or 'beginning'
|
|
2961
|
+
|
|
2962
|
+
self.controller.set_operation_settings(settings)
|
|
2963
|
+
|
|
2964
|
+
def update_progress(self, value):
|
|
2965
|
+
"""Update progress bar (callback from controller)"""
|
|
2966
|
+
if hasattr(self, "progress"):
|
|
2967
|
+
# Stop indeterminate mode and set to determinate with value
|
|
2968
|
+
self.progress.stop()
|
|
2969
|
+
self.progress.config(mode="determinate", value=value)
|
|
2970
|
+
self.root.update_idletasks()
|
|
2971
|
+
|
|
2972
|
+
def operation_completed(self, success, message, output_location):
|
|
2973
|
+
"""Handle operation completion (callback from controller)"""
|
|
2974
|
+
# Stop progress animation
|
|
2975
|
+
self.progress.stop()
|
|
2976
|
+
self.progress.config(mode="determinate", value=100 if success else 0)
|
|
2977
|
+
|
|
2978
|
+
# Update results text
|
|
2979
|
+
self.results_text.config(state=tk.NORMAL)
|
|
2980
|
+
self.results_text.insert(
|
|
2981
|
+
tk.END,
|
|
2982
|
+
"\n"
|
|
2983
|
+
+ self.lang_manager.get(
|
|
2984
|
+
"results_operation_completed", "Operation completed!"
|
|
2985
|
+
)
|
|
2986
|
+
+ "\n",
|
|
2987
|
+
)
|
|
2988
|
+
status_value = (
|
|
2989
|
+
self.lang_manager.get("results_success", "Success")
|
|
2990
|
+
if success
|
|
2991
|
+
else self.lang_manager.get("results_failed", "Failed")
|
|
2992
|
+
)
|
|
2993
|
+
self.results_text.insert(
|
|
2994
|
+
tk.END,
|
|
2995
|
+
f"{self.lang_manager.get('results_status', 'Status:')} {status_value}\n",
|
|
2996
|
+
)
|
|
2997
|
+
self.results_text.insert(
|
|
2998
|
+
tk.END,
|
|
2999
|
+
f"{self.lang_manager.get('results_details', 'Details:')} {message}\n",
|
|
3000
|
+
)
|
|
3001
|
+
|
|
3002
|
+
self.results_text.config(state=tk.DISABLED)
|
|
3003
|
+
|
|
3004
|
+
# Update navigation buttons to show "Open Output" if successful
|
|
3005
|
+
self.update_navigation_buttons()
|
|
3006
|
+
|
|
3007
|
+
# Show completion message
|
|
3008
|
+
if success:
|
|
3009
|
+
messagebox.showinfo(
|
|
3010
|
+
self.lang_manager.get("success", "Success"),
|
|
3011
|
+
f"{self.lang_manager.get('operation_completed', 'Operation completed successfully!')}\n{message}",
|
|
3012
|
+
)
|
|
3013
|
+
else:
|
|
3014
|
+
messagebox.showerror(
|
|
3015
|
+
self.lang_manager.get("error", "Error"),
|
|
3016
|
+
f"{self.lang_manager.get('operation_failed', 'Operation failed!')}\n{message}",
|
|
3017
|
+
)
|
|
3018
|
+
|
|
3019
|
+
def update_ui(self):
|
|
3020
|
+
"""Generic UI update callback"""
|
|
3021
|
+
# This can be used for any general UI updates
|
|
3022
|
+
self.root.update_idletasks()
|
|
3023
|
+
# Update pro features when UI updates (delegated)
|
|
3024
|
+
try:
|
|
3025
|
+
self.update_ui # ensure attribute exists
|
|
3026
|
+
self.update_ui.update_pro_ui(self)
|
|
3027
|
+
except Exception:
|
|
3028
|
+
pass
|
|
3029
|
+
|
|
3030
|
+
def update_pro_features(self):
|
|
3031
|
+
"""Backward-compatible delegate to UpdateUI for pro UI updates"""
|
|
3032
|
+
try:
|
|
3033
|
+
self.update_ui.update_pro_ui(self)
|
|
3034
|
+
except Exception:
|
|
3035
|
+
logger.debug("Error delegating pro UI update", exc_info=True)
|
|
3036
|
+
pass
|
|
3037
|
+
|
|
3038
|
+
def _update_execute_button_state(self):
|
|
3039
|
+
"""Enable or disable the Execute/Next button based on current operation and required inputs."""
|
|
3040
|
+
try:
|
|
3041
|
+
# Default: enable
|
|
3042
|
+
enabled = True
|
|
3043
|
+
if self.controller.selected_operation == "merge":
|
|
3044
|
+
# Require a second file to be selected
|
|
3045
|
+
second = (
|
|
3046
|
+
self.merge_second_file_var.get().strip()
|
|
3047
|
+
if getattr(self, "merge_second_file_var", None)
|
|
3048
|
+
else ""
|
|
3049
|
+
)
|
|
3050
|
+
if not second:
|
|
3051
|
+
enabled = False
|
|
3052
|
+
|
|
3053
|
+
# If results tab and output exists, Next becomes Open - leave it enabled
|
|
3054
|
+
if self.controller.current_tab == 4 and self.controller.current_output:
|
|
3055
|
+
enabled = True
|
|
3056
|
+
|
|
3057
|
+
# Update button state
|
|
3058
|
+
if getattr(self, "next_btn", None):
|
|
3059
|
+
self.next_btn.config(state="normal" if enabled else "disabled")
|
|
3060
|
+
except Exception:
|
|
3061
|
+
logger.debug("Error updating execute button state", exc_info=True)
|
|
3062
|
+
pass # Button may not exist during initialization, ignore
|
|
3063
|
+
|
|
3064
|
+
# Utility methods
|
|
3065
|
+
def open_github(self, event):
|
|
3066
|
+
"""Open GitHub repository"""
|
|
3067
|
+
open_url("https://github.com/mcagriaksoy/SafePDF")
|
|
3068
|
+
|
|
3069
|
+
def open_contact_us(self):
|
|
3070
|
+
"""Open contact us page"""
|
|
3071
|
+
open_url("https://safepdf.de/")
|
|
3072
|
+
|
|
3073
|
+
def _read_current_version(self) -> str:
|
|
3074
|
+
"""Read current packaged version from SafePDF.__version__"""
|
|
3075
|
+
return f"v{SAFEPDF_VERSION}"
|
|
3076
|
+
|
|
3077
|
+
def _load_pro_features(self):
|
|
3078
|
+
"""Delegate loading pro features to UpdateUI"""
|
|
3079
|
+
try:
|
|
3080
|
+
return self.update_ui.load_pro_features()
|
|
3081
|
+
except Exception:
|
|
3082
|
+
logger.debug("Error delegating pro features load", exc_info=True)
|
|
3083
|
+
return []
|
|
3084
|
+
|
|
3085
|
+
def _normalize_tag(self, tag: str) -> str:
|
|
3086
|
+
"""Normalize GitHub tag to dotted version string, e.g. v1_0_2 -> v1.0.2"""
|
|
3087
|
+
if not tag:
|
|
3088
|
+
return "v0.0.0"
|
|
3089
|
+
tag = tag.strip()
|
|
3090
|
+
# Accept tags like v1.0.2 or v1_0_2 or 1.0.2
|
|
3091
|
+
if tag[0].lower() == "v":
|
|
3092
|
+
core = tag[1:]
|
|
3093
|
+
prefix = "v"
|
|
3094
|
+
else:
|
|
3095
|
+
core = tag
|
|
3096
|
+
prefix = ""
|
|
3097
|
+
core = core.replace("_", ".")
|
|
3098
|
+
return prefix + core
|
|
3099
|
+
|
|
3100
|
+
def _compare_versions(self, current: str, latest: str) -> int:
|
|
3101
|
+
"""Compare two version strings like v1.0.2. Return -1 if latest>current, 0 if equal, 1 if current>latest"""
|
|
3102
|
+
|
|
3103
|
+
def to_tuple(v: str):
|
|
3104
|
+
v = v.lstrip("vV")
|
|
3105
|
+
parts = [int(p) if p.isdigit() else 0 for p in v.split(".")]
|
|
3106
|
+
# pad to 3 components
|
|
3107
|
+
while len(parts) < 3:
|
|
3108
|
+
parts.append(0)
|
|
3109
|
+
return tuple(parts[:3])
|
|
3110
|
+
|
|
3111
|
+
try:
|
|
3112
|
+
curr = to_tuple(current)
|
|
3113
|
+
last = to_tuple(latest)
|
|
3114
|
+
if last > curr:
|
|
3115
|
+
return -1
|
|
3116
|
+
if last == curr:
|
|
3117
|
+
return 0
|
|
3118
|
+
return 1
|
|
3119
|
+
except Exception:
|
|
3120
|
+
return 0 # Invalid version format, treat as equal
|
|
3121
|
+
|
|
3122
|
+
def show_help(self):
|
|
3123
|
+
"""Delegate showing help dialog to HelpUI"""
|
|
3124
|
+
try:
|
|
3125
|
+
self.help_ui.show_help()
|
|
3126
|
+
except Exception as e:
|
|
3127
|
+
logger.error(f"Error showing help dialog: {e}", exc_info=True)
|
|
3128
|
+
try:
|
|
3129
|
+
messagebox.showinfo(
|
|
3130
|
+
"Help",
|
|
3131
|
+
"Help content is unavailable. Please check your installation.",
|
|
3132
|
+
)
|
|
3133
|
+
except Exception:
|
|
3134
|
+
pass
|
|
3135
|
+
|
|
3136
|
+
def show_settings(self):
|
|
3137
|
+
"""Delegate to SettingsUI.show_settings_dialog"""
|
|
3138
|
+
try:
|
|
3139
|
+
return self.settings_ui.show_settings_dialog()
|
|
3140
|
+
except Exception:
|
|
3141
|
+
messagebox.showerror("Settings Error", "Settings dialog not available.")
|
|
3142
|
+
|
|
3143
|
+
def view_log_file(self):
|
|
3144
|
+
"""Delegate to SettingsUI.view_log_file"""
|
|
3145
|
+
try:
|
|
3146
|
+
return self.settings_ui.view_log_file()
|
|
3147
|
+
except Exception:
|
|
3148
|
+
messagebox.showinfo("Log File", "Log viewer is unavailable.")
|
|
3149
|
+
|
|
3150
|
+
def refresh_log_view(self, text_widget):
|
|
3151
|
+
"""Refresh the log viewer content"""
|
|
3152
|
+
try:
|
|
3153
|
+
text_widget.config(state=tk.NORMAL)
|
|
3154
|
+
text_widget.delete("1.0", tk.END)
|
|
3155
|
+
with open(LOG_FILE_PATH, "r", encoding="utf-8") as f:
|
|
3156
|
+
content = f.read()
|
|
3157
|
+
text_widget.insert("1.0", content)
|
|
3158
|
+
text_widget.see(tk.END)
|
|
3159
|
+
text_widget.config(state=tk.DISABLED)
|
|
3160
|
+
except Exception as e:
|
|
3161
|
+
logger.error(f"Error refreshing log view: {e}", exc_info=True)
|
|
3162
|
+
text_widget.insert("1.0", f"Error reading log file: {e}")
|
|
3163
|
+
|
|
3164
|
+
def show_pro_dialog(self):
|
|
3165
|
+
"""Delegate to UpdateUI to show Pro dialog"""
|
|
3166
|
+
try:
|
|
3167
|
+
return self.update_ui.show_pro_dialog(self)
|
|
3168
|
+
except Exception:
|
|
3169
|
+
logger.debug("Error delegating show_pro_dialog", exc_info=True)
|
|
3170
|
+
try:
|
|
3171
|
+
messagebox.showerror("Error", "Pro dialog is unavailable.")
|
|
3172
|
+
except Exception:
|
|
3173
|
+
pass
|
|
3174
|
+
|
|
3175
|
+
def clear_log_file(self):
|
|
3176
|
+
"""Delegate to SettingsUI.clear_log_file"""
|
|
3177
|
+
try:
|
|
3178
|
+
return self.settings_ui.clear_log_file()
|
|
3179
|
+
except Exception:
|
|
3180
|
+
messagebox.showerror("Error", "Could not clear the log file.")
|
|
3181
|
+
|
|
3182
|
+
def open_log_folder(self):
|
|
3183
|
+
"""Delegate to SettingsUI.open_log_folder"""
|
|
3184
|
+
try:
|
|
3185
|
+
return self.settings_ui.open_log_folder()
|
|
3186
|
+
except Exception:
|
|
3187
|
+
messagebox.showerror("Error", "Could not open log folder.")
|
|
3188
|
+
|
|
3189
|
+
def cancel_operation(self):
|
|
3190
|
+
"""Cancel current operation with confirmation"""
|
|
3191
|
+
if not self.controller.operation_running:
|
|
3192
|
+
resp = messagebox.askyesno(
|
|
3193
|
+
self.lang_manager.get("info", "Info"),
|
|
3194
|
+
self.lang_manager.get(
|
|
3195
|
+
"cancel_no_operation",
|
|
3196
|
+
"No operation is currently running. \r\nDo you want to close the application?",
|
|
3197
|
+
),
|
|
3198
|
+
)
|
|
3199
|
+
if resp:
|
|
3200
|
+
self.root.quit()
|
|
3201
|
+
return
|
|
3202
|
+
|
|
3203
|
+
# Ask the user to confirm cancellation
|
|
3204
|
+
resp = messagebox.askyesno(
|
|
3205
|
+
self.lang_manager.get("cancel_operation_title", "Cancel Operation"),
|
|
3206
|
+
self.lang_manager.get(
|
|
3207
|
+
"cancel_confirm",
|
|
3208
|
+
"Are you sure you want to cancel the current operation?",
|
|
3209
|
+
),
|
|
3210
|
+
)
|
|
3211
|
+
if not resp:
|
|
3212
|
+
return
|
|
3213
|
+
|
|
3214
|
+
# Ask one more time to avoid accidental cancellation
|
|
3215
|
+
resp2 = messagebox.askyesno(
|
|
3216
|
+
self.lang_manager.get("cancel_confirm_title", "Confirm Cancel"),
|
|
3217
|
+
self.lang_manager.get(
|
|
3218
|
+
"cancel_final",
|
|
3219
|
+
"This will stop the operation. Do you really want to cancel?",
|
|
3220
|
+
),
|
|
3221
|
+
)
|
|
3222
|
+
if not resp2:
|
|
3223
|
+
return
|
|
3224
|
+
|
|
3225
|
+
# Request controller to cancel
|
|
3226
|
+
self.controller.cancel_operation()
|
|
3227
|
+
|
|
3228
|
+
# Update UI to reflect cancellation
|
|
3229
|
+
try:
|
|
3230
|
+
self.progress.stop()
|
|
3231
|
+
self.progress.config(mode="determinate", value=0)
|
|
3232
|
+
self.results_text.config(state=tk.NORMAL)
|
|
3233
|
+
self.results_text.insert(
|
|
3234
|
+
tk.END,
|
|
3235
|
+
"\n"
|
|
3236
|
+
+ self.lang_manager.get(
|
|
3237
|
+
"operation_cancelled", "Operation cancelled by user."
|
|
3238
|
+
)
|
|
3239
|
+
+ "\n",
|
|
3240
|
+
)
|
|
3241
|
+
self.results_text.config(state=tk.DISABLED)
|
|
3242
|
+
except Exception:
|
|
3243
|
+
logger.debug(
|
|
3244
|
+
"Error updating UI after operation cancellation", exc_info=True
|
|
3245
|
+
)
|
|
3246
|
+
pass
|
|
3247
|
+
|
|
3248
|
+
def save_results(self):
|
|
3249
|
+
"""Save operation results"""
|
|
3250
|
+
if self.controller.current_output:
|
|
3251
|
+
output_path = self.controller.current_output
|
|
3252
|
+
if os.path.isfile(output_path):
|
|
3253
|
+
# Single file output
|
|
3254
|
+
save_path = filedialog.asksaveasfilename(
|
|
3255
|
+
title="Save PDF",
|
|
3256
|
+
defaultextension=".pdf",
|
|
3257
|
+
filetypes=[("PDF files", "*.pdf"), ("All files", "*.*")],
|
|
3258
|
+
initialname=os.path.basename(output_path),
|
|
3259
|
+
)
|
|
3260
|
+
if save_path:
|
|
3261
|
+
import shutil
|
|
3262
|
+
|
|
3263
|
+
shutil.copy2(output_path, save_path)
|
|
3264
|
+
messagebox.showinfo("Saved", f"File saved to {save_path}")
|
|
3265
|
+
else:
|
|
3266
|
+
# Directory output
|
|
3267
|
+
save_dir = filedialog.askdirectory(
|
|
3268
|
+
title="Select folder to copy results"
|
|
3269
|
+
)
|
|
3270
|
+
if save_dir:
|
|
3271
|
+
import shutil
|
|
3272
|
+
|
|
3273
|
+
dest_dir = os.path.join(save_dir, os.path.basename(output_path))
|
|
3274
|
+
shutil.copytree(output_path, dest_dir, dirs_exist_ok=True)
|
|
3275
|
+
messagebox.showinfo("Saved", f"Results saved to {dest_dir}")
|
|
3276
|
+
else:
|
|
3277
|
+
messagebox.showwarning("Warning", "No results to save!")
|
|
3278
|
+
|
|
3279
|
+
def toggle_fullscreen(self):
|
|
3280
|
+
"""Toggle maximize mode (keeps taskbar visible like normal Windows apps)"""
|
|
3281
|
+
if not self.is_fullscreen:
|
|
3282
|
+
# Store current geometry
|
|
3283
|
+
self.restore_geometry = self.root.geometry()
|
|
3284
|
+
|
|
3285
|
+
# Get screen dimensions (excluding taskbar)
|
|
3286
|
+
screen_width = self.root.winfo_screenwidth()
|
|
3287
|
+
screen_height = self.root.winfo_screenheight()
|
|
3288
|
+
|
|
3289
|
+
# On Windows, adjust for taskbar (typically 40-48 pixels at bottom)
|
|
3290
|
+
if platform_system() == "Windows":
|
|
3291
|
+
try:
|
|
3292
|
+
import ctypes
|
|
3293
|
+
|
|
3294
|
+
# Get work area (screen minus taskbar)
|
|
3295
|
+
class RECT(ctypes.Structure):
|
|
3296
|
+
_fields_ = [
|
|
3297
|
+
("left", ctypes.c_long),
|
|
3298
|
+
("top", ctypes.c_long),
|
|
3299
|
+
("right", ctypes.c_long),
|
|
3300
|
+
("bottom", ctypes.c_long),
|
|
3301
|
+
]
|
|
3302
|
+
|
|
3303
|
+
rect = RECT()
|
|
3304
|
+
SPI_GETWORKAREA = 0x0030
|
|
3305
|
+
if ctypes.windll.user32.SystemParametersInfoW(
|
|
3306
|
+
SPI_GETWORKAREA, 0, ctypes.byref(rect), 0
|
|
3307
|
+
):
|
|
3308
|
+
screen_width = rect.right - rect.left
|
|
3309
|
+
screen_height = rect.bottom - rect.top
|
|
3310
|
+
x_pos = rect.left
|
|
3311
|
+
y_pos = rect.top
|
|
3312
|
+
else:
|
|
3313
|
+
x_pos = 0
|
|
3314
|
+
y_pos = 0
|
|
3315
|
+
except Exception:
|
|
3316
|
+
x_pos = 0
|
|
3317
|
+
y_pos = 0
|
|
3318
|
+
else:
|
|
3319
|
+
x_pos = 0
|
|
3320
|
+
y_pos = 0
|
|
3321
|
+
|
|
3322
|
+
# Maximize window to fill work area (excludes taskbar)
|
|
3323
|
+
self.root.geometry(f"{screen_width}x{screen_height}+{x_pos}+{y_pos}")
|
|
3324
|
+
self.maximize_btn.config(text="❐") # Change to restore icon
|
|
3325
|
+
self.is_fullscreen = True
|
|
3326
|
+
else:
|
|
3327
|
+
# Restore to previous geometry
|
|
3328
|
+
if self.restore_geometry:
|
|
3329
|
+
self.root.geometry(self.restore_geometry)
|
|
3330
|
+
else:
|
|
3331
|
+
self.root.geometry("780x600")
|
|
3332
|
+
self.center_window()
|
|
3333
|
+
|
|
3334
|
+
self.maximize_btn.config(text="□") # Change back to maximize icon
|
|
3335
|
+
self.is_fullscreen = False
|
|
3336
|
+
|
|
3337
|
+
def open_donation_link(self):
|
|
3338
|
+
"""Open the Buy Me a Coffee donation link"""
|
|
3339
|
+
open_url("https://www.buymeacoffee.com/mcagriaksoy")
|
|
3340
|
+
|
|
3341
|
+
def open_paypal_link(self):
|
|
3342
|
+
"""Open the PayPal donation link"""
|
|
3343
|
+
open_url("https://www.paypal.com/donate/?hosted_button_id=QD5J7HPVUXW5G")
|
|
3344
|
+
|
|
3345
|
+
def select_to_word(self):
|
|
3346
|
+
self.controller.select_operation("to_word")
|
|
3347
|
+
self.highlight_selected_operation(6)
|
|
3348
|
+
self.update_settings_for_operation()
|
|
3349
|
+
self.update_file_tab_ui()
|
|
3350
|
+
if self.notebook is not None:
|
|
3351
|
+
self.notebook.tab(2, state="normal")
|
|
3352
|
+
self.notebook.select(2)
|
|
3353
|
+
|
|
3354
|
+
def select_to_txt(self):
|
|
3355
|
+
self.controller.select_operation("to_txt")
|
|
3356
|
+
self.highlight_selected_operation(7)
|
|
3357
|
+
self.update_settings_for_operation()
|
|
3358
|
+
self.update_file_tab_ui()
|
|
3359
|
+
if self.notebook is not None:
|
|
3360
|
+
self.notebook.tab(2, state="normal")
|
|
3361
|
+
self.notebook.select(2)
|
|
3362
|
+
|
|
3363
|
+
def select_extract_info(self):
|
|
3364
|
+
self.controller.select_operation("extract_info")
|
|
3365
|
+
self.highlight_selected_operation(8)
|
|
3366
|
+
self.update_settings_for_operation()
|
|
3367
|
+
self.update_file_tab_ui()
|
|
3368
|
+
if self.notebook is not None:
|
|
3369
|
+
self.notebook.tab(2, state="normal")
|
|
3370
|
+
self.notebook.select(2)
|
|
3371
|
+
|
|
3372
|
+
def update_file_display(self):
|
|
3373
|
+
"""Update the file display UI after file selection"""
|
|
3374
|
+
try:
|
|
3375
|
+
if self.controller.selected_files:
|
|
3376
|
+
if len(self.controller.selected_files) == 1:
|
|
3377
|
+
# Single file
|
|
3378
|
+
filename = os.path.basename(self.controller.selected_files[0])
|
|
3379
|
+
if hasattr(self, "file_label") and self.file_label:
|
|
3380
|
+
self.file_label.config(
|
|
3381
|
+
text=self.lang_manager.get(
|
|
3382
|
+
"selected_file", "✅ Selected: {filename}"
|
|
3383
|
+
).format(filename=filename),
|
|
3384
|
+
foreground="green",
|
|
3385
|
+
)
|
|
3386
|
+
if hasattr(self, "drop_label") and self.drop_label:
|
|
3387
|
+
self.drop_label.config(
|
|
3388
|
+
text=self.lang_manager.get(
|
|
3389
|
+
"selected_file", "✅ Selected: {filename}"
|
|
3390
|
+
).format(filename=filename),
|
|
3391
|
+
bg="#e8f5e8",
|
|
3392
|
+
fg="#28a745",
|
|
3393
|
+
relief=tk.SOLID,
|
|
3394
|
+
bd=2,
|
|
3395
|
+
)
|
|
3396
|
+
else:
|
|
3397
|
+
# Multiple files (merge operation)
|
|
3398
|
+
filenames = [
|
|
3399
|
+
os.path.basename(f) for f in self.controller.selected_files
|
|
3400
|
+
]
|
|
3401
|
+
if hasattr(self, "file_label") and self.file_label:
|
|
3402
|
+
self.file_label.config(
|
|
3403
|
+
text=f"{self.lang_manager.get('selected_files', 'Selected files: ')}{', '.join(filenames)}",
|
|
3404
|
+
foreground="green",
|
|
3405
|
+
)
|
|
3406
|
+
if hasattr(self, "drop_label") and self.drop_label:
|
|
3407
|
+
self.drop_label.config(
|
|
3408
|
+
text=self.lang_manager.get(
|
|
3409
|
+
"selected_for_merge",
|
|
3410
|
+
"✅ Selected {count} files for merge",
|
|
3411
|
+
).format(count=len(filenames)),
|
|
3412
|
+
bg="#e8f5e8",
|
|
3413
|
+
fg="#28a745",
|
|
3414
|
+
relief=tk.SOLID,
|
|
3415
|
+
bd=2,
|
|
3416
|
+
)
|
|
3417
|
+
|
|
3418
|
+
# Show PDF info for the first file
|
|
3419
|
+
self.show_pdf_info()
|
|
3420
|
+
|
|
3421
|
+
# Update preview for the first file
|
|
3422
|
+
try:
|
|
3423
|
+
self.show_pdf_preview(self.controller.selected_files[0])
|
|
3424
|
+
except Exception:
|
|
3425
|
+
pass
|
|
3426
|
+
else:
|
|
3427
|
+
# No files selected
|
|
3428
|
+
if hasattr(self, "file_label") and self.file_label:
|
|
3429
|
+
self.file_label.config(
|
|
3430
|
+
text=self.lang_manager.get(
|
|
3431
|
+
"preview_no_file_selected", "No file\nselected"
|
|
3432
|
+
).replace("\n", " "),
|
|
3433
|
+
foreground="#888",
|
|
3434
|
+
)
|
|
3435
|
+
if hasattr(self, "drop_label") and self.drop_label:
|
|
3436
|
+
self.drop_label.config(
|
|
3437
|
+
text=self.lang_manager.get(
|
|
3438
|
+
"drop_pdf_file", "📄 Drop PDF File Here\n\nClick to browse"
|
|
3439
|
+
),
|
|
3440
|
+
bg="#f8f9fa",
|
|
3441
|
+
fg="#666",
|
|
3442
|
+
relief=tk.RIDGE,
|
|
3443
|
+
bd=2,
|
|
3444
|
+
)
|
|
3445
|
+
|
|
3446
|
+
# Clear preview
|
|
3447
|
+
try:
|
|
3448
|
+
self.show_pdf_preview(None)
|
|
3449
|
+
except Exception:
|
|
3450
|
+
pass
|
|
3451
|
+
except Exception as e:
|
|
3452
|
+
logger.debug(f"Error updating file display: {e}", exc_info=True)
|
|
3453
|
+
pass
|
|
3454
|
+
|
|
3455
|
+
def _load_language_preference(self):
|
|
3456
|
+
"""Load saved language preference from config file"""
|
|
3457
|
+
try:
|
|
3458
|
+
import json
|
|
3459
|
+
from pathlib import Path
|
|
3460
|
+
|
|
3461
|
+
config_dir = Path.home() / ".safepdf"
|
|
3462
|
+
config_dir.mkdir(exist_ok=True)
|
|
3463
|
+
config_file = config_dir / "config.json"
|
|
3464
|
+
|
|
3465
|
+
if config_file.exists():
|
|
3466
|
+
with open(config_file, "r", encoding="utf-8") as f:
|
|
3467
|
+
config = json.load(f)
|
|
3468
|
+
return config.get("language", "en")
|
|
3469
|
+
except Exception as e:
|
|
3470
|
+
logger.debug(f"Error loading language preference: {e}", exc_info=True)
|
|
3471
|
+
return "en"
|
|
3472
|
+
|
|
3473
|
+
def _save_language_preference(self, language_code):
|
|
3474
|
+
"""Save language preference to config file"""
|
|
3475
|
+
try:
|
|
3476
|
+
import json
|
|
3477
|
+
from pathlib import Path
|
|
3478
|
+
|
|
3479
|
+
config_dir = Path.home() / ".safepdf"
|
|
3480
|
+
config_dir.mkdir(exist_ok=True)
|
|
3481
|
+
config_file = config_dir / "config.json"
|
|
3482
|
+
|
|
3483
|
+
# Load existing config or create new
|
|
3484
|
+
config = {}
|
|
3485
|
+
if config_file.exists():
|
|
3486
|
+
with open(config_file, "r", encoding="utf-8") as f:
|
|
3487
|
+
config = json.load(f)
|
|
3488
|
+
|
|
3489
|
+
# Update language
|
|
3490
|
+
config["language"] = language_code
|
|
3491
|
+
|
|
3492
|
+
# Save back
|
|
3493
|
+
with open(config_file, "w", encoding="utf-8") as f:
|
|
3494
|
+
json.dump(config, f, indent=2)
|
|
3495
|
+
|
|
3496
|
+
except Exception as e:
|
|
3497
|
+
logger.debug(f"Error saving language preference: {e}", exc_info=True)
|