44from tkmacosx import Button
55from sys import argv
66import sys , webbrowser
7- from spellchecker import SpellChecker
7+ # from spellchecker import SpellChecker
88import tkinter as tk
99from requests import get , ConnectionError
1010
2626logs = []
2727
2828# Initialize the spell checker
29- spell = SpellChecker ()
29+ # spell = SpellChecker()
3030custom_words = ["BirdPad" , "Australorp" , "BirdBrush" , "BirdOffice" , "BirdMenu" , "BirdPad" , "Brahma" , "mojavesoft" , "mojaveland" ] # Programmatic list of custom words
3131
3232# Function to strip punctuation
@@ -111,116 +111,9 @@ def log(txt):
111111 print (txt )
112112 logs .append (txt )
113113
114- # Spell check function
115- def check_spelling (event = None ):
116- text_content = text_box .get ("1.0" , tk .END )
117- words = text_content .split ()
118- text_box .tag_remove ("misspelled" , "1.0" , tk .END )
119-
120- for word in words :
121- stripped_word = strip_punctuation (word )
122- # Check if the stripped word is in custom_words case-insensitively
123- if stripped_word and spell .unknown ([stripped_word ]) and stripped_word .lower () not in [w .lower () for w in custom_words ]:
124- start_idx = f"1.0 + { text_content .index (word )} c"
125- end_idx = f"{ start_idx } + { len (word )} c"
126- text_box .tag_add ("misspelled" , start_idx , end_idx )
127-
128- # Autocorrect function
129- updated = False
130-
131- def autocorrect ():
132- global updated
133-
134- if not updated :
135- answer = askyesno ('BirdPad' , "It looks like you're using autocorrect. Would you like to download the extended dictionary via the Internet?" )
136114
137- else :
138- answer = False
139-
140- if answer :
141- try :
142- global custom_words
143- print ("[DEBUG] Updating spellcheck from API..." )
144-
145- ypages = get ("https://mojavesoft.net/api/v1/birdpad/ypages.txt" ).text .split ("\n " )
146-
147- for i in ypages :
148- custom_words .extend (get (i ).text .split ("\n " ))
149- #custom_words = list(set(custom_words))
150- showinfo ("BirdPad" , f"Downloaded extended dictionary! ({ math .floor (len (custom_words )/ 1000 )} k entries)" )
151-
152- except ConnectionError :
153- showerror ("BirdPad" , "mojavesoft.net is not available. Try again in a couple hours." )
154-
155-
156- except Exception as e :
157- showerror ("BirdPad" , e )
158- print (e )
159-
160- updated = True
161- print ("[DEBUG] Spellcheck update complete" )
162-
163-
164-
165- text_content = text_box .get ("1.0" , tk .END )
166- corrected_text = []
167-
168- word = ""
169- for char in text_content :
170- if char in string .whitespace : # Preserve whitespaces (spaces, newlines, etc.)
171- if word :
172- stripped_word = strip_punctuation (word )
173- # Check if the stripped word is in custom_words case-insensitively
174- if stripped_word and spell .unknown ([stripped_word ]) and stripped_word .lower () not in [w .lower () for w in custom_words ]:
175- # Correct the word
176- corrected_word = spell .candidates (stripped_word )
177- if corrected_word :
178- word = word .replace (stripped_word , list (corrected_word )[0 ])
179- corrected_text .append (word )
180- word = ""
181- corrected_text .append (char ) # Append the whitespace character
182- else :
183- word += char
184-
185- # If any word is left at the end, process it
186- if word :
187- stripped_word = strip_punctuation (word )
188- if stripped_word and spell .unknown ([stripped_word ]) and stripped_word .lower () not in [w .lower () for w in custom_words ]:
189- corrected_word = spell .candidates (stripped_word )
190- if corrected_word :
191- word = word .replace (stripped_word , list (corrected_word )[0 ])
192- corrected_text .append (word )
193-
194- # Reinsert the corrected text into the text box without changing the format
195- text_box .delete ("1.0" , tk .END )
196- text_box .insert ("1.0" , "" .join (corrected_text ))
197- check_spelling () # Recheck spelling after correction
198- showinfo ("BirdPad" , "Spellcheck complete." )
199-
200- # Theme change function
201- def toggle_theme ():
202- global dark_mode
203- dark_mode = not dark_mode
204- apply_theme ()
205-
206- # Apply theme
207- def apply_theme ():
208- if dark_mode :
209- window .configure (bg = '#2e2e2e' )
210- text_box .configure (bg = '#333333' , fg = 'white' , insertbackground = 'white' )
211- saveas .configure (bg = '#4c4c4c' , fg = 'white' )
212- load .configure (bg = '#4c4c4c' , fg = 'white' )
213- quit_birdpad .configure (bg = '#4c4c4c' , fg = 'white' )
214- autocorrect_button .configure (bg = '#4c4c4c' , fg = 'white' )
215- theme_button .configure (bg = '#4c4c4c' , fg = 'white' ) # Set dark color for the toggle button
216- else :
217- window .configure (bg = 'white' )
218- text_box .configure (bg = 'white' , fg = 'black' , insertbackground = 'black' )
219- saveas .configure (bg = 'orange' , fg = 'black' )
220- load .configure (bg = 'blue' , fg = 'white' )
221- quit_birdpad .configure (bg = 'red' , fg = 'white' )
222- autocorrect_button .configure (bg = 'green' , fg = 'white' )
223- theme_button .configure (bg = 'gray' , fg = 'black' ) # Set light color for the toggle button
115+
116+
224117
225118
226119# Tkinter setup
@@ -236,27 +129,27 @@ def apply_theme():
236129text_box = scrolledtext .ScrolledText (wrap = "none" , relief = "sunken" , undo = True )
237130text_box .pack (expand = True , fill = 'both' )
238131text_box .tag_configure ("misspelled" , foreground = "red" , underline = True )
239- text_box .bind ('<KeyRelease>' , check_spelling )
132+ # text_box.bind('<KeyRelease>', check_spelling)
240133
241134# Buttons for file handling and other actions
242135if platform .system () == "Darwin" or "--macos" in sys .argv :
243136 log ("[DEBUG] Using macOS-optimized interface." )
244137 saveas = Button (window , text = "Save" , command = saveas_file , bg = 'orange' , borderless = 0 )
245138 load = Button (window , text = "Load" , command = load_file , bg = 'blue' , fg = "white" , borderless = 0 )
246139 quit_birdpad = Button (window , text = "Quit" , bg = 'red' , command = quit_bpad , borderless = 0 )
247- autocorrect_button = Button (window , text = "Autocorrect" , command = autocorrect , bg = 'green' , fg = "white" , borderless = 0 )
248- theme_button = Button (window , text = "Toggle Theme" , command = toggle_theme , borderless = 0 )
140+ # autocorrect_button = Button(window, text="Autocorrect", command=autocorrect, bg='green', fg="white", borderless=0)
141+ # theme_button = Button(window, text="Toggle Theme", command=toggle_theme, borderless=0)
249142else :
250143 log ("[DEBUG] Using default interface." )
251- saveas = tk .Button (window , text = "Save" , command = saveas_file , bg = 'orange' )
252- load = tk .Button (window , text = "Load" , command = load_file , bg = 'blue ' , fg = "white" )
144+ saveas = tk .Button (window , text = "Save" , command = saveas_file , bg = 'green' , fg = "white" )
145+ load = tk .Button (window , text = "Load" , command = load_file , bg = 'purple ' , fg = "white" )
253146 quit_birdpad = tk .Button (window , text = "Quit" , bg = 'red' , command = quit_bpad )
254- autocorrect_button = tk .Button (window , text = "Autocorrect" , command = autocorrect , bg = 'green' , fg = "white" )
255- theme_button = tk .Button (window , text = "Toggle Theme" , command = toggle_theme )
147+ # autocorrect_button = tk.Button(window, text="Autocorrect", command=autocorrect, bg='green', fg="white")
148+ # theme_button = tk.Button(window, text="Toggle Theme", command=toggle_theme)
256149
257150saveas .pack (side = tk .LEFT , fill = 'both' , expand = True )
258151load .pack (side = tk .LEFT , fill = 'both' , expand = True )
259- autocorrect_button .pack (side = tk .LEFT , fill = 'both' , expand = True )
152+ # autocorrect_button.pack(side=tk.LEFT, fill='both', expand=True)
260153quit_birdpad .pack (side = tk .RIGHT , fill = 'both' , expand = True )
261154
262155# Initial text
@@ -270,7 +163,7 @@ def apply_theme():
270163
271164# Default dark mode state
272165dark_mode = False
273- apply_theme ()
166+ # apply_theme()
274167
275168# Button to toggle theme
276169
0 commit comments