Separating public and private methods

This commit is contained in:
2Shirt 2019-08-20 21:15:59 -06:00
parent 0707d650f6
commit 7a9c569251
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -76,37 +76,11 @@ class Menu():
self.separator = ''
self.title = title
def add_action(self, name, details=None):
"""Add action to menu."""
details = details if details else {}
details['Enabled'] = details.get('Enabled', True)
self.actions[name] = details
def add_option(self, name, details=None):
"""Add option to menu."""
details = details if details else {}
details['Enabled'] = details.get('Enabled', True)
self.options[name] = details
def add_set(self, name, details=None):
"""Add set to menu."""
details = details if details else {}
details['Enabled'] = details.get('Enabled', True)
# Safety check
if 'Targets' not in details:
raise KeyError('Menu set has no targets')
# Add set
self.sets[name] = details
def add_toggle(self, name, details=None):
"""Add toggle to menu."""
details = details if details else {}
details['Enabled'] = details.get('Enabled', True)
self.toggles[name] = details
def get_separator_string(self):
def _get_separator_string(self):
"""Format separator length based on name lengths, returns str."""
separator_length = 0
@ -119,9 +93,9 @@ class Menu():
# Done
return self.separator * separator_length
def show(self):
def _show(self):
"""Print menu to screen."""
separator_string = self.get_separator_string()
separator_string = self._get_separator_string()
menu_lines = [self.title, separator_string]
# Sets & toggles
@ -148,6 +122,36 @@ class Menu():
menu_lines = [str(line) for line in menu_lines]
print('\n'.join(menu_lines))
def add_action(self, name, details=None):
"""Add action to menu."""
details = details if details else {}
details['Enabled'] = details.get('Enabled', False)
self.actions[name] = details
def add_option(self, name, details=None):
"""Add option to menu."""
details = details if details else {}
details['Enabled'] = details.get('Enabled', False)
self.options[name] = details
def add_set(self, name, details=None):
"""Add set to menu."""
details = details if details else {}
details['Enabled'] = details.get('Enabled', False)
# Safety check
if 'Targets' not in details:
raise KeyError('Menu set has no targets')
# Add set
self.sets[name] = details
def add_toggle(self, name, details=None):
"""Add toggle to menu."""
details = details if details else {}
details['Enabled'] = details.get('Enabled', False)
self.toggles[name] = details
# Functions
def abort(prompt='Aborted.', show_prompt=True, return_code=1):