This repository was archived by the owner on May 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbirdpad.py
More file actions
179 lines (145 loc) · 6.69 KB
/
birdpad.py
File metadata and controls
179 lines (145 loc) · 6.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import tkinter.filedialog, platform, os, string, math
from tkinter.messagebox import askyesno, showerror, showinfo
from tkinter import scrolledtext
from tkmacosx import Button
from sys import argv
import sys, webbrowser
#from spellchecker import SpellChecker
import tkinter as tk
from requests import get, ConnectionError
# START DONATION CODE
#from tkinter import messagebox
#from random import randint
#import sys
#if randint(0,3) == 1 and not "--no-popup" in sys.argv:
#showinfo("BirdOffice 24.11", "Thank you for downloading BirdPad! If you like this software, make sure to donate at www.mojavesoft.net/donate/!")
# END DONATION CODE
# Initialize logging
logging = False
logs = []
# Initialize the spell checker
#spell = SpellChecker()
custom_words = ["BirdPad", "Australorp", "BirdBrush", "BirdOffice", "BirdMenu", "BirdPad", "Brahma", "mojavesoft", "mojaveland"] # Programmatic list of custom words
# Function to strip punctuation
def strip_punctuation(word):
return word.translate(str.maketrans('', '', string.punctuation))
# File handling functions
def saveas_file():
try:
global fname
fname = tk.filedialog.asksaveasfilename(filetypes=[("Text files", "*.txt"), ("XML files", "*.xml"), ("HTML files", "*.html"), ("HTM files", "*.htm"), ("Python files", "*.py"), ("Arduino C++ files", "*.ino"), ("All files", "*.*")])
log(f"Save file to {fname}.")
with open(fname, "w") as f:
f.write(text_box.get("1.0", tk.END)[0:-1])
showinfo("BirdPad", "File saved successfully!")
except (AttributeError, FileNotFoundError):
showerror(title='BirdPad', message="File not found or failed to save.")
log("File not found or failed to save.")
except NameError:
pass
return fname
def save_file():
try:
global fname
if fname:
with open(fname, 'w', encoding='utf-16') as f:
f.write(text_box.get("1.0", tk.END)[0:-1])
showinfo("BirdPad", "File saved successfully")
except NameError:
fname = saveas_file()
def load_file(fname=None):
if fname:
log(f"Load file from {fname}.")
try:
with open(fname, 'r') as f:
text_box.delete("1.0", tk.END)
text_box.insert("1.0", f.read())
except UnicodeDecodeError:
showerror(title='BirdPad', message="This file is not a text document and cannot be read by BirdPad.")
log("This file is not a text document and cannot be read by BirdPad.")
except FileNotFoundError:
showerror(title='BirdPad', message="File not found.")
log("File not found.")
else:
try:
fname = tk.filedialog.askopenfilename(filetypes=[("Text files", "*.txt"), ("XML files", "*.xml"), ("HTML files", "*.html"), ("HTM files", "*.htm"), ("Python files", "*.py"), ("Arduino C++ files", "*.ino"), ("All files", "*.*")])
log(f"Load file from {fname}.")
with open(fname, 'r') as f:
text_box.delete("1.0", tk.END)
text_box.insert("1.0", f.read())
except UnicodeDecodeError:
showerror(title='BirdPad', message="This file is not a text document and cannot be read by BirdPad.")
log("This file is not a text document and cannot be read by BirdPad.")
except FileNotFoundError:
if fname:
showerror(title='BirdPad', message="File not found.")
log("File not found.")
def quit_bpad():
log(f"Ask if app should be closed.")
answer = askyesno(title='Quit BirdPad', message='Are you sure that you want to quit?')
if answer:
window.destroy()
def resource_path(relative_path):
log(f"Get resource from {relative_path}.")
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def get_updates():
log(f"Ask if app should open browser.")
answer = askyesno(title='BirdOffice Suite', message='Open browser to download BirdOffice?')
if answer:
webbrowser.open_new_tab("https://mojavesoft.net/birdoffice/")
def log(txt):
print(txt)
logs.append(txt)
# Tkinter setup
window = tk.Tk()
window.title('BirdPad 24.11 (Barred Brahma)')
window.geometry("700x700")
window.minsize(width=0, height=500)
photo = tk.PhotoImage(file=resource_path('birdpad.png'))
window.wm_iconphoto(False, photo)
# Textbox with spell checking
text_box = scrolledtext.ScrolledText(wrap="none", relief="sunken", undo=True)
text_box.pack(expand=True, fill='both')
text_box.tag_configure("misspelled", foreground="red", underline=True)
#text_box.bind('<KeyRelease>', check_spelling)
# Buttons for file handling and other actions
if platform.system() == "Darwin" or "--macos" in sys.argv:
log("[DEBUG] Using macOS-optimized interface.")
saveas = Button(window, text="Save", command=saveas_file, bg='orange', borderless=0)
load = Button(window, text="Load", command=load_file, bg='blue', fg="white", borderless=0)
quit_birdpad = Button(window, text="Quit", bg='red', command=quit_bpad, borderless=0)
#autocorrect_button = Button(window, text="Autocorrect", command=autocorrect, bg='green', fg="white", borderless=0)
#theme_button = Button(window, text="Toggle Theme", command=toggle_theme, borderless=0)
else:
log("[DEBUG] Using default interface.")
saveas = tk.Button(window, text="Save", command=saveas_file, bg='green', fg="white")
load = tk.Button(window, text="Load", command=load_file, bg='purple', fg="white")
quit_birdpad = tk.Button(window, text="Quit", bg='red', command=quit_bpad)
#autocorrect_button = tk.Button(window, text="Autocorrect", command=autocorrect, bg='green', fg="white")
#theme_button = tk.Button(window, text="Toggle Theme", command=toggle_theme)
saveas.pack(side=tk.LEFT, fill='both', expand=True)
load.pack(side=tk.LEFT, fill='both', expand=True)
#autocorrect_button.pack(side=tk.LEFT, fill='both', expand=True)
quit_birdpad.pack(side=tk.RIGHT, fill='both', expand=True)
# Initial text
text_box.insert(tk.END, '''Thanks for installing BirdPad 24.11 Barred Brahma!''')
if len(argv) > 1 and not argv[1] == "--log" and not argv[1] == "--macos":
load_file(argv[1])
if "--log" in argv:
logging = True
# Default dark mode state
dark_mode = False
#apply_theme()
# Button to toggle theme
#theme_button.pack(side=tk.LEFT, fill='both', expand=True)
window.mainloop()
# Log save if logging enabled
if logging:
log_file = open("birdpad.log", "a")
log_file.write("\n".join(logs))
log_file.write("\n")
log_file.close()