menu: Replace menu with new Jinja2 template system (#2344)

menu.cfg:
- jinja2 template scripting
- new Setup menu
- new Calibration menu
menu:
- redesigned menu code
- jinja2 support
- option to reverse menu up and down directions
- functionality set to support menu injection from other modules
- a new way of defining menu hierarchy
- other adjustments

Signed-off-by: Janar Sööt <janar.soot@gmail.com>
This commit is contained in:
Janar Sööt 2020-08-09 16:29:55 +03:00 committed by GitHub
parent efebbb9a2f
commit d991b4c83b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1231 additions and 1592 deletions

View File

@ -1895,6 +1895,9 @@
# Timeout for menu. Being inactive this amount of seconds will trigger
# menu exit or return to root menu when having autorun enabled.
# The default is 0 seconds (disabled)
#menu_reverse_navigation:
# When enabled it will reverse up and down directions for list navigation.
# The default is False. This parameter is optional.
#encoder_pins:
# The pins connected to encoder. 2 pins must be provided when
# using encoder. This parameter must be provided when using menu.

View File

@ -3,153 +3,71 @@
# The snippets in this file may be copied into the main printer.cfg file.
# See the "example.cfg" file for description of common config parameters.
# Available menu elements:
# item - purely visual element
# command - same like 'item' but with gcode trigger
# input - same like 'command' but has value changing capabilities
# list - menu element container, with entry and exit gcode triggers
# vsdcard - same as 'list' but will append files from virtual sdcard
# Available options in menu Jinja2 template context:
# Read-only attributes for menu element:
# menu.width - element width (number of display columns)
# menu.ns - element namespace
# menu.event - name of the event that triggered the script
# menu.input - input value, only available in input script context
# List of actions for menu element:
# menu.back(force, update) - will execute menu back command, optional boolean parameters <force> and <update>.
# When <force> is set True then it will also stop editing. Default value is False
# When <update> is set False then parent container items are not updated. Default value is True
# menu.exit(force) - will execute menu exit command, optional boolean parameter <force> default value False
# When <force> is set True then it will also stop editing. Default value is False
#[menu item1]
#type: item
# Type will determine menu item properties and behaviours:
# Common parameters available for all menu config sections.
#[menu some_name]
#type:
# One of command, input, list, text:
# command - basic menu element with various script triggers
# input - same like 'command' but has value changing capabilities.
# Press will start/stop edit mode.
# list - it allows for menu items to be grouped together in a scrollable list.
# Add to the list by creating menu configurations
# using "some_list" as a prefix - for example: [menu some_list some_item_in_the_list]
# vsdlist - same as 'list' but will append files from virtual sdcard (will be removed in the future)
#name:
# This is mandatory attribute for every menu element.
# You can use Python output formatting for parameter and transform values.
# Quotes can be used in the beginning and end of name.
#cursor:
# It allows to change cursor character for selected menu element.
# The default is >
# This parameter is optional.
#width:
# This attribute accepts integer value. Element name is cut to this width.
# This parameter is optional.
#scroll:
# This attribute accepts static boolean value. You can use it together with 'width'.
# When this is enabled then names longer than width are scrolled back and forth.
# The default is disabled. This parameter is optional.
# Name of menu item - evaluated as a template.
#enable:
# This attribute accepts static boolean values and parameters (converted to boolean).
# It accepts multiple logical expressions. Values separated by comma will return True if all elements are true.
# Values on different lines will return True if any element is true.
# You can use logical negation by using character ! as parameter prefix.
#parameter:
# This attribute accepts float values or special variables. Multiple values are delimited by comma.
# All available parameter variables can be listed by 'MENU DO=dump' gcode, menu itself must be running.
# This value is available for output formatting as {0}..{n} Where n is count of parameters.
#transform:
# This attribute allows to transform parameters value to something else.
# More than one transformation can be added. Each transformation must be on separate line.
# These transformed values are available for output formatting as {n+1}..{x}
# Where n is count of parameters and x is count of transformations.
# In order to transform the value of a particular parameter, you must add
# an parameter index as prefix. Like this "transform: 1.choose('OFF','ON')"
# If the index is not set then the default index 0 is used.
#
# map(fromLow,fromHigh,toLow,toHigh) - interpolate re-maps a parameter value from one range to another.
# Output value type is taken from toHigh. It can be int or float.
#
# choose(e1,e2) - boolean chooser, converts the value of the parameter to the boolean type (0 and 1),
# and selects the corresponding value by the index from the list.
#
# choose(e1,e2,...) - int chooser, converts the value of the parameter to the int type
# and selects the corresponding value by the index from the list.
#
# choose({key:value,..}) - special dictionary chooser, parameter value cast type by first key type.
# Selects the corresponding value by the key from the dictionary.
#
# int(), float(), bool(), str(), abs(), bin(), hex(), oct(), days(), hours(), minutes(), seconds()
# These will convert parameter value to the special form.
# int,float,bool,str,abs,bin,hex and oct are python functions.
# days,hours,minutes,seconds will convert parameter value (it's taken as seconds) to time specific value
#
# scale(xx) - Multiplies parameter value by this xx. Pure interger or float value is excpected.
# Template that evaluates to True or False.
#index:
# Position where an item needs to be inserted in list
# By default the item is added at the end. This parameter is optional.
#[menu some_list]
#type: list
#name:
#enable:
#[menu command1]
#[menu some_list some_command]
#type: command
#name:
#cursor:
#width:
#scroll:
#enable:
#parameter:
#transform:
#gcode:
# When menu element is clicked then gcodes on this attribute will be executed.
# Can have multiline gcode script and supports output formatting for parameter and transform values.
#action:
# Special action can be executed. Supports [back, exit] menu commands
# and [respond response_info] command. Respond command will send '// response_info' to host.
# Script to run on button click or long click. Evaluated as a template.
#[menu input1]
#[menu some_list some_input]
#type: input
#name:
#cursor:
#width:
#enable:
#transform:
#parameter:
# Value from parameter (always index 0) is taken as input value when in edit mode.
#gcode:
# This will be triggered in realtime mode, on exit from edit mode
# or in edit mode this will be triggered after click button long press (>0.8sec).
#longpress_gcode:
# In edit mode this will be triggered after click button long press (>0.8sec).
# The default is empty. This parameter is optional.
#reverse:
# This attribute accepts static boolean value.
# When enabled it will reverse increment and decrement directions for input.
# The default is False. This parameter is optional.
#readonly:
# This attribute accepts same logical expression as 'enable'.
# When true then input element is readonly like 'item' and cannot enter to edit mode.
# The default is False. This parameter is optional.
#input:
# Initial value to use when editing - evaluated as a template.
# Result must be float.
#input_min:
# Minimum value of range - evaluated as a template.
# Default -99999.
#input_max:
# Maximum value of range - evaluated as a template.
# Default 99999.
#input_step:
# Editing step - Must be a positive integer or float value.
# It has internal fast rate step. When (input_max - input_min) / input_step > 100
# then fast rate step is 10 * input_step else fast rate step is same input_step
#realtime:
# This attribute accepts static boolean value.
# When enabled it will execute gcode after each value change.
# When enabled then gcode script is run after each value change.
# The default is False. This parameter is optional.
#input_min:
# It accepts integer or float value. Will set minimal bound for edit value.
# The default is 2.2250738585072014e-308. This parameter is optional.
#input_max:
# It accepts integer or float value. Will set maximal bound for edit value.
# The default is 1.7976931348623157e+308. This parameter is optional.
#input_step:
# This is mandatory attribute for input.
# It accepts positive integer or float value. Will determine increment
# and decrement steps for edit value.
#input_step2:
# This is optional attribute for input.
# It accepts positive integer or float value. Will determine fast rate
# increment and decrement steps for edit value.
# The default is 0 (input_step will be used instead)
#[menu list1]
#type:list or vsdcard
#name:
#cursor:
#width:
#scroll:
#enable:
#enter_gcode:
# Will trigger gcode script when entering to this menu container.
# This parameter is optional.
#leave_gcode:
# Will trigger gcode script when leaving from this menu container.
# This parameter is optional.
#show_back:
# This attribute accepts static boolean value.
# Show back [..] as first element.
# The default is True. This parameter is optional.
#show_title:
# This attribute accepts static boolean value.
# Show container name next to back [..] element.
# The default is True. This parameter is optional.
#items:
# Menu elements listed in this container.
# Each element must be on separate line.
# Elements can be grouped on same line by separating them with comma
#
# When element name stars with . then menu system will add parent
# container config name as prefix to element name (delimited by space)
#gcode:
# Script to run on button click, long click or value change. Evaluated as a template.
# The button click will trigger the edit mode start or end.

View File

@ -87,7 +87,7 @@ class PrinterLCD:
name = config.get_name()
if name == 'display':
# only load menu for primary display
self.menu = menu.MenuManager(config, self.lcd_chip)
self.menu = menu.MenuManager(config, self)
self.printer.load_object(config, "display_status")
# Configurable display
self.display_templates = {}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff