- Clipboard Manager
This automation script monitors everything you copy, seamlessly storing each copied text in a smooth graphical interface, so you don't have to search through endless tabs, avoiding the loss of valuable information.
This automation script utilizes the Pyperclip library to seamlessly capture copied data and integrates Tkinter to visually track and manage the copied text.
# Import the tkinter library for creating GUI applications, ttk is an extension module of tkinter that provides more modern interface elements.
import tkinter as tk
from tkinter import ttk
# Import the pyperclip library, which can be used to copy and paste clipboard content.
import pyperclip
# Define a function to update the contents of the listbox, adding new clipboard content to the list.
def update_listbox():
new_item = pyperclip.paste() # Get the current clipboard content
if new_item not in X: # If the content is not in our list, add it
X.append(new_item)
listbox.insert(tk.END, new_item) # Add new item to the end of the listbox
listbox.insert(tk.END, "----------------------") # Add a separator line
listbox.yview(tk.END) # Automatically scroll to the bottom of the listbox
root.after(1000, update_listbox) # Call this function every 1000 milliseconds (1 second) to keep updating
# Define a function to handle the double-click event on listbox items, copying the selected content to the clipboard.
def copy_to_clipboard(event):
selected_item = listbox.get(listbox.curselection()) # Get the currently selected list item
if selected_item:
pyperclip.copy(selected_item) # Copy the selected content to the clipboard
# Create an empty list to store clipboard content.
X = []
# Create the main window
root = tk.Tk()
root.title("Clipboard Manager") # Set the window title
root.geometry("500x500") # Set the window size
root.configure(bg="#f0f0f0") # Set the window background color
# Create a frame component to hold other interface elements
frame = tk.Frame(root, bg="#f0f0f0")
frame.pack(padx=10, pady=10) # Place the frame and set padding
# Create a label inside the frame to display a text prompt
label = tk.Label(frame, text="Clipboard Contents:", bg="#f0f0f0")
label.grid(row=0, column=0) # Use the grid layout manager to place the label
# Create a scrollbar
scrollbar = tk.Scrollbar(root)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y) # Place the scrollbar on the right side of the window, filling in the Y direction
# Create a listbox to display clipboard content
listbox = tk.Listbox(root, width=150, height=150, yscrollcommand=scrollbar.set)
listbox.pack(pady=10) # Place the listbox and set vertical padding
scrollbar.config(command=listbox.yview) # Set the scrollbar to control the vertical scrolling of the listbox
# Call the function to start updating the listbox content
update_listbox()
# Bind the double-click left mouse button event to the copy_to_clipboard function to implement the double-click copy feature
listbox.bind("<Double-Button-1>", copy_to_clipboard)
# Run the main event loop, waiting for user interaction
root.mainloop()
- Code Quality Checker
We understand the importance of writing clean and efficient code—manually analyzing code quality can be a stressful task.
This automation script utilizes the Pylint and Flake8 Python packages for comprehensive code quality review.
# Import the os module for file and directory operations.
import os
# Import the subprocess module for executing external commands.
import subprocess
# Define the analyze_code function, accepting one parameter directory, which is the path of the directory to analyze.
def analyze_code(directory):
# List all files ending with .py in the directory, forming a list.
python_files = [file for file in os.listdir(directory) if file.endswith('.py')]
# If no Python files are found, output a prompt and return.
if not python_files:
print("No Python files found in the specified directory.")
return
# Iterate through the found Python files.
for file in python_files:
print(f"Analyzing file: {file}") # Print the name of the file being analyzed.
file_path = os.path.join(directory, file) # Get the full path of the file.
# Use pylint tool to analyze code quality.
print("\nRunning pylint...") # Prompt to start running pylint.
pylint_command = f"pylint {file_path}" # Construct the pylint command.
subprocess.run(pylint_command, shell=True) # Execute the command, shell=True allows running in the command line.
# Use flake8 tool to analyze code style.
print("\nRunning flake8...") # Prompt to start running flake8.
flake8_command = f"flake8 {file_path}" # Construct the flake8 command.
subprocess.run(flake8_command, shell=True) # Execute the command.
# If this script is run directly, rather than being imported into another script.
if __name__ == "__main__":
directory = r"C:\Users\abhay\OneDrive\Desktop\Part7" # Specify the directory to analyze.
analyze_code(directory) # Call the analysis function.