missionpinball / mpf

Mission Pinball Framework: Open source software to run a real pinball machine.
http://missionpinball.org
MIT License
217 stars 143 forks source link

Initial Implementation for display_segment update_method replace #1820

Open worldpeace-germany opened 3 months ago

worldpeace-germany commented 3 months ago

config_spec.yaml: changed default from not_set to off, left not_set in enum though I believe it can be removed. I couldn't see why not_set is a good default. If really needed for the changes in update_method replace I can add code to exchange not_set for off.

segment_display: Only changed code for update_method replace, stack should behave like before. I tested with various segment displays shows and it seems to behave well. Note:

If the PR gets accepted I would do some additons to mpf-docs 0.80. Just would need to know how to contribute version specific changes.

worldpeace-germany commented 2 months ago

In regards to the last commit fixed and clean up of color handling in segment displays

In general there are some issues when defining segment display shows due to the fact how colors are being handled and how that is being known to user and if that is perceived as a logical definition flow.

In segment display the default color (white) is used

https://github.com/missionpinball/mpf/blob/35a84ba29c54acc6ce1afab28bb0e9edca07e301/mpf/devices/segment_display/segment_display.py#L90

to expand the given color array to the right until the length of the segment display is being filled up. So for a 4 digit display, specified as default color "blue, yellow" this would end up as "blue, yellow, white, white".

During initlize an empty string is sent to the segment display

https://github.com/missionpinball/mpf/blob/35a84ba29c54acc6ce1afab28bb0e9edca07e301/mpf/devices/segment_display/segment_display.py#L101

, each string is colored

https://github.com/missionpinball/mpf/blob/35a84ba29c54acc6ce1afab28bb0e9edca07e301/mpf/devices/segment_display/segment_display_text.py#L94

Since the length is 0, the left_pad_color is used to set the color. So it is not the default color being used, the color set now for this example is "blue, blue, blue, blue". Which on the first view doesn't matter since the display is blank, but at later points in time the code prefers to use the current_state color and not the default_color if no color is being sent, for example

https://github.com/missionpinball/mpf/blob/35a84ba29c54acc6ce1afab28bb0e9edca07e301/mpf/devices/segment_display/segment_display.py#L303

if the other digits cannot display blue they will simply stay blank.

In other parts of the code, if you start a transition the given colors are being expanded

https://github.com/missionpinball/mpf/blob/35a84ba29c54acc6ce1afab28bb0e9edca07e301/mpf/devices/segment_display/segment_display.py#L186, where expanded could as well mean shortend to the length of the text and not the length of the display, so later the empty places are being padded with a color again (see above). If the colors need to be expanded then this

https://github.com/missionpinball/mpf/blob/35a84ba29c54acc6ce1afab28bb0e9edca07e301/mpf/devices/segment_display/segment_display.py#L230

is done by taking the most right color and reuse it for all the other text to the right of this position (so no default color being used).

If a transition text is being used and no color is specified, then the color of the first character of the new text is being used (again not the default color).

https://github.com/missionpinball/mpf/blob/35a84ba29c54acc6ce1afab28bb0e9edca07e301/mpf/devices/segment_display/transitions.py#L139

In general we have default color, sometimes padded to the left and sometimes padded to the right. Question is if the user can follow that behavior or if it is over complicated and thus introduces user mistakes.

The PR will change some of the behavior to make it more consistent

visible and not that because of a wrong color invisible text is shown and confuses the user. But the PR not only makes the handling more consistent but I would consider it a bug if a color is used for padding which might be able to be used for the digits of that segment display.

Once the PR is accepted I will update the documentation to explain the color handling in detail for the users.

sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud