taichi.ui
¶
Submodules¶
Package Contents¶
Classes¶
Taichi Graphical User Interface class. |
|
Functions¶
|
Convert rgb color format to hex color format. |
|
Convert hex color format to rgb color format. |
Attributes¶
- class taichi.ui.GUI(name='Taichi', res=512, background_color=0, show_gui=True, fullscreen=False, fast_gui=False)¶
Taichi Graphical User Interface class.
- Parameters
name (str, optional) – The name of the GUI to be constructed. Default is ‘Taichi’.
res (Union[int, List[int]], optional) – The resolution of created GUI. Default is 512*512. If res is scalar, then width will be equal to height.
background_color (int, optional) – The background color of created GUI. Default is 0x000000.
show_gui (bool, optional) – Specify whether to render the GUI. Default is True.
fullscreen (bool, optional) – Specify whether to render the GUI in fullscreen mode. Default is False.
fast_gui (bool, optional) – Specify whether to use fast gui mode of Taichi. Default is False.
- Returns
The created taichi GUI object.
- Return type
GUI
- class Event¶
- SHIFT = Shift¶
- ALT = Alt¶
- CTRL = Control¶
- ESCAPE = Escape¶
- RETURN = Return¶
- TAB = Tab¶
- BACKSPACE = BackSpace¶
- SPACE =¶
- UP = Up¶
- DOWN = Down¶
- LEFT = Left¶
- RIGHT = Right¶
- CAPSLOCK = Caps_Lock¶
- LMB = LMB¶
- MMB = MMB¶
- RMB = RMB¶
- EXIT = WMClose¶
- WHEEL = Wheel¶
- MOVE = Motion¶
- MOTION¶
- PRESS¶
- RELEASE¶
- close(self)¶
- static get_bool_environ(key, default)¶
Get an environment variable and cast to bool. :param key: The environment variable key. :type key: str :param default: The default value. :type default: bool
- Returns
The environment variable value cast to bool. If the value is not found, directly return argument ‘default’.
- slider(self, text, minimum, maximum, step=1)¶
Create a slider object on canvas to be manipulated with.
- Parameters
text (str) – The title of slider.
minimum (Number) – The minimum value of slider.
maximum (Number) – The maximum value of slider.
step (Number, optional) – The changing step of slider. Default is 1.
- Returns
The created slider object.
- Return type
WidgetValue
- label(self, text)¶
Create a label object on canvas.
- Parameters
text (str) – The title of label.
- Returns
The created label object.
- Return type
WidgetValue
- button(self, text, event_name=None)¶
Create a button object on canvas to be manipulated with.
- Parameters
text (str) – The title of button.
event_name (str, optional) – The event name associated with button. Default is WidgetButton_{text}
- Returns
The event name associated with created button.
- clear(self, color=None)¶
Clear the canvas with the color provided.
- Parameters
color (int, optional) – Specify the color to clear the canvas. Default is the background color of GUI.
- cook_image(self, img)¶
- get_image(self)¶
Get the image data.
- Returns
The image data in numpy contiguous array type.
- Return type
numpy.array
- set_image(self, img)¶
Draw an image on canvas.
- Parameters
img (Union[ti.field, numpy.array]) – The color array representing the image to be drawn. Support greyscale, RG, RGB, and RGBA color representations. Its shape must match GUI resolution.
- circle(self, pos, color=16777215, radius=1)¶
Draw a single circle on canvas.
- Parameters
pos (Union[List[int], numpy.array]) – The position of the circle.
color (int, Optional) – The color of the circle. Default is 0xFFFFFF.
radius (Number, Optional) – The radius of the circle. Default is 1.
- circles(self, pos, radius=1, color=16777215, palette=None, palette_indices=None)¶
Draw a list of circles on canvas.
- Parameters
pos (numpy.array) – The positions of the circles.
radius (Number, optional) – The radius of the circles. Default is 1.
color (int, optional) – The color of the circles. Default is 0xFFFFFF.
palette (list[int], optional) – The List of colors from which to choose to draw. Default is None.
palette_indices (Union[list[int], ti.field, numpy.array], optional) – The List of indices that choose color from palette for each circle. Shape must match pos. Default is None.
- triangles(self, a, b, c, color=16777215)¶
Draw a list of triangles on canvas.
- Parameters
a (numpy.array) – The positions of the first points of triangles.
b (numpy.array) – The positions of the second points of triangles.
c (numpy.array) – The positions of the thrid points of triangles.
color (Union[int, numpy.array], optional) – The color or colors of triangles. Can be either a single color or a list of colors whose shape matches the shape of a & b & c. Default is 0xFFFFFF.
- triangle(self, a, b, c, color=16777215)¶
Draw a single triangle on canvas.
- Parameters
a (List[Number]) – The position of the first point of triangle. Shape must be 2.
b (List[Number]) – The position of the second point of triangle. Shape must be 2.
c (List[Number]) – The position of the third point of triangle. Shape must be 2.
color (int, optional) – The color of the triangle. Default is 0xFFFFFF.
- lines(self, begin, end, radius=1, color=16777215)¶
Draw a list of lines on canvas.
- Parameters
begin (numpy.array) – The positions of one end of lines.
end (numpy.array) – The positions of the other end of lines.
radius (Union[Number, numpy.array], optional) – The width of lines. Can be either a single width or a list of width whose shape matches the shape of begin & end. Default is 1.
color (Union[int, numpy.array], optional) – The color or colors of lines. Can be either a single color or a list of colors whose shape matches the shape of begin & end. Default is 0xFFFFFF.
- line(self, begin, end, radius=1, color=16777215)¶
Draw a single line on canvas.
- Parameters
begin (List[Number]) – The position of one end of line. Shape must be 2.
end (List[Number]) – The position of the other end of line. Shape must be 2.
radius (Number, optional) – The width of line. Default is 1.
color (int, optional) – The color of line. Default is 0xFFFFFF.
- arrows(self, orig, direction, radius=1, color=16777215, **kwargs)¶
Draw a list arrows on canvas.
- Parameters
orig (numpy.array) – The positions where arrows start.
direction (numpy.array) – The directions where arrows point to.
radius (Union[Number, np.array], optional) – The width of arrows. Default is 1.
color (Union[int, np.array], optional) – The color or colors of arrows. Default is 0xffffff.
- arrow(self, orig, direction, radius=1, color=16777215, **kwargs)¶
Draw a single arrow on canvas.
- Parameters
orig (List[Number]) – The position where arrow starts. Shape must be 2.
direction (List[Number]) – The direction where arrow points to. Shape must be 2.
radius (Number, optional) – The width of arrow. Default is 1.
color (int, optional) – The color of arrow. Default is 0xFFFFFF.
- rect(self, topleft, bottomright, radius=1, color=16777215)¶
Draw a single rectangle on canvas.
- Parameters
topleft (List[Number]) – The position of the topleft corner of rectangle. Shape must be 2.
bottomright (List[Number]) – The position of the bottomright corner of rectangle. Shape must be 2.
radius (Number, optional) – The width of rectangle’s sides. Default is 1.
color (int, optional) – The color of rectangle. Default is 0xFFFFFF.
- text(self, content, pos, font_size=15, color=16777215)¶
Draw texts on canvas.
- Parameters
content (str) – The text to be drawn on canvas.
pos (List[Number]) – The position where the text is to be put.
font_size (Number, optional) – The font size of the text.
color (int, optional) – The color of the text. Default is 0xFFFFFF.
- point_field(self, radius, color=16777215, bound=0.5)¶
Draw a field of points on canvas.
- Parameters
radius (np.array) – The pattern and radius of the field of points.
color (Union[int, np.array], optional) – The color or colors of points. Default is 0xFFFFFF.
bound (Number, optional) – The boundary of the field. Default is 0.5.
- arrow_field(self, direction, radius=1, color=16777215, bound=0.5, **kwargs)¶
Draw a field of arrows on canvas.
- Parameters
direction (np.array) – The pattern and direction of the field of arrows.
color (Union[int, np.array], optional) – The color or colors of arrows. Default is 0xFFFFFF.
bound (Number, optional) – The boundary of the field. Default is 0.5.
- show(self, file=None)¶
Show the frame or save current frame as a picture.
- Parameters
file (str, optional) – The path & name of the picture to be saved. Default is None.
- has_key_event(self)¶
Check if there are any key event registered.
- Returns
Bool to indicate whether there is any key event registered.
- get_event(self, *e_filter)¶
Check if the specific event is triggered.
- Parameters
*e_filter (ti.GUI.EVENT) – The specific event to be checked.
- Returns
Bool to indicate whether the specific event is triggered.
- get_events(self, *e_filter)¶
Get a list of events that are triggered.
- Parameters
*e_filter (List[ti.GUI.EVENT]) – The type of events to be filtered.
- Returns
A list of events that are triggered.
- Return type
EVENT
- get_key_event(self)¶
Get keyboard triggered event.
- Returns
The keyboard triggered event.
- Return type
EVENT
- is_pressed(self, *keys)¶
Check if the specific key or keys are pressed.
- Parameters
*keys (Union[str, List[str]]) – The string that stands for keys in keyboard.
- Returns
Bool to indicate whether the key or keys are pressed.
- get_cursor_pos(self)¶
Get the current position of mouse.
- Returns
The current position of mouse.
- property running(self)¶
Get the property of whether the gui is running.
- Returns
The running property of gui(bool).
- property fps_limit(self)¶
Get the property of fps limit.
- Returns
The property of fps limit of gui.
- taichi.ui.rgb_to_hex(c)¶
Convert rgb color format to hex color format.
- Parameters
c (List[int]) – The rgb representation of color.
- Returns
The hex representation of color.
- taichi.ui.hex_to_rgb(color)¶
Convert hex color format to rgb color format.
- Parameters
color (int) – The hex representation of color.
- Returns
The rgb representation of color.
- class taichi.ui.Gui(gui)¶
- sub_window(self, name, x, y, width, height)¶
Creating a context manager for subwindow
Note
All args of this method should align with begin.
- Parameters
x (float) – The x-coordinate (between 0 and 1) of the top-left corner of the subwindow, relative to the full window.
y (float) – The y-coordinate (between 0 and 1) of the top-left corner of the subwindow, relative to the full window.
width (float) – The width of the subwindow relative to the full window.
height (float) – The height of the subwindow relative to the full window.
Usage:
>>> with gui.sub_window(name, x, y, width, height) as g: >>> g.text("Hello, World!")
- begin(self, name, x, y, width, height)¶
Creates a subwindow that holds imgui widgets.
All widget function calls (e.g. text, button) after the begin and before the next end will describe the widgets within this subwindow.
- Parameters
x (float) – The x-coordinate (between 0 and 1) of the top-left corner of the subwindow, relative to the full window.
y (float) – The y-coordinate (between 0 and 1) of the top-left corner of the subwindow, relative to the full window.
width (float) – The width of the subwindow relative to the full window.
height (float) – The height of the subwindow relative to the full window.
- end(self)¶
End the description of the current subwindow.
- text(self, text)¶
Declares a line of text.
- checkbox(self, text, old_value)¶
Declares a checkbox, and returns whether or not it has been checked.
- Parameters
text (str) – a line of text to be shown next to the checkbox
old_value (bool) – whether the checkbox is currently checked
- slider_float(self, text, old_value, minimum, maximum)¶
Declares a slider, and returns its newest value.
- Parameters
text (str) – a line of text to be shown next to the slider
old_value (float) – the current value of the slider.
minimum (float) – the minimum value of the slider.
maximum (float) – the maximum value of the slider.
- color_edit_3(self, text, old_value)¶
Declares a color edit palate.
- Parameters
text (str) – a line of text to be shown next to the palate
old_value (Tuple[float]) – the current value of the color, this should be a tuple of floats in [0,1] that indicates RGB values.
- button(self, text)¶
Declares a button, and returns whether or not it had just been clicked.
- Parameters
text (str) – a line of text to be shown next to the button
- taichi.ui.GGUI_AVAILABLE¶
- taichi.ui.make_camera()¶