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:
parent
efebbb9a2f
commit
d991b4c83b
|
@ -1895,6 +1895,9 @@
|
||||||
# Timeout for menu. Being inactive this amount of seconds will trigger
|
# Timeout for menu. Being inactive this amount of seconds will trigger
|
||||||
# menu exit or return to root menu when having autorun enabled.
|
# menu exit or return to root menu when having autorun enabled.
|
||||||
# The default is 0 seconds (disabled)
|
# 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:
|
#encoder_pins:
|
||||||
# The pins connected to encoder. 2 pins must be provided when
|
# The pins connected to encoder. 2 pins must be provided when
|
||||||
# using encoder. This parameter must be provided when using menu.
|
# using encoder. This parameter must be provided when using menu.
|
||||||
|
|
|
@ -3,153 +3,71 @@
|
||||||
# The snippets in this file may be copied into the main printer.cfg file.
|
# 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.
|
# See the "example.cfg" file for description of common config parameters.
|
||||||
|
|
||||||
# Available menu elements:
|
# Available options in menu Jinja2 template context:
|
||||||
# item - purely visual element
|
# Read-only attributes for menu element:
|
||||||
# command - same like 'item' but with gcode trigger
|
# menu.width - element width (number of display columns)
|
||||||
# input - same like 'command' but has value changing capabilities
|
# menu.ns - element namespace
|
||||||
# list - menu element container, with entry and exit gcode triggers
|
# menu.event - name of the event that triggered the script
|
||||||
# vsdcard - same as 'list' but will append files from virtual sdcard
|
# 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]
|
# Common parameters available for all menu config sections.
|
||||||
#type: item
|
#[menu some_name]
|
||||||
# Type will determine menu item properties and behaviours:
|
#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:
|
#name:
|
||||||
# This is mandatory attribute for every menu element.
|
# Name of menu item - evaluated as a template.
|
||||||
# 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.
|
|
||||||
#enable:
|
#enable:
|
||||||
# This attribute accepts static boolean values and parameters (converted to boolean).
|
# Template that evaluates to True or False.
|
||||||
# It accepts multiple logical expressions. Values separated by comma will return True if all elements are true.
|
#index:
|
||||||
# Values on different lines will return True if any element is true.
|
# Position where an item needs to be inserted in list
|
||||||
# You can use logical negation by using character ! as parameter prefix.
|
# By default the item is added at the end. This parameter is optional.
|
||||||
#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.
|
|
||||||
|
|
||||||
|
#[menu some_list]
|
||||||
#[menu command1]
|
#type: list
|
||||||
#type:command
|
#name:
|
||||||
|
#enable:
|
||||||
|
|
||||||
|
#[menu some_list some_command]
|
||||||
|
#type: command
|
||||||
#name:
|
#name:
|
||||||
#cursor:
|
|
||||||
#width:
|
|
||||||
#scroll:
|
|
||||||
#enable:
|
#enable:
|
||||||
#parameter:
|
|
||||||
#transform:
|
|
||||||
#gcode:
|
#gcode:
|
||||||
# When menu element is clicked then gcodes on this attribute will be executed.
|
# Script to run on button click or long click. Evaluated as a template.
|
||||||
# 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.
|
|
||||||
|
|
||||||
#[menu input1]
|
#[menu some_list some_input]
|
||||||
#type: input
|
#type: input
|
||||||
#name:
|
#name:
|
||||||
#cursor:
|
|
||||||
#width:
|
|
||||||
#enable:
|
#enable:
|
||||||
#transform:
|
#input:
|
||||||
#parameter:
|
# Initial value to use when editing - evaluated as a template.
|
||||||
# Value from parameter (always index 0) is taken as input value when in edit mode.
|
# Result must be float.
|
||||||
#gcode:
|
#input_min:
|
||||||
# This will be triggered in realtime mode, on exit from edit mode
|
# Minimum value of range - evaluated as a template.
|
||||||
# or in edit mode this will be triggered after click button long press (>0.8sec).
|
# Default -99999.
|
||||||
#longpress_gcode:
|
#input_max:
|
||||||
# In edit mode this will be triggered after click button long press (>0.8sec).
|
# Maximum value of range - evaluated as a template.
|
||||||
# The default is empty. This parameter is optional.
|
# Default 99999.
|
||||||
#reverse:
|
#input_step:
|
||||||
# This attribute accepts static boolean value.
|
# Editing step - Must be a positive integer or float value.
|
||||||
# When enabled it will reverse increment and decrement directions for input.
|
# It has internal fast rate step. When (input_max - input_min) / input_step > 100
|
||||||
# The default is False. This parameter is optional.
|
# then fast rate step is 10 * input_step else fast rate step is same input_step
|
||||||
#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.
|
|
||||||
#realtime:
|
#realtime:
|
||||||
# This attribute accepts static boolean value.
|
# 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.
|
# The default is False. This parameter is optional.
|
||||||
#input_min:
|
#gcode:
|
||||||
# It accepts integer or float value. Will set minimal bound for edit value.
|
# Script to run on button click, long click or value change. Evaluated as a template.
|
||||||
# The default is 2.2250738585072014e-308. This parameter is optional.
|
# The button click will trigger the edit mode start or end.
|
||||||
#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)
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ class PrinterLCD:
|
||||||
name = config.get_name()
|
name = config.get_name()
|
||||||
if name == 'display':
|
if name == 'display':
|
||||||
# only load menu for primary 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")
|
self.printer.load_object(config, "display_status")
|
||||||
# Configurable display
|
# Configurable display
|
||||||
self.display_templates = {}
|
self.display_templates = {}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue