Bootstrap Chameleon Logo

Modifying Slate though python

Modifying the Interface

When talking about modifying and getting the interface, it refers to the specific content of the interface, not the interface widgets themselves. It has been mentioned that SWidget objects are pure C++ objects, and there is no corresponding Python object that can be obtained or accessed. In TAPython, all operations on the interface are implemented through ChameleonData.

Modifying Content

For example, in the previous example chameleon_gallery.data.set_text(aka_name="IsPythonReadyText", text="Some Changed text"), we specify the widget name through the variable aka_name, and then pass in the new text.

CAUTION
Be careful not to modify the interface in a non-main thread. For example,threading.Thread(target=target_slate) is not allowed to modify the interface content in another thread. This will trigger UE's SLATE_CROSS_THREAD_CHECK.

Note

  • aka_name needs to be unique within a single ChameleonTool
  • When setting widget content, the widget type does not need to be considered
  • For example, we can use set_text to set text content for STextBlock, and also for SButton. In fact, STextBlock, SEditableText, SEditableTextBox, SMultiLineEditableText, SMultiLineEditableTextBox, SButton, etc., can all use this set_text to set text content
    • Similarly, set_float_value supports both "SSlider" and "SSpinBox" widgets

Manipulating Widgets

In addition to getting and modifying content, we also provide corresponding APIs for some interactive widgets, such as using scroll_to to scroll the SMultiLineEditableTextBox to the desired position.

Similar functions include:

set_scroll_box_offset

TIP
ScrollTo function, for scrolling the scrollbar to the specified location

Controlling Interface Visibility

In the Unreal editor interface, there are many dynamic interfaces that are actually implemented by controlling the visibility of widgets. If you have done GamePlayUMG, you should be able to understand this point intuitively. We will create all the interfaces needed before making the tool, and then the interface switching and other operations are actually controlling visibility (Visibility).

Slate widget visibility has the following 5 types:

Syntax Visible Occupies Space Clickable Child Widgets Clickable
Visible Yes Yes Yes Yes
Collapsed No No No No
Hidden No Yes No No
HitTestInvisible Yes Yes No No
SelfHitTestInvisible Yes Yes No Yes

Among the 5 Visible states above, "Visible" and "Collapsed" are the most commonly used. There are simplified calling versions for all of them. For example, in ObjectDetail, use set_collapsed to control visibility.

set_collapsed

self.data.set_collapsed(self.ui_rightButtonsGroup, bCollapsed)

set_visibility

We can set its state through set_visibility, for example, Shelf Tool uses it to control the visibility state of the last drag box:

    self.data.set_visibility(self.ui_drop_at_last_aka, "Collapsed")

he other three states are related to the response of click events, and are usually used to control which Overlay widget is in the "active" state and which responds to click events.

For example, in Shelf Tool, when the user needs to modify the text below the button, the "HitTestInvisible" state of the text widget is removed, allowing the user to drag the text cursor. Otherwise, the button below responds to the user's click event:

self.data.set_visibility(self.get_ui_text_name(i), "HitTestInvisible" if bLock else "Visible" )

Other

In addition to modifying content and visibility, we can also change the size and position of the entire tool window, etc. For more information, refer to Controlling Other Tools