Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions PrepareForMacUser.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Then reactivate your virtual environment:
deactivate
source venv/bin/activate
```
#### If you are using Apple Silicon (M1/M2/M3)
#### If you are using Apple Silicon (M1/M2/M3/M4)

Run:
```bash
Expand Down Expand Up @@ -44,4 +44,4 @@ export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/lib
Save the file, then run:
```bash
source ~/.zshrc
```
```
39 changes: 24 additions & 15 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,64 @@
import tkinter as tk
from markdown_reader.ui import MarkdownReader
import sys
import os
import sys
import tkinter as tk

import ttkbootstrap as ttkb
from ttkbootstrap.constants import *

from markdown_reader.ui import MarkdownReader


def handle_open_file(event):
"""
Handles file open events from macOS.

:param event event: The open file event from macOS.
:param event event: The open file event from macOS.
"""

file_path = event
if os.path.isfile(file_path) and file_path.lower().endswith(('.md', '.markdown', '.html', '.htm', '.pdf')):
if os.path.isfile(file_path) and file_path.lower().endswith(
(".md", ".markdown", ".html", ".htm", ".pdf")
):
app.load_file(file_path)


if __name__ == "__main__":
try:
from tkinterdnd2 import TkinterDnD

root = TkinterDnD.Tk()

# Apply ttkbootstrap theme to TkinterDnD window
app_style = ttkb.Style(theme="darkly")

print("TkinterDnD enabled - Drag and drop support available")
except ImportError as e:
except (ImportError, RuntimeError) as e:
print(f" Warning: tkinterdnd2 not installed, drag-and-drop will be disabled")
print(f" Error: {e}")
root = ttkb.Window(themename="darkly")

# Ensure window is resizable
root.resizable(width=True, height=True)

app = MarkdownReader(root)

# Handle file open events from macOS Finder
root.createcommand("::tk::mac::OpenDocument", lambda *args: handle_open_file(args[0]))
root.createcommand(
"::tk::mac::OpenDocument", lambda *args: handle_open_file(args[0])
)

# Handle file opening from command line
if len(sys.argv) > 1:
for arg in sys.argv[1:]:
# Skip macOS system parameters (process serial number)
if arg.startswith('-psn'):
if arg.startswith("-psn"):
continue
# Convert to absolute path
file_path = os.path.abspath(arg)
if os.path.isfile(file_path) and file_path.lower().endswith(('.md', '.markdown', '.html', '.htm', '.pdf')):
if os.path.isfile(file_path) and file_path.lower().endswith(
(".md", ".markdown", ".html", ".htm", ".pdf")
):
app.load_file(file_path)
break # Only open the first file

root.mainloop()
root.mainloop()
Loading