Complete documentation
All the internals functions for those who wants to contribute
Types
This file contains the type Configuration and the type Color.
The type Configuration makes it possible to representing all settings and configs in a dictionary but still
have type annotations for every setting.
- 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:
TypedDict- background_image: str
- bg_image_is_set: bool
- bottom_margin: int
- height: int
- image_format: str
- image_name: str
- left_margin: int
- right_margin: int
- save_multiple: bool
- save_rate: int
- save_screen: bool
- show_screen: bool
- top_margin: int
- width: int
Characters
Contains every character in the three sizes, small, medium and large and the function _get_char()
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 corresponds to a row. An X means that the pixel should be set and a space that the pixel should stay as it is.
- casioplot.characters._get_char(char: str, size: str = '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_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._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
local_file_name,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_image"]to the full path for the image- Parameters:
bg_image_setting – The value of the setting
setting["background_image"]- 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._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._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.current_image_number = 1
The number of the current image that is being saved
- 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 virtual screen 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 the text. A tuple that contain 3 integers from 0 to 255
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.save_screen_counter = 0
Counter used to save multiple images of the screen
- 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 pixel color. A tuple that contain 3 integers from 0 to 255
- 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 screen to the disk, if
save_screenin True
These modes are independent and can work at the same time