Windows Clipboard History ★ Deluxe
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()
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") windows clipboard history
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 def load_history(self): if os
HISTORY_FILE = "clipboard_history.json" MAX_HISTORY = 100 = 0: self.listbox.selection_clear(0
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 update_history_display(self): self.listbox.delete(0, tk.END) filtered = self.get_filtered_history() for item in filtered: text = item["text"].replace("\n", " ").replace("\r", "") if len(text) > 80: text = text[:77] + "..." # Pin indicator prefix = "📌 " if (item["text"], item["timestamp"]) in self.pinned else " " display = f"prefixtext" self.listbox.insert(tk.END, display) self.status_var.set(f"History: len(filtered) items (max MAX_HISTORY)")
def toggle_pin(self, index): filtered = self.get_filtered_history() if index < len(filtered): item = filtered[index] item_id = (item["text"], item["timestamp"]) if item_id in self.pinned: self.pinned.discard(item_id) else: self.pinned.add(item_id) self.save_history() self.update_history_display()