Viewport API¶
Manage viewport transforms and overlays.
- class rpa.api.viewport_api.ViewportApi(logger)[source]
Bases:
QObject
- SIG_CURRENT_CLIP_GEOMETRY_CHANGED
- create_html_overlay(html_overlay: Dict) str [source]
Create a floating HTML based overlay on the viewport. The data required to create the HTML overlay needs to be passed in as a dictionary. Following is an example dict with all the key-value pairs that are expected.
html_overaly = { "html": "<span style='color: white; font-size:42px'>Hello RPA!</span>", "x": 0.5, "y": 0.5, "width": 500, "height": 200, "is_visible": True }
“html” value need to be the string value that needs to be overlayed on the viewport.
“x” and “y” values need to passed as normalized 0.0 to 1.0 values. With (0.0, 0.0) at the lower-left and (1.0, 1.0) at the upper-right.
“width” and “height” need to be pixel values.
“is_visible” acccepts a boolean based on which the visibility of the HTML overlay can be controller.
- Parameters:
html_overaly (Dict) – Data required to create HTML overlay.
- Returns:
Unique id of the created HTML overlay.
- Return type:
(str)
- property delegate_mngr
- delete_html_overlays(ids: List[str])[source]
Delets the HTML overlays whose ids have been provided.
- Parameters:
ids (List[str]) – Ids of HTML overlays.
- Returns:
True if success False otherwise.
- Return type:
(bool)
- display_msg(message: str, duration: float = 2.0) bool [source]
Display the given message on the viewport for the given duration. The messages may indicate current status, or other user actions. The displayed message will disappear after the given duration has passed. The duration is in the unit of seconds.
- Parameters:
message (str) – The message to be displayed on the viewport
duration (float) – The amount of time to display the message in seconds. When not given, it defaults to 2.0 seconds.
- Returns:
True if success False otherwise
- Return type:
(bool)
- drag(pointer: Tuple[float, float]) bool [source]
Performs translation based on the given pointer position while in drag operation. start_drag method needs to be called before calling this method. And end_drag method needs to be called after the drag operation is completed.
- Parameters:
pointer (Tuple[float, float]) – Screen space (x,y) coordinate defining the current position while in drag operation for translation.
- Returns:
True if success False otherwise
- Return type:
(bool)
- end_drag() bool [source]
Ends translation by drag operation, and resets the reference pointer position.
- Returns:
True if success False otherwise
- Return type:
(bool)
- fit_to_height(state: bool) bool [source]
Fit the current media to the height of viewing window space
- Parameters:
state (bool) – Enable fit to height when True
- Returns:
True if success False otherwise
- Return type:
(bool)
- fit_to_width(state: bool) bool [source]
Fit the current media to the width of viewing window space
- Parameters:
state (bool) – Enable fit to width when True
- Returns:
True if success False otherwise
- Return type:
(bool)
- fit_to_window(state: bool) bool [source]
Fit the current media to the width and height of viewing window space
- Parameters:
state (bool) – Enable fitting to window when True
- Returns:
True if success False otherwise
- Return type:
(bool)
- flip_x(state: bool) bool [source]
Flip the current view horizontally or default to original view, given the state.
- Parameters:
state (bool) – flip display view horizontally when True
- Returns:
True if success False otherwise
- Return type:
(bool)
- flip_y(state: bool) bool [source]
Flip the current view vertically or default to original view, given the state.
- Parameters:
state (bool) – flip display view vertically when True
- Returns:
True if success False otherwise
- Return type:
(bool)
- get_current_clip_geometry() List[Tuple[float, float]] | None [source]
Returns a list of (x,y) image corners for the current clip in the viewport.
- Returns:
None if there is no current clip otherwise returns a list of the image corners of the current clip.
- Return type:
Optional[List[Tuple[float, float]]]
- get_html_overlay(id: str) Dict [source]
Returns the data of the HTML overlay whose id has been provided. Following is an example of how the returned dict will look like,
{ "html": "<span style='color: white; font-size:42px'>Hello RPA!</span>", "x": 0.5, "y": 0.5, "width": 500, "height": 200, "is_visible": True }
- Parameters:
id (str) – Unique id of a HTML overlay
- Returns:
Data of the HTML overlay.
- Return type:
(Dict)
- get_html_overlay_ids() List[str] [source]
Returns unique ids of all the HTML overlays currently present in the session.
- Returns:
List of HTML overlay ids
- Return type:
(List[str])
- get_scale() List[float] [source]
Get the horizontal and vertical scale values of viewport.
- Returns:
Horizontal and Version scale values
- Return type:
List[float, float]]
- get_translation() List[float] [source]
Get the horizontal and vertical translation values of viewport.
- Returns:
Horizontal and Version translation values
- Return type:
List[float, float]]
- is_feedback_visible(category: int) bool [source]
This method checks whether annotations and ccs(given the category) in the current session across all clips and their corresponding frames are allowed to be visible or not. Category is defined as follows 1 - All 2 - Strokes 3 - Texts 4 - Clip CCs 5 - Frame CCs 6 - Region CCs
- Parameters:
category (int) – Integer that represents the category.
- Returns:
True if annotations and ccs are visible, else False.
- Return type:
bool
- is_text_cursor_set() bool [source]
Check if text-cursor is set on viewport.
- Returns:
Returns True if text-cursor is set on viewport.
- Return type:
(bool)
- scale_on_point(scale_point: Tuple[float, float], delta: float, speed: float, vertical_lock: bool, horizontal_lock: bool) bool [source]
Allow scale in/out at a specific point. Possible to lock the view from scaling vertically or horizontally.
- Parameters:
scale_point (Tuple[float, float]) – Screen space (x,y) coordinate position to scale in/out
delta (float) – 1.0 for scale in operation, and -1.0 for scale out operation
speed (float) – Speed at which scale operation occurs, value set by some user input
vertical_lock (bool) – View locked from scaling vertically when True
horizontal_lock (bool) – View locked from scaling horizontally when True
- Returns:
True if success False otherwise
- Return type:
(bool)
- set_cross_hair_cursor(position: Point) bool [source]
Draw a cross_hair-cursor line on the viewport.
- Parameters:
position (RPA Point) – Position of the cursor
- Returns:
True if success else False
- Return type:
(bool)
- set_feedback_visibility(category: int, value: bool) bool [source]
Enable users to set visibility of all annotations and ccs in the current session. Category is as follows. 1 - All 2 - Strokes 3 - Texts 4 - Clip CCs 5 - Frame CCs 6 - Region CCs :param category: Integer that represents the category that needs to be set. :type category: int :param value: Flag to set visibility of all annotaions and ccs. :type value: bool
- Returns:
True if success False otherwise
- Return type:
(bool)
- set_html_overlay(id: str, html_overlay: Dict)[source]
Set the properties of existing HTML overlays. The properties can be set by passing a dict with the key-value pairs of the properties that need to be chagned.
The passed in the dict should have one or more of the following example dictionary,
html_overaly = { "html": "<span style='color: white; font-size:42px'>Hello RPA!</span>", "x": 0.5, "y": 0.5, "width": 500, "height": 200, "is_visible": True }
“html” value needs to be the string value that needs to be overlayed on the viewport.
“x” and “y” values need to passed as normalized 0.0 to 1.0 values. With (0.0, 0.0) at the lower-left and (1.0, 1.0) at the upper-right.
“width” and “height” need to be pixel values.
“is_visible” acccepts a boolean based on which the visibility of the HTML overlay can be controller.
- Parameters:
id (str) – Unique id of the HTML overaly whose properties need to be set
html_overlay (dict) – Data containing HTML overlay properties to set.
- Returns:
True if success else False
- Return type:
(bool)
- set_mask(mask: str | None) bool [source]
Set a layer of mask on top of the current view
- Parameters:
mask (Optional[str]) –
A mask can either be an image path or a recipe to render. A mask with image path will be rendered with its respective image coordinates matching the viewing media width and height. A mask recipe is defined with a desired aspect ratio and opacity. The recipe format is as follows: “$aspect_ratio@$opacity” There can be multiple recipes for a particular mask. In these instances, “&” can be used to denote the recipe list. .. rubric:: Examples
”/some/path/to/mask/images/mask_example.tif” “2.35@0.5” “1.755@1.0&1.655@0.7”
The mask will be rendered on top of the current view. When None, any existing rendered mask will be removed.
- Returns:
True if success False otherwise
- Return type:
(bool)
- set_scale(horizontal: float, vertical: float | None = None) bool [source]
Set the horizontal and/or vertical factor to scale in/out of viewport
- Parameters:
horizontal (float) – Horizontal scale factor
vertical (float) – Vertical scale factor. When None, it will be the same value as Horizontal scale factor.
- Returns:
True if success False otherwise
- Return type:
(bool)
- set_text_cursor(position: Point, size: int) bool [source]
Draw a text-cursor line on the viewport.
- Parameters:
position (RPA Point) – Position of the cursor
size (int) – Size of the cursor
- Returns:
True if success else False
- Return type:
(bool)
- set_translation(horizontal: float, vertical: float) bool [source]
Set the horizontal and/or vertical factor to translation in/out of viewport
- Parameters:
horizontal (float) – Horizontal translation factor
vertical (float) – Vertical translation factor.
- Returns:
True if success False otherwise
- Return type:
(bool)
- start_drag(pointer: Tuple[float, float]) bool [source]
Sets the starting reference pointer position for translation by drag operation. After this method, use drag method to drag and use finally end_drag to complete the drag operation.
- Parameters:
pointer (Tuple[float, float]) – Screen space (x,y) coordinate defining the start position of drag operation for translation.
- Returns:
True if success False otherwise
- Return type:
(bool)
- staticMetaObject = <PySide2.QtCore.QMetaObject object>
- unset_text_cursor() bool [source]
Remove text cursor from viewport.
- Parameters:
position (RPA Point) – Position of the cursor
size (int) – Size of the cursor
- Returns:
True if success else False
- Return type:
(bool)