-
-
Couldn't load subscription status.
- Fork 381
ADDED Clipboard Manager #495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
Clipboard Manager/README.md
This file contains hidden or 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,25 @@ | ||
|
|
||
| # 📋 Clipboard Manager | ||
|
|
||
| **Clipboard Manager** is a Python desktop application that automatically monitors and saves your clipboard history. With a simple GUI, you can view, manage, and clear all the text you've copied, ensuring that nothing important is lost. | ||
|
|
||
| --- | ||
|
|
||
| ## **Requirements** | ||
| - Python 3.x | ||
| - `pyperclip` library | ||
| ```bash | ||
| pip install pyperclip | ||
| ```` | ||
|
|
||
| --- | ||
|
|
||
| ## **Benefits** | ||
|
|
||
| * 🖱 **Real-time monitoring**: Automatically tracks copied text. | ||
| * 📝 **Persistent history**: Saves all clipboard entries to a text file in your home directory. | ||
| * 📜 **Scrollable GUI**: Easily browse your clipboard history. | ||
| * 🗑 **Clear history**: Delete all stored entries from both the GUI and the file. | ||
| * 🔄 **Thread-safe updates**: Updates the GUI without freezing the application. | ||
|
|
||
|
|
103 changes: 103 additions & 0 deletions
Clipboard Manager/main.py
This file contains hidden or 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,103 @@ | ||
| import pyperclip | ||
| import tkinter as tk | ||
| from tkinter import scrolledtext | ||
| import time | ||
| import threading | ||
| import os | ||
| import queue | ||
|
|
||
| history_file = os.path.join(os.path.expanduser("~"), "clipboard_history.txt") | ||
|
|
||
| if not os.path.exists(history_file): | ||
| with open(history_file, "w", encoding="utf-8") as f: | ||
| f.write("Clipboard History:\n\n") | ||
|
|
||
| last_text = "" | ||
|
|
||
| gui_queue = queue.Queue() | ||
|
|
||
| MAX_HISTORY_LINES = 1000 | ||
|
|
||
|
|
||
| def monitor_clipboard(): | ||
| global last_text | ||
| while True: | ||
| try: | ||
| text = pyperclip.paste() | ||
| except Exception: | ||
| time.sleep(1) | ||
| continue | ||
| if text != last_text and text.strip() != "": | ||
| last_text = text | ||
| timestamped_text = f"{time.strftime('%Y-%m-%d %H:%M:%S')} - {text}\n" | ||
| try: | ||
| with open(history_file, "a", encoding="utf-8") as f: | ||
| f.write(timestamped_text) | ||
| except Exception: | ||
| pass | ||
| gui_queue.put(timestamped_text) | ||
| time.sleep(1) | ||
|
|
||
| def limit_file_size(): | ||
| try: | ||
| with open(history_file, "r", encoding="utf-8") as f: | ||
| lines = f.readlines() | ||
|
|
||
| header = lines[:2] | ||
| history = lines[2:] | ||
| if MAX_HISTORY_LINES is not None and len(history) > MAX_HISTORY_LINES: | ||
| history = history[-MAX_HISTORY_LINES:] | ||
| with open(history_file, "w", encoding="utf-8") as f: | ||
| f.writelines(header + history) | ||
| except Exception: | ||
| pass | ||
|
|
||
|
|
||
| def process_queue(): | ||
| while not gui_queue.empty(): | ||
| text = gui_queue.get() | ||
| text_area.configure(state='normal') | ||
| text_area.insert(tk.END, text) | ||
| text_area.configure(state='disabled') | ||
| text_area.yview(tk.END) | ||
| root.after(100, process_queue) | ||
|
|
||
| # | ||
| def clear_history(): | ||
| text_area.configure(state='normal') | ||
| text_area.delete(1.0, tk.END) | ||
| text_area.configure(state='disabled') | ||
| try: | ||
| with open(history_file, "w", encoding="utf-8") as f: | ||
| f.write("Clipboard History:\n\n") | ||
| except Exception: | ||
| pass | ||
|
|
||
| root = tk.Tk() | ||
| root.title("Clipboard Manager") | ||
| root.geometry("600x400") | ||
|
|
||
| text_area = scrolledtext.ScrolledText(root, wrap=tk.WORD, state='disabled') | ||
| text_area.pack(expand=True, fill='both', padx=10, pady=10) | ||
|
|
||
| clear_button = tk.Button(root, text="Clear History", command=clear_history) | ||
| clear_button.pack(pady=5) | ||
|
|
||
|
|
||
| limit_file_size() | ||
| try: | ||
| with open(history_file, "r", encoding="utf-8") as f: | ||
| text_area.configure(state='normal') | ||
| text_area.insert(tk.END, f.read()) | ||
| text_area.configure(state='disabled') | ||
| except Exception: | ||
| pass | ||
|
|
||
|
|
||
| thread = threading.Thread(target=monitor_clipboard, daemon=True) | ||
| thread.start() | ||
|
|
||
|
|
||
| root.after(100, process_queue) | ||
|
|
||
| root.mainloop() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.