ui#

Module: ui.containers#

UI container module.

Panel2D(size, *[, position, color, opacity, ...])

A 2D UI Panel.

TabPanel2D(*[, position, size, title, ...])

Render content within a Tab.

TabUI(*[, position, size, nb_tabs, ...])

UI element to add multiple panels within a single window.

ImageContainer2D(img_path, *[, position, size])

A 2D container to hold an image.

GridUI(actors, *[, captions, ...])

Add actors in a grid and interact with them individually.

Module: ui.core#

UI core module that describe UI abstract class.

UI(*[, position])

An umbrella class for all UI elements.

Rectangle2D(*[, size, position, color, opacity])

A 2D rectangle sub-classed from UI.

Disk2D(outer_radius, *[, inner_radius, ...])

A 2D disk UI component.

TextBlock2D(*[, text, font_size, ...])

Wrap over the default vtkTextActor and helps setting the text.

Button2D(icon_fnames, *[, position, size])

A 2D overlay button and is of type vtkTexturedActor2D.

Module: ui.elements#

UI components module.

TextBox2D(width, height, *[, text, ...])

An editable 2D text box that behaves as a UI component.

LineSlider2D(*[, center, initial_value, ...])

A 2D Line Slider.

LineDoubleSlider2D(*[, line_width, ...])

A 2D Line Slider with two sliding rings.

RingSlider2D(*[, center, initial_value, ...])

A disk slider.

RangeSlider(*[, line_width, inner_radius, ...])

A set of a LineSlider2D and a LineDoubleSlider2D.

Option(label, *[, position, font_size, checked])

A set of a Button2D and a TextBlock2D to act as a single option for checkboxes and radio buttons.

Checkbox(labels, *[, checked_labels, ...])

A 2D set of :class:'Option' objects.

RadioButton(labels, checked_labels, *[, ...])

A 2D set of :class:'Option' objects.

ComboBox2D(*[, items, position, size, ...])

UI element to create drop-down menus.

ListBox2D(values, *[, position, size, ...])

UI component that allows the user to select items from a list.

ListBoxItem2D(list_box, size, *[, ...])

The text displayed in a listbox.

FileMenu2D(directory_path, *[, extensions, ...])

A menu to select files in the current folder.

DrawShape(shape_type, *[, drawpanel, position])

Create and Manage 2D Shapes.

DrawPanel(*[, size, position, is_draggable])

The main Canvas(Panel2D) on which everything would be drawn.

PlaybackPanel(*[, loop, position, width])

A playback controller that can do essential functionalities.

Card2D(image_path, *[, body_text, ...])

Card element to show image and related text

SpinBox(*[, position, size, padding, ...])

SpinBox UI.

Module: ui.helpers#

Helper variable or function for UI Elements.

clip_overflow(textblock, width, *[, side])

Clips overflowing text of TextBlock2D with respect to width.

wrap_overflow(textblock, wrap_width, *[, side])

Wraps overflowing text of TextBlock2D with respect to width.

check_overflow(textblock, width, *[, ...])

Checks if the text is overflowing.

cal_bounding_box_2d(vertices)

Calculate the min, max position and the size of the bounding box.

rotate_2d(vertices, angle)

Rotate the given vertices by an angle.

Panel2D#

class fury.ui.containers.Panel2D(size, *, position=(0, 0), color=(0.1, 0.1, 0.1), opacity=0.7, align='left', border_color=(1, 1, 1), border_width=0, has_border=False)[source]#

Bases: UI

A 2D UI Panel.

Can contain one or more UI elements.

Attributes:
alignment[left, right]

Alignment of the panel with respect to the overall screen.

add_element(element, coords, *, anchor='position')[source]#

Add a UI component to the panel.

The coordinates represent an offset from the lower left corner of the panel.

Parameters:
elementUI

The UI item to be added.

coords(float, float) or (int, int)

If float, normalized coordinates are assumed and they must be between [0,1]. If int, pixels coordinates are assumed and it must fit within the panel’s size.

property border_color#
property border_width#
property color#
left_button_dragged(i_ren, _obj, _panel2d_object)[source]#
left_button_pressed(i_ren, _obj, panel2d_object)[source]#
property opacity#
re_align(window_size_change)[source]#

Re-organise the elements in case the window size is changed.

Parameters:
window_size_change(int, int)

New window size (width, height) in pixels.

remove_element(element)[source]#

Remove a UI component from the panel.

Parameters:
elementUI

The UI item to be removed.

resize(size)[source]#

Set the panel size.

Parameters:
size(float, float)

Panel size (width, height) in pixels.

set_visibility(visibility)[source]#

Set visibility of this UI component.

update_border_coords()[source]#

Update the coordinates of the borders

update_element(element, coords, *, anchor='position')[source]#

Update the position of a UI component in the panel.

Parameters:
elementUI

The UI item to be updated.

coords(float, float) or (int, int)

New coordinates. If float, normalized coordinates are assumed and they must be between [0,1]. If int, pixels coordinates are assumed and it must fit within the panel’s size.

TabPanel2D#

class fury.ui.containers.TabPanel2D(*, position=(0, 0), size=(100, 100), title='New Tab', color=(0.5, 0.5, 0.5), content_panel=None)[source]#

Bases: UI

Render content within a Tab.

Attributes:
content_panel: :class: ‘Panel2D’

Hold all the content UI components.

text_block: :class: ‘TextBlock2D’

Renders the title of the tab.

add_element(element, coords, *, anchor='position')[source]#

Add a UI component to the content panel.

The coordinates represent an offset from the lower left corner of the panel.

Parameters:
elementUI

The UI item to be added.

coords(float, float) or (int, int)

If float, normalized coordinates are assumed and they must be between [0,1]. If int, pixels coordinates are assumed and it must fit within the panel’s size.

property color#

Return the background color of tab panel.

remove_element(element)[source]#

Remove a UI component from the content panel.

Parameters:
elementUI

The UI item to be removed.

resize(size)[source]#

Resize Tab panel.

Parameters:
size(int, int)

New width and height in pixels.

property title#

Return the title of tab panel.

property title_bold#

Is the title of a tab panel bold.

property title_color#

Return the title color of tab panel.

property title_font_size#

Return the title font size of tab panel.

property title_italic#

Is the title of a tab panel italic.

update_element(element, coords, *, anchor='position')[source]#

Update the position of a UI component in the content panel.

Parameters:
elementUI

The UI item to be updated.

coords(float, float) or (int, int)

New coordinates. If float, normalized coordinates are assumed and they must be between [0,1]. If int, pixels coordinates are assumed and it must fit within the panel’s size.

TabUI#

class fury.ui.containers.TabUI(*, position=(0, 0), size=(100, 100), nb_tabs=1, active_color=(1, 1, 1), inactive_color=(0.5, 0.5, 0.5), draggable=False, startup_tab_id=None, tab_bar_pos='top')[source]#

Bases: UI

UI element to add multiple panels within a single window.

Attributes:
tabs: :class: List of ‘TabPanel2D’

Stores all the instances of ‘TabPanel2D’ that renders the contents.

add_element(tab_idx, element, coords, *, anchor='position')[source]#

Add element to content panel after checking its existence.

collapse_tab_ui(iren, _obj, _tab_comp)[source]#

Handle events when Tab UI is collapsed.

left_button_dragged(i_ren, _obj, _sub_component)[source]#
left_button_pressed(i_ren, _obj, _sub_component)[source]#
remove_element(tab_idx, element)[source]#

Remove element from content panel after checking its existence.

select_tab_callback(iren, _obj, _tab_comp)[source]#

Handle events when a tab is selected.

update_element(tab_idx, element, coords, *, anchor='position')[source]#

Update element on content panel after checking its existence.

update_tabs()[source]#

Update position, size and callbacks for tab panels.

ImageContainer2D#

class fury.ui.containers.ImageContainer2D(img_path, *, position=(0, 0), size=(100, 100))[source]#

Bases: UI

A 2D container to hold an image.

Currently Supports: - png and jpg/jpeg images

Attributes:
size: (float, float)

Image size (width, height) in pixels.

imgImageData

The image loaded from the specified path.

resize(size)[source]#

Resize the image.

Parameters:
size(float, float)

image size (width, height) in pixels.

scale(factor)[source]#

Scale the image.

Parameters:
factor(float, float)

Scaling factor (width, height) in pixels.

set_img(img)[source]#

Modify the image used by the vtkTexturedActor2D.

Parameters:
imgimageData

GridUI#

class fury.ui.containers.GridUI(actors, *, captions=None, caption_offset=(0, -100, 0), cell_padding=0, cell_shape='rect', aspect_ratio=1.7777777777777777, dim=None, rotation_speed=1, rotation_axis=(0, 1, 0))[source]#

Bases: UI

Add actors in a grid and interact with them individually.

ANTICLOCKWISE_ROTATION_X = array([-10,   1,   0,   0])#
ANTICLOCKWISE_ROTATION_Y = array([-10,   0,   1,   0])#
CLOCKWISE_ROTATION_X = array([10,  1,  0,  0])#
CLOCKWISE_ROTATION_Y = array([10,  0,  1,  0])#
key_press_callback(istyle, obj, _what)[source]#
static left_click_callback(istyle, _obj, _what)[source]#
static left_click_callback2(istyle, obj, self)[source]#
static left_release_callback(istyle, _obj, _what)[source]#
static left_release_callback2(istyle, _obj, _what)[source]#
static mouse_move_callback(istyle, _obj, _what)[source]#
static mouse_move_callback2(istyle, obj, self)[source]#
resize(size)[source]#

Resize the button.

Parameters:
size(float, float)

Button size (width, height) in pixels.

UI#

class fury.ui.core.UI(*, position=(0, 0))[source]#

Bases: object

An umbrella class for all UI elements.

While adding UI elements to the scene, we go over all the sub-elements that come with it and add those to the scene automatically.

Attributes:
position(float, float)

Absolute coordinates (x, y) of the lower-left corner of this UI component.

center(float, float)

Absolute coordinates (x, y) of the center of this UI component.

size(int, int)

Width and height in pixels of this UI component.

on_left_mouse_button_pressed: function

Callback function for when the left mouse button is pressed.

on_left_mouse_button_released: function

Callback function for when the left mouse button is released.

on_left_mouse_button_clicked: function

Callback function for when clicked using the left mouse button (i.e. pressed -> released).

on_left_mouse_double_clicked: function

Callback function for when left mouse button is double clicked (i.e pressed -> released -> pressed -> released).

on_left_mouse_button_dragged: function

Callback function for when dragging using the left mouse button.

on_right_mouse_button_pressed: function

Callback function for when the right mouse button is pressed.

on_right_mouse_button_released: function

Callback function for when the right mouse button is released.

on_right_mouse_button_clicked: function

Callback function for when clicking using the right mouse button (i.e. pressed -> released).

on_right_mouse_double_clicked: function

Callback function for when right mouse button is double clicked (i.e pressed -> released -> pressed -> released).

on_right_mouse_button_dragged: function

Callback function for when dragging using the right mouse button.

on_middle_mouse_button_pressed: function

Callback function for when the middle mouse button is pressed.

on_middle_mouse_button_released: function

Callback function for when the middle mouse button is released.

on_middle_mouse_button_clicked: function

Callback function for when clicking using the middle mouse button (i.e. pressed -> released).

on_middle_mouse_double_clicked: function

Callback function for when middle mouse button is double clicked (i.e pressed -> released -> pressed -> released).

on_middle_mouse_button_dragged: function

Callback function for when dragging using the middle mouse button.

on_key_press: function

Callback function for when a keyboard key is pressed.

property actors#

Actors composing this UI component.

add_callback(prop, event_type, callback, *, priority=0)[source]#

Add a callback to a specific event for this UI component.

Parameters:
propvtkProp

The prop on which is callback is to be added.

event_typestring

The event code.

callbackfunction

The callback function.

priorityint

Higher number is higher priority.

add_to_scene(scene)[source]#

Allow UI objects to add their own props to the scene.

Parameters:
scenescene
property center#
handle_events(actor)[source]#
static key_press_callback(i_ren, obj, self)[source]#
static left_button_click_callback(i_ren, obj, self)[source]#
static left_button_release_callback(i_ren, obj, self)[source]#
static middle_button_click_callback(i_ren, obj, self)[source]#
static middle_button_release_callback(i_ren, obj, self)[source]#
static mouse_move_callback(i_ren, obj, self)[source]#
property position#
static right_button_click_callback(i_ren, obj, self)[source]#
static right_button_release_callback(i_ren, obj, self)[source]#
set_visibility(visibility)[source]#

Set visibility of this UI component.

property size#

Rectangle2D#

class fury.ui.core.Rectangle2D(*, size=(0, 0), position=(0, 0), color=(1, 1, 1), opacity=1.0)[source]#

Bases: UI

A 2D rectangle sub-classed from UI.

property color#

Get the rectangle’s color.

property height#
property opacity#

Get the rectangle’s opacity.

resize(size)[source]#

Set the button size.

Parameters:
size(float, float)

Button size (width, height) in pixels.

property width#

Disk2D#

class fury.ui.core.Disk2D(outer_radius, *, inner_radius=0, center=(0, 0), color=(1, 1, 1), opacity=1.0)[source]#

Bases: UI

A 2D disk UI component.

property color#

Get the color of this UI component.

property inner_radius#
property opacity#

Get the opacity of this UI component.

property outer_radius#

TextBlock2D#

class fury.ui.core.TextBlock2D(*, text='Text Block', font_size=18, font_family='Arial', justification='left', vertical_justification='bottom', bold=False, italic=False, shadow=False, size=None, color=(1, 1, 1), bg_color=None, position=(0, 0), auto_font_scale=False, dynamic_bbox=False)[source]#

Bases: UI

Wrap over the default vtkTextActor and helps setting the text.

Contains member functions for text formatting.

Attributes:
actorvtkTextActor

The text actor.

messagestr

Get message from the text.

position(float, float)

(x, y) in pixels.

color(float, float, float)

Get text color.

bg_color(float, float, float)

RGB: Values must be between 0-1.

font_sizeint

Get text font size.

font_familystr

Get font family.

justificationstr

Get text justification.

vertical_justificationstr

Get text vertical justification.

boldbool

Return whether the text is bold.

italicbool

Return whether the text is italicised.

shadowbool

Return whether the text has shadow.

size(int, int)

Size (width, height) in pixels of the text bounding box.

auto_font_scalebool

Return whether text font is automatically scaled.

dynamic_bboxbool

Automatically resize the bounding box according to the content.

property auto_font_scale#

Return whether text font is automatically scaled.

Returns:
bool

Text is auto_font_scaled if True.

property background_color#

Get background color.

Returns:
(float, float, float) or None

If None, there no background color. Otherwise, background color in RGB.

property bold#

Return whether the text is bold.

Returns:
bool

Text is bold if True.

cal_size_from_message()[source]#

Calculate size of background according to the message it contains.

property color#

Get text color.

Returns:
(float, float, float)

Returns text color in RGB.

property dynamic_bbox#

Automatically resize the bounding box according to the content.

Returns:
bool

Bounding box is dynamic if True.

property font_family#

Get font family.

Returns:
str

Text font family.

property font_size#

Get text font size.

Returns:
int

Text font size.

property italic#

Return whether the text is italicised.

Returns:
bool

Text is italicised if True.

property justification#

Get text justification.

Returns:
str

Text justification.

property message#

Get message from the text.

Returns:
str

The current text message.

resize(size)[source]#

Resize TextBlock2D.

Parameters:
size(int, int)

Text bounding box size(width, height) in pixels.

property shadow#

Return whether the text has shadow.

Returns:
bool

Text is shadowed if True.

update_alignment()[source]#

Update Text Alignment.

update_bounding_box(*, size=None)[source]#

Update Text Bounding Box.

Parameters:
size(int, int) or None

If None, calculates bounding box. Otherwise, uses the given size.

property vertical_justification#

Get text vertical justification.

Returns:
str

Text vertical justification.

Button2D#

class fury.ui.core.Button2D(icon_fnames, *, position=(0, 0), size=(30, 30))[source]#

Bases: UI

A 2D overlay button and is of type vtkTexturedActor2D.

Currently supports:

- Multiple icons.
- Switching between icons.
property color#

Get the button’s color.

next_icon()[source]#

Increment the state of the Button.

Also changes the icon.

next_icon_id()[source]#

Set the next icon ID while cycling through icons.

resize(size)[source]#

Resize the button.

Parameters:
size(float, float)

Button size (width, height) in pixels.

scale(factor)[source]#

Scale the button.

Parameters:
factor(float, float)

Scaling factor (width, height) in pixels.

set_icon(icon)[source]#

Modify the icon used by the vtkTexturedActor2D.

Parameters:
iconimageData
set_icon_by_name(icon_name)[source]#

Set the button icon using its name.

Parameters:
icon_namestr

TextBox2D#

class fury.ui.elements.TextBox2D(width, height, *, text='Enter Text', position=(100, 10), color=(0, 0, 0), font_size=18, font_family='Arial', justification='left', bold=False, italic=False, shadow=False)[source]#

Bases: UI

An editable 2D text box that behaves as a UI component.

Currently supports: - Basic text editing. - Cursor movements. - Single and multi-line text boxes. - Pre text formatting (text needs to be formatted beforehand).

Attributes:
textstr

The current text state.

actorvtkActor2d

The text actor.

widthint

The number of characters in a single line of text.

heightint

The number of lines in the textbox.

window_leftint

Left limit of visible text in the textbox.

window_rightint

Right limit of visible text in the textbox.

caret_posint

Position of the caret in the text.

initbool

Flag which says whether the textbox has just been initialized.

add_character(character)[source]#

Insert a character into the text and moves window and caret.

Parameters:
characterstr
edit_mode()[source]#

Turn on edit mode.

handle_character(key, key_char)[source]#

Handle button events.

# TODO: Need to handle all kinds of characters like !, +, etc.

Parameters:
characterstr
key_press(i_ren, _obj, _textbox_object)[source]#

Handle Key press for textboxself.

Parameters:
i_ren: :class:`CustomInteractorStyle`
obj: :class:`vtkActor`

The picked actor

_textbox_object: :class:`TextBox2D`
left_button_press(i_ren, _obj, _textbox_object)[source]#

Handle left button press for textbox.

Parameters:
i_ren: :class:`CustomInteractorStyle`
obj: :class:`vtkActor`

The picked actor

_textbox_object: :class:`TextBox2D`
left_move_left()[source]#

Move left boundary of the text window left-wards.

left_move_right()[source]#

Move left boundary of the text window right-wards.

move_caret_left()[source]#

Move the caret towards left.

move_caret_right()[source]#

Move the caret towards right.

move_left()[source]#

Handle left button press.

move_right()[source]#

Handle right button press.

remove_character()[source]#

Remove a character and moves window and caret accordingly.

render_text(*, show_caret=True)[source]#

Render text after processing.

Parameters:
show_caretbool

Whether or not to show the caret.

right_move_left()[source]#

Move right boundary of the text window left-wards.

right_move_right()[source]#

Move right boundary of the text window right-wards.

set_message(message)[source]#

Set custom text to textbox.

Parameters:
message: str

The custom message to be set.

showable_text(show_caret)[source]#

Chop out text to be shown on the screen.

Parameters:
show_caretbool

Whether or not to show the caret.

width_set_text(text)[source]#

Add newlines to text where necessary.

This is needed for multi-line text boxes.

Parameters:
textstr

The final text to be formatted.

Returns:
str

A multi line formatted text.

LineSlider2D#

class fury.ui.elements.LineSlider2D(*, center=(0, 0), initial_value=50, min_value=0, max_value=100, length=200, line_width=5, inner_radius=0, outer_radius=10, handle_side=20, font_size=16, orientation='horizontal', text_alignment='', text_template='{value:.1f} ({ratio:.0%})', shape='disk')[source]#

Bases: UI

A 2D Line Slider.

A sliding handle on a line with a percentage indicator.

Attributes:
line_widthint

Width of the line on which the disk will slide.

lengthint

Length of the slider.

trackRectangle2D

The line on which the slider’s handle moves.

handleDisk2D

The moving part of the slider.

textTextBlock2D

The text that shows percentage.

shapestring

Describes the shape of the handle. Currently supports ‘disk’ and ‘square’.

default_color(float, float, float)

Color of the handle when in unpressed state.

active_color(float, float, float)

Color of the handle when it is pressed.

property bottom_y_position#
format_text()[source]#

Return formatted text to display along the slider.

handle_move_callback(i_ren, _vtkactor, _slider)[source]#

Handle movement.

Parameters:
i_renCustomInteractorStyle
vtkactorvtkActor

The picked actor

sliderLineSlider2D
handle_release_callback(i_ren, _vtkactor, _slider)[source]#

Change color when handle is released.

Parameters:
i_renCustomInteractorStyle
vtkactorvtkActor

The picked actor

sliderLineSlider2D
property left_x_position#
property ratio#
property right_x_position#
set_position(position)[source]#

Set the disk’s position.

Parameters:
position(float, float)

The absolute position of the disk (x, y).

property top_y_position#
track_click_callback(i_ren, _vtkactor, _slider)[source]#

Update disk position and grab the focus.

Parameters:
i_renCustomInteractorStyle
vtkactorvtkActor

The picked actor

_sliderLineSlider2D
update()[source]#

Update the slider.

property value#

LineDoubleSlider2D#

class fury.ui.elements.LineDoubleSlider2D(*, line_width=5, inner_radius=0, outer_radius=10, handle_side=20, center=(450, 300), length=200, initial_values=(0, 100), min_value=0, max_value=100, font_size=16, text_template='{value:.1f}', orientation='horizontal', shape='disk')[source]#

Bases: UI

A 2D Line Slider with two sliding rings.

Useful for setting min and max values for something.

Currently supports: - Setting positions of both disks.

Attributes:
line_widthint

Width of the line on which the disk will slide.

lengthint

Length of the slider.

trackvtkActor

The line on which the handles move.

handles[vtkActor, vtkActor]

The moving slider disks.

text[TextBlock2D, TextBlock2D]

The texts that show the values of the disks.

shapestring

Describes the shape of the handle. Currently supports ‘disk’ and ‘square’.

default_color(float, float, float)

Color of the handles when in unpressed state.

active_color(float, float, float)

Color of the handles when they are pressed.

property bottom_disk_ratio#

Return the ratio of the bottom disk.

property bottom_disk_value#

Return the value of the bottom disk.

property bottom_y_position#
coord_to_ratio(coord)[source]#

Convert the x coordinate of a disk to the ratio.

Parameters:
coordfloat
format_text(disk_number)[source]#

Return formatted text to display along the slider.

Parameters:
disk_numberint

Index of the disk.

handle_move_callback(i_ren, vtkactor, _slider)[source]#

Handle movement.

Parameters:
i_renCustomInteractorStyle
vtkactorvtkActor

The picked actor

_sliderLineDoubleSlider2D
handle_release_callback(i_ren, vtkactor, _slider)[source]#

Change color when handle is released.

Parameters:
i_renCustomInteractorStyle
vtkactorvtkActor

The picked actor

_sliderLineDoubleSlider2D
property left_disk_ratio#

Return the ratio of the left disk.

property left_disk_value#

Return the value of the left disk.

property left_x_position#
ratio_to_coord(ratio)[source]#

Convert the ratio to the absolute coordinate.

Parameters:
ratiofloat
ratio_to_value(ratio)[source]#

Convert the ratio to the value of the disk.

Parameters:
ratiofloat
property right_disk_ratio#

Return the ratio of the right disk.

property right_disk_value#

Return the value of the right disk.

property right_x_position#
set_position(position, disk_number)[source]#

Set the disk’s position.

Parameters:
position(float, float)

The absolute position of the disk (x, y).

disk_numberint

The index of disk being moved.

property top_disk_ratio#

Return the ratio of the top disk.

property top_disk_value#

Return the value of the top disk.

property top_y_position#
update(disk_number)[source]#

Update the slider.

Parameters:
disk_numberint

Index of the disk to be updated.

value_to_ratio(value)[source]#

Convert the value of a disk to the ratio.

Parameters:
valuefloat

RingSlider2D#

class fury.ui.elements.RingSlider2D(*, center=(0, 0), initial_value=180, min_value=0, max_value=360, slider_inner_radius=40, slider_outer_radius=44, handle_inner_radius=0, handle_outer_radius=10, font_size=16, text_template='{ratio:.0%}')[source]#

Bases: UI

A disk slider.

A disk moves along the boundary of a ring. Goes from 0-360 degrees.

Attributes:
mid_track_radius: float

Distance from the center of the slider to the middle of the track.

previous_value: float

Value of Rotation of the actor before the current value.

trackDisk2D

The circle on which the slider’s handle moves.

handleDisk2D

The moving part of the slider.

textTextBlock2D

The text that shows percentage.

default_color(float, float, float)

Color of the handle when in unpressed state.

active_color(float, float, float)

Color of the handle when it is pressed.

property angle#

Return Angle (in rad) the handle makes with x-axis.

format_text()[source]#

Return formatted text to display along the slider.

handle_move_callback(i_ren, _obj, _slider)[source]#

Move the slider’s handle.

Parameters:
i_renCustomInteractorStyle
objvtkActor

The picked actor

_sliderRingSlider2D
handle_release_callback(i_ren, _obj, _slider)[source]#

Change color when handle is released.

Parameters:
i_renCustomInteractorStyle
vtkactorvtkActor

The picked actor

_sliderRingSlider2D
property mid_track_radius#
move_handle(click_position)[source]#

Move the slider’s handle.

Parameters:
click_position: (float, float)

Position of the mouse click.

property previous_value#
property ratio#
track_click_callback(i_ren, _obj, _slider)[source]#

Update disk position and grab the focus.

Parameters:
i_renCustomInteractorStyle
objvtkActor

The picked actor

_sliderRingSlider2D
update()[source]#

Update the slider.

property value#

RangeSlider#

class fury.ui.elements.RangeSlider(*, line_width=5, inner_radius=0, outer_radius=10, handle_side=20, range_slider_center=(450, 400), value_slider_center=(450, 300), length=200, min_value=0, max_value=100, font_size=16, range_precision=1, orientation='horizontal', value_precision=2, shape='disk')[source]#

Bases: UI

A set of a LineSlider2D and a LineDoubleSlider2D. The double slider is used to set the min and max value for the LineSlider2D

Attributes:
range_slider_center(float, float)

Center of the LineDoubleSlider2D object.

value_slider_center(float, float)

Center of the LineSlider2D object.

range_sliderLineDoubleSlider2D

The line slider which sets the min and max values

value_sliderLineSlider2D

The line slider which sets the value

range_slider_handle_move_callback(i_ren, obj, _slider)[source]#

Update range_slider’s handles.

Parameters:
i_renCustomInteractorStyle
objvtkActor

The picked actor

_sliderRangeSlider

Option#

class fury.ui.elements.Option(label, *, position=(0, 0), font_size=18, checked=False)[source]#

Bases: UI

A set of a Button2D and a TextBlock2D to act as a single option for checkboxes and radio buttons. Clicking the button toggles its checked/unchecked status.

Attributes:
labelstr

The label for the option.

font_sizeint

Font Size of the label.

deselect()[source]#
select()[source]#
toggle(i_ren, _obj, _element)[source]#

Checkbox#

class fury.ui.elements.Checkbox(labels, *, checked_labels=(), padding=1, font_size=18, font_family='Arial', position=(0, 0))[source]#

Bases: UI

A 2D set of :class:’Option’ objects. Multiple options can be selected.

Attributes:
labelslist(string)

List of labels of each option.

optionsdict(Option)

Dictionary of all the options in the checkbox set.

paddingfloat

Get the padding between options.

property font_size#

Gets the font size of text.

property padding#

Get the padding between options.

RadioButton#

class fury.ui.elements.RadioButton(labels, checked_labels, *, padding=1, font_size=18, font_family='Arial', position=(0, 0))[source]#

Bases: Checkbox

A 2D set of :class:’Option’ objects. Only one option can be selected.

Attributes:
labelslist(string)

List of labels of each option.

optionsdict(Option)

Dictionary of all the options in the checkbox set.

paddingfloat

Get the padding between options.

ComboBox2D#

class fury.ui.elements.ComboBox2D(*, items=None, position=(0, 0), size=(300, 200), placeholder='Choose selection...', draggable=True, selection_text_color=(0, 0, 0), selection_bg_color=(1, 1, 1), menu_text_color=(0.2, 0.2, 0.2), selected_color=(0.9, 0.6, 0.6), unselected_color=(0.6, 0.6, 0.6), scroll_bar_active_color=(0.6, 0.2, 0.2), scroll_bar_inactive_color=(0.9, 0.0, 0.0), menu_opacity=1.0, reverse_scrolling=False, font_size=20, line_spacing=1.4)[source]#

Bases: UI

UI element to create drop-down menus.

Attributes:
selection_box: :class: ‘TextBox2D’

Display selection and placeholder text.

drop_down_button: :class: ‘Button2D’

Button to show or hide menu.

drop_down_menu: :class: ‘ListBox2D’

Container for item list.

append_item(*items)[source]#

Append additional options to the menu.

Parameters:
itemsn-d list, n-d tuple, Number or str

Additional options.

left_button_dragged(i_ren, _obj, _sub_component)[source]#
left_button_pressed(i_ren, _obj, _sub_component)[source]#
menu_toggle_callback(i_ren, _vtkactor, _combobox)[source]#

Toggle visibility of drop down menu list.

Parameters:
i_renCustomInteractorStyle
vtkactorvtkActor

The picked actor

comboboxComboBox2D
resize(size)[source]#

Resize ComboBox2D.

Parameters:
size(int, int)

ComboBox size(width, height) in pixels.

select_option_callback(i_ren, _obj, listboxitem)[source]#

Select the appropriate option

Parameters:
i_ren: :class:`CustomInteractorStyle`
obj: :class:`vtkActor`

The picked actor

listboxitem: :class:`ListBoxItem2D`
property selected_text#
property selected_text_index#
set_visibility(visibility)[source]#

Set visibility of this UI component.

ListBox2D#

class fury.ui.elements.ListBox2D(values, *, position=(0, 0), size=(100, 300), multiselection=True, reverse_scrolling=False, font_size=20, line_spacing=1.4, text_color=(0.2, 0.2, 0.2), selected_color=(0.9, 0.6, 0.6), unselected_color=(0.6, 0.6, 0.6), scroll_bar_active_color=(0.6, 0.2, 0.2), scroll_bar_inactive_color=(0.9, 0.0, 0.0), background_opacity=1.0)[source]#

Bases: UI

UI component that allows the user to select items from a list.

Attributes:
on_change: function

Callback function for when the selected items have changed.

clear_selection()[source]#
down_button_callback(i_ren, _obj, _list_box)[source]#

Pressing down button scrolls down in the combo box.

Parameters:
i_ren: :class:`CustomInteractorStyle`
obj: :class:`vtkActor`

The picked actor

_list_box: :class:`ListBox2D`
resize(size)[source]#
scroll_click_callback(i_ren, _obj, _rect_obj)[source]#

Callback to change the color of the bar when it is clicked.

Parameters:
i_ren: :class:`CustomInteractorStyle`
obj: :class:`vtkActor`

The picked actor

_rect_obj: :class:`Rectangle2D`
scroll_drag_callback(i_ren, _obj, _rect_obj)[source]#

Drag scroll bar in the combo box.

Parameters:
i_ren: :class:`CustomInteractorStyle`
obj: :class:`vtkActor`

The picked actor

rect_obj: :class:`Rectangle2D`
scroll_release_callback(i_ren, _obj, _rect_obj)[source]#

Callback to change the color of the bar when it is released.

Parameters:
i_ren: :class:`CustomInteractorStyle`
obj: :class:`vtkActor`

The picked actor

rect_obj: :class:`Rectangle2D`
select(item, *, multiselect=False, range_select=False)[source]#

Select the item.

Parameters:
item: ListBoxItem2D’s object

Item to select.

multiselect: {True, False}

If True and multiselection is allowed, the item is added to the selection. Otherwise, the selection will only contain the provided item unless range_select is True.

range_select: {True, False}

If True and multiselection is allowed, all items between the last selected item and the current one will be added to the selection. Otherwise, the selection will only contain the provided item unless multi_select is True.

up_button_callback(i_ren, _obj, _list_box)[source]#

Pressing up button scrolls up in the combo box.

Parameters:
i_ren: :class:`CustomInteractorStyle`
obj: :class:`vtkActor`

The picked actor

_list_box: :class:`ListBox2D`
update()[source]#

Refresh listbox’s content.

update_scrollbar()[source]#

Change the scroll-bar height when the values in the listbox change

ListBoxItem2D#

class fury.ui.elements.ListBoxItem2D(list_box, size, *, text_color=(1.0, 0.0, 0.0), selected_color=(0.4, 0.4, 0.4), unselected_color=(0.9, 0.9, 0.9), background_opacity=1.0)[source]#

Bases: UI

The text displayed in a listbox.

deselect()[source]#
property element#
left_button_clicked(i_ren, _obj, _list_box_item)[source]#

Handle left click for this UI element.

Parameters:
i_ren: :class:`CustomInteractorStyle`
obj: :class:`vtkActor`

The picked actor

_list_box_item: :class:`ListBoxItem2D`
resize(size)[source]#
select()[source]#

FileMenu2D#

class fury.ui.elements.FileMenu2D(directory_path, *, extensions=None, position=(0, 0), size=(100, 300), multiselection=True, reverse_scrolling=False, font_size=20, line_spacing=1.4)[source]#

Bases: UI

A menu to select files in the current folder.

Can go to new folder, previous folder and select multiple files.

Attributes:
extensions: [‘extension1’, ‘extension2’, ….]

To show all files, extensions=[“*”] or [“”] List of extensions to be shown as files.

listbox:class: ‘ListBox2D’

Container for the menu.

directory_click_callback(i_ren, _obj, listboxitem)[source]#

Handle the move into a directory if it has been clicked.

Parameters:
i_ren: :class:`CustomInteractorStyle`
obj: :class:`vtkActor`

The picked actor

listboxitem: :class:`ListBoxItem2D`
get_all_file_names()[source]#

Get file and directory names.

Returns:
all_file_names: list((string, {“directory”, “file”}))

List of all file and directory names as string.

get_directory_names()[source]#

Find names of all directories in the current_directory

Returns:
directory_names: list(string)

List of all directory names as string.

get_file_names()[source]#

Find names of all files in the current_directory

Returns:
file_names: list(string)

List of all file names as string.

resize(size)[source]#
scroll_callback(i_ren, _obj, _filemenu_item)[source]#

Handle scroll and change the slot text colors.

Parameters:
i_ren: :class:`CustomInteractorStyle`
obj: :class:`vtkActor`

The picked actor

_filemenu_item: :class:`FileMenu2D`
set_slot_colors()[source]#

Set the text color of the slots based on the type of element they show. Blue for directories and green for files.

DrawShape#

class fury.ui.elements.DrawShape(shape_type, *, drawpanel=None, position=(0, 0))[source]#

Bases: UI

Create and Manage 2D Shapes.

cal_bounding_box()[source]#

Calculate the min, max position and the size of the bounding box.

property center#
clamp_position(*, center=None)[source]#

Clamp the given center according to the DrawPanel canvas.

Parameters:
center(float, float)

(x, y) in pixels.

Returns:
new_center: ndarray(int)

New center for the shape.

property is_selected#
left_button_dragged(i_ren, _obj, shape)[source]#
left_button_pressed(i_ren, _obj, shape)[source]#
left_button_released(i_ren, _obj, shape)[source]#
remove()[source]#

Remove the Shape and all related actors.

resize(size)[source]#

Resize the UI.

rotate(angle)[source]#

Rotate the vertices of the UI component using specific angle.

Parameters:
angle: float

Value by which the vertices are rotated in radian.

selection_change()[source]#
update_shape_position(center_position)[source]#

Update the center position on the canvas.

Parameters:
center_position: (float, float)

Absolute pixel coordinates (x, y).

DrawPanel#

class fury.ui.elements.DrawPanel(*, size=(400, 400), position=(0, 0), is_draggable=False)[source]#

Bases: UI

The main Canvas(Panel2D) on which everything would be drawn.

cal_min_boundary_distance(position)[source]#

Calculate minimum distance between the current position and canvas boundary.

Parameters:
position: (float,float)

current position of the shape.

Returns:
float

Minimum distance from the boundary.

clamp_mouse_position(mouse_position)[source]#

Restrict the mouse position to the canvas boundary.

Parameters:
mouse_position: (float,float)

Current mouse position.

Returns:
list(float)

New clipped position.

property current_mode#
draw_shape(shape_type, current_position)[source]#

Draw the required shape at the given position.

Parameters:
shape_type: string

Type of shape - line, quad, circle.

current_position: (float,float)

Lower left corner position for the shape.

handle_mouse_click(position)[source]#
handle_mouse_drag(position)[source]#
left_button_dragged(i_ren, _obj, element)[source]#
left_button_pressed(i_ren, _obj, element)[source]#
resize(size)[source]#

Resize the UI.

resize_shape(current_position)[source]#

Resize the shape.

Parameters:
current_position: (float,float)

Lower left corner position for the shape.

show_rotation_slider()[source]#

Display the RingSlider2D to allow rotation of shape from the center.

update_button_icons(current_mode)[source]#

Update the button icon.

Parameters:
current_mode: string

Current mode of the UI.

update_shape_selection(selected_shape)[source]#

PlaybackPanel#

class fury.ui.elements.PlaybackPanel(*, loop=False, position=(0, 0), width=None)[source]#

Bases: UI

A playback controller that can do essential functionalities. such as play, pause, stop, and seek.

property current_time#

Get current time of the progress slider.

Returns:
float

Progress slider current value.

property current_time_str#

Returns current time as a string.

Returns:
str

Current time formatted as a string in the form:HH:MM:SS.

property final_time#

Set final progress slider time value.

Returns:
float

Final time for the progress slider.

hide()[source]#
loop()[source]#

Set repeating mode to loop.

pause()[source]#

Pause the playback

play()[source]#

Play the playback

play_once()[source]#

Set repeating mode to repeat once.

show()[source]#
property speed#

Returns current speed.

Returns:
str

Current time formatted as a string in the form:HH:MM:SS.

stop()[source]#

Stop the playback

property width#

Return the width of the PlaybackPanel

Returns:
float

The width of the PlaybackPanel.

Card2D#

class fury.ui.elements.Card2D(image_path, *, body_text='', draggable=True, title_text='', padding=10, position=(0, 0), size=(400, 400), image_scale=0.5, bg_color=(0.5, 0.5, 0.5), bg_opacity=1, title_color=(0.0, 0.0, 0.0), body_color=(0.0, 0.0, 0.0), border_color=(1.0, 1.0, 1.0), border_width=0, maintain_aspect=False)[source]#

Bases: UI

Card element to show image and related text

Attributes:
image: :class: ‘ImageContainer2D’

Renders the image on the card.

title_box: :class: ‘TextBlock2D’

Displays the title on card.

body_box: :class: ‘TextBLock2D’

Displays the body text.

property body#

Returns the body text of the card.

property color#

Returns the background color of card.

left_button_dragged(i_ren, _obj, _sub_component)[source]#
left_button_pressed(i_ren, _obj, _sub_component)[source]#
resize(size)[source]#

Resize Card2D.

Parameters:
size(int, int)

Card2D size(width, height) in pixels.

property title#

Returns the title text of the card

SpinBox#

class fury.ui.elements.SpinBox(*, position=(350, 400), size=(300, 100), padding=10, panel_color=(1, 1, 1), min_val=0, max_val=100, initial_val=50, step=1, max_column=10, max_line=2)[source]#

Bases: UI

SpinBox UI.

decrement()[source]#

Decrement the current value by the step.

decrement_callback(i_ren, _obj, _button)[source]#
increment()[source]#

Increment the current value by the step.

increment_callback(i_ren, _obj, _button)[source]#
resize(size)[source]#

Resize SpinBox.

Parameters:
size(float, float)

SpinBox size(width, height) in pixels.

textbox_update_value(textbox)[source]#
validate_value(value)[source]#

Validate and convert the given value into integer.

Parameters:
valuestr

Input value received from the textbox.

Returns:
int

If valid return converted integer else the previous value.

property value#

clip_overflow#

fury.ui.helpers.clip_overflow(textblock, width, *, side='right')[source]#

Clips overflowing text of TextBlock2D with respect to width.

Parameters:
textblockTextBlock2D

The textblock object whose text needs to be clipped.

widthint

Required width of the clipped text.

sidestr, optional

Clips the overflowing text according to side. It takes values “left” or “right”.

Returns:
clipped textstr

Clipped version of the text.

wrap_overflow#

fury.ui.helpers.wrap_overflow(textblock, wrap_width, *, side='right')[source]#

Wraps overflowing text of TextBlock2D with respect to width.

Parameters:
textblockTextBlock2D

The textblock object whose text needs to be wrapped.

wrap_widthint

Required width of the wrapped text.

sidestr, optional

Clips the overflowing text according to side. It takes values “left” or “right”.

Returns:
wrapped textstr

Wrapped version of the text.

check_overflow#

fury.ui.helpers.check_overflow(textblock, width, *, overflow_postfix='', side='right')[source]#

Checks if the text is overflowing.

Parameters:
textblockTextBlock2D

The textblock object whose text is to be checked.

width: int

Required width of the text.

overflow_postfix: str, optional

Postfix to be added to the text if it is overflowing.

Returns:
mid_ptr: int

Overflow index of the text.

cal_bounding_box_2d#

fury.ui.helpers.cal_bounding_box_2d(vertices)[source]#

Calculate the min, max position and the size of the bounding box.

Parameters:
verticesndarray

vertices of the actors.

rotate_2d#

fury.ui.helpers.rotate_2d(vertices, angle)[source]#

Rotate the given vertices by an angle.

Parameters:
verticesndarray

vertices of the actors.

angle: float

Value by which the vertices are rotated in radian.