Skip to content
This repository was archived by the owner on May 18, 2025. It is now read-only.

Commit 71d5c9e

Browse files
authored
Merge pull request #8 from BirdOffice-Suite/beta
Last minute fixes
2 parents a9b9761 + 1d03758 commit 71d5c9e

File tree

2 files changed

+126
-120
lines changed

2 files changed

+126
-120
lines changed

birdpad.py

Lines changed: 13 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from tkmacosx import Button
55
from sys import argv
66
import sys, webbrowser
7-
from spellchecker import SpellChecker
7+
#from spellchecker import SpellChecker
88
import tkinter as tk
99
from requests import get, ConnectionError
1010

@@ -26,7 +26,7 @@
2626
logs = []
2727

2828
# Initialize the spell checker
29-
spell = SpellChecker()
29+
#spell = SpellChecker()
3030
custom_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():
236129
text_box = scrolledtext.ScrolledText(wrap="none", relief="sunken", undo=True)
237130
text_box.pack(expand=True, fill='both')
238131
text_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
242135
if 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)
249142
else:
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

257150
saveas.pack(side=tk.LEFT, fill='both', expand=True)
258151
load.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)
260153
quit_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
272165
dark_mode = False
273-
apply_theme()
166+
#apply_theme()
274167

275168
# Button to toggle theme
276169

old.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# old code ripped out from production - do not use
2+
3+
def autocorrect():
4+
global updated
5+
6+
if not updated:
7+
answer = askyesno('BirdPad', "It looks like you're using autocorrect. Would you like to download the extended dictionary via the Internet?")
8+
9+
else:
10+
answer = False
11+
12+
if answer:
13+
try:
14+
global custom_words
15+
print("[DEBUG] Updating spellcheck from API...")
16+
17+
ypages = get("https://mojavesoft.net/api/v1/birdpad/ypages.txt").text.split("\n")
18+
19+
for i in ypages:
20+
custom_words.extend(get(i).text.split("\n"))
21+
#custom_words = list(set(custom_words))
22+
showinfo("BirdPad", f"Downloaded extended dictionary! ({math.floor(len(custom_words)/1000)}k entries)")
23+
24+
except ConnectionError:
25+
showerror("BirdPad", "mojavesoft.net is not available. Try again in a couple hours.")
26+
27+
28+
except Exception as e:
29+
showerror("BirdPad", e)
30+
print(e)
31+
32+
updated = True
33+
print("[DEBUG] Spellcheck update complete")
34+
35+
36+
37+
text_content = text_box.get("1.0", tk.END)
38+
corrected_text = []
39+
40+
word = ""
41+
for char in text_content:
42+
if char in string.whitespace: # Preserve whitespaces (spaces, newlines, etc.)
43+
if word:
44+
stripped_word = strip_punctuation(word)
45+
# Check if the stripped word is in custom_words case-insensitively
46+
if stripped_word and spell.unknown([stripped_word]) and stripped_word.lower() not in [w.lower() for w in custom_words]:
47+
# Correct the word
48+
corrected_word = spell.candidates(stripped_word)
49+
if corrected_word:
50+
word = word.replace(stripped_word, list(corrected_word)[0])
51+
corrected_text.append(word)
52+
word = ""
53+
corrected_text.append(char) # Append the whitespace character
54+
else:
55+
word += char
56+
57+
# If any word is left at the end, process it
58+
if word:
59+
stripped_word = strip_punctuation(word)
60+
if stripped_word and spell.unknown([stripped_word]) and stripped_word.lower() not in [w.lower() for w in custom_words]:
61+
corrected_word = spell.candidates(stripped_word)
62+
if corrected_word:
63+
word = word.replace(stripped_word, list(corrected_word)[0])
64+
corrected_text.append(word)
65+
66+
# Reinsert the corrected text into the text box without changing the format
67+
text_box.delete("1.0", tk.END)
68+
text_box.insert("1.0", "".join(corrected_text))
69+
check_spelling() # Recheck spelling after correction
70+
showinfo("BirdPad", "Spellcheck complete.")
71+
72+
# Theme change function
73+
def toggle_theme():
74+
global dark_mode
75+
dark_mode = not dark_mode
76+
apply_theme()
77+
78+
# Apply theme
79+
def apply_theme():
80+
if dark_mode:
81+
window.configure(bg='#2e2e2e')
82+
text_box.configure(bg='#333333', fg='white', insertbackground='white')
83+
saveas.configure(bg='#4c4c4c', fg='white')
84+
load.configure(bg='#4c4c4c', fg='white')
85+
quit_birdpad.configure(bg='#4c4c4c', fg='white')
86+
autocorrect_button.configure(bg='#4c4c4c', fg='white')
87+
theme_button.configure(bg='#4c4c4c', fg='white') # Set dark color for the toggle button
88+
else:
89+
window.configure(bg='white')
90+
text_box.configure(bg='white', fg='black', insertbackground='black')
91+
saveas.configure(bg='orange', fg='black')
92+
load.configure(bg='blue', fg='white')
93+
quit_birdpad.configure(bg='red', fg='white')
94+
autocorrect_button.configure(bg='green', fg='white')
95+
theme_button.configure(bg='gray', fg='black') # Set light color for the toggle button
96+
97+
# Spell check function
98+
def check_spelling(event=None):
99+
text_content = text_box.get("1.0", tk.END)
100+
words = text_content.split()
101+
text_box.tag_remove("misspelled", "1.0", tk.END)
102+
103+
for word in words:
104+
stripped_word = strip_punctuation(word)
105+
# Check if the stripped word is in custom_words case-insensitively
106+
if stripped_word and spell.unknown([stripped_word]) and stripped_word.lower() not in [w.lower() for w in custom_words]:
107+
start_idx = f"1.0 + {text_content.index(word)}c"
108+
end_idx = f"{start_idx} + {len(word)}c"
109+
text_box.tag_add("misspelled", start_idx, end_idx)
110+
111+
# Autocorrect function
112+
updated = False
113+

0 commit comments

Comments
 (0)