graphics_manager module

class graphics_manager.GraphicsCache(coordinates: list, width: int, tags: str | tuple, tool: int, fill_color: str = '', shape_fill: bool = False, interior_fill_color: str = '', outline_fill_color: str = '', stipple: str = '', joinstyle: str = 'round', capstyle: str = 'round', text: str = '', font_name: str = '', font_file: str = '', font_size: int = 0)[source]

Bases: object

Object that stores the coordinates and attributes of the plotted 2d graphic elements.

capstyle: str = 'round'
coordinates: list
fill_color: str = ''
font_file: str = ''
font_name: str = ''
font_size: int = 0
interior_fill_color: str = ''
joinstyle: str = 'round'
outline_fill_color: str = ''
shape_fill: bool = False
stipple: str = ''
tags: str | tuple
text: str = ''
tool: int
width: int
class graphics_manager.GraphicsManager(app, canvas, is_overlay=False)[source]

Bases: object

GraphicsManager Class manages the drawing and display of annotations(graphics) that gets drawn onto the images.

annotation_visibility_checker()[source]

Checks if annotations are allowed to be displayed on the screen.

check_if_overlay()[source]

Checks if current operations are being done on the overlay canvas.

convert_width_to_max_size(stroke_width=None, item=None)[source]

Converts the width of the canvas item from the actual image size to maximized window mode. Used with Load and Save.

Parameters:
  • stroke_width (float|int,optional) – Width or font size to be converted to the size of the image.

  • item (str, optional) – Canvas item type. “font” if the item type is text, else None.

Returns:

Width that matches the image size in the maximized windowed mode.

coordinates_to_image_size(coordinate_list, item: str = None, round_: bool = False)[source]

Scales the coordinates to match the actual image size. Coordinates are stored in the original image size for file saving and loading purposes.

Parameters:
  • coordinate_list (tuple|list) – Coordinates to be converted to the size of the image.

  • item (str, optional) – Canvas item type. “text” if the item type is text, else None.

  • round (bool,optional) – Ignored in this method, Used in childclass to round floats to integer.

Returns:

Coordinates that matches the size of the loaded image.

create_proxy_annotation(tags, fill_color=None, coordinates=None, width=None, joinstyle='round', stipple=None, capstyle=None, text=None, tool=None, project_override=False)[source]

Creates a proxy version of the drawing to be displayed on the windowed mode.

Parameters:
  • tags

  • fill_color

  • coordinates

  • width

  • joinstyle

  • stipple

  • capstyle

  • text

  • tool

  • project_override (bool) – True if method being called from load project protocol.

Returns:

None

create_text_selection_border()[source]

Creates four line segments on the canvas to act as a selection border.

Returns:

None

delete_item(event=None)[source]

Calls the erase_graphic method with an item id passed.

Parameters:

event (tkinter.Event) – Keypress event.

Returns:

None

draw_graphic_elements_from_project_file(is_overlay=False)[source]

Unpacks the loaded_graphics_data_dict and based on the tool used, mimics the events that happens during the normal drawing.

Parameters:

is_overlay – If True, the graphic elements from OVERLAY_GRAPHICS_INDEX([-1])gets drawn on the overlay_canvas. Default False.

Returns:

None

draw_graphics(event)[source]

Called on Mouse drag event. Plots a temporary shape using the raw mouse coordinates. Erases the item instantly.

Parameters:

event (tkinter.Event) – Mouse Drag event.

Returns:

None

draw_release(event=0, text=None, project_override=False, image_sized_coordinates=None)[source]
Called on Mouse release. Fetches the raw coordinates, cleans it scales it to the maximized and windowed size and plots the shape.

The coordinates and width are also scaled to match the actual image before saving the graphics_cache object to the dictionary.

Parameters:
  • event (tkinter.Event) – Mouse click release event.

  • text (str,optional) – Text, if using the text insert tool.

  • project_override (bool) – True if the method is being called from a loaded project protocol. Default False.

  • image_sized_coordinates (list|tuple,optional) – Pre-generated coordinates relative to the actual image size.

Returns:

None

erase_graphic(event=None, radius=0, current_item=None)[source]

Removes an item from the canvas and deletes the object from the dictionaries.

Parameters:
  • event (tkinter.Event) – Mouse event.

  • radius (int) – Search radius.

  • current_item (int,optional) – Item id of the element in the canvas to remove.

Returns:

None

find_item(event, radius=0, filter=None)[source]

Returns the canvas item closest to the Mouse Click event.

Parameters:
  • event (tkinter.Event) – Mouse click event

  • radius (int) – Radius to search for. Default 0

  • filter (str) – Specific item to look for. eg- “text”

Returns:

Id of the canvas item.

Return type:

int

flush_mouse_events()[source]

Clears the stored mouse events and temporary coordinates, and sets the state of ready_to_draw to False. :returns: None

force_hide_all_canvas_annotations()[source]

Hides all drawing and text annotations on the image canvas. :returns: None

get_dynamic_coordinates(mode, coordinate_list=None)[source]

Returns the scaled coordinates that matches the size of the zoomed image.

Parameters:
  • mode (str) – Mode of the displayed image. “actual” or “zoomed”.

  • coordinate_list (list|tuple, optional) – Coordinates to scale.

Returns:

Scaled Coordinates that matches the zoomed image size.

get_dynamic_stroke_width(mode: str)[source]

Returns a stroke width that matches the zoomed image size.

Parameters:

mode (str) – Type of zoom, “actual”, “zoomed”.

Returns:

Scaled width size that matches the zoomed image size.

Return type:

float

get_proxy_stroke_width(stroke_width=None, is_font_size=False)[source]

Calculates the Canvas size difference between maximized and windowed mode and uses that value to adjust the stroke width/font size accordingly.

Parameters:
  • stroke_width (float, optional) – Width of the stroke to be converted to match the proxy window.

  • is_font_size (bool) – True when the passed coordinates represent the font size.

Returns:

get_selection_color(hex_color)[source]

Checks the given hex value to see if it’s on the brighter or darker side, then returns a contrasting color close to the given color range.

Parameters:

hex_color – Hex color.

hex_to_rgb(hex_color: str)[source]

Converts a color from Hex to RGB values

Parameters:

hex_color (str) – Hex Color code to be converted into RGB values

Returns:

RGB values as a tuple.

Return type:

tuple

hide_current_text_items()[source]

Hides the text items on the canvas. :returns: None

hide_parent_annotations(hide_current: bool = False)[source]

Hides the annotations displayed on the maximized display mode.

Parameters:

hide_current (bool) – If True hide the annotations on the currently displayed image index too. Default False.

Returns:

None

hide_proxy_annotations(hide_current=False)[source]

Hides the annotations displayed on the windowed display mode.

Parameters:

hide_current (bool) – If True hide the annotations on the currently displayed image index too. Default False.

Returns:

None

hide_text_item_selection_border()[source]

Hides the selection border around the selected text item.

Returns:

None

image_coordinates_to_max_size(coordinate_list, item: str = None, round_: bool = False)[source]

Converts the coordinates of the canvas item from the actual image size to maximized window mode. Used with Load and Save.

Parameters:
  • coordinate_list (tuple|list) – Coordinates to be converted to the size of the image.

  • item (str, optional) – Canvas item type. “text” if the item type is text, else None.

  • round (bool) – True rounds the values to the closest integer. Default False.

Returns:

Coordinates that matches the image size in the maximized windowed mode.

initial_canvas_click(event)[source]

Called on the initial mouse click on the canvas. Stores the mouse coordinates and sets the stroke width based on the display mode.

Parameters:

event (tkinter.Event) – Mouse click event.

Returns:

None

peucker_algorithm(points, tolerance)[source]

An algorithm that decimates a curve composed of line segments to a similar curve with fewer points.

Parameters:
  • points (tuple|list) – Points to decimate.

  • tolerance (float) – A float number to control the decimation.

Returns:

A list of simplified coordinates.

Return type:

list

remove_text_item_selection()[source]

Removes the current text item as the selected_text_item. :returns: None

reposition_text_item(event, constraint=False)[source]

Reposition the text item based on coordinates from the mouse drag event.

Parameters:
  • event (tkinter.Event) – Mouse Drag event.

  • constraint (bool) – True constraints the text to an axis. False allows free repositioning.

Returns:

None

reset_actual_size()[source]

Resets the visual scale of items on the canvas from actual scale to the default scale of the image in the viewport.

Returns:

None

reset_zoomed_size()[source]

Resets the visual scale of items on the canvas from the zoomed size to the default scale of the image in the viewport.

Returns:

None

reveal_parent_annotations()[source]

Displays the annotations of the current image index displayed on the maximized display mode.

Returns:

None

reveal_proxy_annotations()[source]

Displays the annotations of the current image index displayed on the windowed display mode.

Returns:

None

reveal_text_item_selection_border()[source]

Shows the selection border around the selected text item.

Returns:

None

scale_coordinates(coordinate_list=None, scale_mode: str = None, scale_item: str = None, round_: bool = False)[source]

Scale the coordinates of the canvas item to match the specified display mode.

Parameters:
  • coordinate_list (list|tuple,optional) – Coordinates to be scaled.

  • scale_mode (str) – “+” Scales the coordinates from window size to maximized size. “-” Scales the other way.

  • scale_item (str) – Item to be scaled, items like “text”,”images” have only a single x,y coordinate and require different calculations.

  • round (bool) – True rounds the output into an integer. Default False.

Returns:

The scaled coordinates.

Return type:

(list|tuple)

scale_item_to_current_scale(item_id: int, mode: str)[source]

Scale an item in the canvas to match the current zoom level of the image.

Parameters:

item_id (int) – id of the canvas item to be scaled to match the zoomed image size. mode (str): Mode of the displayed image. “actual” or “zoomed”.

Returns:

None

scale_to_actual_size()[source]

Scales the visible items on the canvas visually to match the Actual Image size in viewport.

Returns:

None

scale_to_zoomed_size(mode, lock_zoom=False)[source]

Scales the visible items on the canvas visually to match the Zoomed image size in viewport.

Returns:

None

select_canvas_item(event, item_id=None)[source]

Fetches the clicked item on the canvas. If the item is a text, draw the surrounding border.

Parameters:
  • event (tkinter.Event) – Mouse Click event

  • item_id (int) – id of the canvas item.

Returns:

None

select_text_item(text_id=None, enable_scale_slider=True)[source]

Assigns the text item as the selected_text_item and draws the selection border around it.

Parameters:
  • text_id (int) – id of the text item on the canvas.

  • enable_scale_slider – True enables the scale slider that controls the scale of the text. Default True.

Returns:

None

set_text_drag_offset(event)[source]

Sets the initial position of the text item before repositioning.

Parameters:

event (tkinter.Event) – Mouse click event.

Returns:

None

update_text_color(event)[source]

Updates the color of the clicked text item.

Parameters:

event (tkinter.Event) – Mouse click event

Returns:

update_text_item_coords()[source]

Updates the text item coordinates in the data dictionaries after conversion.

Args:

Returns:

None

update_text_item_scale(value: float = None, increment: str = None)[source]

Updates the scale of the selected text item using the provided value.

Parameters:
  • value (float, optional) – A multiplier number.

  • increment (str, optional) – “+” adds +1 to the current scale, “-” subtracts -1 from the current scale., optional

Returns:

None

width_to_image_size(stroke_width=None, item=None)[source]

Scales the width to match the actual image size. Width is saved in the original image size for file saving and loading purposes.

Parameters:
  • stroke_width (float|int,optional) – Stroke to be converted to match the actual size of the image.

  • item (str, optional) – Canvas item type. “font” if the item type is text, else None.

Returns:

Width or Font size that matches the size of the loaded image.

wipe_current_annotations()[source]

Wipes all annotations (including text) drawn on the currently loaded image. Returns:

class graphics_manager.OverlayGraphicsManager(app, canvas, is_overlay=True, *args, **kwargs)[source]

Bases: GraphicsManager

Child Class that handles the creation and display of graphic elements and overlay images on the Overlay Canvas.

add_image_to_overlay_canvas(image_path: str)[source]

Places the imported image in the overlay canvas. If the imported image and the currently viewed image size is the same, the imported image is scaled to fit.

Parameters:

image_path (str) – File path for the imported image.

Returns:

None

change_overlay_image_opacity(opacity: float = None)[source]

Controls the opacity of the selected overlay image.

Parameters:

opacity (float) – Float range from 0 to 1.

Returns:

None

convert_width_to_max_size(stroke_width=None, item=None)[source]

Converts the width from Ghost Overlay Image to match the maximized display mode. Used while loading a project file.

Parameters:
  • stroke_width

  • item – Canvas item.

coordinates_to_image_size(coordinate_list, item: str = None, round_: bool = False)[source]

Route method that calls the rescale_overlay_elements_to_absolute_overlay_size.

Parameters:
  • coordinate_list – Coordinates to be scaled to match the size of the Ghost Overlay image.

  • item (str) – Item in the canvas.

  • round (bool) – True rounds the float to an integer. Default False.

Returns:

Rescaled coordinates that matches the Ghost Image size of the Overlay Canvas (1920x1080).

create_overlay_image_selection_border()[source]

Plots a six segmented line segment to act as a selection border while selecting the overlay images. :returns: None

delete_item(event=None)[source]

Removes the selected overlay image or text item from the canvas, and deletes the data from the dictionary.

Parameters:

event (tkinter.Event) – Keypress event.

Returns:

None

draw_graphic_elements_from_project_file(is_overlay=True)[source]

Checks the Overlay image index in the project file for any overlay images and adds the images and applies the saved transformations to it. Unpacks the loaded_graphics_data_dict and based on the tool used, mimics the events that happens during the normal drawing.

Parameters:

is_overlay (bool) – True, Argument has no use in child method.

Returns:

None

get_viewport_size_from_absolute_overlay_size(coordinate_list, item: str = None, round_: bool = False)[source]

Route method that calls the image_coordinates_to_max_size.

Parameters:
  • coordinate_list (tuple|list) – Coordinates to be scaled from the absolute size to match the maximized display mode.

  • item (str) – Canvas item.

  • round (bool) – True rounds the float to an integer. Default False.

Returns:

Rescaled coordinates that matches the maximized display mode of the overlay canvas.

hide_overlay_image_selection_border()[source]

Hides the selection border of the overlay image.

Returns:

None

hide_parent_overlay_annotations()[source]

Hides the annotations displayed on maximized display mode.

Returns:

None

hide_proxy_overlay_annotations()[source]

Hides the annotations displayed on windowed display mode.

Returns:

None

image_coordinates_to_max_size(coordinate_list, item: str = None, round_: bool = False)[source]

Converts the coordinates from Ghost Overlay Image to match the maximized display mode. Used while loading a project file.

Parameters:
  • coordinate_list – Coordinates to rescale.

  • item (str) – Canvas item.

  • round (bool) – True rounds the float to an integer. Default False.

Returns:

Coordinates that match the maximzed display mode.

redraw_selected_image(redraw_opacity: bool = False, redraw_rotation: bool = False)[source]

Redraws the selected overlay image by loading it from disk and applying the re applying the transformations and opacity.

Parameters:
  • redraw_opacity (bool) – True updates the image opacity using the stored value. False skips the operation. Default False

  • redraw_rotation (bool) – True updates the image rotation using the stored value. False skips the operation. Default False

Returns:

None

remove_overlay_image_selection()[source]

Removes the selection of the selected overlay image, and resets the image control sliders.

Returns:

None

reposition_overlay_image(event=None, position: tuple = None, constraint: bool = False)[source]

Repositions the overlay image using the mouse drag cordinates or a set of predefined coordinates.

Parameters:
  • event (tkinter.Event) – Mouse Drag event.

  • position (tuple,optional) – New Coordinates for the image.

  • constraint (bool) – True constraints the live positioning to a single axis.Default False.

Returns:

None

rescale_overlay_elements_to_absolute_overlay_size(element, item, round_: bool = False)[source]

Converts the attributes of the overlay elements to match the size of the overlay ghost image (1920x1080).

Parameters:
  • element – Coordinates, width , fontsize to rescale to the absolute size of the overlay.

  • item (str) – Type of item.

  • round (bool) – True rounds the float to an integer. Default False.

Returns:

Rescaled element data that matches the size of the Overlay ghost image size.

rescale_overlay_images_to_view()[source]

Iterates through the overlay images and scales them to match the current display mode.

Returns:

None

reset_selected_image()[source]

Resets the loaded overlay image to the size and position during import by reloading it from disk.

Returns:

None

reveal_overlay_image_selection_border()[source]

Displays the selection border of the selected overlay image.

Returns:

None

reveal_parent_overlay_annotations()[source]

Reveals the annotations displayed on maximized display mode.

Returns:

None

reveal_proxy_overlay_annotations()[source]

Reveals the annotations displayed on windowed display mode.

Returns:

None

rotate_overlay_image(value: int)[source]

Rotates the selected overlay image by the given value.

Parameters:

value (int) – Integer of range 0 to 360.

Returns:

None

scale_overlay_image(factor: float = 1, size: tuple = None, increment: str = None)[source]

Scales the selected overlay image by a multiplier value.

Parameters:
  • factor (float) – Value that multiplies the scale of the current selected overlay image.

  • size (tuple,optional) – Predefined size for the selected overlay image.

  • increment (str,optional) – “+” Increments image scale by +1 and “-” decrements the scale by 1.

Returns:

None

select_canvas_item(event, item_id=None)[source]

Fetches the clicked item on the canvas. If the item is an image or text, draw the surrounding border.

Parameters:
  • event (tkinter.Event) – Mouse Click event

  • item_id (int) – id of the canvas item.

Returns:

None

select_overlay_image(image_id=None)[source]

Assigns the overlay image item as the selected_overlay_image and draws the selection border around it.

Parameters:

image_id (int) – id of the text item on the canvas.

Returns:

None

set_overlay_image_drag_offset(event)[source]

Sets the initial position for overlay image repositioning.

Parameters:

event (tkinter.Event) – Mouse click event.

Returns:

None

update_overlay_image_coordinates()[source]

Converts the updated overlay image coordinates into multiple display modes and updates them in the dictionary.

Returns:

None

width_to_image_size(stroke_width=None, item: str = None)[source]

Scales the width to match the size of the Overlay Ghost Image.

Parameters:
  • stroke_width – Width to scale.

  • item (str) – canvas item

Returns:

Scaled width matching the overlay canvas size.

Return type:

(float|int)

wipe_current_annotations()[source]

Wipes all overlay images added to the Overlay canvas. :returns: None

class graphics_manager.OverlayImageCache(image_object: <module 'PIL.Image' from 'F:\\Python Projects\\R-View Tool Project Folder\\R-View Tool\\venv\\Lib\\site-packages\\PIL\\Image.py'>, image_path: str, coordinates: list | tuple, max_coordinates: list | tuple, proxy_coordinates: list | tuple, size: tuple, max_size: tuple, proxy_size: tuple, opacity: int, angle: int, tags: str | tuple)[source]

Bases: object

Object that stores the filepath and transformation values for the imported overlay image elements.

angle: int
coordinates: list | tuple
image_object: <module 'PIL.Image' from 'F:\\Python Projects\\R-View Tool Project Folder\\R-View Tool\\venv\\Lib\\site-packages\\PIL\\Image.py'>
image_path: str
max_coordinates: list | tuple
max_size: tuple
opacity: int
proxy_coordinates: list | tuple
proxy_size: tuple
size: tuple
tags: str | tuple