Difference between revisions of "IC Python API:RLPy RUi"

From Reallusion Wiki!
Jump to: navigation, search
(Created page with "{{TOC}} {{Parent|IC_Python_API:RL_Python_Modules|Modules}} ==Detailed Description== This class provides UI related operations. <syntaxhighlight lang="Python"> # add hot key -...")
 
m
 
Line 1: Line 1:
 
{{TOC}}
 
{{TOC}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
==Detailed Description==
+
{{last_modified}}
This class provides UI related operations.
+
 
<syntaxhighlight lang="Python">
+
== 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 [[IC_Python_API:RLPy_RIDialog|RIDialog]] and [[IC_Python_API:RLPy_RIDockWidget|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
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
# Get MainWindow QWidget address
 +
main_widget = wrapInstance(int(RLPy.RUi.GetMainWindow()), PySide2.QtWidgets.QWidget)
 +
</syntaxhighlight>
 +
 
 +
=== 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 - [[IC_Python_API:Enums#RLPy.EMenu|RLPy.EMenu]]
 +
 
 +
==== Returns ====
 +
:The QMenu address for the newly created menu item - QMenu address
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
# Add menu item to Plugins menu
 +
menu_item = "TestMenu"
 +
menu_address = RLPy.RUi.AddMenu(menu_item, RLPy.EMenu_Plugins)
 +
print(menu_address)
  
# add hot key - space
 
def do_somthing():
 
  print("do something.")
 
 
sapce_hot_key = RLPy.RUi.AddHotKey("Space")
 
space_action = wrapInstance(int(sapce_hot_key), PySide2.QtWidgets.QAction)
 
space_action.triggered.connect(do_somthing)
 
# remove hot key
 
RLPy.RUi.RemoveHotKey(sapce_hot_key)
 
 
 
# add Test menu
 
# add Test menu
 
plugin_menu = wrapInstance(int(RLPy.RUi.AddMenu("Test", RLPy.EMenu_Plugins)), PySide2.QtWidgets.QMenu)
 
plugin_menu = wrapInstance(int(RLPy.RUi.AddMenu("Test", RLPy.EMenu_Plugins)), PySide2.QtWidgets.QMenu)
 
plugin_action = plugin_menu.addAction("sub menu action")
 
plugin_action = plugin_menu.addAction("sub menu action")
 
plugin_action.triggered.connect(do_somthing)
 
plugin_action.triggered.connect(do_somthing)
# remove menu
 
RLPy.RUi.RemoveMenu(plugin_menu)
 
 
# open file dialog
 
file_path = RLPy.RUi.OpenFileDialog("Json Files(*.json)")
 
print(file_path)
 
  
 
# open multiple files dialog
 
file_path_list = RLPy.RUi.OpenFilesDialog("Json Files(*.json)")
 
print(file_path_list)
 
  
 
# save file dialog
 
file_path = RLPy.RUi.SaveFileDialog("Json Files(*.json)")
 
print(file_path)
 
  
 
# show message box
 
RLPy.RUi.ShowMessageBox("Title", "Msg", RLPy.EMsgButton_Ok)
 
 
# show message box with checked option
 
RLPy.RUi.ShowMessageBox("Title", "Msg", RLPy.EMsgButton_Ok, True, "CheckBoxMsg")
 
 
</syntaxhighlight>
 
</syntaxhighlight>
==Member Functions==
+
 
===AddHotKey===
+
=== RemoveMenu ( self, pMenu ) ===
<syntaxhighlight lang="Python">
+
 
RLPy.RUi.AddHotKey ( strKeySequence )
+
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
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
# Remove menu item from Plugins menu
 +
menu_item = "TestMenu"
 +
menu_address = RLPy.RUi.AddMenu(menu_item, RLPy.EMenu_Plugins)
 +
result = RLPy.RUi.RemoveMenu(menu_address)
 +
print(result)
 
</syntaxhighlight>
 
</syntaxhighlight>
Add HotKey.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''strKeySequence''' [IN] Hot key sequence - string
+
=== AddHotKey ( self, strKeySequence ) ===
</div>
+
 
====Returns====
+
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.
<div style="margin-left: 2em;">HotKey action - QAction
+
 
</div>
+
==== Parameters ====
-----
+
:'''strKeySequence''' [IN] The desired hot key name, to be compared to the keys in the '''QKeySequence''' of the Qt component - string
===AddMenu===
+
 
<syntaxhighlight lang="Python">
+
==== Returns ====
RLPy.RUi.AddMenu ( args )
+
The QAction address for the newly created hotkey - QAction address
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
import PySide2
 +
from PySide2.QtWidgets import QWidget
 +
from PySide2.shiboken2 import wrapInstance
 +
 
 +
# Define global function
 +
def do_space_action():
 +
    print("Space action start.")
 +
 
 +
# Add hot key to trigger action
 +
space_action = wrapInstance(int(RLPy.RUi.AddHotKey("Space")), PySide2.QtWidgets.QAction)
 +
space_action.triggered.connect(do_space_action)
 +
 
 +
# Add hot key(combo key) to trigger action
 +
space_action = wrapInstance(int(RLPy.RUi.AddHotKey("Ctrl+G")), PySide2.QtWidgets.QAction)
 +
space_action.triggered.connect(do_space_action)
 
</syntaxhighlight>
 
</syntaxhighlight>
Add menu.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''strMenuName''' [IN] Name of the menu - string
+
=== RemoveHotKey ( self, pAction ) ===
  
'''eParent''' [IN] Parent of the menu - RLPy.EMenu
+
Remove a hotkey event registered to the given '''QAction''' address.
*'''RLPy.EMenu_Plugins Plugins menu.
+
 
</div>
+
==== Parameters ====
====Returns====
+
:'''pAction''' [IN] The '''QAction''' address of the hotkey designated for removal - QAction address
<div style="margin-left: 2em;">Address of menu - QMenu
+
 
</div>
+
==== Return ====
-----
+
:Success - RLPy.RStatus.Success
===CreateRDialog===
+
:Failure - RLPy.RStatus.Failure
<syntaxhighlight lang="Python">
+
 
RLPy.RUi.CreateRDialog ( args )
+
<syntaxhighlight lang="python" line='line'>
 +
import PySide2
 +
from PySide2.QtWidgets import QWidget
 +
from PySide2.shiboken2 import wrapInstance
 +
# Define global function
 +
def do_space_action():
 +
    print("Space action start.")
 +
 
 +
# Remove hotkey
 +
space_action = wrapInstance(int(RLPy.RUi.AddHotKey("Space")), PySide2.QtWidgets.QAction)
 +
space_action.triggered.connect(do_space_action)
 +
result = RLPy.RUi.RemoveHotKey(space_action)
 +
print(result)
 
</syntaxhighlight>
 
</syntaxhighlight>
Create dialog.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''eDialogType''' [IN] dialog is normal or exclusive - RLPy.EDialogType
+
=== GetResolutionType ( self ) ===
*'''RLPy.EDialogType_Normal'''
+
 
*'''RLPy.EDialogType_Exclusive'''
+
Get the application resolution settings.
</div>
+
 
====Returns====
+
==== Returns ====
<div style="margin-left: 2em;">RIDialog smart pointer - RLPy.RIDialog
+
:The current application resolution mode - [[IC_Python_API:Enums#RLPy.EResolutionType|RLPy.EResolutionType]]
</div>
+
 
-----
+
<syntaxhighlight lang="python" line='line'>
===CreateRDockWidget===
+
# Get resolution type
<syntaxhighlight lang="Python">
+
resolusion_type = RLPy.RUi.GetResolutionType()
RLPy.RUi.CreateRDockWidget ( )
+
print(resolusion_type)
 
</syntaxhighlight>
 
</syntaxhighlight>
Create dockwidget.
+
 
====Returns====
+
=== GetCSSType ( self ) ===
<div style="margin-left: 2em;">RIDockWidget smart pointer - RLPy.RIDockWidget
+
 
</div>
+
Get the current application cascading style sheet (CSS) settings.
-----
+
 
===GetCSSType===
+
==== Returns ====
<syntaxhighlight lang="Python">
+
:Application CSS settings - [[IC_Python_API:Enums#RLPy.ECSSType|RLPy.ECSSType]]
RLPy.RUi.GetCSSType ( )
+
 
</syntaxhighlight>
+
<syntaxhighlight lang="python" line='line'>
Get CSS type.
+
# Get CSS type
====Returns====
+
css_type = RLPy.RUi.GetCSSType()
<div style="margin-left: 2em;">Type of CSS - RLPy.ECSSType
+
print(css_type)
*'''RLPy.ECSSType_Color_0'''
+
*'''RLPy.ECSSType_Color_1'''
+
</div>
+
-----
+
===GetMainWindow===
+
<syntaxhighlight lang="Python">
+
RLPy.RUi.GetMainWindow ( )
+
</syntaxhighlight>
+
Get MainWindow's address.
+
====Returns====
+
<div style="margin-left: 2em;">Address of main window - QWidget
+
</div>
+
-----
+
===GetResolutionType===
+
<syntaxhighlight lang="Python">
+
RLPy.RUi.GetResolutionType ( )
+
 
</syntaxhighlight>
 
</syntaxhighlight>
Get resolution type.
 
====Returns====
 
<div style="margin-left: 2em;">Type of resolution - RLPy.EResolutionType
 
*'''RLPy.EResolutionType_Large'''
 
*'''RLPy.EResolutionType_Original'''
 
*'''RLPy.EResolutionType_Small'''
 
</div>
 
-----
 
===OpenFileDialog===
 
<syntaxhighlight lang="Python">
 
RLPy.RUi.OpenFileDialog ( args )
 
</syntaxhighlight>
 
Show the open file dialog and returns the selected file path name.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''strFilter''' [IN] File filter - string
+
=== ShowMessage ( self, strTitle, strMsg, eBtn, bChecked, strCheckBoxMsg ) ===
</div>
+
 
====Returns====
+
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 [[IC_Python_API:Enums#RLPy.EMsgButton|RLPy.EMsgButton]] enum return value. Activated checkboxes in the message box can be intercepted with the ''' [[IC_Python_API:Enums#RLPy.EMsgButton|RLPy.EMsgButton]]_Ok''' return value.
<div style="margin-left: 2em;">File path of selected file - string
+
 
</div>
+
See Also: [[IC_Python_API:Enums#RLPy.EMsgButton|RLPy.EMsgButton]]
-----
+
 
===OpenFilesDialog===
+
==== Parameters ====
<syntaxhighlight lang="Python">
+
:'''strTitle''' [IN] MessageBox title name - string
RLPy.RUi.OpenFilesDialog ( args )
+
:'''strMsg''' [IN] MessageBox message - string
 +
:'''eBtn''' [IN] MessageBox button options (Use bitwise operators to combine different types of buttons) - [[IC_Python_API:Enums#RLPy.EMsgButton|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 [[IC_Python_API:Enums#RLPy.EMsgButton|RLPy.EMsgButton]] - integer
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
# show message box
 +
RLPy.RUi.ShowMessageBox("Title", "Msg", RLPy.EMsgButton_Ok)
 +
 
 +
# show message box with checked option
 +
RLPy.RUi.ShowMessageBox("Title", "Msg", RLPy.EMsgButton_Ok, True, "CheckBoxMsg")
 +
 
 +
# Show normal message box
 +
button_result_1 = RLPy.RUi.ShowMessageBox("Test Message Box", "Show message box test.", RLPy.EMsgButton_Ok)
 +
if button_result_1 == RLPy.EMsgButton_Ok:
 +
    print("Click button Ok.")
 +
 
 +
# Show one-checked message box
 +
button_result_2 = RLPy.RUi.ShowMessageBox("Test Message Box", "Show message box test one-checked.", RLPy.EMsgButton_Ok, True, "Don’t show next time.")
 +
if btn_result != RLPy.EMsgButton_OkDontAskAgain: //must OK??
 +
    print("Click Button Ok.")
 +
else:
 +
    print("Click Button Don’t ask again.")
 
</syntaxhighlight>
 
</syntaxhighlight>
Show the open file dialog and returns multiple selected file path names.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''strFilter''' [IN] File filter - string
+
=== OpenFileDialog ( self, strFilter, strStartingDirectory ) ===
</div>
+
 
====Returns====
+
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.
<div style="margin-left: 2em;">File paths of selected files - string
+
 
</div>
+
See also: [[#OpenFilesDialog ( self, strFilter, strStartingDirectory )|OpenFilesDialog]]
-----
+
 
===RemoveHotKey===
+
==== Parameters ====
<syntaxhighlight lang="Python">
+
:'''strFilter''' [IN] File extension filters - string
RLPy.RUi.RemoveHotKey ( pAction )
+
:'''strStartingDirectory''' [IN] The starting directory when opening a file (can be left blank) - string
 +
 
 +
==== Returns ====
 +
:The directory path of the opened file - string
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
# Open file dialog without starting directory
 +
file_path = RLPy.RUi.OpenFileDialog("Json Files(*.json)")
 +
print(file_path)
 +
     
 +
# open multiple files dialog
 +
file_path_list = RLPy.RUi.OpenFilesDialog("Json Files(*.json)")
 +
print(file_path_list)
 +
 
 +
# Open file dialog with starting directory
 +
template_data_path = RLPy.RApplication.GetTemplateDataPath()
 +
file_path = RLPy.RUi.OpenFileDialog("Json Files(*.json)", template_data_path)
 +
print(file_path)
 
</syntaxhighlight>
 
</syntaxhighlight>
Remove HotKey.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''pAction''' [IN] HotKey to remove - QAction
+
=== OpenFilesDialog ( self, strFilter, strStartingDirectory ) ===
</div>
+
 
====Returns====
+
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.
<div style="margin-left: 2em;">Success or Failure - RLPy.RStatus
+
 
</div>
+
See also: [[#OpenFileDialog ( self, strFilter, strStartingDirectory )|OpenFileDialog]]
-----
+
 
===RemoveMenu===
+
==== Parameters ====
<syntaxhighlight lang="Python">
+
:'''strFilter''' [IN] File extension filters - string
RLPy.RUi.RemoveMenu ( pMenu )
+
:'''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
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
# Open file dialog with all files
 +
file_path = RLPy.RUi.OpenFileDialog("All Files(*)")
 +
print(file_path)
 +
 
 +
# Open file dialog with one format
 +
file_path = RLPy.RUi.OpenFileDialog("Json Files(*.json)")
 +
print(file_path)
 +
 
 +
# Open file dialog with multi format
 +
file_path = RLPy.RUi.OpenFileDialog("Image Files(*.jpg; *.jpeg; *.bmp; *.gif; *.png; *.tga)")
 +
print(file_path)
 +
 
 +
# Open file dialog with starting directory
 +
template_data_path = RLPy.RApplication.GetTemplateDataPath()
 +
file_path = RLPy.RUi.OpenFileDialog("Json Files(*.json)", template_data_path)
 +
print(file_path)
 
</syntaxhighlight>
 
</syntaxhighlight>
Remove Menu.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''pMenu''' [IN] menu to remove - QMenu
+
=== SaveFileDialog ( self, strFilter ) ===
</div>
+
 
====Returns====
+
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.
<div style="margin-left: 2em;">Success or Failure - RLPy.RStatus
+
 
</div>
+
==== Parameters ====
-----
+
:'''strFilter''' [IN] File extension filters - string
===SaveFileDialog===
+
 
<syntaxhighlight lang="Python">
+
==== Returns ====
RLPy.RUi.SaveFileDialog ( strFilter )
+
:File path of the saved file - string
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
# save file dialog
 +
file_path = RLPy.RUi.SaveFileDialog("Json Files(*.json)")
 +
print(file_path)
 
</syntaxhighlight>
 
</syntaxhighlight>
Show the save file dialog and returns the selected file path name.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''strFilter''' [IN] File filter - string
+
=== CreateRDialog ( self, eDialogType ) ===
</div>
+
 
====Returns====
+
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.
<div style="margin-left: 2em;">File path of selected file - string
+
 
</div>
+
==== Parameters ====
-----
+
:'''eDialogType''' [IN] type of dialog, if nothing is entered, then a normal dialog is created - [[IC_Python_API:Enums#RLPy.EDialogType|RLPy.EDialogType]]
===ShowMessageBox===
+
 
<syntaxhighlight lang="Python">
+
==== Returns ====
RLPy.RUi.ShowMessageBox ( args )
+
:Smart pointer to the newly created dialog object - [[IC_Python_API:RLPy_RIDialog|RIDialog]] smart pointer
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
# Create normal RIDialog instance
 +
rl_normal_dialog = RLPy.RUi.CreateRDialog()
 +
print(rl_normal_dialog)
 +
 
 +
# Create normal RIDialog instance
 +
rl_normal_dialog = RLPy.RUi.CreateRDialog(RLPy.EDialogType_Normal)
 +
print(rl_normal_dialog)
 +
 
 +
# Create exclusive RIDialog instance
 +
rl_exclusive_dialog = RLPy.RUi.CreateRDialog(RLPy.EDialogType_Exclusive)
 +
print(rl_exclusive_dialog)
 
</syntaxhighlight>
 
</syntaxhighlight>
Show message.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''strTitle''' [IN] Title of message box - string
+
=== CreateRDockWidget ( self ) ===
  
'''strMsg''' [IN] Message in message box - string
+
Create a new dock widget object and return it as [[IC_Python_API:RLPy_RIDockWidget|RIDockWidget]].
  
'''eBtn''' [IN] Button configuration - RLPy.EMsgButton
+
==== Parameters ====
*'''RLPy.EMsgButton_NoButton'''
+
:'''strMenuName''' [IN] The desired menu item name - string
*'''RLPy.EMsgButton_Ok'''
+
:'''eParent''' [IN] The parent menu for this menu item, currently only supports the plugins menu - [[IC_Python_API:Enums#RLPy.EMenu|RLPy.EMenu]]
*'''RLPy.EMsgButton_Save'''
+
*'''RLPy.EMsgButton_SaveAll'''
+
*'''RLPy.EMsgButton_Open'''
+
*'''RLPy.EMsgButton_Yes'''
+
*'''RLPy.EMsgButton_YesToAll'''
+
*'''RLPy.EMsgButton_No'''
+
*'''RLPy.EMsgButton_NoToAll'''
+
*'''RLPy.EMsgButton_Abort'''
+
*'''RLPy.EMsgButton_Retry'''
+
*'''RLPy.EMsgButton_Overlook'''
+
*'''RLPy.EMsgButton_Close'''
+
*'''RLPy.EMsgButton_Cancel'''
+
*'''RLPy.EMsgButton_Discard'''
+
*'''RLPy.EMsgButton_Help'''
+
*'''RLPy.EMsgButton_Apply'''
+
*'''RLPy.EMsgButton_Reset'''
+
*'''RLPy.EMsgButton_RestoreDefaults'''
+
*'''RLPy.EMsgButton_OkDontAskAgain'''
+
  
'''bChecked''' [IN] show checked message box if True - bool
+
=== Returns ===
 +
:The newly created dock widget - [[IC_Python_API:RLPy_RIDockWidget|RIDockWidget]]
  
'''strCheckBoxMsg''' [IN] Checked message - string
+
<syntaxhighlight lang="python" line='line'>
</div>
+
# Create RIDockWidget instance
====Returns====
+
rl_dockwidget = RLPy.RUi.CreateRDockWidget()
<div style="margin-left: 2em;">Button status - int
+
print(rl_dockwidget)
</div>
+
</syntaxhighlight>

Latest revision as of 00:33, 12 May 2020

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)