From 7711bd26fbe0a4d2711c11de904c622dc9f22f07 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Sat, 1 Mar 2025 00:49:20 +0100 Subject: [PATCH] personalization: add get_typical_input_len() to ConfigurableParameter The aim is to tell a user interface how wide an input text field should be chosen to be convenient -- ideally showing the entire value in all cases, but not too huge for fields that have no sane size limit. Change-Id: I2568a032167a10517d4d75d8076a747be6e21890 --- pySim/esim/saip/personalization.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pySim/esim/saip/personalization.py b/pySim/esim/saip/personalization.py index 99183cbd..55400ded 100644 --- a/pySim/esim/saip/personalization.py +++ b/pySim/esim/saip/personalization.py @@ -259,6 +259,14 @@ class ConfigurableParameter: return (None, None) return (min(vals), max(vals)) + @classmethod + def get_typical_input_len(cls): + '''return a good length to use as the visible width of a user interface input field. + May be overridden by subclasses. + This default implementation returns the maximum allowed value length -- a good fit for most subclasses. + ''' + return cls.get_len_range()[1] or 16 + @classmethod def get_all_implementations(cls, blacklist=None, allow_abstract=False): # return a set() so that multiple inheritance does not return dups @@ -268,7 +276,6 @@ class ConfigurableParameter: and ((not blacklist) or (c not in blacklist))) ) - class DecimalParam(ConfigurableParameter): """Decimal digits. The input value may be a string of decimal digits like '012345', or an int. The output of validate_val() is a string with only decimal digits 0-9, in the required length with leading zeros if necessary. @@ -339,6 +346,16 @@ class BinaryParam(ConfigurableParameter): val = super().validate_val(val) return bytes(val) + @classmethod + def get_typical_input_len(cls): + # override to return twice the length, because of hex digits. + min_len, max_len = cls.get_len_range() + if max_len is None: + return None + # two hex characters per value octet. + # (maybe *3 to also allow for spaces?) + return max_len * 2 + class EnumParam(ConfigurableParameter): value_map = {