Please enable JavaScript to view this site.

winIDEA Help

Version: 9.21.366

Navigation: winIDEA SDK > How-to guides

Scroll Prev Top Next More

How to create a custom User Menu in Python

In this topic:

Requirements

Create and set up a Python script

Add utility functions

Build the User Menu

Apply the User Menu to a Workspace

 

 

Introduction

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.

 

 

Requirements

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

 

 

Configuration steps

Create and set up a Python script

number1

Use your preferred Python IDE to create a new Python script.

 

number2

Import winIDEA SDK.

 

number3

Add the initial import and SDK setup to the script.

import isystem.connect as ic
 
 
conn_mgr = ic.ConnectionMgr()
conn_mgr.connect()
ws_ctrl = ic.CWorkspaceController(conn_mgr)

 

 

Add utility functions

Add functions that simplify the addition of tools, separators, and submenus to the User Menu.

 

number1

Add a tool.

def add_menu_tool(optToMenu, strMenuText, strCommand):
   optUM = optToMenu.add()
   optUM.set_multi({'Type':'ExternalTool', 'Name':strMenuText, 'Command':strCommand})

 

 

number2

Add a separator.

def add_menu_separator(optToMenu):
   optUM = optToMenu.add()
   optUM.set('Type', 'Separator')

 

 

number3

Add a submenu.

def add_menu_sub(optToMenu, strSubMenuName):
   optUM = optToMenu.add()
   optUM.set_multi({'Type':'SubMenu', 'Name':strSubMenuName})
   return optUM.opt('SubMenu')

 

 

Build the User Menu

Follow these steps to configure and customize the User Menu in the main part of the script.

 

number1

Access the Workspace configuration.

cfg_ctrl = ic.CConfigurationController(conn_mgr)
optWS = cfg_ctrl.ide_ws()

 

 

number2

Set up Workspace tools.

This will add Local Tools that will be used to launch external batch files.

 

optTools = optWS.opt('Tools.Tool')
optTool = optTools.add()
optTool.set_multi({'MenuText':'Power Cycle System Tool', 'Command': r'C:\power_cycle_system.bat'})
optTool = optTools.add()
optTool.set_multi({'MenuText':'Open CAN Monitor Tool', 'Command': r'C:\open_can_monitor.bat'})
optTool = optTools.add()
optTool.set_multi({'MenuText':'Send CAN Message Tool', 'Command': r'C:\send_can_message.bat'})

 

 

number3

Add a tool item to the User Menu.

optUserMenu = optWS.opt('UserMenu')
add_menu_tool(optUserMenu, 'Power Cycle System', 'Power Cycle System Tool')

 

 

Number4

Add a separator.

add_menu_separator(optUserMenu)

 

 

Number5

Add Items to the submenu.

optSubMenu = add_menu_sub(optUserMenu, 'CAN Control')
add_menu_tool(optSubMenu , 'Open CAN Monitor', 'Open CAN Monitor Tool')
add_menu_tool(optSubMenu , 'Send CAN Message', 'Send CAN Message Tool')

 

 

number6

Refresh the User Menu.

After configuring and building the User Menu, refresh it to reflect the changes.

 

ws_ctrl.invoke('/IDE/IDE', {'Operation': 'RefreshMenu'})

 

 

Apply the User Menu to a Workspace

Once the script is ready you need to execute it once to apply the configuration to your Workspace.

 

number1

Save the script to the winIDEA Workspace folder.

 

number2

Open the Workspace in winIDEA.

 

number3

Run the script under Tools | External Scripts | <script name>.

 

scripts-CustomUserMenu

 

 

Number4

Save the Workspace.

The User Menu will be available upon restarting winIDEA and opening the Workspace.

 

CustomUserMenu

 

 

You can modify the Custom Tools that were added (e.g., changing path to batch files) via Tools | Customize | Local Tools:

 

CustomUserMenu-Customize-LocalTools

 

 

More resources

How to create a winIDEA workspace programmatically in Python

Python in winIDEA

winIDEA SDK - User's Guide

 

 

Copyright © 2025 TASKING