Updated menu / title sections

* Added set_title() which sets window title and global_vars['Title']
* menu_select() will now display global_vars['Title'] above title
  * (If it exists)
  * Bugfix: fixed a few bad calls of menu_select()
This commit is contained in:
Alan Mason 2017-11-30 21:08:52 -08:00
parent 850a1fca73
commit 4ed6d41d10
6 changed files with 39 additions and 13 deletions

View file

@ -131,7 +131,9 @@ def select_backup_destination(auto_select=True):
return destinations[0] return destinations[0]
selection = menu_select( selection = menu_select(
'Where are we backing up to?', destinations, actions) title = 'Where are we backing up to?',
main_entries = destinations,
action_entries = actions)
if selection == 'M': if selection == 'M':
raise GenericAbort raise GenericAbort
else: else:

View file

@ -224,6 +224,10 @@ def menu_select(title='~ Untitled Menu ~',
if not main_entries and not action_entries: if not main_entries and not action_entries:
raise Exception("MenuError: No items given") raise Exception("MenuError: No items given")
# Set title
if 'Title' in global_vars:
title = '{}\n\n{}'.format(global_vars['Title'])
# Build menu # Build menu
menu_splash = '{}\n\n'.format(title) menu_splash = '{}\n\n'.format(title)
width = len(str(len(main_entries))) width = len(str(len(main_entries)))
@ -361,6 +365,13 @@ def run_program(cmd, args=[], check=True, pipe=True, shell=False):
return process_return return process_return
def set_title(title='~Some Title~'):
"""Set title.
Used for window title and menu titles."""
global_vars['Title'] = title
os.system('title {}'.format(title))
def show_info(message='~Some message~', info='~Some info~', indent=8, width=32): def show_info(message='~Some message~', info='~Some info~', indent=8, width=32):
"""Display info with formatting.""" """Display info with formatting."""
print_standard('{indent}{message:<{width}}{info}'.format( print_standard('{indent}{message:<{width}}{info}'.format(

View file

@ -300,7 +300,7 @@ def remove_volume_letters(keep=''):
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
pass pass
def select_disk(prompt='Which disk?'): def select_disk(title='Which disk?'):
"""Select a disk from the attached disks""" """Select a disk from the attached disks"""
disks = get_attached_disk_info() disks = get_attached_disk_info()
@ -334,7 +334,10 @@ def select_disk(prompt='Which disk?'):
] ]
# Menu loop # Menu loop
selection = menu_select(prompt, disk_options, actions) selection = menu_select(
title = title,
main_entries = disk_options,
action_entries = actions)
if (selection.isnumeric()): if (selection.isnumeric()):
return disk_options[int(selection)-1]['Disk'] return disk_options[int(selection)-1]['Disk']

View file

@ -180,7 +180,10 @@ def select_windows_version():
actions = [{'Name': 'Main Menu', 'Letter': 'M'},] actions = [{'Name': 'Main Menu', 'Letter': 'M'},]
# Menu loop # Menu loop
selection = menu_select('Which version of Windows are we installing?', WINDOWS_VERSIONS, actions) selection = menu_select(
title = 'Which version of Windows are we installing?',
main_entries = WINDOWS_VERSIONS,
action_entries = actions)
if selection.isnumeric(): if selection.isnumeric():
return WINDOWS_VERSIONS[int(selection)-1] return WINDOWS_VERSIONS[int(selection)-1]

View file

@ -62,6 +62,7 @@ def menu_backup():
'GenericAbort': 'Skipped', 'GenericAbort': 'Skipped',
'GenericRepair': 'Repaired', 'GenericRepair': 'Repaired',
}} }}
set_title('{}: Backup Menu'.format(KIT_NAME_FULL))
# Set ticket Number # Set ticket Number
os.system('cls') os.system('cls')
@ -154,7 +155,6 @@ def menu_backup():
pause('\nPress Enter to return to main menu... ') pause('\nPress Enter to return to main menu... ')
def menu_root(): def menu_root():
title = '{}: Main Menu'.format(KIT_NAME_FULL)
menus = [ menus = [
{'Name': 'Create Backups', 'Menu': menu_backup}, {'Name': 'Create Backups', 'Menu': menu_backup},
{'Name': 'Setup Windows', 'Menu': menu_setup}, {'Name': 'Setup Windows', 'Menu': menu_setup},
@ -168,11 +168,12 @@ def menu_root():
# Main loop # Main loop
while True: while True:
set_title(KIT_NAME_FULL)
selection = menu_select( selection = menu_select(
title=title, title = 'Main Menu',
main_entries=menus, main_entries = menus,
action_entries=actions, action_entries = actions,
secret_exit=True) secret_exit = True)
if (selection.isnumeric()): if (selection.isnumeric()):
try: try:
@ -191,6 +192,7 @@ def menu_root():
def menu_setup(): def menu_setup():
"""Format a drive, partition for MBR or GPT, apply a Windows image, and rebuild the boot files""" """Format a drive, partition for MBR or GPT, apply a Windows image, and rebuild the boot files"""
errors = False errors = False
set_title('{}: Setup Menu'.format(KIT_NAME_FULL))
# Set ticket ID # Set ticket ID
os.system('cls') os.system('cls')
@ -295,13 +297,16 @@ def menu_setup():
pause('\nPress Enter to return to main menu... ') pause('\nPress Enter to return to main menu... ')
def menu_tools(): def menu_tools():
title = '{}: Tools Menu'.format(KIT_NAME_FULL)
tools = [k for k in sorted(PE_TOOLS.keys())] tools = [k for k in sorted(PE_TOOLS.keys())]
actions = [{'Name': 'Main Menu', 'Letter': 'M'},] actions = [{'Name': 'Main Menu', 'Letter': 'M'},]
set_title(KIT_NAME_FULL)
# Menu loop # Menu loop
while True: while True:
selection = menu_select(title, tools, actions) selection = menu_select(
title = 'Tools Menu',
main_entries = tools,
action_entries = actions)
if (selection.isnumeric()): if (selection.isnumeric()):
tool = tools[int(selection)-1] tool = tools[int(selection)-1]
cmd = [PE_TOOLS[tool]['Path']] + PE_TOOLS[tool].get('Args', []) cmd = [PE_TOOLS[tool]['Path']] + PE_TOOLS[tool].get('Args', [])
@ -342,7 +347,9 @@ def select_minidump_path():
return None return None
# Menu # Menu
selection = menu_select('Which BSoD / MiniDump path are we scanning?', dumps, []) selection = menu_select(
title = 'Which BSoD / MiniDump path are we scanning?',
main_entries = dumps)
return dumps[int(selection) - 1]['Name'] return dumps[int(selection) - 1]['Name']
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -8,7 +8,7 @@ os.chdir(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(os.getcwd()) sys.path.append(os.getcwd())
from functions.winpe_menus import * from functions.winpe_menus import *
init_global_vars() init_global_vars()
os.system('title {}: Root Menu'.format(KIT_NAME_FULL)) set_title('{}: Root Menu'.format(KIT_NAME_FULL))
global_vars['LogFile'] = r'{LogDir}\WinPE.log'.format(**global_vars) global_vars['LogFile'] = r'{LogDir}\WinPE.log'.format(**global_vars)
if __name__ == '__main__': if __name__ == '__main__':