-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Mmabiaa/Content-Branch
Uploading Updates
- Loading branch information
Showing
8 changed files
with
239 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from tkinter import Menu | ||
from file_operations import * | ||
from text_formatting import * | ||
from insertions import * | ||
from tkinter import messagebox | ||
|
||
|
||
def create_menu(root): | ||
menu = Menu(root) | ||
root.config(menu=menu) | ||
|
||
# File menu | ||
file_menu = Menu(menu, tearoff=False) | ||
menu.add_cascade(label="File", menu=file_menu) | ||
file_menu.add_command(label="New", command=new_file) | ||
file_menu.add_command(label="Open", command=open_file) | ||
file_menu.add_command(label="Save", command=save_file) | ||
file_menu.add_command(label="Save As", command=save_as_file) | ||
file_menu.add_separator() | ||
file_menu.add_command(label="Exit", command=root.quit) | ||
|
||
# Edit menu | ||
edit_menu = Menu(menu, tearoff=False) | ||
menu.add_cascade(label="Edit", menu=edit_menu) | ||
edit_menu.add_command(label="Undo", command=lambda: text_area.event_generate("<<Undo>>")) | ||
edit_menu.add_command(label="Redo", command=lambda: text_area.event_generate("<<Redo>>")) | ||
edit_menu.add_separator() | ||
edit_menu.add_command(label="Cut", command=lambda: text_area.event_generate("<<Cut>>")) | ||
edit_menu.add_command(label="Copy", command=lambda: text_area.event_generate("<<Copy>>")) | ||
edit_menu.add_command(label="Paste", command=lambda: text_area.event_generate("<<Paste>>")) | ||
edit_menu.add_command(label="Select All", command=lambda: text_area.event_generate("<<SelectAll>>")) | ||
edit_menu.add_separator() | ||
|
||
# Format menu | ||
format_menu = Menu(menu, tearoff=False) | ||
menu.add_cascade(label="Format", menu=format_menu) | ||
format_menu.add_command(label="Font", command=choose_font) | ||
format_menu.add_command(label="Increase Font Size", command=increase_font_size) | ||
format_menu.add_command(label="Decrease Font Size", command=decrease_font_size) | ||
format_menu.add_command(label="Color", command=choose_color) | ||
format_menu.add_separator() | ||
format_menu.add_command(label="Bold", command=apply_bold) | ||
format_menu.add_command(label="Italic", command=apply_italic) | ||
format_menu.add_command(label="Underline", command=apply_underline) | ||
format_menu.add_command(label="Strikethrough", command=apply_strikethrough) | ||
|
||
# Theme menu | ||
theme_menu = Menu(menu, tearoff=False) | ||
menu.add_cascade(label="Theme", menu=theme_menu) | ||
theme_menu.add_command(label="Light", command=lambda: change_theme("light")) | ||
theme_menu.add_command(label="Dark", command=lambda: change_theme("dark")) | ||
theme_menu.add_command(label="Gray", command=lambda: change_theme("gray")) | ||
theme_menu.add_command(label="Green", command=lambda: change_theme("green")) | ||
theme_menu.add_command(label="Blue", command=lambda: change_theme("blue")) | ||
theme_menu.add_command(label="Purple", command=lambda: change_theme("purple")) | ||
theme_menu.add_command(label="Red", command=lambda: change_theme("red")) | ||
theme_menu.add_command(label="Orange", command=lambda: change_theme("orange")) | ||
theme_menu.add_command(label="Yellow", command=lambda: change_theme("yellow")) | ||
theme_menu.add_command(label="Brown", command=lambda: change_theme("brown")) | ||
theme_menu.add_command(label="Pink", command=lambda: change_theme("pink")) | ||
theme_menu.add_command(label="Cyan", command=lambda: change_theme("cyan")) | ||
theme_menu.add_command(label="Custom", command=lambda: change_theme("custom")) | ||
|
||
|
||
# Help menu | ||
help_menu = Menu(menu, tearoff=False) | ||
menu.add_cascade(label="Help", menu=help_menu) | ||
help_menu.add_command(label="About", command=about) | ||
|
||
# Insert menu | ||
insert_menu = Menu(menu, tearoff=False) | ||
menu.add_cascade(label="Insert", menu=insert_menu) | ||
insert_menu.add_command(label="Image", command=insert_image) | ||
insert_menu.add_command(label="Video", command=insert_video) | ||
|
||
def about(): | ||
messagebox.showinfo("About", "Mmabiaa Text Editor\nVersion 1.0\n\n Created by Boateng Agyenim Prince\n\n A simple text editor built using python and tkinter") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,50 @@ | ||
from tkinter import filedialog, messagebox | ||
from tkinter import filedialog, messagebox, END | ||
import os | ||
from text_formatting import * | ||
|
||
filename = None | ||
|
||
def new_file(text_area): | ||
def new_file(root): | ||
#new_file : clears the text area and resets the filename | ||
global filename | ||
text_area.delete(1.0, 'end') | ||
text_area.delete(1.0, END) | ||
filename = None | ||
root.title("Mmabia Text Pad- Untitled File") | ||
|
||
def open_file(text_area): | ||
def open_file(root): | ||
#open_file : opens a file dialog,reads the selected file and displays it contents in the text area | ||
global filename | ||
filename = filedialog.askopenfilename(defaultextension=".txt", | ||
filetypes=[("All Files", "."), ("Text Documents", "*.txt")]) | ||
|
||
if filename: | ||
with open(filename, 'r') as file: | ||
text_area.delete(1.0, 'end') | ||
text_area.delete(1.0, END) | ||
text_area.insert(1.0, file.read()) | ||
root.title(f"Mmabia Textpad - {os.path.basename(filename)}") | ||
|
||
def save_file(text_area): | ||
|
||
def save_file(root): | ||
#save_file : saves the current file | ||
global filename | ||
|
||
if filename: | ||
try: | ||
with open(filename, 'w') as file: | ||
file.write(text_area.get(1.0, 'end')) | ||
file.write(text_area.get(1.0, END)) | ||
root.title(f"Mmabia Textpad - {os.path.basename(filename)}") | ||
except Exception as e: | ||
messagebox.showerror("Error", str(e)) | ||
|
||
def save_as_file(text_area): | ||
else: | ||
save_as_file() | ||
|
||
|
||
def save_as_file(root): | ||
#save_as_file : opens a save dialog and saves the file with a name | ||
global filename | ||
|
||
filename = filedialog.asksaveasfilename(defaultextension=".txt", | ||
filetypes=[("All Files", "."), ("Text Documents", "*.txt")]) | ||
|
||
if filename: | ||
with open(filename, 'w') as file: | ||
file.write(text_area.get(1.0, 'end')) | ||
|
||
def create_text_area(root): | ||
from tkinter.scrolledtext import ScrolledText | ||
|
||
global text_area | ||
text_area = ScrolledText(root, wrap='word', undo=True) | ||
file.write(text_area.get(1.0, END)) | ||
root.title(f"Mmabiaa Textpad - {os.path.basename(filename)}") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from tkinter import filedialog, messagebox, PhotoImage, END | ||
from text_formatting import* | ||
|
||
|
||
|
||
def insert_image(): | ||
filepath = filedialog.askopenfilename(filetypes=[("Image Files", ".png;.jpg;.jpeg;.gif")]) | ||
if filepath: | ||
try: | ||
image = PhotoImage(file=filepath) | ||
text_area.image_create(END, image=image) | ||
text_area.image = image # Keep a reference to avoid garbage collection | ||
except Exception as e: | ||
messagebox.showerror("Error", str(e)) | ||
|
||
def insert_video(): | ||
filepath = filedialog.askopenfilename(filetypes=[("Video Files", ".mp4;.avi;*.mov")]) | ||
if filepath: | ||
messagebox.showinfo("Info", "Video inserted. (This is a placeholder implementation.)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import logging | ||
import os | ||
|
||
# Configure logging | ||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | ||
|
||
def log_info(message): | ||
"""Log an informational message.""" | ||
logging.info(message) | ||
|
||
def log_error(message): | ||
"""Log an error message.""" | ||
logging.error(message) | ||
|
||
def get_file_extension(filename): | ||
"""Return the file extension for a given filename.""" | ||
return os.path.splitext(filename)[1] | ||
|
||
def is_valid_text_file(filename): | ||
"""Check if the given filename has a valid text file extension.""" | ||
valid_extensions = ['.txt', '.md', '.rtf'] | ||
return get_file_extension(filename) in valid_extensions | ||
|
||
def show_message(title, message): | ||
"""Display a message box with the given title and message.""" | ||
from tkinter import messagebox | ||
messagebox.showinfo(title, message) | ||
|
||
def confirm_exit(): | ||
"""Confirm if the user wants to exit the application.""" | ||
from tkinter import messagebox | ||
return messagebox.askokcancel("Quit", "Do you really want to quit?") | ||
|
||
def clear_text_area(text_area): | ||
"""Clear the content of the text area.""" | ||
text_area.delete(1.0, 'end') |