menu: add ability for enable to hide certain menus
This commit is contained in:
@@ -32,9 +32,16 @@ panel: preheat
|
||||
method: printer.gcode.script
|
||||
# Parameters that would be passed with the method above
|
||||
params: {"script":"G28 X"}
|
||||
# Enable allows hiding of a menu if the condition is false. This statement is evaluated in Jinja2
|
||||
# Available variables are listed below.
|
||||
enable: {{ printer.power_devices.count > 0 }}
|
||||
```
|
||||
Available panels are listed here: [docs/panels.md](panels.md)
|
||||
|
||||
Certain variables are available for conditional testing of the enable statement:
|
||||
```
|
||||
printer.power_devices.count # Number of power devices configured in Moonraker
|
||||
```
|
||||
|
||||
|
||||
A sample configuration of a main menu would be as follows:
|
||||
|
@@ -1,9 +1,12 @@
|
||||
## Changelog
|
||||
|
||||
#### 2020 11 28
|
||||
* Add option for enable in menu for configuration. This can hide certain options
|
||||
|
||||
#### 2020 11 18
|
||||
* Changed configuration file format.
|
||||
* Moved default configuration file to an include folder.
|
||||
* Added ability to do a confirm dialog from a menu item when running a script
|
||||
* Changed configuration file format.
|
||||
* Moved default configuration file to an include folder.
|
||||
* Added ability to do a confirm dialog from a menu item when running a script
|
||||
* Added "Save Config" button to default configuration's Configuration menu.
|
||||
|
||||
#### 2020 11 14
|
||||
|
@@ -7,6 +7,8 @@ from gi.repository import Gtk, Gdk, GLib
|
||||
from ks_includes.KlippyGtk import KlippyGtk
|
||||
from ks_includes.screen_panel import ScreenPanel
|
||||
|
||||
from jinja2 import Template
|
||||
|
||||
logger = logging.getLogger("KlipperScreen.MenuPanel")
|
||||
|
||||
def create_panel(*args):
|
||||
@@ -16,6 +18,7 @@ class MenuPanel(ScreenPanel):
|
||||
def initialize(self, panel_name, items):
|
||||
_ = self.lang.gettext
|
||||
|
||||
self.activate()
|
||||
grid = self.arrangeMenuItems(items, 4)
|
||||
|
||||
b = KlippyGtk.ButtonImage('back', _('Back'))
|
||||
@@ -24,10 +27,26 @@ class MenuPanel(ScreenPanel):
|
||||
|
||||
self.panel = grid
|
||||
|
||||
def activate(self):
|
||||
self.j2_data = {
|
||||
"printer": {
|
||||
"power_devices": {
|
||||
"count": len(self._screen.printer.get_power_devices())
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.debug("j2_data: %s" % self.j2_data)
|
||||
|
||||
def arrangeMenuItems (self, items, columns, expandLast=False):
|
||||
grid = Gtk.Grid()
|
||||
grid.set_row_homogeneous(True)
|
||||
grid.set_column_homogeneous(True)
|
||||
logger.debug(items)
|
||||
for item in items:
|
||||
key = list(item)[0]
|
||||
logger.debug(item)
|
||||
if not self.evaluate_enable(item[key]['enable']):
|
||||
items.remove(item)
|
||||
|
||||
l = len(items)
|
||||
i = 0
|
||||
@@ -60,3 +79,22 @@ class MenuPanel(ScreenPanel):
|
||||
i += 1
|
||||
|
||||
return grid
|
||||
|
||||
def evaluate_enable(self, enable):
|
||||
if enable == True:
|
||||
return True
|
||||
if enable == False:
|
||||
return False
|
||||
|
||||
try:
|
||||
logger.debug("Template: '%s'" % enable)
|
||||
logger.debug("Date: %s" % self.j2_data)
|
||||
j2_temp = Template(enable)
|
||||
result = j2_temp.render(self.j2_data)
|
||||
logger.debug("Result: %s" % result)
|
||||
if result == 'True':
|
||||
return True
|
||||
return False
|
||||
except:
|
||||
logger.debug("Error evaluating enable statement: %s", enable)
|
||||
return False
|
||||
|
@@ -3,3 +3,4 @@ requests==2.25.0
|
||||
vext==0.7.4
|
||||
websocket-client==0.57.0
|
||||
humanize==3.1.0
|
||||
jinja2==2.11.2
|
||||
|
Reference in New Issue
Block a user