Browse Source

Load menu from file

master
Doug Le Tough 4 years ago
parent
commit
24cfabb6d1
2 changed files with 23 additions and 14 deletions
  1. +12
    -0
      config/main_menu.py
  2. +11
    -14
      ui/__init__.py

+ 12
- 0
config/main_menu.py View File

@ -0,0 +1,12 @@
{
curses.KEY_F1: ('F1', 'Domains', self.display_domains),
curses.KEY_F2: ('F2', 'Devices', self.display_devices),
curses.KEY_F3: ('F3', 'Networks', self.display_networks),
curses.KEY_F4: ('F4', 'Storages', self.display_storages),
curses.KEY_F5: ('F5', 'Interfaces', self.display_interfaces),
curses.KEY_F6: ('F6', 'Secrets', self.display_secrets),
curses.KEY_F7: ('F7', 'Overview', self.display_overview),
curses.KEY_F8: ('F8', 'Quit', self.quit_ui),
curses.KEY_UP: ('Up', 'Up ↑', self.previous_item),
curses.KEY_DOWN: ('Down', 'Down ↓', self.next_item),
}

+ 11
- 14
ui/__init__.py View File

@ -13,7 +13,14 @@ locale.setlocale(locale.LC_ALL, '')
class UI(object):
""" The main U.I class"""
def __init__(self, min_lines, min_cols, displayManager, logger):
self.conf_file = os.path.join(os.environ['HOME'], '.config', 'pycursesvirtmgr.py', 'windows_definition.py')
self.windows_conf_file = os.path.join(os.environ['HOME'],
'.config',
'pycursesvirtmgr.py',
'windows_definition.py')
self.menu_conf_file = os.path.join(os.environ['HOME'],
'.config',
'pycursesvirtmgr.py',
'main_menu.py')
self.logger = logger
self.logger.log('Starting U.I', 'info')
self.displayManager = displayManager
@ -63,7 +70,7 @@ class UI(object):
def load_window_definitions(self):
""" Load all windows definitions """
self.logger.log('Loading windows definitions', 'info')
with open(self.conf_file,'r') as definition:
with open(self.windows_conf_file,'r') as definition:
windows = eval(definition.read())
self.logger.log('Windows definitions: %s' % str(windows), 'info')
return windows
@ -74,18 +81,8 @@ class UI(object):
def load_menu_keys(self):
""" Load main menu keys """
self.logger.log('Loading menu keys', 'info')
menu_keys = {
curses.KEY_F1: ('F1', 'Domains', self.display_domains),
curses.KEY_F2: ('F2', 'Devices', self.display_devices),
curses.KEY_F3: ('F3', 'Networks', self.display_networks),
curses.KEY_F4: ('F4', 'Storages', self.display_storages),
curses.KEY_F5: ('F5', 'Interfaces', self.display_interfaces),
curses.KEY_F6: ('F6', 'Secrets', self.display_secrets),
curses.KEY_F7: ('F7', 'Overview', self.display_overview),
curses.KEY_F8: ('F8', 'Quit', self.quit_ui),
curses.KEY_UP: ('Up', 'Up ↑', self.previous_item),
curses.KEY_DOWN: ('Down', 'Down ↓', self.next_item),
}
with open(self.menu_conf_file,'r') as definition:
menu_keys = eval(definition.read())
self.logger.log('Menu keys: %s' % str(menu_keys), 'info')
return menu_keys


Loading…
Cancel
Save