Opens a dialog box for browsing a directory. In --noUI mode, you can simply enter a path here.
# Import the .NET class System.Environment from mscorlib.dll first
# Otherwise the Environment.SpecialFolder Enumeration is not available
from System import Environment
import os
# Set the necessary fields
dialog_message = "Select Python Example Directory"
preselected_path = r"c:\Python"
# Store the selected path
selected_path = system.ui.browse_directory_dialog(dialog_message, preselected_path, Environment.SpecialFolder.Desktop, True)
# Remember to check if the user canceled the dialog
if(selected_path != None):
# List files in the specified directory
print(os.listdir(selected_path))
It consists of 4 parameters:
oa string containing the message
oa string containing the path that will be preselected when the dialog box opens
othe Environment.SpecialFolder contains the root folder for the browse dialog box
oa boolean parameter: If True, a button allowing you to create new folders is displayed in the dialog box.
This method returns the selected path. If you cancel the dialog box, nothing is returned.
This method allows you to choose between one of several listed items.
# Set the necessary fields
option_list = ["TM221C16R", "TM241C24R", "TM258LF66DT4L"]
dialog_message = "Select the controller which should be added to the project:"
# A python tuple will be returned with the index of the selected item or -1 if canceled
selected_item = system.ui.choose(dialog_message, option_list, True)
# Remember to check if the user canceled the dialog
if(selected_item[0] != -1):
print(option_list[selected_item[0]] + " will be added to the project.")
It consists of 3 parameters:
oa string containing the message
oa list of options to be displayed: The objects are converted to string in order to display them.
oa boolean parameter: If True, a button allowing you to create new folders is displayed in the dialog box.
This method returns a Python tuple containing 2 items:
othe index of the selected item, or
-1 if cancelable was set to True and you canceled the dialog box
othe selected item or None
This method indicates an error detection message. It inhibits any further actions until the message has been acknowledged.
system.ui.error("Error")
This method indicates an information message. It inhibits any further actions until the message has been acknowledged.
# Set the necessary fields
dialog_message = "Project update has been completed successfully"
# This method is used to display a simple message to the user
system.ui.info(dialog_message)
This method displays an Open File dialog box. In --noUI mode, you can simply enter a path here.
# Set the necessary fields
dialog_title = "Select a Project"
dialog_filename = None
initial_directory = None
file_filter = "(*.project)|*.project"
# Open a select file dialog which only accepts *.project files
selected_file = system.ui.open_file_dialog(dialog_title, dialog_filename, initial_directory, file_filter)
# Remember to check if the user canceled the dialog
if(selected_file != None):
# Open the specified project
if projects.primary:
projects.primary.close()
projects.open(selected_file)
This method queries the input or edit of a text string.
# Set the necessary fields
dialog_message = "Please enter a filename for your project:"
dialog_prefilled_text = "c:\Python\QueryStringExample.project"
# This functions queries a string from the user
project_name = system.ui.query_string(dialog_message, dialog_prefilled_text)
# If a project is opened, the project will be saved under the new nameif(projects.primary):
projects.primary.save_as(project_name)
It returns a string with the entered text.
This method displays a Save File dialog box. In --noUI mode, you can simply enter a path here.
import os
# Set the necessary fields
dialog_title = "Select a Filename"
initial_directory, dialog_filename = os.path.split(projects.primary.path)
file_filter = "(*.project)|*.project"
# Open a select file dialog which only accepts *.project files
selected_file = system.ui.save_file_dialog(dialog_title, dialog_filename, initial_directory, file_filter)
# Remember to check if the user canceled the dialog
if(selected_file != None):
# File was saved under the specified name, lets close the project
projects.primary.close()
This method indicates a warning message. It inhibits any further actions until the message has been acknowledged.
# Set the necessary fields
dialog_message = "Project update failed. Please check the log for detailed errors."
# This method is used to display a simple warning to the user
system.ui.warning(dialog_message)