### Install PyShortcuts with GUI Support Source: https://newville.github.io/pyshortcuts/install.html Install PyShortcuts with the '[gui]' extra to include the wxPython package, enabling the graphical user interface. This command also installs the base package and its dependencies. ```bash pip install "pyshortcuts[gui]" ``` -------------------------------- ### Launch the pyshortcut GUI Source: https://newville.github.io/pyshortcuts/pyshortcut_app.html If wxPython is installed, you can launch a graphical interface for creating shortcuts using this command. ```bash ~> pyshortcut --wxgui ``` -------------------------------- ### Install PyShortcuts Source: https://newville.github.io/pyshortcuts/install.html Use this command to install the PyShortcuts package. It automatically installs required dependencies like charset-normalizer and pywin32 on Windows. ```bash pip install pyshortcuts ``` -------------------------------- ### pyshortcut Command-Line Usage Source: https://newville.github.io/pyshortcuts/pyshortcut_app.html Examples and syntax for using the pyshortcut command-line program to create desktop shortcuts. ```APIDOC ## pyshortcut Command-Line Program ### Description Creates desktop shortcuts for Python scripts. ### Method Command-line execution ### Endpoint `pyshortcut` ### Parameters #### Command-line Arguments - **-h, --help** (flag) - Show help message and exit. - **-v, --version** (flag) - Show program's version number and exit. - **-n NAME, --name=NAME** (string) - Name for the shortcut. - **-i ICON, --icon=ICON** (string) - Path to the icon file for the shortcut. - **-f FOLDER, --folder=FOLDER** (string) - Subfolder on the desktop to place the shortcut. - **-e EXE, --executable=EXE** (string) - The executable to use (defaults to 'python'). - **-t, --terminal** (flag) - Run the script in a Terminal Window (default: True). - **-g, --gui** (flag) - Run the script as a GUI, without a Terminal Window (default: False). - **-d, --desktop** (flag) - Create a desktop shortcut (default: True). - **-s, --startmenu** (flag) - Create a Start Menu shortcut (default: True). - **-w, --wxgui** (flag) - Run the GUI version of pyshortcut. - **-b, --bootstrap** (flag) - Create a desktop shortcut to run the GUI version of pyshortcut. - **scriptname** (string) - The name of the script to create a shortcut for. Arguments to the script can be included by enclosing the script name and arguments in quotes. ### Request Example ```bash ~> pyshortcut -n MyApp -i /home/user/icons/myicon.icns /home/user/bin/myapp.py ``` ### Request Example with Arguments ```bash ~> pyshortcut -n MyApp -i /home/user/icons/myicon.icns "/home/user/bin/myapp.py -t 10" ``` ### Response This command-line tool does not return a structured response. It creates shortcuts on the file system. ``` -------------------------------- ### Get ISO formatted time Source: https://newville.github.io/pyshortcuts/utilities.html Provides a shorthand for generating ISO format timestamps. ```python from datetime import datetime def isotime(dtime=None, timepec='seconds', sep=' '): """return ISO format of current timestamp: 2024-04-27 17:31:12 """ if dtime is None: dtime = datetime.now() return datetime.isoformat(dtime, timespec=timespec, sep=sep) ``` -------------------------------- ### Get current working directory Source: https://newville.github.io/pyshortcuts/utilities.html Shorthand for resolving the current working directory as a POSIX-style path. ```python pathlib.Path('.').resolve().as_posix() ``` -------------------------------- ### Fix wxPython GUI display issue on macOS with Anaconda Source: https://newville.github.io/pyshortcuts/pyshortcut_app.html If your wxPython application does not start on macOS with Anaconda Python, add this code to your script before starting the mainloop. ```python import wx wx.PyApp.IsDisplayAvailable = lambda _: True ``` -------------------------------- ### Get home directory Source: https://newville.github.io/pyshortcuts/utilities.html Resolves the user's home directory, accounting for SUDO_USER on POSIX and using win32com on Windows. ```python pathlib.Path.home().resolve().as_posix() ``` -------------------------------- ### pyshortcut GUI Application Source: https://newville.github.io/pyshortcuts/pyshortcut_app.html Instructions on how to launch and use the graphical user interface for creating shortcuts. ```APIDOC ## The pyshortcut GUI ### Description A graphical user interface application that simplifies the process of creating shortcuts. ### Method Command-line execution ### Endpoint `pyshortcut --wxgui` ### Usage Launch the GUI by running the command `pyshortcut --wxgui` in your terminal. This requires the wxPython package to be installed. ### Bootstrap Option To create a desktop shortcut that launches the pyshortcut GUI itself: ```bash ~> pyshortcut --bootstrap ``` This command creates a shortcut with a ladder icon that, when clicked, will launch the pyshortcut GUI. ### Request Example (Bootstrap) ```bash ~> pyshortcut --bootstrap ``` ### Response This command creates a shortcut file on the desktop. The `--bootstrap` command internally uses Python code to generate this shortcut: ```python #!/usr/bin/env python import os import sys from pyshortcuts import make_shortcut, platform bindir = 'Scripts' if platform.startswith('win') else 'bin' pyshortcut = os.path.normpath(os.path.join(sys.prefix, bindir, 'pyshortcut')) scut = make_shortcut(f"{pyshortcut:s} --wxgui", name='PyShortcut', terminal=False) ``` ``` -------------------------------- ### make_shortcut() Source: https://newville.github.io/pyshortcuts/genindex.html Documentation for the make_shortcut function used to generate desktop shortcuts. ```APIDOC ## make_shortcut() ### Description A built-in function provided by the PyShortcuts library to create desktop shortcuts for Python scripts. ### Method Function Call ### Parameters - **script_path** (string) - Required - The path to the Python script for which the shortcut is being created. - **name** (string) - Optional - The name of the shortcut to be created on the desktop. ``` -------------------------------- ### Create a bootstrap shortcut for the pyshortcut GUI Source: https://newville.github.io/pyshortcuts/pyshortcut_app.html This command creates a desktop shortcut with a ladder icon that launches the pyshortcut GUI application. ```python #!/usr/bin/env python import os import sys from pyshortcuts import make_shortcut, platform bindir = 'Scripts' if platform.startswith('win') else 'bin' pyshortcut = os.path.normpath(os.path.join(sys.prefix, bindir, 'pyshortcut')) scut = make_shortcut(f"{pyshortcut:s} --wxgui", name='PyShortcut', terminal=False) ``` -------------------------------- ### Create a basic shortcut using pyshortcut Source: https://newville.github.io/pyshortcuts/pyshortcut_app.html Use this command to create a desktop shortcut for a Python script. Specify the shortcut name, icon, and the script path. ```bash ~> pyshortcut -n MyApp -i /home/user/icons/myicon.icns /home/user/bin/myapp.py ``` -------------------------------- ### Create Shortcut from Command Line Source: https://newville.github.io/pyshortcuts/python.html Create a shortcut for a Python command directly from the command line using the `pyshortcut` utility. This provides a quick way to create shortcuts without writing a Python script. ```bash ~> pyshortcut -n "Update Pyshortcuts" "_ -m pip install pyshortcuts" ``` -------------------------------- ### Create Desktop Shortcut for a Python Script Source: https://newville.github.io/pyshortcuts/python.html Use `make_shortcut` to create a shortcut for a Python script. Specify the script path, shortcut name, and optionally an icon file. ```python from pyshortcuts import make_shortcut make_shortcut('/home/user/bin/myapp.py', name='MyApp', icon='/home/user/icons/myicon.ico') ``` -------------------------------- ### Create a shortcut with script arguments using pyshortcut Source: https://newville.github.io/pyshortcuts/pyshortcut_app.html To include command-line options for the script, enclose the script name and its arguments in double quotes. ```bash ~> pyshortcut -n MyApp -i /home/user/icons/myicon.icns "/home/user/bin/myapp.py -t 10" ``` -------------------------------- ### wxPython GUI Note for macOS Source: https://newville.github.io/pyshortcuts/pyshortcut_app.html A specific note for users encountering issues running wxPython GUIs with Anaconda Python on macOS. ```APIDOC # Note for running wxPython GUIs on macOS with Anaconda Python ### Description Addresses potential issues when running wxPython applications with Anaconda Python on macOS, specifically the "This program needs access to the screen" error. ### Solution If you encounter the error message: ``` ~> python my_wxpython_app.py This program needs access to the screen. Please run with a Framework build of python, and only when you are logged in on the main display of your Mac. ``` Add the following lines to your Python script before starting the wxPython mainloop: ```python import wx wx.PyApp.IsDisplayAvailable = lambda _: True ``` This workaround allows your wxPython application to run correctly under these specific conditions. ``` -------------------------------- ### Create Shortcut for a Single Python Command Source: https://newville.github.io/pyshortcuts/python.html Wrap a single Python command in a shortcut. Use `_` or `{}` to indicate the current Python executable. This is useful for commands like upgrading packages. ```python import sys from pyshortcuts import make_shortcut pycmd = "_ -m pip install --upgrade pyshortcuts" make_shortcut(pycmd, name='Update Pyshortcuts') ``` -------------------------------- ### make_shortcut() Function Source: https://newville.github.io/pyshortcuts/python.html The `make_shortcut` function is the primary way to create shortcuts from within a Python script. It offers various parameters to customize the shortcut's behavior and appearance. ```APIDOC ## Python Function: make_shortcut ### Description Creates a desktop shortcut for a given script or command. ### Parameters #### Path Parameters * **script** (string) - Required - Path to the script, can include command-line arguments. * **name** (string or None) - Optional - The display name for the shortcut. Defaults to the script name. * **description** (string or None) - Optional - A longer description for the script. Defaults to the script name. * **icon** (string or None) - Optional - Filename for the shortcut's icon. Defaults to the Python icon. * **working_dir** (string or None) - Optional - The directory from which the script should be run. * **folder** (string or None) - Optional - Name of a subfolder on the Desktop for the shortcut. See Note 1. * **terminal** (bool) - Optional - Whether the shortcut should run in a terminal window. Defaults to True. * **desktop** (bool) - Optional - Whether to add the shortcut to the Desktop. Defaults to True. * **startmenu** (bool) - Optional - Whether to add the shortcut to the Start Menu. Defaults to True (except on macOS). * **executable** (string or None) - Optional - The executable to use for running the script. Defaults to the current Python executable. See Note 3. * **noexe** (bool) - Optional - If True, the script itself is the entire command, without an explicit executable. Defaults to False. ### Notes 1. The `folder` parameter allows organizing shortcuts into subfolders on the Desktop and/or Start Menu. 2. The Start Menu is not available on Darwin (macOS). 3. The `executable` parameter defaults to the Python executable used to create the shortcut. ### Request Example ```python from pyshortcuts import make_shortcut # Create a shortcut for a Python script make_shortcut('/home/user/bin/myapp.py', name='MyApp', icon='/home/user/icons/myicon.ico') # Create a shortcut for a Python command pycmd = "_ -m pip install --upgrade pyshortcuts" make_shortcut(pycmd, name='Update Pyshortcuts') ``` ``` -------------------------------- ### Debug runtime of code sections Source: https://newville.github.io/pyshortcuts/utilities.html Tracks and reports incremental execution times for specific sections of code. ```python import numpy as np from pyshortcuts import debugtimer, sleep SHOW_TIMING = True dtimer = debugtimer('test timer', precision=4) sleep(0.50) dtimer.add('slept for 0.500 seconds') nx = 10_000_000 x = np.arange(nx, dtype='float64')/3.0 dtimer.add(f'created numpy array len={nx}') s = np.sqrt(x) dtimer.add('took sqrt') if SHOW_TIMING: dtimer.show() ``` -------------------------------- ### Format floating point numbers Source: https://newville.github.io/pyshortcuts/utilities.html Converts floats to strings with fixed length and maximized precision, useful for table formatting. ```python >>>from pyshortcuts import gformat >>> gformat(1023/78, length=11) ' 13.1153846' >>> gformat(10.2, length=11) ' 10.2000000' >>> gformat(-1/732023, length=11)) '-1.36608e-6' >>> gformat(-1/732023, length=15) '-0.000001366077' >>> gformat(6/80030, length=7) ' 7.5e-5' ``` -------------------------------- ### High-precision sleep Source: https://newville.github.io/pyshortcuts/utilities.html Implements a more accurate sleep function using a busy-wait loop with perf_counter. ```python def sleep(duration): "more accurate sleep()" end = perf_counter() + duration while perf_counter() < end: pass ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.