IC Python API:RLPy RUi

From Reallusion Wiki!
Jump to: navigation, search
Main article: Modules.
Last modified: 05/12/2020

Description

This class is a package of instructions related to the application user interface (UI). It includes the ability to bridge communication between plugins and the application UI system, provides operations for the main window and menu, application version settings, show message boxes, open file browse dialog, as well as adding RIDialog and RIDockWidget related components, and much more. By using this class, developers can define plugin behaviors via custom user interfaces to achieve their goals.

Member Functions

GetMainWindow ( self )

Get the QWidget address for the main window. You can bind the main window to a PySide object by using this function, for UI operations.

Returns

QWidget address for the main window - QWidget address
1 # Get MainWindow QWidget address
2 main_widget = wrapInstance(int(RLPy.RUi.GetMainWindow()), PySide2.QtWidgets.QWidget)

AddMenu ( self, strMenuName, eParent )

Currently, this function can only create menu items within the Plugins menu. The Qmenu address is returned upon creation.

Parameters

strMenuName [IN] The desired menu item name - string
eParent [IN] The parent menu for this menu item - RLPy.EMenu

Returns

The QMenu address for the newly created menu item - QMenu address
1 # Add menu item to Plugins menu
2 menu_item = "TestMenu"
3 menu_address = RLPy.RUi.AddMenu(menu_item, RLPy.EMenu_Plugins)
4 print(menu_address)
5 
6 # add Test menu
7 plugin_menu = wrapInstance(int(RLPy.RUi.AddMenu("Test", RLPy.EMenu_Plugins)), PySide2.QtWidgets.QMenu)
8 plugin_action = plugin_menu.addAction("sub menu action")
9 plugin_action.triggered.connect(do_somthing)

RemoveMenu ( self, pMenu )

Remove a menu item from the main window. Currently, this function only supports removal of menu items from the Plugins menu.

Parameters

pMenu [IN] Menu item address for removal - QMenu address

Return

Success - RLPy.RStatus.Success
Failure - RLPy.RStatus.Failure
1 # Remove menu item from Plugins menu
2 menu_item = "TestMenu"
3 menu_address = RLPy.RUi.AddMenu(menu_item, RLPy.EMenu_Plugins)
4 result = RLPy.RUi.RemoveMenu(menu_address)
5 print(result)

AddHotKey ( self, strKeySequence )

Create and register a hotkey event. The input hotkey string will be compared with the keys within QKeySequence of the Qt component and returns a QAction address. If the given hotkey is already registered to another event, then the previous event will be replaced by the newly registered hotkey event. In order to revert to the previous event, one must first unregister the current event.

Parameters

strKeySequence [IN] The desired hot key name, to be compared to the keys in the QKeySequence of the Qt component - string

Returns

The QAction address for the newly created hotkey - QAction address

 1 import PySide2
 2 from PySide2.QtWidgets import QWidget
 3 from PySide2.shiboken2 import wrapInstance
 4 
 5 # Define global function
 6 def do_space_action():
 7     print("Space action start.")
 8 
 9 # Add hot key to trigger action
10 space_action = wrapInstance(int(RLPy.RUi.AddHotKey("Space")), PySide2.QtWidgets.QAction)
11 space_action.triggered.connect(do_space_action)
12 
13 # Add hot key(combo key) to trigger action
14 space_action = wrapInstance(int(RLPy.RUi.AddHotKey("Ctrl+G")), PySide2.QtWidgets.QAction)
15 space_action.triggered.connect(do_space_action)

RemoveHotKey ( self, pAction )

Remove a hotkey event registered to the given QAction address.

Parameters

pAction [IN] The QAction address of the hotkey designated for removal - QAction address

Return

Success - RLPy.RStatus.Success
Failure - RLPy.RStatus.Failure
 1 import PySide2
 2 from PySide2.QtWidgets import QWidget
 3 from PySide2.shiboken2 import wrapInstance
 4 # Define global function
 5 def do_space_action():
 6     print("Space action start.")
 7 
 8 # Remove hotkey
 9 space_action = wrapInstance(int(RLPy.RUi.AddHotKey("Space")), PySide2.QtWidgets.QAction)
10 space_action.triggered.connect(do_space_action)
11 result = RLPy.RUi.RemoveHotKey(space_action)
12 print(result)

GetResolutionType ( self )

Get the application resolution settings.

Returns

The current application resolution mode - RLPy.EResolutionType
1 # Get resolution type
2 resolusion_type = RLPy.RUi.GetResolutionType()
3 print(resolusion_type)

GetCSSType ( self )

Get the current application cascading style sheet (CSS) settings.

Returns

Application CSS settings - RLPy.ECSSType
1 # Get CSS type
2 css_type = RLPy.RUi.GetCSSType()
3 print(css_type)

ShowMessage ( self, strTitle, strMsg, eBtn, bChecked, strCheckBoxMsg )

Display a message box on the screen. The title, text content, and button options are configurable. Bitwise operations can be applied to combine different button types. The message box can also be set to contain a checkbox and a message to go with it. Developers can configure the appropriate response for the RLPy.EMsgButton enum return value. Activated checkboxes in the message box can be intercepted with the RLPy.EMsgButton_Ok return value.

See Also: RLPy.EMsgButton

Parameters

strTitle [IN] MessageBox title name - string
strMsg [IN] MessageBox message - string
eBtn [IN] MessageBox button options (Use bitwise operators to combine different types of buttons) - RLPy.EMsgButton
bChecked [IN] Whether to show a checkbox. Once it is present, its check state is also determined by this parameter - boolean
strCheckBoxMsg [IN] The message accompanies the checkbox - string

Returns

The integer value of this user interface's RLPy.EMsgButton - integer
 1 # show message box
 2 RLPy.RUi.ShowMessageBox("Title", "Msg", RLPy.EMsgButton_Ok)
 3   
 4 # show message box with checked option
 5 RLPy.RUi.ShowMessageBox("Title", "Msg", RLPy.EMsgButton_Ok, True, "CheckBoxMsg")
 6 
 7 # Show normal message box
 8 button_result_1 = RLPy.RUi.ShowMessageBox("Test Message Box", "Show message box test.", RLPy.EMsgButton_Ok)
 9 if button_result_1 == RLPy.EMsgButton_Ok:
10     print("Click button Ok.")
11 
12 # Show one-checked message box
13 button_result_2 = RLPy.RUi.ShowMessageBox("Test Message Box", "Show message box test one-checked.", RLPy.EMsgButton_Ok, True, "Don’t show next time.")
14 if btn_result != RLPy.EMsgButton_OkDontAskAgain: //must OK??
15     print("Click Button Ok.")
16 else:
17     print("Click Button Don’t ask again.")

OpenFileDialog ( self, strFilter, strStartingDirectory )

Browse for a file by opening the file open dialog window according to the extension filter and a starting directory. If the starting directory is an empty string, then it will automatically browse to the last directory location recorded by the application as the opening path.

See also: OpenFilesDialog

Parameters

strFilter [IN] File extension filters - string
strStartingDirectory [IN] The starting directory when opening a file (can be left blank) - string

Returns

The directory path of the opened file - string
 1 # Open file dialog without starting directory
 2 file_path = RLPy.RUi.OpenFileDialog("Json Files(*.json)")
 3 print(file_path)
 4       
 5 # open multiple files dialog
 6 file_path_list = RLPy.RUi.OpenFilesDialog("Json Files(*.json)")
 7 print(file_path_list)
 8 
 9 # Open file dialog with starting directory
10 template_data_path = RLPy.RApplication.GetTemplateDataPath()
11 file_path = RLPy.RUi.OpenFileDialog("Json Files(*.json)", template_data_path)
12 print(file_path)

OpenFilesDialog ( self, strFilter, strStartingDirectory )

Browse for multiple files by opening the file open dialog window according to the extension filter and a starting directory. If the starting directory is an empty string, then it will automatically browse to the last directory location recorded by the application as the opening path.

See also: OpenFileDialog

Parameters

strFilter [IN] File extension filters - string
strStartingDirectory [IN] The starting directory when opening a file (can be left blank) - string

Returns

A list of absolute paths to multiple files - string list
 1 # Open file dialog with all files
 2 file_path = RLPy.RUi.OpenFileDialog("All Files(*)")
 3 print(file_path)
 4 
 5 # Open file dialog with one format
 6 file_path = RLPy.RUi.OpenFileDialog("Json Files(*.json)")
 7 print(file_path)
 8 
 9 # Open file dialog with multi format
10 file_path = RLPy.RUi.OpenFileDialog("Image Files(*.jpg; *.jpeg; *.bmp; *.gif; *.png; *.tga)")
11 print(file_path)
12 
13 # Open file dialog with starting directory
14 template_data_path = RLPy.RApplication.GetTemplateDataPath()
15 file_path = RLPy.RUi.OpenFileDialog("Json Files(*.json)", template_data_path)
16 print(file_path)

SaveFileDialog ( self, strFilter )

Launch a save file dialog window and save a file to a specified file path. The possible file types can be restricted by the strFilter parameter. Once a file is saved, its absolute path is returned.

Parameters

strFilter [IN] File extension filters - string

Returns

File path of the saved file - string
1 # save file dialog
2 file_path = RLPy.RUi.SaveFileDialog("Json Files(*.json)")
3 print(file_path)

CreateRDialog ( self, eDialogType )

Create either a normal or exclusive dialog object and return it. A normal dialog can exist among other instances at the same time, while exclusive means that only one instance can be displayed at any given time.

Parameters

eDialogType [IN] type of dialog, if nothing is entered, then a normal dialog is created - RLPy.EDialogType

Returns

Smart pointer to the newly created dialog object - RIDialog smart pointer
 1 # Create normal RIDialog instance
 2 rl_normal_dialog = RLPy.RUi.CreateRDialog()
 3 print(rl_normal_dialog)
 4 
 5 # Create normal RIDialog instance
 6 rl_normal_dialog = RLPy.RUi.CreateRDialog(RLPy.EDialogType_Normal)
 7 print(rl_normal_dialog)
 8 
 9 # Create exclusive RIDialog instance
10 rl_exclusive_dialog = RLPy.RUi.CreateRDialog(RLPy.EDialogType_Exclusive)
11 print(rl_exclusive_dialog)

CreateRDockWidget ( self )

Create a new dock widget object and return it as RIDockWidget.

Parameters

strMenuName [IN] The desired menu item name - string
eParent [IN] The parent menu for this menu item, currently only supports the plugins menu - RLPy.EMenu

Returns

The newly created dock widget - RIDockWidget
1 # Create RIDockWidget instance
2 rl_dockwidget = RLPy.RUi.CreateRDockWidget()
3 print(rl_dockwidget)