Advertisement
Python253

notepad_navigator

May 4th, 2024
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.90 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: notepad_navigator.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. This script provides a simple interface for interacting with Notepad windows on Windows operating systems.
  9. It allows users to move and resize Notepad windows to specific locations on the screen.
  10.  
  11. Requirements:
  12. - Python 3.x
  13. - Windows operating system
  14.  
  15. Functions:
  16. 1. move_and_resize_notepad():
  17.    - Prompts the user to select a cell location and then moves and resizes the Notepad window accordingly.
  18. 2. main_menu():
  19.    - Displays a menu for the user to choose options like moving and resizing Notepad or exiting the program.
  20.  
  21. Usage:
  22. To use this script, run it in a Python environment.
  23. Follow the on-screen instructions to choose options from the menu.
  24.  
  25. Additional Notes:
  26. - This script assumes that Notepad is available and accessible on the system.
  27. - It uses ctypes to interact with the Windows API for window manipulation.
  28. """
  29.  
  30. import subprocess
  31. import time
  32. import ctypes
  33. import ctypes.wintypes
  34.  
  35. # Define necessary Win32 API functions using ctypes
  36. screen = ctypes.windll.user32
  37.  
  38. # Function to move and resize Notepad
  39. def move_and_resize_notepad():
  40.     # Prompt user for cell selection
  41.     print("\nSelect a cell to move the Notepad window:\n")
  42.     print("\t\t |   |   |   |   |   |   | ")
  43.     print("\t\t-|---|---|---|---|---|---|-")
  44.     print("\t\t | T1| T2| T3| T4| T5| T6| ")
  45.     print("\t\t-|---|---|---|---|---|---|-")
  46.     print("\t\t | C1| C2| C3| C4| C5| C6| ")
  47.     print("\t\t-|---|---|---|---|---|---|-")
  48.     print("\t\t | B1| B2| B3| B4| B5| B6| ")
  49.     print("\t\t-|---|---|---|---|---|---|-")
  50.     print("\t\t |   |   |   |   |   |   |\n")
  51.     choice = input("Enter your choice (e.g., T3): ").upper()
  52.  
  53.     print("\nNotepad Co-Ordinates Have Been Set!\n")
  54.  
  55.     # Validate user choice
  56.     if (
  57.         len(choice) == 2
  58.         and choice[0] in ["T", "C", "B"]
  59.         and choice[1] in ["1", "2", "3", "4", "5", "6"]
  60.     ):
  61.         row = choice[0]  # Extract row (T, C, B)
  62.         col = int(choice[1]) - 1  # Extract column (1-based index)
  63.  
  64.         # Calculate position based on user choice
  65.         screen_width = screen.GetSystemMetrics(0)
  66.         screen_height = screen.GetSystemMetrics(1)
  67.         cell_width = screen_width // 6
  68.         cell_height = screen_height // 3
  69.  
  70.         if row == "T":          # TOP ROW
  71.             y = 0
  72.         elif row == "C":        # CENTER ROW
  73.             y = cell_height
  74.         elif row == "B":        # BOTTOM ROW
  75.             y = cell_height * 2
  76.  
  77.         x = col * cell_width
  78.         width = int(input("Enter the width of the Notepad window: "))
  79.         height = int(input("\nEnter the height of the Notepad window: "))
  80.  
  81.         print(
  82.             "\nNotepad Dimensions Have Been Set!\n\nOpening Notepad...\n\nMoving Notepad...\n"
  83.         )
  84.  
  85.         # Start Notepad
  86.         subprocess.Popen(["notepad.exe"])
  87.  
  88.         time.sleep(1)  # Wait for Notepad to open
  89.  
  90.         # Move and resize window
  91.         hwnd = screen.FindWindowW(None, "Untitled - Notepad")
  92.         if hwnd:
  93.             screen.SetWindowPos(hwnd, None, x, y, width, height, 0)
  94.             print("Moved and resized Notepad Successfully!\n\n\n\n")
  95.         else:
  96.             print("\nNotepad window not found!\n")
  97.  
  98.     else:
  99.         print("\nInvalid choice. Notepad window will not be moved!\n")
  100.  
  101. # Main menu
  102. def main_menu():
  103.     while True:
  104.         print("\n\n\n\n\t\t\t:: NOTEPAD NAVIGATOR ::\n")
  105.         print("\nChoose an option:\n")
  106.         print("1. Move and resize Notepad")
  107.         print("2. Exit")
  108.  
  109.         choice = input("\nEnter your choice: ")
  110.  
  111.         if choice == "1":
  112.             move_and_resize_notepad()
  113.         elif choice == "2":
  114.             print("\nExiting Program...\tGoodBye!\n\n")
  115.             break
  116.         else:
  117.             print("\nInvalid choice! Please enter a valid option.\n")
  118.  
  119. if __name__ == "__main__":
  120.     main_menu()
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement