Clipboard History: Windows

def on_close(self): self.running = False self.save_history() self.root.destroy() if == " main ": root = tk.Tk() # Add placeholder text workaround class EntryWithPlaceholder(tk.Entry): def init (self, master=None, placeholder="", **kwargs): super(). init (master, **kwargs) self.placeholder = placeholder self.bind("<FocusIn>", self.on_focus_in) self.bind("<FocusOut>", self.on_focus_out) self.on_focus_out() def on_focus_in(self, e): if self.get() == self.placeholder: self.delete(0, tk.END) self.config(fg="black") def on_focus_out(self, e): if not self.get(): self.insert(0, self.placeholder) self.config(fg="grey") tk.Entry = EntryWithPlaceholder

def clear_history(self): if messagebox.askyesno("Clear History", "Delete all clipboard history?"): self.history = [] self.pinned.clear() self.save_history() self.update_history_display() self.status_var.set("History cleared") windows clipboard history

def create_widgets(self): # Top frame top_frame = tk.Frame(self.root) top_frame.pack(fill=tk.X, padx=5, pady=5) tk.Label(top_frame, text="Clipboard History", font=("Arial", 14, "bold")).pack(side=tk.LEFT) tk.Button(top_frame, text="Clear History", command=self.clear_history).pack(side=tk.RIGHT, padx=2) tk.Button(top_frame, text="Paste to Clipboard", command=self.paste_selected).pack(side=tk.RIGHT, padx=2) # Search bar self.search_var = tk.StringVar() self.search_var.trace("w", lambda *a: self.update_history_display()) search_entry = tk.Entry(self.root, textvariable=self.search_var, placeholder="Search...") search_entry.pack(fill=tk.X, padx=5, pady=2) # Listbox with scrollbar frame = tk.Frame(self.root) frame.pack(fill=tk.BOTH, expand=True, padx=5, pady=5) scrollbar = tk.Scrollbar(frame) scrollbar.pack(side=tk.RIGHT, fill=tk.Y) self.listbox = tk.Listbox(frame, yscrollcommand=scrollbar.set, font=("Consolas", 10)) self.listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True) self.listbox.bind("<Double-Button-1>", lambda e: self.paste_selected()) self.listbox.bind("<Button-3>", self.show_context_menu) # right-click scrollbar.config(command=self.listbox.yview) # Status bar self.status_var = tk.StringVar() self.status_var.set("Monitoring clipboard...") status_bar = tk.Label(self.root, textvariable=self.status_var, bd=1, relief=tk.SUNKEN, anchor=tk.W) status_bar.pack(side=tk.BOTTOM, fill=tk.X) def on_close(self): self

def show_context_menu(self, event): try: index = self.listbox.nearest(event.y) if index >= 0: self.listbox.selection_clear(0, tk.END) self.listbox.selection_set(index) menu = tk.Menu(self.root, tearoff=0) menu.add_command(label="Copy to clipboard", command=self.paste_selected) menu.add_command(label="Pin / Unpin", command=lambda: self.toggle_pin(index)) menu.add_command(label="Delete", command=lambda: self.delete_selected(index)) menu.post(event.x_root, event.y_root) except: pass **kwargs): super(). init (master

self.history = [] self.pinned = set() self.load_history() self.last_text = pyperclip.paste() self.running = True # GUI self.create_widgets() self.update_history_display() # Start background monitor self.monitor_thread = threading.Thread(target=self.monitor_clipboard, daemon=True) self.monitor_thread.start() self.root.protocol("WM_DELETE_WINDOW", self.on_close)

def delete_selected(self, index): filtered = self.get_filtered_history() if index < len(filtered): item = filtered[index] # Remove from history for i, h in enumerate(self.history): if h["text"] == item["text"] and h["timestamp"] == item["timestamp"]: del self.history[i] # Remove from pinned if exists self.pinned.discard((item["text"], item["timestamp"])) break self.save_history() self.update_history_display() self.status_var.set("Item deleted")

def load_history(self): if os.path.exists(HISTORY_FILE): try: with open(HISTORY_FILE, "r", encoding="utf-8") as f: data = json.load(f) self.history = data.get("history", []) self.pinned = set(tuple(x) for x in data.get("pinned", [])) except: self.history = [] self.pinned = set()