How to create a custom User Menu in Python
In this topic:
•Create and set up a Python script
•Apply the User Menu to a Workspace
This guide will walk you through the process of building and configuring a custom User Menu using winIDEA SDK and Python. You'll learn how to use a Python script to create tools, separators, and submenus, and integrate them into winIDEA's User Menu.
With custom User Menu, you can:
•Simplify repetitive tasks - Performing the same tasks repeatedly during development or testing can be simplified by adding these tasks to the User Menu, saving time and reducing errors. Some examples:
oRun a script to power cycle the system.
oRun a script that sets up system for debugging (e.g., set breakpoints, initialize peripheral states, load predefined data into memory).
•Centralize your workflow - The User Menu provides a single location to access various tools and commands, eliminating the need to navigate through directories or switch between multiple applications. Some examples:
oLaunch a CAN monitoring tool to observe traffic.
oSend custom CAN messages for diagnostics or simulation.
•winIDEA version 9.21.296 or newer
•Python environment installed. See Python in winIDEA for more information
•winIDEA SDK for Python. See winIDEA SDK for more information
Use your preferred Python IDE to create a new Python script. |
Import winIDEA SDK. |
Add the initial import and SDK setup to the script. |
import isystem.connect as ic |
Add functions that simplify the addition of tools, separators, and submenus to the User Menu.
Add a tool. |
def add_menu_tool(optToMenu, strMenuText, strCommand): |
Add a separator. |
def add_menu_separator(optToMenu): |
Add a submenu. |
def add_menu_sub(optToMenu, strSubMenuName): |
Follow these steps to configure and customize the User Menu in the main part of the script.
Access the Workspace configuration. |
cfg_ctrl = ic.CConfigurationController(conn_mgr) |
Set up Workspace tools. |
This will add Local Tools that will be used to launch external batch files.
optTools = optWS.opt('Tools.Tool') |
Add a tool item to the User Menu. |
optUserMenu = optWS.opt('UserMenu') |
Add a separator. |
add_menu_separator(optUserMenu) |
Add Items to the submenu. |
optSubMenu = add_menu_sub(optUserMenu, 'CAN Control') |
Refresh the User Menu. |
After configuring and building the User Menu, refresh it to reflect the changes.
ws_ctrl.invoke('/IDE/IDE', {'Operation': 'RefreshMenu'}) |
Once the script is ready you need to execute it once to apply the configuration to your Workspace.
Save the script to the winIDEA Workspace folder. |
Open the Workspace in winIDEA. |
Run the script under Tools | External Scripts | <script name>. |
Save the Workspace. |
The User Menu will be available upon restarting winIDEA and opening the Workspace.
You can modify the Custom Tools that were added (e.g., changing path to batch files) via Tools | Customize | Local Tools:
•How to create a winIDEA workspace programmatically in Python
•winIDEA SDK - User's Guide