From 7a9c569251ba2a027c25458645f8ee4596547a46 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 20 Aug 2019 21:15:59 -0600 Subject: [PATCH] Separating public and private methods --- scripts/wk/std.py | 62 +++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/scripts/wk/std.py b/scripts/wk/std.py index 9cb57b68..fddd1c0c 100644 --- a/scripts/wk/std.py +++ b/scripts/wk/std.py @@ -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):