From 75a42ec54dbf721caa659ddf02c1f46fc2cb4bef Mon Sep 17 00:00:00 2001 From: mlot Date: Fri, 6 Jun 2025 13:40:57 -0400 Subject: initial commit for archiving --- Chap8PracMcbDelete.pyw | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Chap8PracMcbDelete.pyw (limited to 'Chap8PracMcbDelete.pyw') diff --git a/Chap8PracMcbDelete.pyw b/Chap8PracMcbDelete.pyw new file mode 100644 index 0000000..5dc8e40 --- /dev/null +++ b/Chap8PracMcbDelete.pyw @@ -0,0 +1,34 @@ +#! ptyhon3 + +# Chapter 8 Practice Project +# Extend the Multiclipboard project to include a delete option + + +# Loads and saves clipboard text based on a key word from the command line +# Usage: py.exe mcb.pyw save - Saves to clipboard +# py.exe mcb.pyw - Loads keyword to clipboard +# py.exe mcb.pyw list - Loads all keywords to clipboard +# py.exe mcb.pyw delete - Deletes all keywords +# py.exe mcb.pyw delete - Deletes a specific keyword + +import sys +import pyperclip +import shelve + +mcbShelf = shelve.open('mcb') + +if len(sys.argv) == 3 and sys.argv[1].lower() == 'save': + mcbShelf[sys.argv[2]] = pyperclip.paste() +elif len(sys.argv) == 3 and sys.argv[1].lower() == 'delete': + del mcbShelf[sys.argv[2]] +elif len(sys.argv) == 2: + if sys.argv[1].lower() == 'list': + pyperclip.copy(str(list(mcbShelf.keys()))) + elif sys.argv[1].lower() == 'delete': + for k in list(mcbShelf.keys()): + del mcbShelf[k] + elif sys.argv[1] in mcbShelf: + pyperclip.copy(mcbShelf[sys.argv[1]]) + + +mcbShelf.close() -- cgit