Constants

Adding new constants is easy as pi with the Constant constructor:

esc.commands.Constant(value, key, description, menu)[source]

Register a new constant. Constants are just exceedingly boring operations that pop no values and push a constant value, so this is merely syntactic sugar.

Parameters:
  • value – The value of the constant, as a Decimal or a value that can be converted to one.
  • key – The key to press to select the constant from the menu.
  • description – A brief description to show next to the key.
  • menu – A Menu to place this function on.

The one trick here is that if you want to add your constant to the constants menu, you may not have access to the constants menu. In this case, use the trick for adding to existing menus:

from esc.commands import Constant, main_menu
constants_menu = main_menu.child('i')
Constant(299792458, 'c', 'speed of light (m/s)', constants_menu)

Since the constants menu is built in to esc, i will always be the constants menu and there is no need to perform the other checks described in the linked section.