laforge submitted this change.

View Change

Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved
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
Jenkins: skip-card-test
---
M pySim/esim/saip/personalization.py
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/pySim/esim/saip/personalization.py b/pySim/esim/saip/personalization.py
index 8f59556..31851f3 100644
--- a/pySim/esim/saip/personalization.py
+++ b/pySim/esim/saip/personalization.py
@@ -250,6 +250,13 @@
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

class DecimalParam(ConfigurableParameter):
"""Decimal digits. The input value may be a string of decimal digits like '012345', or an int. The output of
@@ -353,6 +360,16 @@
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):
"""ConfigurableParameter for named integer enumeration values.

To view, visit change 40202. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I2568a032167a10517d4d75d8076a747be6e21890
Gerrit-Change-Number: 40202
Gerrit-PatchSet: 11
Gerrit-Owner: neels <nhofmeyr@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge@osmocom.org>