pyplace (a place by percentage Python package)
Full definition:
Pyplace is a easy to use package to get the placement and dimensions of a child container base on the percentage given the size of a parent container and/or the relative origin of the child and parent containers.
In a few words definition:
A littler utility to stop remembering tons of numbers and start using percentages for containers size and placement.
Installation
Using the pip installer
$ python -m pip install pyplace
Using the offline installer or source code
- a. Download the .whl file from one of our release and run:
$ python -m pip install pyplace-file-name.whl
Been pyplace-file-name the name of the file downloaded.
- b. If you clone or download the .zip file and then extract it. the repo you just have to go to the repository path and run:
$ python setup.py install
Usage
from pyplace.pbd import *
Is the main package module it contains two methods get_container() and get_child_container() witch will be described in more details down below:
get_container(parent_size: tuple, percentages: tuple, origin: tuple = None)
"""Gets a new parent container base on the size and percentages given.
Args:
parent_size: The width and height size reference for the new parent container.
percentages: The width and height percentages to get the size for the new parent container.
(optional) origin: The x and y coordinates to place the new parent container.
Raises:
TypeError: If an argument variable was not send as a tuple.
Returns:
A Container class with the x, y, width and height values for the new parent container.
"""
get_child_container(parent_container: Container, size_percentages: tuple, place_percentages: tuple = (0,0))
"""Gets a new child container base on the parent container and size percentages given.
Args:
parent_container: The x, y, width and height value of the parent container.
size_percentages: The width and height percentages to get the size for the new child container.
(optional) place_percentages: The x and y percentages to get the placement for the new child container.
Raises:
TypeError: If an argument variable was not send as a tuple.
Returns:
A Container class with the x, y, width and height values for the new child container.
"""
Example:
# full screen window with a window container and four child containers.
from pyplace.pbp import get_container, get_child_container
# we assume the display resolution is 1280x720 for this example.
import pyautogui
# Returns: tuple(1280, 720)
screen_width, screen_height = pyautogui.size()
window = get_container(parent_size=(screen_with, screen_height), percentages=(1, 1))
# Returns: tuple(0, 0, 1280, 720)
window.get_dimensions()
upper_left_box = get_child_container(parent_container=window, size_percentages=(0.5, 0.5))
# Returns: tuple(0, 0, 640, 360)
upper_left_box.get_dimensions()
lower_left_box = get_child_container(parent_container=window, size_percentages=(0.5, 0.5), place_percentages=(0, 0.5))
# Returns: tuple(0, 360, 640, 360)
lower_left_box.get_dimensions()
upper_right_box = get_child_container(parent_container=window, size_percentages=(0.5, 0.5), place_percentages=(0.5, 0))
# Returns: tuple(640, 0, 640, 360)
upper_right_box.get_dimensions()
lower_right_box = get_child_container(parent_container=window, size_percentages=(0.5, 0.5), place_percentages=(0.5, 0.5))
# Returns: tuple(640, 360, 640, 360)
lower_right_box.get_dimensions()
This will create one parent (main target) and four children (relative to the main target) containers.
Container
when we call the get_container or get_child_container we get a Container instance that we can use for getting a tuple of single variables holding the size and placement information for the container we created.
here are the attributes and method we get on this class:
# attribute list.
__x # the container x position.
__y # the container x position.
__width # the container width size.
__height # the container height size.
# method list.
get_x() # returns the x value for the container.
x(x: int) # sets the x value for the container.
get_y() # returns the y value for the container.
y(y: int) # sets the y value for the container.
get_placement() # returns a tuple with the x and y of the container.
placement(x: int, y: int) # sets the x and y of the container.
get_width() # returns the width value for the container.
width(width: int) # sets the width value for the container.
get_height() # returns the height value for the container.
height(height: int) # sets the height value for the container.
get_size() # returns a tuple with the width and height of the container.
size(width: int, height: int) # sets the width and height of the container.
get_dimensions() # returns a tuple with the x, y, width and height of the container.
dimensions(x: int, y: int, width: int, height: int) # sets the x, y, width and height of the container.
Metadata
Release files for pyplace 0.6.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyplace-0.6.11.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyplace-0.6.11-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.1 kB
Release files / pyplace-0.6.11.tar.gz
| Download URL | pyplace-0.6.11.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3880a3463d40b5fa12c921bd74b8b8b9b48fc955d5e48325e448d877601a82b5
|
|
BLAKE2b-256 checksum How to use checksums |
ff1ae2cdf200e533a90db9aed42afe516de22209fa16cc06db0967b95a303c9a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5
|
Release files / pyplace-0.6.11-py3-none-any.whl
| Download URL | pyplace-0.6.11-py3-none-any.whl |
|---|---|
| Size | 18.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a742afb37cd8c6cb7670be73e6eed89160d5c03b0af5ea70730121dc9860e1d5
|
|
BLAKE2b-256 checksum How to use checksums |
9e7d7f73abeb1a8c4ebcd7cc9c3975e4ddb696d492bf56fa9bd25367d9fc7ff6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5
|