Clipboard utilities for use with Python.
Project description
Description
Package for accessing the clipboard with Python.
Installation
pip install clip-util
Features
Windows Only
Allows you to set text, RTF, and HTML to the clipboard on Windows. Any other format can also be specified using the format type integer, specified by Windows.
Supported Clipboard Formats
- Text
- HTML
- RTF
Usage
Clipboard
Will open and close every time the values are set, or retrieved. It's better to use a context manager.
from clipboard import Clipboard
clipboard = Clipboard()
# Set Clipboard
clipboard['text'] = 'Hello World!'
# OR
clipboard.set_clipboard('Hello World!')
# Get Clipboard
text = clipboard['text']
# OR
text = clipboard.get_clipboard('text')
# Supports HTML
clipboard['html'] = '<h1>Hello World</h1>'
Context Manager
from clipboard import Clipboard
with Clipboard() as clipboard:
# Set Clipboard
clipboard['text'] = 'Hello World!'
# OR
clipboard.set_clipboard('Hello World!')
# Get Clipboard
text = clipboard['text']
# OR
text = clipboard.get_clipboard('text')
# HTML
clipboard['html'] = '<h1>Hello World</h1>'
Clipboard Formats
You can use clip-util
to access the clipboard formats directly.
ClipboardFormat
: Enum for clipboard formats.
ClipboardFormat.CF_HTML
: Represents HTML format.
ClipboardFormat.CF_RTF
: Represents RTF format.
from clipboard import Clipboard
from clipboard import ClipboardFormat
from clipboard import HTMLClipboard
with Clipboard() as clipboard:
# Get All Available Formats
format_ids: list[int] = clipboard.available_formats()
# Get Specific Format by ID
# Use parentheses to access the format
formats: list[ClipboardFormat] = []
for format_id in format_ids:
if format_id in ClipboardFormat:
format: ClipboardFormat = ClipboardFormat(format_id)
formats.append(format)
else:
# Format is not supported directly by this library
pass
# Get Specified Format by Name
# Use bracket notation to access the format
format_name: str
for format_name in [f.name for f in formats]:
if format_name in ClipboardFormat:
format: ClipboardFormat = ClipboardFormat[format_name]
name: str = format.name
else:
# Format is not supported directly by this library
pass
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
clip-util-0.1.19.tar.gz
(9.1 kB
view hashes)
Built Distribution
clip_util-0.1.19-py3-none-any.whl
(10.9 kB
view hashes)
Close
Hashes for clip_util-0.1.19-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e69cb7a085308327d6e4ab4948a9df8c025c8427de440b533e83cd16e148aab6 |
|
MD5 | eb645feb92c3d93fb46360b5e2364a87 |
|
BLAKE2b-256 | 581a7ad490dbbadc83b2f8933bdad2657c63b5f2ae07a4a2bd521f842a9f1f09 |