This is SevenSegmentDisp. It is a wxPython
custom control that simulates a
Although wxPython already has been shipped with a similar control for quite some time, this one aims to be more beautiful (segments have rounded corners!), fully customizable yet easy to use. With only a few settings you might be able to find something completely to your taste.
Three settings for the control colours are available: the display background colour and colours for the lit and blank segments. As for the display geometry, segments width, height and thickness as well as the separation between them can be set.
You can also tilt (shear) the display by arbitrarily choosing the tilt angle.
The display size is whatever is set via SetSize, and it will keep its proportions according to the geometry set.
The control can also show a "." and/or a ":", allocating space for them when set, and freeing it when not used.
Click here to download the code. It is a compressed file containing these three python files: sevensegment.py (the control itself), sevensegmentdemo.py (a small demo that shows all of the capabilities of the control) and colourselect2.py (a colour selector/picker based on wxPython's colourselect but slightly aesthetically modified).
To run it, type
python3 sevensegment.py
or
python3 sevensegmentdemo.py
Tested on wxPython 4.0.4
(gtk3) on Python 3.7.3 on Raspberry Pi OS
and on wxPython 4.0.7p2
(gtk2) on Python 3.5.2 on Mint (Mate). The files
mentioned here are distributed under the BSD-3-Clause
License, except colourselect2, which is based on
colourselect, by Lorne White, and both are distributed under the wxWidgets
Licence.
Sets the character to be shown on the control.
The value passed to the control can be integer or string. An invalid value will be silent ignored and converted to an empty space (all segments off).
Examples of valid values:
3 or "3" | will display a "3" |
"A" | all decimal and hex digits ar allowed, but also some other ones as per the _opts dict. Please see the code for a complete list. |
"3." | will display a "3" with a trailing dot (if EnableDot is True, which it is, by default) |
"3:" | will display a "3" with a trailing colon (if EnableColon is True, which it is, by default) |
"3.:" or "3:." | will display a trailing dot and a trailing colon (if EnableDot and EnableColon are True -- they are, by default) |
"." or " ." | will display an empty display with a trailing dot |
":" or " :" | will display an empty display with a trailing colon |
".:" or ":." or " .:" or " :." | will display an empty display with a trailing dot and a trailing colon |
Sets the display colours.
Keywords: "background",
"segment_on", "segment_off"
; values: wx.Colour
or a valid 3 or 4-tuple cf. wx.Colour arguments.
e.g: SetColours(segment_on=(255,
0, 0), background=wx.BLACK)
returns a dictionary:
{"background":
background wx.Colour,
"segment_on":
lit segments wx.Colour,
"segment_off":
blank segments wx.Colour}
Sets the display geometry. Keywords:
"thickness", "width", "height", "separation"
;
values: int
e.g: SetGeometry(thickness=28,
separation=1)
or SetGeometry(width=50)
,
etc.
returns a dictionary:
{"thickness":
segment thickness,
"width":
horizontal (a, d, g) segments
width,
"height":
vertical (b, c, e, f) segments
height,
"separation":
distance between segments}
Sets the display tilt in degrees.
Returns the display tilt in degrees.
Tells the display to use a trailing "."
Returns True if EnableDot is set.
Tells the display to use a trailing ":"
Returns True if EnableColon is set.