שיתוף | תוכנה לסידור טקסטים לנגן (מניעת שבירת מילים).
-
שלום לכולם,
בטח הרבה מכם מכירים את הבעיה המעצבנת הזאת בנגנים הפשוטים: כשפותחים קובץ טקסט (חומש, הלכה וכו'), הנגן חותך את השורות בדיוק לפי מספר התווים במסך, וזה תמיד יוצא באמצע מילה. זה הופך את הקריאה למאמץ מעצבן.
הכנתי לעצמי כלי קטן בפייתון שפותר את זה, וחשבתי שזה יכול לעזור לעוד אנשים כאן.
מה התוכנה עושה?
סורקת תיקייה שלמה (כולל כל התת-תיקיות שבפנים).
חותכת את הטקסט בצורה חכמה: אם מילה עומדת להישבר בסוף השורה, היא פשוט יורדת שורה אחת קודם.
אפשר לבחור כמה תווים נכנסים אצלכם בשורה בנגן (בדרך כלל 24 או 26).
ויוצרת תיקייה חדשה עם הקבצים המתוקנים.
מסדר הטקסט לנגן.exe . פשוט בוחרים תיקייה, מגדירים מספר תווים ולוחצים על הכפתור.
תמונות והקוד מקור בספויילר
בהצלחה!
גירסא יותר קלה אך עם ממשק גרפי לא ככ טוב.exe
קוד מקור למעוניינים:import os import tkinter as tk from tkinter import filedialog, messagebox def wrap_text(text, limit): words = text.split() if not words: return "" lines = [] current_line = [] current_length = 0 for word in words: space = 1 if current_line else 0 if current_length + len(word) + space > limit: lines.append(" ".join(current_line)) current_line = [word] current_length = len(word) else: current_line.append(word) current_length += len(word) + space if current_line: lines.append(" ".join(current_line)) return "\n".join(lines) def start_processing(): input_dir = entry_input.get() try: max_len = int(entry_limit.get()) except ValueError: messagebox.showerror("שגיאה", "אנא הכנס מספר תקין במגבלת התווים") return if not input_dir or not os.path.exists(input_dir): messagebox.showerror("שגיאה", "אנא בחר תיקיית מקור תקינה") return output_dir = input_dir + "_Fixed" count = 0 for root, dirs, files in os.walk(input_dir): for file in files: if file.endswith(".txt"): full_path = os.path.join(root, file) rel_path = os.path.relpath(full_path, input_dir) dest_path = os.path.join(output_dir, rel_path) os.makedirs(os.path.dirname(dest_path), exist_ok=True) try: with open(full_path, 'r', encoding='utf-8') as f: content = f.readlines() processed = [wrap_text(line, max_len) for line in content] with open(dest_path, 'w', encoding='utf-8') as f: f.write("\n".join(processed)) count += 1 except: continue messagebox.showinfo("סיום", f"התהליך הסתיים! {count} קבצים עובדו ונשמרו ב:\n{output_dir}") def browse_folder(): folder = filedialog.askdirectory() if folder: entry_input.delete(0, tk.END) entry_input.insert(0, folder) # עיצוב החלון root = tk.Tk() root.title("מתקן טקסט לנגן") root.geometry("400x250") tk.Label(root, text="בחר תיקיית ספרים:").pack(pady=5) entry_input = tk.Entry(root, width=40) entry_input.pack(pady=5) tk.Button(root, text="עיון...", command=browse_folder).pack(pady=5) tk.Label(root, text="מגבלת תווים לשורה:").pack(pady=5) entry_limit = tk.Entry(root, width=10) entry_limit.insert(0, "24") entry_limit.pack(pady=5) tk.Button(root, text="הפעל תיקון", command=start_processing, bg="green", fg="white").pack(pady=20) root.mainloop()גילוי נאות: תוכנה זאת נוצרה ע"י ai.