mininterface 0.7.5__tar.gz → 0.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. mininterface-0.8.0/LICENSE +165 -0
  2. mininterface-0.8.0/PKG-INFO +265 -0
  3. mininterface-0.7.5/PKG-INFO → mininterface-0.8.0/README.md +80 -83
  4. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/__init__.py +26 -10
  5. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/__main__.py +16 -21
  6. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/auxiliary.py +28 -1
  7. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/cli_parser.py +52 -22
  8. mininterface-0.7.5/mininterface/facet.py → mininterface-0.8.0/mininterface/facet/__init__.py +7 -52
  9. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/form_dict.py +2 -2
  10. mininterface-0.8.0/mininterface/interfaces.py +106 -0
  11. mininterface-0.7.5/mininterface/mininterface.py → mininterface-0.8.0/mininterface/mininterface/__init__.py +54 -88
  12. mininterface-0.8.0/mininterface/mininterface/adaptor.py +59 -0
  13. mininterface-0.8.0/mininterface/options.py +55 -0
  14. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/showcase.py +24 -9
  15. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/start.py +3 -3
  16. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/tag.py +140 -72
  17. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/tag_factory.py +17 -15
  18. mininterface-0.8.0/mininterface/text_interface/__init__.py +161 -0
  19. mininterface-0.8.0/mininterface/text_interface/adaptor.py +158 -0
  20. mininterface-0.8.0/mininterface/text_interface/facet.py +29 -0
  21. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/textual_interface/__init__.py +20 -8
  22. mininterface-0.8.0/mininterface/textual_interface/adaptor.py +91 -0
  23. mininterface-0.7.5/mininterface/textual_interface/textual_facet.py → mininterface-0.8.0/mininterface/textual_interface/facet.py +2 -3
  24. mininterface-0.8.0/mininterface/textual_interface/file_picker_input.py +399 -0
  25. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/textual_interface/textual_app.py +93 -40
  26. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/textual_interface/textual_button_app.py +1 -2
  27. mininterface-0.8.0/mininterface/textual_interface/widgets.py +154 -0
  28. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/tk_interface/__init__.py +11 -12
  29. mininterface-0.7.5/mininterface/tk_interface/tk_window.py → mininterface-0.8.0/mininterface/tk_interface/adaptor.py +42 -12
  30. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/tk_interface/date_entry.py +4 -5
  31. mininterface-0.7.5/mininterface/tk_interface/tk_facet.py → mininterface-0.8.0/mininterface/tk_interface/facet.py +2 -2
  32. mininterface-0.8.0/mininterface/tk_interface/secret_entry.py +36 -0
  33. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/tk_interface/utils.py +81 -62
  34. mininterface-0.8.0/mininterface/types/__init__.py +4 -0
  35. mininterface-0.8.0/mininterface/types/alias.py +29 -0
  36. mininterface-0.8.0/mininterface/types/flags.py +69 -0
  37. mininterface-0.8.0/mininterface/types/internal.py +7 -0
  38. mininterface-0.8.0/mininterface/types/rich_tags.py +440 -0
  39. mininterface-0.8.0/mininterface/web_interface/__init__.py +87 -0
  40. mininterface-0.8.0/mininterface/web_interface/app.py +24 -0
  41. mininterface-0.8.0/mininterface/web_interface/child_adaptor.py +68 -0
  42. mininterface-0.8.0/mininterface/web_interface/parent_adaptor.py +69 -0
  43. mininterface-0.8.0/pyproject.toml +65 -0
  44. mininterface-0.7.5/LICENSE +0 -674
  45. mininterface-0.7.5/README.md +0 -204
  46. mininterface-0.7.5/mininterface/config.py +0 -28
  47. mininterface-0.7.5/mininterface/interfaces.py +0 -61
  48. mininterface-0.7.5/mininterface/text_interface.py +0 -135
  49. mininterface-0.7.5/mininterface/textual_interface/textual_adaptor.py +0 -93
  50. mininterface-0.7.5/mininterface/textual_interface/widgets.py +0 -67
  51. mininterface-0.7.5/mininterface/types.py +0 -231
  52. mininterface-0.7.5/pyproject.toml +0 -40
  53. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/ValidationFail.py +0 -0
  54. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/exceptions.py +0 -0
  55. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/experimental.py +0 -0
  56. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/redirectable.py +0 -0
  57. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/subcommands.py +0 -0
  58. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/tk_interface/external_fix.py +0 -0
  59. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/tk_interface/redirect_text_tkinter.py +0 -0
  60. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/type_stubs.py +0 -0
  61. {mininterface-0.7.5 → mininterface-0.8.0}/mininterface/validators.py +0 -0
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,265 @@
1
+ Metadata-Version: 2.3
2
+ Name: mininterface
3
+ Version: 0.8.0
4
+ Summary: A minimal access to GUI, TUI, CLI and config
5
+ License: LGPL-3.0-or-later
6
+ Author: Edvard Rejthar
7
+ Author-email: edvard.rejthar@nic.cz
8
+ Requires-Python: >=3.10,<4.0
9
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Provides-Extra: all
16
+ Provides-Extra: gui
17
+ Provides-Extra: img
18
+ Provides-Extra: tui
19
+ Provides-Extra: ui
20
+ Provides-Extra: web
21
+ Requires-Dist: autocombobox (==1.4.2) ; extra == "gui" or extra == "ui" or extra == "all"
22
+ Requires-Dist: humanize
23
+ Requires-Dist: pillow ; extra == "img" or extra == "gui" or extra == "ui" or extra == "all"
24
+ Requires-Dist: pyyaml
25
+ Requires-Dist: simple_term_menu
26
+ Requires-Dist: textual (<2.0.0)
27
+ Requires-Dist: textual-serve ; extra == "web" or extra == "ui" or extra == "all"
28
+ Requires-Dist: textual_imageview ; extra == "img" or extra == "tui" or extra == "ui" or extra == "all"
29
+ Requires-Dist: tkcalendar ; extra == "gui" or extra == "ui" or extra == "all"
30
+ Requires-Dist: tkinter-tooltip
31
+ Requires-Dist: tkinter_form (==0.2.1)
32
+ Requires-Dist: tkscrollableframe
33
+ Requires-Dist: typing_extensions
34
+ Requires-Dist: tyro (>=0.9,<0.10)
35
+ Project-URL: Homepage, https://github.com/CZ-NIC/mininterface
36
+ Description-Content-Type: text/markdown
37
+
38
+ # Mininterface – access to GUI, TUI, CLI and config files
39
+ [![Build Status](https://github.com/CZ-NIC/mininterface/actions/workflows/run-unittest.yml/badge.svg)](https://github.com/CZ-NIC/mininterface/actions)
40
+ [![Downloads](https://static.pepy.tech/badge/mininterface)](https://pepy.tech/project/mininterface)
41
+
42
+ Write the program core, do not bother with the input/output.
43
+
44
+ ![Hello world example: GUI window](https://github.com/CZ-NIC/mininterface/blob/main/asset/hello-gui.avif?raw=True "A minimal use case – GUI")
45
+ ![Hello world example: TUI fallback](https://github.com/CZ-NIC/mininterface/blob/main/asset/hello-tui.avif?raw=True "A minimal use case – TUI fallback")
46
+
47
+ Check out the code, which is surprisingly short, that displays such a window or its textual fallback.
48
+
49
+ ```python
50
+ from dataclasses import dataclass
51
+ from mininterface import run
52
+
53
+ @dataclass
54
+ class Env:
55
+ """ This calculates something. """
56
+
57
+ my_flag: bool = False
58
+ """ This switches the functionality """
59
+
60
+ my_number: int = 4
61
+ """ This number is very important """
62
+
63
+ if __name__ == "__main__":
64
+ m = run(Env, prog="My application")
65
+ m.form()
66
+ # Attributes are suggested by the IDE
67
+ # along with the hint text 'This number is very important'.
68
+ print(m.env.my_number)
69
+ ```
70
+
71
+ # Contents
72
+ - [You got CLI](#you-got-cli)
73
+ - [You got config file management](#you-got-config-file-management)
74
+ - [You got dialogues](#you-got-dialogues)
75
+ - [Background](#background)
76
+ - [Installation](#installation)
77
+ - [Docs](#docs)
78
+ - [Gallery](#gallery)
79
+ - [Hello world](#hello-world)
80
+
81
+ ## You got CLI
82
+ It was all the code you need. No lengthy blocks of code imposed by an external dependency. Besides the GUI/TUI, you receive powerful YAML-configurable CLI parsing.
83
+
84
+
85
+ ```bash
86
+ $ ./program.py --help
87
+ usage: My application [-h] [-v] [--my-flag | --no-my-flag] [--my-number INT]
88
+
89
+ This calculates something.
90
+
91
+ ╭─ options ───────────────────────────────────────────────────────────────╮
92
+ │ -h, --help show this help message and exit │
93
+ │ -v, --verbose Verbosity level. Can be used twice to increase. │
94
+ │ --my-flag, --no-my-flag │
95
+ │ This switches the functionality (default: False) │
96
+ │ --my-number INT This number is very important (default: 4) │
97
+ ╰─────────────────────────────────────────────────────────────────────────╯
98
+ ```
99
+
100
+ ## You got config file management
101
+ Loading config file is a piece of cake. Alongside `program.py`, put `program.yaml` and put there some of the arguments. They are seamlessly taken as defaults.
102
+
103
+ ```yaml
104
+ my_number: 555
105
+ ```
106
+
107
+ ```bash
108
+ $ program.py --help
109
+ ...
110
+ │ --my-number INT This number is very important (default: 555) │
111
+ ```
112
+
113
+ ## You got dialogues
114
+ Check out several useful methods to handle user dialogues. Here we bound the interface to a `with` statement that redirects stdout directly to the window.
115
+
116
+ ```python
117
+ with run(Env) as m:
118
+ print(f"Your important number is {m.env.my_number}")
119
+ boolean = m.is_yes("Is that alright?")
120
+ ```
121
+
122
+ ![Small window with the text 'Your important number'](https://github.com/CZ-NIC/mininterface/blob/main/asset/hello-with-statement.webp?raw=True "With statement to redirect the output")
123
+ ![The same in terminal'](https://github.com/CZ-NIC/mininterface/blob/main/asset/hello-with-statement-tui.avif?raw=True "With statement in TUI fallback")
124
+
125
+ # Background
126
+
127
+ Wrapper between various libraries that provide a user interface.
128
+
129
+ Writing a small and useful program might be a task that takes fifteen minutes. Adding a CLI to specify the parameters is not so much overhead. But building a simple GUI around it? HOURS! Hours spent on researching GUI libraries, wondering why the Python desktop app ecosystem lags so far behind the web world. All you need is a few input fields validated through a clickable window... You do not deserve to add hundred of lines of the code just to define some editable fields. `Mininterface` is here to help.
130
+
131
+ The config variables needed by your program are kept in cozy dataclasses. Write less! The syntax of [tyro](https://github.com/brentyi/tyro) does not require any overhead (as its `argparse` alternatives do). You just annotate a class attribute, append a simple docstring and get a fully functional application:
132
+
133
+ * Call it as `program.py --help` to display full help.
134
+ * Use any flag in CLI: `program.py --my-flag` causes `env.my_flag` be set to `True`.
135
+ * The main benefit: Launch it without parameters as `program.py` to get a full working window with all the flags ready to be edited.
136
+ * Running on a remote machine? Automatic regression to the text interface.
137
+ * Or access your program via [web browser](http://127.0.0.1:8000/Interfaces/#webinterface-or-web).
138
+
139
+ # Installation
140
+
141
+ Install with a single command from [PyPi](https://pypi.org/project/mininterface/).
142
+
143
+ ```bash
144
+ pip install mininterface[all] # GPLv3 and compatible
145
+ ```
146
+
147
+ ## Bundles
148
+
149
+ There are various bundles. We mark the bundles with GPL3 dependencies.
150
+
151
+ | bundle | size | licence | description |
152
+ | ------ | ---- | ----------- | ---- |
153
+ | mininterface | 30 MB | LGPL | standard (GUI, TUI) |
154
+ | mininterface | 36 MB | LGPL | standard (GUI, TUI) |
155
+ | mininterface[web] | 36 MB | | including [WebInterface](Interfaces.md#webinterface-or-web) |
156
+ | mininterface[img] | | | images |
157
+ | mininterface[tui] | | | images |
158
+ | mininterface[gui] | | GPL | images, combobox, calendar |
159
+ | mininterface[ui] | 100 MB | GPL | full installation |
160
+ | mininterface[all] | 100 MB | GPL | full installation, same as `ui`, reserved for future use (big dependencies, optional interfaces) |
161
+
162
+ ## Minimal installation
163
+
164
+ Should you need just the CLI part and you are happy with basic text dialogs, use these commands instead:
165
+
166
+ ```bash
167
+ pip install --no-dependencies mininterface
168
+ pip install tyro typing_extensions pyyaml simple_term_menu
169
+ ```
170
+
171
+ ## MacOS GUI
172
+
173
+ If the GUI does not work on MacOS, you might need to launch: `brew install python-tk`
174
+
175
+ # Docs
176
+ See the docs overview at [https://cz-nic.github.io/mininterface/](https://cz-nic.github.io/mininterface/Overview/).
177
+
178
+ # Gallery
179
+
180
+ These projects have the code base reduced thanks to the mininterface:
181
+
182
+ * **[deduplidog](https://github.com/CZ-NIC/deduplidog/)** – Find duplicates in a scattered directory structure
183
+ * **[touch-timestamp](https://github.com/CZ-NIC/touch-timestamp/)** – A powerful dialog to change the files' timestamp
184
+
185
+ # Hello world
186
+
187
+ Take a look at the following example.
188
+ 1. We define any Env class.
189
+ 2. Then, we initialize mininterface with [`run(Env)`][mininterface.run] – the missing fields will be prompter for
190
+ 3. Then, we use various dialog methods, like [`is_yes`][mininterface.Mininterface.is_yes], [`choice`][mininterface.Mininterface.choice] or [`form`][mininterface.Mininterface.form].
191
+
192
+ Below, you find the screenshots how the program looks in various environments ([graphic](Interfaces.md#guiinterface-or-tkinterface-or-gui) interface, [web](Interfaces.md#webinterface-or-web) interface...).
193
+
194
+ ```python3
195
+ from dataclasses import dataclass
196
+ from pathlib import Path
197
+ from mininterface import run
198
+
199
+ @dataclass
200
+ class Env:
201
+ my_file: Path # This is my help text
202
+ my_flag: bool = False
203
+ my_number: int = 4
204
+
205
+ if __name__ == "__main__":
206
+ # Here, the user will be prompted
207
+ # for missing parameters (`my_file`) automatically
208
+ with run(Env) as m:
209
+
210
+ # You can lean on the typing
211
+ # Ex. directly read from the file object:
212
+ print("The file contents:", m.env.my_file.read_text())
213
+
214
+ # You can use various dialog methods,
215
+ # like `is_yes` for bool
216
+ if m.is_yes("Do you want to continue?"):
217
+
218
+ # or `choice` for choosing a value
219
+ fruit = m.choice(("apple", "banana", "sirup"), "Choose a fruit")
220
+
221
+ if fruit == "apple":
222
+ # or `form` for an arbitrary values
223
+ m.form({
224
+ "How many": 0,
225
+ "Choose another file": m.env.my_file
226
+ })
227
+ ```
228
+
229
+ Launch with `./program.py`:
230
+
231
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_tk1.avif?raw=True)
232
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_tk2.avif?raw=True)
233
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_tk3.avif?raw=True)
234
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_tk4.avif?raw=True)
235
+
236
+ Or at the remote machine `MININTERFACE_INTERFACE=tui ./program.py`:
237
+
238
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_textual1.avif?raw=True)
239
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_textual2.avif?raw=True)
240
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_textual3.avif?raw=True)
241
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_textual4.avif?raw=True)
242
+
243
+ Or via the plain text `MININTERFACE_INTERFACE=text ./program.py`:
244
+
245
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_text.avif?raw=True)
246
+
247
+ Or via web browser `MININTERFACE_INTERFACE=web ./program.py`:
248
+
249
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_web.avif?raw=True)
250
+
251
+ You can always set Env via CLI or a config file:
252
+
253
+ ```bash
254
+ $ MININTERFACE_INTERFACE=gui ./program.py --help
255
+ usage: program.py [-h] [OPTIONS]
256
+
257
+ ╭─ options ──────────────────────────────────────────────────────────────╮
258
+ │ -h, --help show this help message and exit │
259
+ │ -v, --verbose Verbosity level. Can be used twice to increase. │
260
+ │ --my-file PATH This is my help text (required) │
261
+ │ --my-flag, --no-my-flag │
262
+ │ (default: False) │
263
+ │ --my-number INT (default: 4) │
264
+ ╰────────────────────────────────────────────────────────────────────────╯
265
+ ```
@@ -1,31 +1,4 @@
1
- Metadata-Version: 2.3
2
- Name: mininterface
3
- Version: 0.7.5
4
- Summary: A minimal access to GUI, TUI, CLI and config
5
- License: GPL-3.0-or-later
6
- Author: Edvard Rejthar
7
- Author-email: edvard.rejthar@nic.cz
8
- Requires-Python: >=3.10,<4.0
9
- Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
10
- Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.10
12
- Classifier: Programming Language :: Python :: 3.11
13
- Classifier: Programming Language :: Python :: 3.12
14
- Classifier: Programming Language :: Python :: 3.13
15
- Requires-Dist: autocombobox (==1.4.2)
16
- Requires-Dist: humanize
17
- Requires-Dist: pyyaml
18
- Requires-Dist: textual (<2.0.0)
19
- Requires-Dist: tkinter-tooltip
20
- Requires-Dist: tkinter_form (==0.2.1)
21
- Requires-Dist: tkscrollableframe
22
- Requires-Dist: typing_extensions
23
- Requires-Dist: tyro (>=0.9,<0.10)
24
- Project-URL: Homepage, https://github.com/CZ-NIC/mininterface
25
- Description-Content-Type: text/markdown
26
-
27
1
  # Mininterface – access to GUI, TUI, CLI and config files
28
- [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
29
2
  [![Build Status](https://github.com/CZ-NIC/mininterface/actions/workflows/run-unittest.yml/badge.svg)](https://github.com/CZ-NIC/mininterface/actions)
30
3
  [![Downloads](https://static.pepy.tech/badge/mininterface)](https://pepy.tech/project/mininterface)
31
4
 
@@ -66,7 +39,7 @@ if __name__ == "__main__":
66
39
  - [Installation](#installation)
67
40
  - [Docs](#docs)
68
41
  - [Gallery](#gallery)
69
- - [Examples](#examples)
42
+ - [Hello world](#hello-world)
70
43
 
71
44
  ## You got CLI
72
45
  It was all the code you need. No lengthy blocks of code imposed by an external dependency. Besides the GUI/TUI, you receive powerful YAML-configurable CLI parsing.
@@ -114,15 +87,17 @@ with run(Env) as m:
114
87
 
115
88
  # Background
116
89
 
117
- Wrapper between the [tyro](https://github.com/brentyi/tyro) `argparse` replacement and [tkinter_form](https://github.com/JohanEstebanCuervo/tkinter_form/) that converts dicts into a GUI.
90
+ Wrapper between various libraries that provide a user interface.
118
91
 
119
92
  Writing a small and useful program might be a task that takes fifteen minutes. Adding a CLI to specify the parameters is not so much overhead. But building a simple GUI around it? HOURS! Hours spent on researching GUI libraries, wondering why the Python desktop app ecosystem lags so far behind the web world. All you need is a few input fields validated through a clickable window... You do not deserve to add hundred of lines of the code just to define some editable fields. `Mininterface` is here to help.
120
93
 
121
94
  The config variables needed by your program are kept in cozy dataclasses. Write less! The syntax of [tyro](https://github.com/brentyi/tyro) does not require any overhead (as its `argparse` alternatives do). You just annotate a class attribute, append a simple docstring and get a fully functional application:
95
+
122
96
  * Call it as `program.py --help` to display full help.
123
97
  * Use any flag in CLI: `program.py --my-flag` causes `env.my_flag` be set to `True`.
124
98
  * The main benefit: Launch it without parameters as `program.py` to get a full working window with all the flags ready to be edited.
125
99
  * Running on a remote machine? Automatic regression to the text interface.
100
+ * Or access your program via [web browser](http://127.0.0.1:8000/Interfaces/#webinterface-or-web).
126
101
 
127
102
  # Installation
128
103
 
@@ -132,13 +107,28 @@ Install with a single command from [PyPi](https://pypi.org/project/mininterface/
132
107
  pip install mininterface[all] # GPLv3 and compatible
133
108
  ```
134
109
 
110
+ ## Bundles
111
+
112
+ There are various bundles. We mark the bundles with GPL3 dependencies.
113
+
114
+ | bundle | size | licence | description |
115
+ | ------ | ---- | ----------- | ---- |
116
+ | mininterface | 30 MB | LGPL | standard (GUI, TUI) |
117
+ | mininterface | 36 MB | LGPL | standard (GUI, TUI) |
118
+ | mininterface[web] | 36 MB | | including [WebInterface](Interfaces.md#webinterface-or-web) |
119
+ | mininterface[img] | | | images |
120
+ | mininterface[tui] | | | images |
121
+ | mininterface[gui] | | GPL | images, combobox, calendar |
122
+ | mininterface[ui] | 100 MB | GPL | full installation |
123
+ | mininterface[all] | 100 MB | GPL | full installation, same as `ui`, reserved for future use (big dependencies, optional interfaces) |
124
+
135
125
  ## Minimal installation
136
126
 
137
127
  Should you need just the CLI part and you are happy with basic text dialogs, use these commands instead:
138
128
 
139
129
  ```bash
140
130
  pip install --no-dependencies mininterface
141
- pip install tyro typing_extensions pyyaml
131
+ pip install tyro typing_extensions pyyaml simple_term_menu
142
132
  ```
143
133
 
144
134
  ## MacOS GUI
@@ -155,77 +145,84 @@ These projects have the code base reduced thanks to the mininterface:
155
145
  * **[deduplidog](https://github.com/CZ-NIC/deduplidog/)** – Find duplicates in a scattered directory structure
156
146
  * **[touch-timestamp](https://github.com/CZ-NIC/touch-timestamp/)** – A powerful dialog to change the files' timestamp
157
147
 
158
- # Examples
148
+ # Hello world
159
149
 
160
- A powerful [`m.form`](https://cz-nic.github.io/mininterface/Mininterface/#mininterface.Mininterface.form) dialog method accepts either a dataclass or a dict. Take a look on both.
150
+ Take a look at the following example.
151
+ 1. We define any Env class.
152
+ 2. Then, we initialize mininterface with [`run(Env)`][mininterface.run] – the missing fields will be prompter for
153
+ 3. Then, we use various dialog methods, like [`is_yes`][mininterface.Mininterface.is_yes], [`choice`][mininterface.Mininterface.choice] or [`form`][mininterface.Mininterface.form].
161
154
 
162
- ## A complex dataclass.
155
+ Below, you find the screenshots how the program looks in various environments ([graphic](Interfaces.md#guiinterface-or-tkinterface-or-gui) interface, [web](Interfaces.md#webinterface-or-web) interface...).
163
156
 
164
157
  ```python3
165
- from typing import Annotated
166
158
  from dataclasses import dataclass
167
- from mininterface.validators import not_empty
168
- from mininterface import run, Tag, Validation
169
-
170
- @dataclass
171
- class NestedEnv:
172
- another_number: int = 7
173
- """ This field is nested """
159
+ from pathlib import Path
160
+ from mininterface import run
174
161
 
175
162
  @dataclass
176
163
  class Env:
177
- nested_config: NestedEnv
178
-
179
- mandatory_str: str
180
- """ As there is no default value, you will be prompted automatically to fill up the field """
181
-
182
- my_number: int | None = None
183
- """ This is not just a dummy number, if left empty, it is None. """
184
-
185
- my_string: str = "Hello"
186
- """ A dummy string """
187
-
164
+ my_file: Path # This is my help text
188
165
  my_flag: bool = False
189
- """ Checkbox test """
190
-
191
- my_validated: Annotated[str, Validation(not_empty)] = "hello"
192
- """ A validated field """
166
+ my_number: int = 4
193
167
 
194
- m = run(Env, title="My program")
195
- # See some values
196
- print(m.env.nested_config.another_number) # 7
197
- print(m.env)
198
- # Env(nested_config=NestedEnv(another_number=7), my_number=5, my_string='Hello', my_flag=False, my_validated='hello')
199
-
200
- # Edit values in a dialog
201
- m.form()
168
+ if __name__ == "__main__":
169
+ # Here, the user will be prompted
170
+ # for missing parameters (`my_file`) automatically
171
+ with run(Env) as m:
172
+
173
+ # You can lean on the typing
174
+ # Ex. directly read from the file object:
175
+ print("The file contents:", m.env.my_file.read_text())
176
+
177
+ # You can use various dialog methods,
178
+ # like `is_yes` for bool
179
+ if m.is_yes("Do you want to continue?"):
180
+
181
+ # or `choice` for choosing a value
182
+ fruit = m.choice(("apple", "banana", "sirup"), "Choose a fruit")
183
+
184
+ if fruit == "apple":
185
+ # or `form` for an arbitrary values
186
+ m.form({
187
+ "How many": 0,
188
+ "Choose another file": m.env.my_file
189
+ })
202
190
  ```
203
191
 
204
- As the attribute `mandatory_str` requires a value, a prompt appears automatically:
192
+ Launch with `./program.py`:
205
193
 
206
- ![Complex example missing field](https://github.com/CZ-NIC/mininterface/blob/main/asset/complex_example_missing_field.avif?raw=True)
194
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_tk1.avif?raw=True)
195
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_tk2.avif?raw=True)
196
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_tk3.avif?raw=True)
197
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_tk4.avif?raw=True)
207
198
 
208
- Then, full form appears:
199
+ Or at the remote machine `MININTERFACE_INTERFACE=tui ./program.py`:
209
200
 
210
- ![Complex example](https://github.com/CZ-NIC/mininterface/blob/main/asset/complex_example.avif?raw=True)
201
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_textual1.avif?raw=True)
202
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_textual2.avif?raw=True)
203
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_textual3.avif?raw=True)
204
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_textual4.avif?raw=True)
211
205
 
212
- ## Form with paths
206
+ Or via the plain text `MININTERFACE_INTERFACE=text ./program.py`:
213
207
 
214
- We have a dict with some paths. Here is how it looks.
208
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_text.avif?raw=True)
215
209
 
216
- ```python
217
- from pathlib import Path
218
- from mininterface import run, Tag
210
+ Or via web browser `MININTERFACE_INTERFACE=web ./program.py`:
219
211
 
220
- m = run(title="My program")
221
- my_dictionary = {
222
- "paths": Tag("", annotation=list[Path]),
223
- "default_paths": Tag([Path("/tmp"), Path("/usr")], annotation=list[Path])
224
- }
212
+ ![Tutorial](https://github.com/CZ-NIC/mininterface/blob/main/asset/tutorial_web.avif?raw=True)
225
213
 
226
- # Edit values in a dialog
227
- m.form(my_dictionary)
228
- ```
229
-
230
- ![List of paths](https://github.com/CZ-NIC/mininterface/blob/main/asset/list_of_paths.avif?raw=True)
214
+ You can always set Env via CLI or a config file:
231
215
 
216
+ ```bash
217
+ $ MININTERFACE_INTERFACE=gui ./program.py --help
218
+ usage: program.py [-h] [OPTIONS]
219
+
220
+ ╭─ options ──────────────────────────────────────────────────────────────╮
221
+ │ -h, --help show this help message and exit │
222
+ │ -v, --verbose Verbosity level. Can be used twice to increase. │
223
+ │ --my-file PATH This is my help text (required) │
224
+ │ --my-flag, --no-my-flag │
225
+ │ (default: False) │
226
+ │ --my-number INT (default: 4) │
227
+ ╰────────────────────────────────────────────────────────────────────────╯
228
+ ```