String Formatting for tokens/variables in text slides - idea/discussion

31 views
Skip to first unread message

driskel

unread,
Jun 2, 2018, 12:25:24 PM6/2/18
to MPF Users
Text Widgets string formatting request/discussion for variables/tokens:

Number grouping is a very useful feature, I am wondering if it can be expanded to token_format or something similar and then move
the number_grouping definition inside a collection of token_formats.

My challenge here is that I am interested in showing scores on my machine something similar to this:

47,150 = 47.15k
5,130,000 = 5.130m

I am wondering if the idea of variable/token tranformation definitions would be a useful feature.
   
These would be string formatting transformation on tokens/variables used in text widgets (score, player, etc...)
for display only and chained in order of their index in the collection.  I am not familiar with python code, but in .NET
it is basically string.Format().

Here are a few examples:

# just two decimal places
String.Format("{0:0.00}", 123.4567);      # "123.46"
String.Format("{0:0.00}", 123.4);         # "123.40"
String.Format("{0:0.00}", 123.0);         # "123.00

# max. two decimal places
String.Format("{0:0.##}", 123.4567);      # "123.46"
String.Format("{0:0.##}", 123.4);         # "123.4"
String.Format("{0:0.##}", 123.0);         # "123"

# at least two digits before decimal point
String.Format("{0:00.0}", 123.4567);      # "123.5"
String.Format("{0:00.0}", 23.4567);       # "23.5"
String.Format("{0:00.0}", 3.4567);        # "03.5"
String.Format("{0:00.0}", -3.4567);       # "-03.5"

# thousands seperator
String.Format("{0:0,0.0}", 12345.67);     # "12,345.7"
String.Format("{0:0,0}", 12345.67);       # "12,346"

# zero formatting
String.Format("{0:0.0}", 0.0);            # "0.0"
String.Format("{0:0.#}", 0.0);            # "0"
String.Format("{0:#.0}", 0.0);            # ".0"
String.Format("{0:#.#}", 0.0);            # ""

So a text widget could be configured something like this:

slides:
    score_slide
:
       
- type: text
          text
: score (score)
          token_format
:
           
- number_as_m
           
- number_grouping

We could have a few built into the system, and we add, override at the config and mode config level.

Example:

token_format:
    number_grouping
:    
    number_as_money
        formatting_definition
:
           
"$(value)"

Just food for thought. If this is currently doable in configuration. I am sorry for adding to the noise.

Thank you.




driskel

unread,
Jun 2, 2018, 12:54:44 PM6/2/18
to MPF Users
We could also add as a format parameter, is it a regular expression

token_format:
    number_grouping
:    
    number_as_money
        formatting_definition
:
           
"$(value)"
        regex
: true/false

jabdoa

unread,
Jun 3, 2018, 6:47:35 AM6/3/18
to MPF Users
We already support that using Python format strings (https://pyformat.info) in text placeholders for segment displays. I want to add the same to slides and widgets but it will require some refactoring and I cannot tell when it will be done. We might be able to create some intermediate solutions using variable_player or similar.


Jan

driskel

unread,
Jun 3, 2018, 8:39:33 AM6/3/18
to MPF Users
I have no immediate need and can work with what I have.  I am glad to hear that you have on the roadmap formatting in slides and widgets. I think that will be a great addition.

Thank you for the response.
Reply all
Reply to author
Forward
0 new messages