Usage¶
To use niceprint in a project
$ pip install niceprint
- exception niceprint.InvalidColor(*args, **kwargs)[source]¶
Bases:
Exception
Shows that the color is not accepted
- add_note()¶
Exception.add_note(note) – add a note to the exception
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class niceprint.MultiColoredPrint(*args, color: Iterable = '', bg: Iterable = '', delimiter=' ', time=0, lock: bool = True)[source]¶
Bases:
object
Prints words or text individually according to the given time and color
>>> from niceprint import MultiColoredPrint as MP >>> text = "Multiple Text" >>> MP(text, color=['c', 'g'])
Prints multiple text with multiple colors, different backgrounds and a special delimiter after each color.
- Parameters:
args (Iterable) – Items to print
color (str) – Foreground color
bg (str) – Background color
delimiter (str) – Character to print out after every item
time (int or float) – Time for each item
lock (bool) – If lock is true, there will be no access to the console till the printing is over.
- Raises:
InvalidColor – If color is invalid
- class niceprint.Percentage(max=100, fg='', bg='')[source]¶
Bases:
object
Creates a percentage class
>>> from niceprint import Percentage >>> pg = Percentage(10) >>> pg.tick() 0% >>> pg.fill(text = ['Starting...', 'Almost Done', 'Just a sec..'])
- Parameters:
max (int) – Maximum number
fg (str) – Foreground color
bg (str) – Background color
- Raises:
InvalidColor – If color is not accepted
- fill(time: Union[int, float] = 0, text: Union[str, list] = '')[source]¶
Increases the percentage value till the end with multiple or single text
- Parameters:
time (int or float) – Time between each increment in seconds
text (str or list or Tuple) – Items to print at the end of the bar
- Return type:
None
- class niceprint.Print(*text, fg=None, bg=None, time=0.03, lock=True, end='\n', format=False)[source]¶
Bases:
object
Print Letters individualy according to given time
>>> from niceprint import Print >>> Print("Hello",color="red",time=0.1)
Throws InvalidColor exception is the color is not in color list
To get the accepted colors
>>> from niceprint import Print >>> Print.get_colors()
Prints any amount of text with the given color and background.
- Parameters:
text (Iterable) – Items to print out. Can be anything iterable
fg (str) – Foreground color
bg (str) – Background color
lock (bool) – If lock is true, there will be no access to the console till the printing is over.
end (str) – Character to end with
format (bool) – If format is true, any item in @param ‘text’ that is a dict, will be formated with json.dumps with indent of 2
- Raises:
InvalidColor – If color is not in the color list
- colors = ['red', 'green', 'blue', 'magenta', 'black', 'yellow', 'cyan']¶
- class niceprint.ProgressBar(len=10, color='', bg='', char='#', **kwargs)[source]¶
Bases:
object
Creates a progress bar with the given length, color, background and character.
>>> from niceprint import ProgressBar as pb >>> progress = pb(color='c', bg='k') >>> progress.fill(ms=10) [# ]
- Parameters:
len (int) – Length of progress bar
color (str) – Foreground color
bg (str) – Background Color
char (str) – Character in bar
- Raises:
InvalidColor – If color is invalid
- fill(ms=10, sec=None, text='')[source]¶
Fill up the progress bar according to time. >>> from niceprint import ProgressBar as pb >>> progress = pb(2, ‘c’, ‘r’) >>> progress.fill(text = [‘One text’]) [# ] One text [##] One text >>> progress.empty() >>> progress.fill(text = [‘Text 1’, ‘Text 2’]) [# ] Text 1 [##] Text 2 :param int ms: Time between each pulse in milliseconds :param sec:Time between each pulse in seconds :type sec: int or float :param text: Items to print at the end of the bar :type text: str or list or tuple
- pulse(step=1, ms=1, sec=None, text: str = '')[source]¶
Increase the progress bar by amount of step and with a text :param int ms: Time between each pulse in milliseconds :param sec:Time between each pulse in seconds :type sec: int or float :param str text: Items to print at the end of the bar
- set_bgcolor(color) bool [source]¶
Sets the backgroun color of the char in the bar returns True if color has been set else False
- set_char(char, *args) bool [source]¶
Sets the character of the progress bar returns True if char has been set else False
- class niceprint.SetInterval(interval: Union[int, float], function, end: int = 1000, callback: Callable = None, show_progress: bool = False, req: bool = False, args: list = None, kwargs: dict = None)[source]¶
Bases:
object
Sets an interval for functions.
Creates an instance of SetInterval.
- Parameters:
interval (int or float) – time between intervals
function (Callable) – the function to call
end (int) – number of times to run
callback (Callable) – function to call after code run
show_progress (bool) – If to show a progress bar to indicate running #buggy
req (bool) – if to add self to the called function. usefull if function should cancel the interval
args (Iterable) – List of positional arguments
kwargs (dict) – List of named arguments
- Return type:
None
- Warning:
Asynchronous Thread. Does not wait.
- class niceprint.Spinner(fg='c', bg='', *args)[source]¶
Bases:
object
Creates a spinner
>>> from niceprint import Spinner >>> sp = Spinner() >>> sp.rotate()
- Parameters:
fg (str) – Foreground color
bg (str) – Background color
- Raises:
InvalidColor – If color is not accepted
- rotate(times: int = 5, time: int = 0.1, text: Union[str, list] = '')[source]¶
Rotates the spiner N(times) with a time interval of T(time)
- Parameters:
times (int) – Times to rotate
time (int or float) – Time between each turn in seconds
text (str or list or tuple) – Items to print at the end of the bar