Skip to main content

A Python module to bridge with Windows PowerShell for native GUI elements.

Project description

PyPwsh - Python and PowerShell GUI Bridge

PyPI Version License Python Version

pypwsh.py is a Python module that leverages Windows PowerShell and XAML/WPF/WinForms to provide simple, native Windows graphical user interface (GUI) elements like dropdown menus, file selectors, and folder browsers. This allows Python scripts to easily integrate rich user input without requiring external Python GUI libraries.


Prerequisites and Setup

This project can be used with embeddable Python distribution as well for portability. You may download a copy from this project's github homepage.

1. Requirements

  • Windows PowerShell: Available by default on all modern Windows operating systems, it is used by the script to run the GUI functions.

2. Environment Setup

To run pypwsh.py from any location, the directory containing the Python executable (python.exe) must be added to the USER's PATH environment variable. The script will automatically find the system's default PowerShell executable.

Component Path to Add to User PATH
Python Executable The full absolute path to the _pyemb folder.

Steps to Update User Path:

  1. Locate the Path: Navigate to your project folder and find the _pyemb subdirectory inside rose_core. Copy the full absolute path to this folder (e.g., D:\MyProjects\pypwsh_repo\rose_core\_pyemb).
  2. Open Environment Variables: Search for and open "Edit the system environment variables", then click the "Environment Variables..." button.
  3. Edit User Path:
    • Under the "User variables for [username]" section, select the variable named Path.
    • Click "Edit...".
  4. Add Python Path:
    • In the Edit window, click "New".
    • Paste the full absolute path you copied in Step 1.
  5. Save Changes: Click "OK" on all open windows.
  6. Verification: Open a new Command Prompt or PowerShell window and type python --version to confirm Python runs correctly.

Module API Reference

The module contains the following functions, all of which execute a temporary PowerShell script to display a GUI and return the user's selection to the Python caller.

pypwsh_dropdown()

Displays an editable dropdown list box populated with a list of options.

Parameter Type Default Description
options_list list ["", "Rose", "Tulip"] The list of strings to populate the dropdown.
allowBlankSubmission bool True If False, the user cannot confirm an empty string.
removeBlankEntriesFromList bool False Removes "" entries from the initial list display.
allowEditingListItems bool True Allows the user to edit a selected item before confirming.
Returns str "" The confirmed string selection.

Example Usage

from pypwsh import pypwsh_dropdown

# Example 1: Editable list with blank submissions allowed
chosen_item = pypwsh_dropdown(
    options_list=["", "Task A", "Task B", "Task C"],
    allowBlankSubmission=True,
    allowEditingListItems=True
)
print(f"Chosen Item: {chosen_item}")

# Example 2: Non-editable list, blank entries removed
chosen_color = pypwsh_dropdown(
    options_list=["Red", "", "Green", "Blue"],
    removeBlankEntriesFromList=True,
    allowEditingListItems=False
)
print(f"Chosen Color: {chosen_color}")

pypwsh_filebrowse()

Displays a graphical file selection dialog.

Parameter Type Default Description
initial_path str "" A starting directory or file path to populate the text box.
filter str `"All Files (.) ."`
title str "Select a File" The title for the file selection window.
Returns str "" The full path to the selected file, or an empty string on error/cancel.

Example Usage

from pypwsh import pypwsh_filebrowse
import os

# Example 1: Select a specific file type, starting in the user's home directory
home_path = os.path.expanduser("~")
selected_file = pypwsh_filebrowse(
    initial_path=home_path,
    filter="Excel Files (*.xlsx)|*.xlsx|CSV Files (*.csv)|*.csv",
    title="Choose a Data File"
)
print(f"Selected File Path: {selected_file}")

pypwsh_folderbrowse()

Displays a graphical folder selection dialog.

Parameter Type Default Description
initial_path str "" A starting directory path to populate the text box.
description str "Select a Folder" The description text for the dialog window.
title str "Folder Browser" The title for the folder selection window.
Returns str "" The full path to the selected folder, or an empty string on error/cancel.

Example Usage

from pypwsh import pypwsh_folderbrowse

# Example 1: Select a destination folder
selected_folder = pypwsh_folderbrowse(
    initial_path="C:\\Temp",
    description="Please select the destination directory for output logs.",
    title="Log File Destination"
)
print(f"Selected Folder Path: {selected_folder}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypwsh-0.1.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypwsh-0.1.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file pypwsh-0.1.1.tar.gz.

File metadata

  • Download URL: pypwsh-0.1.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for pypwsh-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d4ff4fe2d817efd59d3a55370b91c610133c1403b271fe8e6b954d493daecab4
MD5 0cb314c37833c14f2bb61d6fb3292463
BLAKE2b-256 ce29fa142edcd46c6c4bcafa143bf3f673a9f09c41b1e0ac133e6b5b8e476c5e

See more details on using hashes here.

File details

Details for the file pypwsh-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pypwsh-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for pypwsh-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 accfd5972ff62d6ee928a20060d3293b64fbac4c7d4f74c695321b3e2c46048c
MD5 8d9054b96c53973c31bd0be8e3fec886
BLAKE2b-256 9a8feb8afe1ac9cd96ccedab4ddfca2a4a7b7909bfac947dfa52b00e750ce241

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page