From fe7c821605f2433cb18b364a68efe39ba10462ba Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Sun, 19 Feb 2023 18:34:12 -0800 Subject: [PATCH] Add a display_name attribute to Setting --- settngs.py | 25 +++++++++++++++++++++++++ testing/settngs.py | 7 +++++++ 2 files changed, 32 insertions(+) diff --git a/settngs.py b/settngs.py index d43d9cf..c23dff3 100644 --- a/settngs.py +++ b/settngs.py @@ -93,11 +93,35 @@ class Setting: metavar: str | None = None, dest: str | None = None, # ComicTagger + display_name: str = '', cmdline: bool = True, file: bool = True, group: str = '', exclusive: bool = False, ): + """ + + Args: + *names: Passed directly to argparse + action: Passed directly to argparse + nargs: Passed directly to argparse + const: Passed directly to argparse + default: Passed directly to argparse + type: Passed directly to argparse + choices: Passed directly to argparse + required: Passed directly to argparse + help: Passed directly to argparse + metavar: Passed directly to argparse, defaults to `dest` uppercased + dest: This is the name used to retrieve the value from a `Config` object as a dictionary + display_name: This is not used by settngs. This is a human-readable name to be used when generating a GUI. + Defaults to `dest`. + cmdline: If this setting can be set via the commandline + file: If this setting can be set via a file + group: The group this option is in. + This is an internal argument and should only be set by settngs + exclusive: If this setting is exclusive to other settings in this group. + This is an internal argument and should only be set by settngs + """ if not names: raise ValueError('names must be specified') # We prefix the destination name used by argparse so that there are no conflicts @@ -130,6 +154,7 @@ class Setting: self.argparse_args = args self.group = group self.exclusive = exclusive + self.display_name = display_name or dest self.argparse_kwargs = { 'action': action, diff --git a/testing/settngs.py b/testing/settngs.py index 5f56fa9..97de527 100644 --- a/testing/settngs.py +++ b/testing/settngs.py @@ -78,6 +78,7 @@ success = [ 'const': None, 'default': None, 'dest': 'test_setting', # dest is calculated by Setting and is not used by argparse + 'display_name': 'test_setting', # defaults to dest 'exclusive': False, 'file': True, 'group': 'tst', @@ -117,6 +118,7 @@ success = [ 'const': None, 'default': None, 'dest': 'testing', # dest is calculated by Setting and is not used by argparse + 'display_name': 'testing', # defaults to dest 'exclusive': False, 'file': True, 'group': 'tst', @@ -155,6 +157,7 @@ success = [ 'const': None, 'default': None, 'dest': 'test', # dest is calculated by Setting and is not used by argparse + 'display_name': 'test', # defaults to dest 'exclusive': False, 'file': True, 'group': 'tst', @@ -194,6 +197,7 @@ success = [ 'const': None, 'default': None, 'dest': 'test', # dest is calculated by Setting and is not used by argparse + 'display_name': 'test', # defaults to dest 'exclusive': False, 'file': True, 'group': 'tst', @@ -232,6 +236,7 @@ success = [ 'const': None, 'default': None, 'dest': 'test', + 'display_name': 'test', # defaults to dest 'exclusive': False, 'file': True, 'group': 'tst', @@ -270,6 +275,7 @@ success = [ 'const': None, 'default': None, 'dest': 'test', + 'display_name': 'test', # defaults to dest 'exclusive': False, 'file': True, 'group': 'tst', @@ -306,6 +312,7 @@ success = [ 'const': None, 'default': None, 'dest': 'test', + 'display_name': 'test', # defaults to dest 'exclusive': False, 'file': True, 'group': '',