Skip to main content

pyTGR3

A minimal lib for rendering things on Terminal.

Installation

Install pyTGR with pip

  pip install pyTGR

Features

  • Cross platform (i think).
  • Loading animations.
  • Print Image / Video on terminal.
  • Key Events
  • Terminal Events (like when the terminal is resized and the cursor position changes).
  • Print History.
  • And some Terminal related functions.
  • Examples provided.

Usage/Examples

import pyTGR
renderer = pyTGR.pyTGR()

Terminal Related Functions:

    def set_bg(self, bg):
             """
        For setting the bg color.
        :param bg: rgb color code
        :return: None
        """
    def get_terminal_size(self):
          """
        Returns the terminal size ,[cols , lines]
        :return: Size [ cols , lines ]
        """
    def set_cursor(self, x, y):
          """
        Move the terminal cursor to a given position.
        :param x: x - position.
        :param y: y - position.
        :return: None
        """
    def get_cursor_pos(self):
        """
        Returns the position of the cursor.
        :return: Position
        """
    def clear_terminal(self):
           """
        Used for clearing the terminal.
        :return: None
        """
    def close_terminal(self):
          """
        Used to close the terminal.
        :return: None
        """

Printing Related Functions:

    def print(self, data, end="\n"):
        """
        Prints str
        :param data: str , the str to be printed.
        :param end: The end param for printing. By default '\n'
        :return: None
        """
    def text(self, text, fg_, bg_):
        """
        Print Text , with fg and bg color.
        :param text:Text to be printed.
        :param fg_: Foreground color rgb.
        :param bg_: Background color rgb.
        :return: None
        """
    def new_row(self):
        """
        Move to a new row.
        :return: None
        """
    def updating_text(self, txt, color=[255, 255, 255], bg_=[0, 0, 0]):
        """
        A text which can be changed.
        :param txt: Primary text.
        :param color: Foreground color rgb.
        :param bg_: Background color rgb.
        :return: None
        """
    def fixed_text(self, txt, bg_, fg_, x, y):
        """
        Text which can be fixed a position , and doesn't get removed by the clear func.
        :param txt: Test to be saved.
        :param bg_: background color rgb.
        :param fg_: foreground color rgb.
        :param x: x - position.
        :param y: y - position.
        :return: None
        """
    def remove_fixed_text(self, txt):
        """
        To remove a text from fixed texts.
        :param txt: The text which is to be removed.
        :return: None
        """
        ```

Drawing Related Functions:
```python
    def draw_vertical_pixel(self, color):
        """
        Print a pixel , vertically.
        :param color: Color of the pixel , rgb .
        :return: None
        """
    def draw_horizontal_pixel(self, color):
        """
        Print a pixel , horizontally.
        :param color: Color: Color of the pixel , rgb .
        :return: None
        """
    def draw_pixel(self, x, y, color):
        """
        Print a pixel , at a given position.
        :param x: x - position.
        :param y: y - position.
        :param color: Color of the pixel.
        :return: None
        """
    def draw_line(self, x, y, width, color):
        """
        To draw a line.
        :param x: x  - position
        :param y: y - position
        :param width: width of the line.
        :param color: Color of the line , rgb.
        :return: None
        """
    def draw_circle(self, diameter, color):
        """
        To draw a circle.
        :param diameter: The diameter of the circle.
        :param color: color of the circle , rgb.
        :return: None
        """
    def draw_rect(self, x, y, width, height, color, filled=True):
        """
        To draw rectangle.
        :param x: x - position.
        :param y: y - position.
        :param width: width of the rectangle.
        :param height: height of the rectangle.
        :param color: color of the rectangle , rgb.
        :param filled: If the rectangle should be filled. (optional)
        :return: None
        """

Event Related Functions:

    def init_terminal_events(self, function):
        """
        To monitor Terminal events.
        Types of events:
            change in size: size
            change in cursor position : cursor
        :param function: A function which will be called on events ,event will be passed as an argument.
        :return: None
        """
    def init_keyboard(self, on_press):
        """
        To monitor Keyboard events.
        :param on_press: The function to be called if a key is pressed ,key will be passed as an argument.
        :return: None
        """
# pyTGR.Key returns the keys
# This can be seen in the example given (square movement)

Loading Animations:

    def spinning_animation_bars(self, revolutions, delay, side_text=" Loading...", color=[255, 255, 255]):
        """
        Animation : spinning - 1.
        :param revolutions: Times.
        :param delay: The delay between the change of each symbol.
        :param side_text: The text about the animation.
        :param color: The color of the bars in rgb.
        :return: None
        """
    def spinning_animation(self, delay, revolutions, side_text=" Loading...", color=[255, 255, 255]):
        """
        Animation : spinning - 2.
        :param delay: The delay between the change of each symbol.
        :param revolutions: Times.
        :param side_text: The text about the animation.
        :param color: The color of the symbols in rgb.
        :return: None
        """
    def bar_animation(self, delay, len_, color_1=[47, 152, 237], color_2=[96, 96, 97],
                      finished_text="Finished Loading..."):
        """
        Animation : Bar
        :param delay: Delay between each bar.
        :param len_: Number of bars.
        :param color_1: Color in rgb.
        :param color_2: color in rgb.
        :param finished_text: The text on finishing.
        :return: None
        """
   def strip_animation(self, duration, strips, finished_text="Loaded...", color=[255, 255, 255]):
        """
        Animation - Strip.
        :param duration: delay between each strip.
        :param strips: number of strips.
        :param finished_text: The text on finishing.
        :param color: color of the strips.
        :return: None
        """
    def loading_percentage(self, delay, max_percent=100, color=[255, 255, 255]):
        """
        Animation - progressive.
        :param delay: The delay between each progress.
        :param max_percent: The max. (optional)
        :param color: The color of the loader. (optional)
        :return: None
        """

Image/Video Functions:

    def print_img_color(self, file, print_size=2, resize_img=None, print_img=True):
        """
        For printing a img.
        :param file: File name.
        :param print_size: The size of the print. (optional)
        :param resize_img: The size to which the image have to be resized. (optional)
        :param print_img: If you want to print the image. (optional)
        :return: Image_string
        """
    def play_video_color(self, path, frame_delay=0.09, size=None, reduce_by=None):
        """
        Play video.
        :param path: The path of the video.
        :param frame_delay: The delay between each frame, int. (optional)
        :param size: The of the video played. (optional)
        :param reduce_by: The ratio by which the video size should be reduced. (optional)
        :return: None
        """
    def play_video_ascii(self, path, frame_delay=0.09, size=None):
        """
        To play a video in ascii form.
        :param path: The path of the video.
        :param frame_delay: The delay between each frame, int. (optional)
        :param size: The size of the video played. (optional)
        :return: None
        """
    def print_image_ascii(self, path, size=None, print_=True):
        """
        Print an image as ascii.
        :param path: The path of the image.
        :param size: The size of the image to be printed in.(optional)
        :param print_: The printing of image , bool.(optional)
        :return: The ascii image.
        """

Terminal History:

This Feature can be used to get what all have been printed in the terminal before , delete it , update it with new bg.. This will only work if you replace the real print statement with the print statement provided by the pyTGR class.

    def clear_history(self):
        """
        Clears the History of Terminal.
        :return: None
        """
    def update_from_history(self):
        """
        Refresh the terminal's bg. Uses the data stored in Terminal History.
        :return: None
        """
# pyTGR.term_history , can be used to access the terminal history.

Examples Provided:

Examples are provided in the Examples class.

License

MIT

Authors

Release files for pyTGR 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyTGR 2.0.1
File Size Uploaded
pyTGR-2.0.1.tar.gz 10.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyTGR 2.0.1
File Interpreter ABI Platform
pyTGR-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 19.9 kB

Release files / pyTGR-2.0.1.tar.gz

Download URL pyTGR-2.0.1.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b8fbe81183451e566e38e3223d67731ada0713a4c301c215eb930abcc70a9672
BLAKE2b-256 checksum
How to use checksums
f3713f08b947158f1b1391ec1f67bab39ae2726d64af1923e055615687bab9ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

Release files / pyTGR-2.0.1-py3-none-any.whl

Download URL pyTGR-2.0.1-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3060b6100049e9bbad52c667202066bba783a5393b09c664fa8bfd3ed6bbe261
BLAKE2b-256 checksum
How to use checksums
b4b7ad0671b5b09c5c68cbe6d7183c217dcbc3d8fce509314c8961598d46f532
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page