Complete documentation¶
All the internals functions for those who wants to contribute
Types¶
This file contains the types Configuration, Color and Text_size
- casioplot.types.Color¶
A color is represented as a tuple of three integers, each integer is in the range [0, 255] and represents the intensity of the color in the red, green and blue channels respectively.
alias of
tuple[int,int,int]
- class casioplot.types.Configuration¶
Bases:
TypedDictThe type
Configurationmakes it possible to representing all settings and configs in a dictionary but still have type annotations for every setting.- background: str¶
- bg_in_use: bool¶
- bottom: int¶
- close_window: bool¶
- correct_colors: bool¶
- debuging_messages: bool¶
- height: int¶
- image_format: str¶
- image_name: str¶
- left: int¶
- right: int¶
- save_multiple: bool¶
- save_rate: int¶
- save_screen: bool¶
- show_screen: bool¶
- top: int¶
- width: int¶
- casioplot.types.Text_size¶
The three accpeted text sizes
alias of
Literal[‘small’, ‘medium’, ‘large’]
Characters¶
Contains every character in the three sizes,
It’s main function is to store all the character maps.
Every size has it’s one dictionary there is a key for every character and the values are tuples of strings that represent the character in a sort of character map, every string corresonds to a row.
- casioplot.characters._get_char(char: str, size: Literal['small', 'medium', 'large'] = 'medium') tuple¶
Gets the char_map of a character in a given size
Gets the character from the dictionaries, serves as an interface for
casioplot.pyto get the characters it needs- Parameters:
char – The character
size – The size of the character
- Returns:
A tuple of string that represent the character
- Raises:
ValueError – If the character is not implemented for the given size
- casioplot.characters._size_to_dict¶
A dictionary that maps the size of the font to the font dictionary
- casioplot.characters.large¶
The large font dictionary. This dictionary contains the large font characters.
- casioplot.characters.medium¶
The medium font dictionary. This dictionary contains the medium font characters.
- casioplot.characters.small¶
The small font dictionary. This dictionary contains the small font characters.
Settings¶
Takes care of the settings
Finds the configs files, gets the settings from them and check settings
for wrong settings and config files.
If any of the checks fails the program is terminated.
casioplot.py imports the _settings object from this file.
_settings contains values for every setting defined in the class Configuration.
(see types.py for more details about Configuration)
- casioplot.settings._check_setting(section: str, setting: str) None¶
Checks individual settings
- casioplot.settings._check_settings(config: Configuration) None¶
Checks if all settings have a value, have the correct type of data and have a proper value.
Also checks the margins if there is a background image.
- Parameters:
config – The settings to be checked
- casioplot.settings._check_toml(toml: dict) None¶
Checks for wrong settings and section in the toml
_check_settings()doesn’t notice this type of error because_get_configuration_from_file()doesn’t read them, so they aren’t part of the config return by_get_configuration_from_file()
- casioplot.settings._closest_strings(original: str, options: tuple[str, ...]) tuple[str, ...]¶
Return all string of the tuple :param options: that have an edit distance from :param original: less than max_edit_distance. It uses the Damerau-Levenshtein edit distance algorithm
- casioplot.settings._get_configuration_from_file(file_path: str) tuple[Configuration, str]¶
Gets the configuration and the default file pointer of a config file from its path
Preset configuration files like
default.tomlhave no default file pointer- Parameters:
file_path – The full path of the config file
- Returns:
A tuple with the configuration and the default file pointer
- casioplot.settings._get_file_from_pointer(pointer: str) str¶
Translates a default file pointer into a full path for the config file
- Parameters:
pointer – The default file pointer, it must be in the format
global/file_nameorpresets/file_name- Returns:
The full path of the config file
- casioplot.settings._get_first_config_file() str¶
Get the most ‘custom’ configuration file
This function returns the most ‘custom’ configuration file in the following order:
casioplot_config.tomlfile in the directory of the project that is usingcasioplotThe first toml file in
~/.config/casioplotdirectory in alphabetical orderThe default configuration file,
casioplot/presets/default.toml
- Returns:
The full configuration file path
- casioplot.settings._get_image_path(bg_image_setting: str) str¶
Translates the
setting["background"]to the full path for the image- Parameters:
bg_image_setting – The value of the setting
setting["background"]- Returns:
The full path of the image
- casioplot.settings._get_settings() Configuration¶
Gets the settings from config files and makes sure that they are correct
See
Configurationfor more details about the settings format that it returns Seepresets/default.tomlfor the default settings and explanations- Returns:
The settings, checked and ready to be used
- casioplot.settings._join_configs(config: Configuration, default_config: Configuration)¶
Adds settings from
default_configtoconfigif they are missing formconfig- Parameters:
config – The current config, the one that will raise an error during the checks
default_config – The configuration from a default file
- casioplot.settings._settings: Configuration¶
The settings used by the package
Casioplot¶
Contains all the functions from casioplot calculator module.
- Available functions for the user:
Contains the original functions from the casioplot calculator module
and the code needed to emulate the screen.
- casioplot.casioplot._BLACK: tuple[int, int, int] = (0, 0, 0)¶
RGB black
- casioplot.casioplot._WHITE: tuple[int, int, int] = (255, 255, 255)¶
RGB white
- casioplot.casioplot._current_image_number = 1¶
The number of the current image that is being saved
- casioplot.casioplot._debuging_color(color: tuple[int, int, int], function: str) None¶
Prints a message telling if the color is valid
Used by the functions set_pixel or draw_string It is only called if the setting
debuging_messagesis true- Parameters:
color – The color of a pixel
function – the function that called this function
- casioplot.casioplot._debuging_coordinates(x: int, y: int, function: str) None¶
Prints a message telling if the coordinates are out of bounds
Used by the functions set_pixel, get_pixel or draw_string It is only called if the setting
debuging_messagesis true- Parameters:
x – x coordinate (from the left)
y – y coordinate (from the top)
function – the function that called this function
- casioplot.casioplot._run_at_exit() None¶
This function should be called at the end of the program to close the tkinter window
- casioplot.casioplot._save_screen(image_suffix: str = '') None¶
Saves the virtual screen as an image
Only used by the function
show_screen()- Parameters:
image_suffix – The setting
save_multipleis True needs to create images with the namecasioplot2.pngfor example
- casioplot.casioplot._save_screen_counter = 1¶
Counter used to save multiple images of the screen
- casioplot.casioplot._screen_dimensions() tuple[int, int]¶
Calculates the dimensions of the screen in pixels
- casioplot.casioplot.clear_screen() None¶
Clear the canvas, sets every pixel to white
- casioplot.casioplot.draw_string(x: int, y: int, text: str, color: tuple[int, int, int] = (0, 0, 0), size: Literal['small', 'medium', 'large'] = 'medium') None¶
Draw a string on the canvas with the given RGB color and size.
- Parameters:
x – x coordinate (from the left)
y – y coordinate (from the top)
text – text that will be drawn
color – The color of a pixel
size – Size of the text. String from the following values:
"small","medium"or"large"
- Raises:
ValueError – Raise a
ValueErrorif the size isn’t correct
- casioplot.casioplot.get_pixel(x: int, y: int) tuple[int, int, int] | None¶
Get the RGB color of the pixel at the given coordinates of the canvas
Using a try statement is faster than checking if the coordinates are in bounds
- Parameters:
x – x coordinate (from the left)
y – y coordinate (from the top)
- Returns:
The pixel color. A tuple that contain 3 integers from 0 to 255 or None if the pixel is out of the canvas
- casioplot.casioplot.set_pixel(x: int, y: int, color: tuple[int, int, int] = (0, 0, 0)) None¶
Set the RGB color of the pixel at the given coordinates
Using a try statement is faster than checking if the coordinates are in bounds.
- Parameters:
x – x coordinate (from the left)
y – y coordinate (from the top)
color – The color of a pixel
- casioplot.casioplot.show_screen() None¶
Shows or saves the virtual screen
This function implement two distinct modes:
show the virtual screen in real time in a tkinter window, if
show_screenis TrueSave the virtual screen to the disk, if
save_screenin True
These modes are independent and can work at the same time