A littler utility to stop remembering tons of numbers and star using percentages for containers size and placement.
Project description
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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyplace-0.6.11.tar.gz.
File metadata
- Download URL: pyplace-0.6.11.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3880a3463d40b5fa12c921bd74b8b8b9b48fc955d5e48325e448d877601a82b5
|
|
| MD5 |
68ca7f7d87f6a0c42121ee29af51f25a
|
|
| BLAKE2b-256 |
ff1ae2cdf200e533a90db9aed42afe516de22209fa16cc06db0967b95a303c9a
|
File details
Details for the file pyplace-0.6.11-py3-none-any.whl.
File metadata
- Download URL: pyplace-0.6.11-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a742afb37cd8c6cb7670be73e6eed89160d5c03b0af5ea70730121dc9860e1d5
|
|
| MD5 |
3db1ee407b199367452f6402585c9f29
|
|
| BLAKE2b-256 |
9e7d7f73abeb1a8c4ebcd7cc9c3975e4ddb696d492bf56fa9bd25367d9fc7ff6
|