ui

Button2D(icon_fnames[, position, size])

A 2D overlay button and is of type vtkTexturedActor2D.

Checkbox(labels[, padding, font_size, …])

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

CustomInteractorStyle()

Manipulate the camera and interact with objects in the scene.

Disk2D(outer_radius[, inner_radius, center, …])

A 2D disk UI component.

FileMenu2D(directory_path[, extensions, …])

A menu to select files in the current folder.

GridUI(actors[, captions, caption_offset, …])

Add actors in a grid and interact with them individually.

ImageContainer2D(img_path[, position, size])

A 2D container to hold an image.

LineDoubleSlider2D([line_width, …])

A 2D Line Slider with two sliding rings.

LineSlider2D([center, initial_value, …])

A 2D Line Slider.

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.

Option(label[, position, font_size])

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

Panel2D(size[, position, color, opacity, align])

A 2D UI Panel.

RadioButton(labels[, padding, font_size, …])

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

RangeSlider([line_width, inner_radius, …])

A set of a LineSlider2D and a LineDoubleSlider2D.

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

A 2D rectangle sub-classed from UI.

RingSlider2D([center, initial_value, …])

A disk slider.

TextBlock2D([text, font_size, font_family, …])

Wraps over the default vtkTextActor and helps setting the text.

TextBox2D(width, height[, text, position, …])

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

UI([position])

An umbrella class for all UI elements.

grid(actors[, captions, caption_offset, …])

Creates a grid of actors that lies in the xy-plane.

read_viz_icons([style, fname])

Read specific icon from specific style.

rotate(actor[, rotation])

Rotate actor around axis by angle.

set_input(vtk_object, inp)

Set Generic input function which takes into account VTK 5 or 6.

warn()

Issue a warning, or maybe ignore it or raise an exception.

with_metaclass(meta, \*bases)

Create a base class with a metaclass.

Button2D

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

Bases: fury.ui.UI

A 2D overlay button and is of type vtkTexturedActor2D.

Currently supports:

- Multiple icons.
- Switching between icons.
__init__(self, icon_fnames, position=(0, 0), size=(30, 30))[source]

Init class instance.

Parameters
icon_fnamesList(string, string)

((iconname, filename), (iconname, filename), ….)

position(float, float), optional

Absolute coordinates (x, y) of the lower-left corner of the button.

size(int, int), optional

Width and height in pixels of the button.

color

Gets the button’s color.

next_icon(self)[source]

Increments the state of the Button.

Also changes the icon.

next_icon_id(self)[source]

Sets the next icon ID while cycling through icons.

resize(self, size)[source]

Resize the button.

Parameters
size(float, float)

Button size (width, height) in pixels.

scale(self, factor)[source]

Scales the button.

Parameters
factor(float, float)

Scaling factor (width, height) in pixels.

set_icon(self, icon)[source]

Modifies the icon used by the vtkTexturedActor2D.

Parameters
iconimageDataGeometryFilter
set_icon_by_name(self, icon_name)[source]

Set the button icon using its name.

Parameters
icon_namestr

Checkbox

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

Bases: fury.ui.UI

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

Attributes
labelslist(string)

List of labels of each option.

optionslist(Option)

List of all the options in the checkbox set.

paddingfloat

Gets the padding between options.

__init__(self, labels, padding=1, font_size=18, font_family='Arial', position=(0, 0))[source]
Parameters
labelslist(string)

List of labels of each option.

paddingfloat

The distance between two adjacent options

font_sizeint

Size of the text font.

font_familystr

Currently only supports Arial.

position(float, float)

Absolute coordinates (x, y) of the lower-left corner of the button of the first option.

font_size

Gets the font size of text.

padding

Gets the padding between options.

CustomInteractorStyle

class fury.ui.CustomInteractorStyle[source]

Bases: vtkInteractionStylePython.vtkInteractorStyleUser

Manipulate the camera and interact with objects in the scene.

This interactor style allows the user to interactively manipulate (pan, rotate and zoom) the camera. It also allows the user to interact (click, scroll, etc.) with objects in the scene.

Several events handling methods from vtkInteractorStyleUser have been overloaded to allow the propagation of the events to the objects the user is interacting with.

In summary, while interacting with the scene, the mouse events are as follows:

- Left mouse button: rotates the camera
- Right mouse button: dollys the camera
- Mouse wheel: dollys the camera
- Middle mouse button: pans the camera
__init__(self)[source]

Init.

SetInteractor(self, interactor)[source]

Define new interactor.

add_active_prop(self, prop)[source]
add_callback(self, prop, event_type, callback, priority=0, args=[])[source]

Add a callback associated to a specific event for a VTK prop.

Parameters
propvtkProp
event_typeevent code
callbackfunction
priorityint
force_render(self)[source]

Causes the scene to refresh.

get_prop_at_event_position(self)[source]

Return the prop that lays at the event position.

on_char(self, _obj, evt)[source]
on_key_press(self, _obj, evt)[source]
on_key_release(self, _obj, evt)[source]
on_left_button_down(self, _obj, evt)[source]
on_left_button_up(self, _obj, evt)[source]
on_middle_button_down(self, _obj, evt)[source]
on_middle_button_up(self, _obj, evt)[source]
on_mouse_move(self, _obj, evt)[source]

On mouse move.

on_mouse_wheel_backward(self, _obj, evt)[source]

On mouse wheel backward.

on_mouse_wheel_forward(self, _obj, evt)[source]

On mouse wheel forward.

on_right_button_down(self, _obj, evt)[source]
on_right_button_up(self, _obj, evt)[source]
propagate_event(self, evt, *props)[source]
remove_active_prop(self, prop)[source]

Disk2D

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

Bases: fury.ui.UI

A 2D disk UI component.

__init__(self, outer_radius, inner_radius=0, center=(0, 0), color=(1, 1, 1), opacity=1.0)[source]

Initializes a rectangle.

Parameters
outer_radiusint

Outer radius of the disk.

inner_radiusint, optional

Inner radius of the disk. A value > 0, makes a ring.

center(float, float), optional

Coordinates (x, y) of the center of the disk.

color(float, float, float), optional

Must take values in [0, 1].

opacityfloat, optional

Must take values in [0, 1].

color

Gets the rectangle’s color.

inner_radius
opacity

Gets the rectangle’s opacity.

outer_radius

FileMenu2D

class fury.ui.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: fury.ui.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.

__init__(self, directory_path, extensions=None, position=(0, 0), size=(100, 300), multiselection=True, reverse_scrolling=False, font_size=20, line_spacing=1.4)[source]
Parameters
extensions: list(string)

List of extensions to be shown as files.

directory_path: string

Path of the directory where this dialog should open.

position(float, float)

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

size(int, int)

Width and height in pixels of this UI component.

multiselection: {True, False}

Whether multiple values can be selected at once.

reverse_scrolling: {True, False}

If True, scrolling up will move the list of files down.

font_size: int

The font size in pixels.

line_spacing: float

Distance between listbox’s items in pixels.

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

A callback to 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(self)[source]

Gets file and directory names.

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

List of all file and directory names as string.

get_directory_names(self)[source]

Finds names of all directories in the current_directory

Returns
directory_names: list(string)

List of all directory names as string.

get_file_names(self)[source]

Finds names of all files in the current_directory

Returns
file_names: list(string)

List of all file names as string.

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

A callback to 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(self)[source]

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

GridUI

class fury.ui.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: fury.ui.UI

Add actors in a grid and interact with them individually.

__init__(self, 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]

Init scene.

Parameters
position(float, float)

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

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(self, 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(self, size)[source]

Resize the button.

Parameters
size(float, float)

Button size (width, height) in pixels.

ImageContainer2D

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

Bases: fury.ui.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.

imgvtkImageDataGeometryFilters

The image loaded from the specified path.

__init__(self, img_path, position=(0, 0), size=(100, 100))[source]
Parameters
img_pathstring

Path of the image

position(float, float), optional

Absolute coordinates (x, y) of the lower-left corner of the image.

size(int, int), optional

Width and height in pixels of the image.

resize(self, size)[source]

Resize the image.

Parameters
size(float, float)

image size (width, height) in pixels.

scale(self, factor)[source]

Scales the image.

Parameters
factor(float, float)

Scaling factor (width, height) in pixels.

set_img(self, img)[source]

Modifies the image used by the vtkTexturedActor2D.

Parameters
imgimageDataGeometryFilter

LineDoubleSlider2D

class fury.ui.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}', shape='disk')[source]

Bases: fury.ui.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.

__init__(self, 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}', shape='disk')[source]
Parameters
line_widthint

Width of the line on which the disk will slide.

inner_radiusint

Inner radius of the handles (if disk).

outer_radiusint

Outer radius of the handles (if disk).

handle_sideint

Side length of the handles (if sqaure).

center(float, float)

Center of the slider.

lengthint

Length of the slider.

initial_values(float, float)

Initial values of the two handles.

min_valuefloat

Minimum value of the slider.

max_valuefloat

Maximum value of the slider.

font_sizeint

Size of the text to display alongside the slider (pt).

text_templatestr, callable

If str, text template can contain one or multiple of the replacement fields: {value:}, {ratio:}. If callable, this instance of :class:LineDoubleSlider2D will be passed as argument to the text template function.

shapestring

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

coord_to_ratio(self, coord)[source]

Converts the x coordinate of a disk to the ratio

Parameters
coordfloat
format_text(self, disk_number)[source]

Returns formatted text to display along the slider.

Parameters
disk_numberIndex of the disk.
handle_move_callback(self, i_ren, vtkactor, _slider)[source]

Actual handle movement.

Parameters
i_renCustomInteractorStyle
vtkactorvtkActor

The picked actor

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

Change color when handle is released.

Parameters
i_renCustomInteractorStyle
vtkactorvtkActor

The picked actor

_sliderLineDoubleSlider2D
left_disk_ratio

Returns the ratio of the left disk.

left_disk_value

Returns the value of the left disk.

left_x_position
ratio_to_coord(self, ratio)[source]

Converts the ratio to the absolute coordinate.

Parameters
ratiofloat
ratio_to_value(self, ratio)[source]

Converts the ratio to the value of the disk.

Parameters
ratiofloat
right_disk_ratio

Returns the ratio of the right disk.

right_disk_value

Returns the value of the right disk.

right_x_position
set_position(self, position, disk_number)[source]

Sets the disk’s position.

Parameters
position(float, float)

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

disk_numberint

The index of disk being moved.

update(self, disk_number)[source]

Updates the slider.

Parameters
disk_numberIndex of the disk to be updated.
value_to_ratio(self, value)[source]

Converts the value of a disk to the ratio

Parameters
valuefloat

LineSlider2D

class fury.ui.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, text_template='{value:.1f} ({ratio:.0%})', shape='disk')[source]

Bases: fury.ui.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.

__init__(self, 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, text_template='{value:.1f} ({ratio:.0%})', shape='disk')[source]
Parameters
center(float, float)

Center of the slider’s center.

initial_valuefloat

Initial value of the slider.

min_valuefloat

Minimum value of the slider.

max_valuefloat

Maximum value of the slider.

lengthint

Length of the slider.

line_widthint

Width of the line on which the disk will slide.

inner_radiusint

Inner radius of the handles (if disk).

outer_radiusint

Outer radius of the handles (if disk).

handle_sideint

Side length of the handles (if sqaure).

font_sizeint

Size of the text to display alongside the slider (pt).

text_templatestr, callable

If str, text template can contain one or multiple of the replacement fields: {value:}, {ratio:}. If callable, this instance of :class:LineSlider2D will be passed as argument to the text template function.

shapestring

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

format_text(self)[source]

Returns formatted text to display along the slider.

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

Actual handle movement.

Parameters
i_renCustomInteractorStyle
vtkactorvtkActor

The picked actor

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

Change color when handle is released.

Parameters
i_renCustomInteractorStyle
vtkactorvtkActor

The picked actor

sliderLineSlider2D
left_x_position
ratio
right_x_position
set_position(self, position)[source]

Sets the disk’s position.

Parameters
position(float, float)

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

track_click_callback(self, i_ren, _vtkactor, _slider)[source]

Update disk position and grab the focus.

Parameters
i_renCustomInteractorStyle
vtkactorvtkActor

The picked actor

_sliderLineSlider2D
update(self)[source]

Updates the slider.

value

ListBox2D

class fury.ui.ListBox2D(values, position=(0, 0), size=(100, 300), multiselection=True, reverse_scrolling=False, font_size=20, line_spacing=1.4)[source]

Bases: fury.ui.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.

__init__(self, values, position=(0, 0), size=(100, 300), multiselection=True, reverse_scrolling=False, font_size=20, line_spacing=1.4)[source]
Parameters
values: list of objects

Values used to populate this listbox. Objects must be castable to string.

position(float, float)

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

size(int, int)

Width and height in pixels of this UI component.

multiselection: {True, False}

Whether multiple values can be selected at once.

reverse_scrolling: {True, False}

If True, scrolling up will move the list of files down.

font_size: int

The font size in pixels.

line_spacing: float

Distance between listbox’s items in pixels.

clear_selection(self)[source]
down_button_callback(self, 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(self, size)[source]
scroll_click_callback(self, 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(self, i_ren, _obj, _rect_obj)[source]

Dragging scroll bar in the combo box.

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

The picked actor

rect_obj: :class:`Rectangle2D`
scroll_release_callback(self, 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(self, 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(self, 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(self)[source]

Refresh listbox’s content.

update_scrollbar(self)[source]

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

ListBoxItem2D

class fury.ui.ListBoxItem2D(list_box, size)[source]

Bases: fury.ui.UI

The text displayed in a listbox.

__init__(self, list_box, size)[source]
Parameters
list_box: :class:`ListBox`

The ListBox reference this text belongs to.

size: int

The size of the listbox item.

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

A callback to handle left click for this UI element.

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

The picked actor

_list_box_item: :class:`ListBoxItem2D`
select(self)[source]

Option

class fury.ui.Option(label, position=(0, 0), font_size=18)[source]

Bases: fury.ui.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.

__init__(self, label, position=(0, 0), font_size=18)[source]
Parameters
labelstr

Text to be displayed next to the option’s button.

position(float, float)

Absolute coordinates (x, y) of the lower-left corner of the button of the option.

font_sizeint

Font size of the label.

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

Panel2D

class fury.ui.Panel2D(size, position=(0, 0), color=(0.1, 0.1, 0.1), opacity=0.7, align='left')[source]

Bases: fury.ui.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.

__init__(self, size, position=(0, 0), color=(0.1, 0.1, 0.1), opacity=0.7, align='left')[source]
Parameters
size(int, int)

Size (width, height) in pixels of the panel.

position(float, float)

Absolute coordinates (x, y) of the lower-left corner of the panel.

color(float, float, float)

Must take values in [0, 1].

opacityfloat

Must take values in [0, 1].

align[left, right]

Alignment of the panel with respect to the overall screen.

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

Adds 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.

color
left_button_dragged(self, i_ren, _obj, _panel2d_object)[source]
left_button_pressed(self, i_ren, _obj, panel2d_object)[source]
opacity
re_align(self, window_size_change)[source]

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

Parameters
window_size_change(int, int)

New window size (width, height) in pixels.

remove_element(self, element)[source]

Removes a UI component from the panel.

Parameters
elementUI

The UI item to be removed.

resize(self, size)[source]

Sets the panel size.

Parameters
size(float, float)

Panel size (width, height) in pixels.

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

Updates 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.

RadioButton

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

Bases: fury.ui.Checkbox

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

Attributes
labelslist(string)

List of labels of each option.

optionslist(Option)

List of all the options in the checkbox set.

paddingfloat

Gets the padding between options.

__init__(self, labels, padding=1, font_size=18, font_family='Arial', position=(0, 0))[source]
Parameters
labelslist(string)

List of labels of each option.

paddingfloat

The distance between two adjacent options

font_sizeint

Size of the text font.

font_familystr

Currently only supports Arial.

position(float, float)

Absolute coordinates (x, y) of the lower-left corner of the button of the first option.

RangeSlider

class fury.ui.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, value_precision=2, shape='disk')[source]

Bases: fury.ui.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

__init__(self, 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, value_precision=2, shape='disk')[source]
Parameters
line_widthint

Width of the slider tracks

inner_radiusint

Inner radius of the handles.

outer_radiusint

Outer radius of the handles.

handle_sideint

Side length of the handles (if square).

range_slider_center(float, float)

Center of the LineDoubleSlider2D object.

value_slider_center(float, float)

Center of the LineSlider2D object.

lengthint

Length of the sliders.

min_valuefloat

Minimum value of the double slider.

max_valuefloat

Maximum value of the double slider.

font_sizeint

Size of the text to display alongside the sliders (pt).

range_precisionint

Number of decimal places to show the min and max values set.

value_precisionint

Number of decimal places to show the value set on slider.

shapestring

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

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

Actual movement of range_slider’s handles.

Parameters
i_renCustomInteractorStyle
objvtkActor

The picked actor

_sliderRangeSlider

Rectangle2D

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

Bases: fury.ui.UI

A 2D rectangle sub-classed from UI.

__init__(self, size=(0, 0), position=(0, 0), color=(1, 1, 1), opacity=1.0)[source]

Initializes a rectangle.

Parameters
size(int, int)

The size of the rectangle (width, height) in pixels.

position(float, float)

Coordinates (x, y) of the lower-left corner of the rectangle.

color(float, float, float)

Must take values in [0, 1].

opacityfloat

Must take values in [0, 1].

color

Gets the rectangle’s color.

height
opacity

Gets the rectangle’s opacity.

resize(self, size)[source]

Sets the button size.

Parameters
size(float, float)

Button size (width, height) in pixels.

width

RingSlider2D

class fury.ui.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: fury.ui.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.

__init__(self, 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]
Parameters
center(float, float)

Position (x, y) of the slider’s center.

initial_valuefloat

Initial value of the slider.

min_valuefloat

Minimum value of the slider.

max_valuefloat

Maximum value of the slider.

slider_inner_radiusint

Inner radius of the base disk.

slider_outer_radiusint

Outer radius of the base disk.

handle_outer_radiusint

Outer radius of the slider’s handle.

handle_inner_radiusint

Inner radius of the slider’s handle.

font_sizeint

Size of the text to display alongside the slider (pt).

text_templatestr, callable

If str, text template can contain one or multiple of the replacement fields: {value:}, {ratio:}, {angle:}. If callable, this instance of :class:RingSlider2D will be passed as argument to the text template function.

angle

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

format_text(self)[source]

Returns formatted text to display along the slider.

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

Move the slider’s handle.

Parameters
i_renCustomInteractorStyle
objvtkActor

The picked actor

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

Change color when handle is released.

Parameters
i_renCustomInteractorStyle
vtkactorvtkActor

The picked actor

_sliderRingSlider2D
mid_track_radius
move_handle(self, click_position)[source]

Moves the slider’s handle.

Parameters
click_position: (float, float)

Position of the mouse click.

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

Update disk position and grab the focus.

Parameters
i_renCustomInteractorStyle
objvtkActor

The picked actor

_sliderRingSlider2D
update(self)[source]

Updates the slider.

value

TextBlock2D

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

Bases: fury.ui.UI

Wraps over the default vtkTextActor and helps setting the text.

Contains member functions for text formatting.

Attributes
actorvtkTextActor

The text actor.

messagestr

Gets message from the text.

position(float, float)

(x, y) in pixels.

color(float, float, float)

Gets text color.

bg_color(float, float, float)

RGB: Values must be between 0-1.

font_sizeint

Gets text font size.

font_familystr

Gets font family.

justificationstr

Gets text justification.

vertical_justificationstr

Gets text vertical justification.

boldbool

Returns whether the text is bold.

italicbool

Returns whether the text is italicised.

shadowbool

Returns whether the text has shadow.

__init__(self, text='Text Block', font_size=18, font_family='Arial', justification='left', vertical_justification='bottom', bold=False, italic=False, shadow=False, color=(1, 1, 1), bg_color=None, position=(0, 0))[source]
Parameters
textstr

The initial text while building the actor.

position(float, float)

(x, y) in pixels.

color(float, float, float)

RGB: Values must be between 0-1.

bg_color(float, float, float)

RGB: Values must be between 0-1.

font_sizeint

Size of the text font.

font_familystr

Currently only supports Arial.

justificationstr

left, right or center.

vertical_justificationstr

bottom, middle or top.

boldbool

Makes text bold.

italicbool

Makes text italicised.

shadowbool

Adds text shadow.

background_color

Gets background color.

Returns
(float, float, float) or None

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

bold

Returns whether the text is bold.

Returns
bool

Text is bold if True.

color

Gets text color.

Returns
(float, float, float)

Returns text color in RGB.

font_family

Gets font family.

Returns
str

Text font family.

font_size

Gets text font size.

Returns
int

Text font size.

italic

Returns whether the text is italicised.

Returns
bool

Text is italicised if True.

justification

Gets text justification.

Returns
str

Text justification.

message

Gets message from the text.

Returns
str

The current text message.

shadow

Returns whether the text has shadow.

Returns
bool

Text is shadowed if True.

vertical_justification

Gets text vertical justification.

Returns
str

Text vertical justification.

TextBox2D

class fury.ui.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: fury.ui.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.

__init__(self, 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]
Parameters
widthint

The number of characters in a single line of text.

heightint

The number of lines in the textbox.

textstr

The initial text while building the actor.

position(float, float)

(x, y) in pixels.

color(float, float, float)

RGB: Values must be between 0-1.

font_sizeint

Size of the text font.

font_familystr

Currently only supports Arial.

justificationstr

left, right or center.

boldbool

Makes text bold.

italicbool

Makes text italicised.

shadowbool

Adds text shadow.

add_character(self, character)[source]

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

Parameters
characterstr
edit_mode(self)[source]

Turns on edit mode.

handle_character(self, character)[source]

Main driving function that handles button events.

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

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

Key press handler for textbox

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

The picked actor

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

Left button press handler for textbox

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

The picked actor

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

Moves left boundary of the text window left-wards.

left_move_right(self)[source]

Moves left boundary of the text window right-wards.

move_caret_left(self)[source]

Moves the caret towards left.

move_caret_right(self)[source]

Moves the caret towards right.

move_left(self)[source]

Handles left button press.

move_right(self)[source]

Handles right button press.

remove_character(self)[source]

Removes a character and moves window and caret accordingly.

render_text(self, show_caret=True)[source]

Renders text after processing.

Parameters
show_caretbool

Whether or not to show the caret.

right_move_left(self)[source]

Moves right boundary of the text window left-wards.

right_move_right(self)[source]

Moves right boundary of the text window right-wards.

set_message(self, message)[source]

Set custom text to textbox.

Parameters
message: str

The custom message to be set.

showable_text(self, show_caret)[source]

Chops out text to be shown on the screen.

Parameters
show_caretbool

Whether or not to show the caret.

width_set_text(self, text)[source]

Adds 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.

UI

class fury.ui.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_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_button_dragged: function

Callback function for when dragging using the right mouse button.

on_key_press: function

Callback function for when a keyboard key is pressed.

__init__(self, position=(0, 0))[source]

Init scene.

Parameters
position(float, float)

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

actors

Actors composing this UI component.

add_callback(self, 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(self, scene)[source]

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

Parameters
scenescene
center
handle_events(self, 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 mouse_move_callback(i_ren, obj, self)[source]
position
static right_button_click_callback(i_ren, obj, self)[source]
static right_button_release_callback(i_ren, obj, self)[source]
set_visibility(self, visibility)[source]

Set visibility of this UI component.

size

grid

fury.ui.grid(actors, captions=None, caption_offset=(0, -100, 0), cell_padding=0, cell_shape='rect', aspect_ratio=1.7777777777777777, dim=None)[source]

Creates a grid of actors that lies in the xy-plane.

Parameters
actorslist of vtkProp3D objects

Actors to be layout in a grid manner.

captionslist of vtkProp3D objects or list of str

Objects serving as captions (can be any vtkProp3D object, not necessarily text). There should be one caption per actor. By default, there are no captions.

caption_offsettuple of float (optional)

Tells where to position the caption w.r.t. the center of its associated actor. Default: (0, -100, 0).

cell_paddingtuple of 2 floats or float

Each grid cell will be padded according to (pad_x, pad_y) i.e. horizontally and vertically. Padding is evenly distributed on each side of the cell. If a single float is provided then both pad_x and pad_y will have the same value.

cell_shapestr

Specifies the desired shape of every grid cell. ‘rect’ ensures the cells are the tightest. ‘square’ ensures the cells are as wide as high. ‘diagonal’ ensures the content of the cells can be rotated without colliding with content of the neighboring cells.

aspect_ratiofloat

Aspect ratio of the grid (width/height). Default: 16:9.

dimtuple of int

Dimension (nb_rows, nb_cols) of the grid. If provided, aspect_ratio will be ignored.

Returns
fury.actor.Container object

Object that represents the grid containing all the actors and captions, if any.

read_viz_icons

fury.ui.read_viz_icons(style='icomoon', fname='infinity.png')[source]

Read specific icon from specific style.

Parameters
stylestr

Current icon style. Default is icomoon.

fnamestr

Filename of icon. This should be found in folder HOME/.fury/style/. Default is infinity.png.

Returns
pathstr

Complete path of icon.

rotate

fury.ui.rotate(actor, rotation=(90, 1, 0, 0))[source]

Rotate actor around axis by angle.

Parameters
actorvtkActor or other prop
rotationtuple

Rotate with angle w around axis x, y, z. Needs to be provided in the form (w, x, y, z).

set_input

fury.ui.set_input(vtk_object, inp)[source]

Set Generic input function which takes into account VTK 5 or 6.

Parameters
vtk_object: vtk object
inp: vtkPolyData or vtkImageData or vtkAlgorithmOutput
Returns
vtk_object

Notes

This can be used in the following way::

from fury.utils import set_input poly_mapper = set_input(vtk.vtkPolyDataMapper(), poly_data)

warn

fury.ui.warn()

Issue a warning, or maybe ignore it or raise an exception.

with_metaclass

fury.ui.with_metaclass(meta, *bases)[source]

Create a base class with a metaclass.