Would you like to be able to setup configuration INI files for your python apps with a nice UI?
If so, all you need to do is add comments! Or, even better, create a new file (or files) named …_defaults.ini
next to original files (so, for config.ini
, it’ll be config_defaults.ini
) — this way, your app won’t delete comments while saving file. Also, it’ll help if your INI-parser doesn’t support comments, or if you don’t want user to lose all settings next time app is updated.
How those comments should look?
I’ve tried to make them as human-readable as possible. So, they will be helpful not just for Content Manager, but for anybody who might want to edit configs manually. Although those comments might be a bit wordy.
Put the name of parameter on the same line, like so:
SCALE=100 ; App scale
If you want to change a popup hint, add some text in brackets:
SCALE=100 ; App scale (specifies size of the app)
By the way, you don’t need to start that text in upper case, it’ll be fixed automatically, so your comments would look nice as well.
CM groups parameters by sections, using section names as sub-headers, but you can easily change their names:
[CONFIG]
; Main options
SCALE=100 ; App scale (specifies size of the app)
[THEME]
; Extra params
BRIGHTNESS=100 ; App brightness (switches to bright theme if more than 50)
To specify type of value, put semicolon and then descibe how it should work, and app will figure out the rest:
SCALE=100 ; App scale (specifies size of the app); from 50% to 200%
You can set how value might be locked depending on another value, like that:
SCALE=100 ; App scale; from 50% to 200%; only with THEME/BRIGHTNESS
SCALE=100 ; App scale; not available with THEME/BRIGHTNESS or THEME/CUSTOM
If you’re referring to a value within the same section, section name is not needed. Or add a file name with “/”, if you need to reference another file. Also, you can use any combination of “or”, “and” and “not”.
What inputs are supported?
Here, I put required values as “<…>” and optional as “[…]”.
Checkbox (“<ON_VALUE> or <OFF_VALUE>” ):
ENABLE_SCALING=1 ; Enable scaling; 1 or 0
SCALE=100 ; Smaller app (specifies size of the app); 50 or 100
ACTIVE=True ; Is something active; "True" or "False"
Content Manager will consider any parameter with value like “on”, “off”, “true”, “false”, “yes”, “no” as a checkbox value, but for “0” or “1”, or something more unusual, you need to define type explicitly. For improved readability, you can surround ON_VALUE and OFF_VALUE with quotes.
Range (“from <MINIMUM>[POSTFIX] to <MAXIMUM>[POSTFIX]”):
TIME_SCALE=0.9 ; Time scale; from 80% to 120%
LOOP_TIME=1000 ; Looping speed; from 1000 ms to 5000 ms
ALLOWED_TEMPERATURE=50 ; Allowed temperature; from 10 °C to 400 °C
Only first POSTFIX is taken into account, but why would you omit last one anyway?
Drop-down list (<VALUE_1>, <VALUE_2>, …):
THEME0=BRIGHT ; App theme #1; BRIGHT, DARK, BLACK
THEME1=BRIGHT ; App theme #2; BRIGHT for bright theme, DARK for darker theme or BLACK
THEME2=BRIGHT ; App theme #3; bright theme is BRIGHT, darker theme is DARK, black theme is BLACK
Here, all three of those examples define the same set of values, but second and third also make them a bit more readable. As you can see, it looks quite readable in INI-file as well. Values list should contain at least one comma, so CM would be able to distinguish it from checkbox.
File or directory:
SOURCE_ANY=data.bin ; Any input; local file
SOURCE_CSV=data.csv ; Source table; local file (*.csv)
ICON_FILE=images/icon.png ; Icon; file (PNG Files (*.png)|*.png|Image Files (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg)
STORAGE_DIR=storage ; Directory with files; local directory
FONTS_DIR=C:\Windows\Fonts ; Any input; directory
If you want users to be able to pick any file, from any disk, remove “local”, but, please, don’t forget to adjust code as well.
Keyboard button:
PIT=66 ; Teleport to pits; keyboard button
If you need something else, please, contact me.
Some tips
For postfix range, don’t forget to separate it with space if needed;
If any of your values contain symbols which affect parsing, use quotation marks. Any will do, “`”, “"”, “'”, even ““” and “””, so you can put quotation marks inside:
THEME=BRIGHT ; App theme; BRIGHT for "bright, “nice” theme", DARK for "darker or \"dark\" theme" or BLACK
Content Manager will try to guess a lot of stuff, so if you don’t want to bother entering value name, but want to specify type, just put ;;
.