SwiftGUI 0.11.6__tar.gz → 0.11.8__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.
- {swiftgui-0.11.6 → swiftgui-0.11.8}/PKG-INFO +3 -4
- {swiftgui-0.11.6 → swiftgui-0.11.8}/pyproject.toml +1 -1
- swiftgui-0.11.8/src/SwiftGUI/Combined_Elements/Form.py +211 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Files/ConfigurationEditor.py +1 -1
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/Input.py +4 -2
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Windows.py +4 -1
- swiftgui-0.11.6/src/SwiftGUI/Combined_Elements/Form.py +0 -194
- {swiftgui-0.11.6 → swiftgui-0.11.8}/LICENSE +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/README.md +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Base.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/BasePopup.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Canvas_Elements/Arc.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Canvas_Elements/Bitmap.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Canvas_Elements/Element.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Canvas_Elements/Image.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Canvas_Elements/Line.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Canvas_Elements/Oval.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Canvas_Elements/Polygon.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Canvas_Elements/Rectangle.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Canvas_Elements/Text.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Canvas_Elements/_Base.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Canvas_Elements/__init__.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Colors.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Combined_Elements/BaseCombinedElement.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Combined_Elements/Console.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Combined_Elements/MultistateButton.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Compat.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Debug.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/DecoratorKeys.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/ElementFlags.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Events.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Examples/AllElements.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Examples/AllThemes.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Examples/GlobalOptionBrowser.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Examples/Previews.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Examples/__init__.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Extended_Elements/ColorChooserButton.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Extended_Elements/FileBrowseButton.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Extended_Elements/Image.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Extended_Elements/ImageButton.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Extended_Elements/Separator.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Extended_Elements/Spacer.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Extended_Elements/TabFrame.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Extended_Elements/Table.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Extras/SwiftGUI.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Extras/__init__.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Files/ConfigFile.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Files/DictFile.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Files/ProgramDirectory.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Files/__init__.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Fonts.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/GlobalOptions.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/KeyFunctions.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/KeyManager.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Literals.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Popups/ElementPopup.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Popups/ListPicker.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Popups/Popups.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Popups/VirtualKeyboard.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Popups/__init__.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Themes/FourColors.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Themes/Thematic.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Themes/_BaseTheme.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Themes/__init__.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Tools.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Utilities/Images.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Utilities/Threads.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/Button.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/Canvas.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/Checkbox.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/Combobox.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/Frame.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/GridFrame.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/LabelFrame.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/Listbox.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/Notebook.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/Progressbar.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/Radiobutton.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/Scale.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/Scrollbar.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/Spinbox.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/TKContainer.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/Text.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/TextField.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/Widget_Elements/Treeview.py +0 -0
- {swiftgui-0.11.6 → swiftgui-0.11.8}/src/SwiftGUI/__init__.py +0 -0
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: SwiftGUI
|
|
3
|
-
Version: 0.11.
|
|
3
|
+
Version: 0.11.8
|
|
4
4
|
Summary: An easy-to-use package for quickly creating smaller and bigger GUIs
|
|
5
|
-
License
|
|
6
|
-
License-File: LICENSE
|
|
5
|
+
License: Apache-2.0
|
|
7
6
|
Author: Eric aka CheesecakeTV
|
|
8
7
|
Author-email: cheesecaketv53+pypi@gmail.com
|
|
9
8
|
Requires-Python: >=3.10
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
|
|
2
|
+
from collections.abc import Iterable, Callable
|
|
3
|
+
from functools import partial
|
|
4
|
+
from typing import Any, Hashable, Mapping
|
|
5
|
+
from SwiftGUI.Compat import Self
|
|
6
|
+
import json
|
|
7
|
+
|
|
8
|
+
from SwiftGUI import BaseElement, Frame, Text, Input, BaseCombinedElement, Button, Event
|
|
9
|
+
#from SwiftGUI.Widget_Elements.Separator import HorizontalSeparator
|
|
10
|
+
from SwiftGUI.Extended_Elements.Spacer import Spacer
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Advanced / Combined elements
|
|
14
|
+
class Form(BaseCombinedElement):
|
|
15
|
+
"""
|
|
16
|
+
Grid-Layout-Form with text-Input-combinations
|
|
17
|
+
|
|
18
|
+
It is WIP, but I'm adding more functionality regularely
|
|
19
|
+
I'll probably throw this whole class out of the window and redo it, since it is so unfathomly bad atm.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
texts:Iterable[str] | Mapping[Hashable, str], # Text = keys, or (Text, key)-pairs
|
|
25
|
+
*,
|
|
26
|
+
default_values: Iterable[Any] | Mapping[Hashable, str] = None,
|
|
27
|
+
key: Hashable = None,
|
|
28
|
+
key_function: Callable | Iterable[Callable] = None,
|
|
29
|
+
default_event: bool = None,
|
|
30
|
+
small_clear_buttons: bool = None,
|
|
31
|
+
big_clear_button: bool = None,
|
|
32
|
+
submit_button: bool = None,
|
|
33
|
+
#submit_key: Any = None,
|
|
34
|
+
return_submits: bool = None,
|
|
35
|
+
):
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
:param texts: Texts displayed before the input-elements. Pass a dict to specify the keys of each input. Beware: The value becomes a dict if you specify keys
|
|
39
|
+
:param default_values: Initial values. Pass as a list or a dict
|
|
40
|
+
:param key:
|
|
41
|
+
:param key_function:
|
|
42
|
+
:param default_event: If any input changes, an event gets thrown
|
|
43
|
+
:param small_clear_buttons: Small x-buttons behind each input to clear it with one click
|
|
44
|
+
:param big_clear_button: One big clear-button under the inputs to clear all inputs at once
|
|
45
|
+
:param submit_button: True, if there should be a submit-button that throws an event when clicked. Ignores the default event
|
|
46
|
+
:param return_submits: True, if pressing enter should be equal to pressing submit. Ignores the default event
|
|
47
|
+
"""
|
|
48
|
+
self._has_key_mapping = isinstance(texts, Mapping)
|
|
49
|
+
|
|
50
|
+
if self._has_key_mapping:
|
|
51
|
+
values = list(texts.values())
|
|
52
|
+
else:
|
|
53
|
+
values = list(texts)
|
|
54
|
+
|
|
55
|
+
_max_len = max(map(len, values))
|
|
56
|
+
|
|
57
|
+
self._input_elements: list[Input] = list()
|
|
58
|
+
self._text_elements: list[Text] = list()
|
|
59
|
+
|
|
60
|
+
self._small_clear_buttons = small_clear_buttons
|
|
61
|
+
self._return_submits = return_submits
|
|
62
|
+
|
|
63
|
+
if self._has_key_mapping:
|
|
64
|
+
layout = [
|
|
65
|
+
*[
|
|
66
|
+
self._make_row(k,t, text_len=_max_len) for t,k in texts.items()
|
|
67
|
+
]
|
|
68
|
+
]
|
|
69
|
+
else:
|
|
70
|
+
layout = [
|
|
71
|
+
*[
|
|
72
|
+
self._make_row(t, text_len=_max_len) for t in values
|
|
73
|
+
]
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
button_row: list[BaseElement] = list()
|
|
77
|
+
|
|
78
|
+
if big_clear_button:
|
|
79
|
+
self.clear_button = Button(
|
|
80
|
+
"Clear",
|
|
81
|
+
key_function= lambda: self.clear_all_values(throw_default_event=True),
|
|
82
|
+
)
|
|
83
|
+
button_row.append(self.clear_button)
|
|
84
|
+
|
|
85
|
+
if submit_button:
|
|
86
|
+
self.submit_button = Button(
|
|
87
|
+
"Submit",
|
|
88
|
+
key_function=self.throw_event,
|
|
89
|
+
)
|
|
90
|
+
button_row.append(self.submit_button)
|
|
91
|
+
|
|
92
|
+
if button_row:
|
|
93
|
+
layout.append(button_row)
|
|
94
|
+
|
|
95
|
+
super().__init__(
|
|
96
|
+
layout,
|
|
97
|
+
key=key,
|
|
98
|
+
key_function=key_function,
|
|
99
|
+
default_event=default_event,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
if default_values is not None:
|
|
103
|
+
self.set_value(default_values)
|
|
104
|
+
|
|
105
|
+
def _make_row(self, text: str, key: Hashable = None, text_len: int = 20) -> list[BaseElement]:
|
|
106
|
+
"""
|
|
107
|
+
Create a single row of elements
|
|
108
|
+
:param text:
|
|
109
|
+
:param key:
|
|
110
|
+
:return:
|
|
111
|
+
"""
|
|
112
|
+
input_elem = Input(
|
|
113
|
+
key=key,
|
|
114
|
+
default_event=True,
|
|
115
|
+
key_function=self.throw_default_event,
|
|
116
|
+
)
|
|
117
|
+
self._input_elements.append(input_elem)
|
|
118
|
+
|
|
119
|
+
if self._return_submits:
|
|
120
|
+
input_elem.bind_event(
|
|
121
|
+
Event.KeyEnter,
|
|
122
|
+
key_function= self.throw_event,
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
row: list[BaseElement] = [
|
|
126
|
+
Text(
|
|
127
|
+
text,
|
|
128
|
+
width= text_len,
|
|
129
|
+
),
|
|
130
|
+
input_elem,
|
|
131
|
+
]
|
|
132
|
+
|
|
133
|
+
if self._small_clear_buttons:
|
|
134
|
+
row.append(Button(
|
|
135
|
+
text= "x",
|
|
136
|
+
width=2,
|
|
137
|
+
key_function= lambda: input_elem.set_value("", throw_event=True),
|
|
138
|
+
takefocus= False,
|
|
139
|
+
))
|
|
140
|
+
|
|
141
|
+
return row
|
|
142
|
+
|
|
143
|
+
@BaseCombinedElement._run_after_window_creation
|
|
144
|
+
def set_value(self, val: Iterable | Mapping) -> Self:
|
|
145
|
+
"""
|
|
146
|
+
Either pass a dict (Mapping) to overwrite specific items or an iterable to overwrite one after another
|
|
147
|
+
:param val:
|
|
148
|
+
:return:
|
|
149
|
+
"""
|
|
150
|
+
if isinstance(val, Mapping):
|
|
151
|
+
super().set_value(val)
|
|
152
|
+
else:
|
|
153
|
+
for value, elem in zip(val, self._input_elements):
|
|
154
|
+
elem.value = value
|
|
155
|
+
|
|
156
|
+
def values(self) -> tuple:
|
|
157
|
+
"""
|
|
158
|
+
Return a tuple with all form-values one after the other
|
|
159
|
+
:return:
|
|
160
|
+
"""
|
|
161
|
+
return tuple(map(lambda a:a.value, self._input_elements))
|
|
162
|
+
|
|
163
|
+
def _get_value(self):
|
|
164
|
+
if self._has_key_mapping:
|
|
165
|
+
return super()._get_value()
|
|
166
|
+
|
|
167
|
+
return self.values()
|
|
168
|
+
|
|
169
|
+
@BaseElement._run_after_window_creation
|
|
170
|
+
def update_texts(self,**kwargs) -> Self:
|
|
171
|
+
"""
|
|
172
|
+
Evoke .update on every text-element
|
|
173
|
+
:param kwargs:
|
|
174
|
+
:return:
|
|
175
|
+
"""
|
|
176
|
+
for elem in self._text_elements:
|
|
177
|
+
elem._update_initial(**kwargs)
|
|
178
|
+
return self
|
|
179
|
+
|
|
180
|
+
@BaseElement._run_after_window_creation
|
|
181
|
+
def update_inputs(self,**kwargs) -> Self:
|
|
182
|
+
"""
|
|
183
|
+
Evoke .update on every text-element
|
|
184
|
+
:param kwargs:
|
|
185
|
+
:return:
|
|
186
|
+
"""
|
|
187
|
+
for elem in self._input_elements:
|
|
188
|
+
elem._update_initial(**kwargs)
|
|
189
|
+
return self
|
|
190
|
+
|
|
191
|
+
def clear_all_values(self, throw_default_event: bool = False):
|
|
192
|
+
"""
|
|
193
|
+
Does what it says
|
|
194
|
+
:return:
|
|
195
|
+
"""
|
|
196
|
+
for elem in self._input_elements:
|
|
197
|
+
elem.value = ""
|
|
198
|
+
|
|
199
|
+
if throw_default_event:
|
|
200
|
+
self.throw_default_event()
|
|
201
|
+
|
|
202
|
+
def set_focus(self):
|
|
203
|
+
"""
|
|
204
|
+
Focus the first row of this element
|
|
205
|
+
:return:
|
|
206
|
+
"""
|
|
207
|
+
self._input_elements[0].set_focus()
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
@@ -214,8 +214,10 @@ class Input(BaseWidget):
|
|
|
214
214
|
self._value_change_callback = self.window.get_event_function(self, key= self.key, key_function= self._key_function)
|
|
215
215
|
self._tk_target_value.trace_add("write", self._event_callback)
|
|
216
216
|
|
|
217
|
-
def set_value(self, val:str) -> Self:
|
|
218
|
-
|
|
217
|
+
def set_value(self, val:str, throw_event: bool = False) -> Self:
|
|
218
|
+
if not throw_event:
|
|
219
|
+
self._prev_value = val
|
|
220
|
+
|
|
219
221
|
super().set_value(val)
|
|
220
222
|
return self
|
|
221
223
|
|
|
@@ -182,10 +182,13 @@ class ValueDict:
|
|
|
182
182
|
valuedict_logger.debug(f"I was converted to json with these keys: {tuple(ret.keys())}")
|
|
183
183
|
return ret
|
|
184
184
|
|
|
185
|
-
def from_json(self, saved_dict: dict) -> Self:
|
|
185
|
+
def from_json(self, saved_dict: dict | None) -> Self:
|
|
186
186
|
"""
|
|
187
187
|
Restore the values previously acquired through .to_json
|
|
188
188
|
"""
|
|
189
|
+
if saved_dict is None:
|
|
190
|
+
return self
|
|
191
|
+
|
|
189
192
|
valuedict_logger.debug(f"These keys were updated from json: {tuple(saved_dict.keys())}")
|
|
190
193
|
|
|
191
194
|
win_elems = self._window.all_key_elements
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
from collections.abc import Iterable, Callable
|
|
3
|
-
from functools import partial
|
|
4
|
-
from typing import Any, Hashable
|
|
5
|
-
from SwiftGUI.Compat import Self
|
|
6
|
-
import json
|
|
7
|
-
|
|
8
|
-
from SwiftGUI import BaseElement, Frame, Text, Input, BaseCombinedElement, Button, Event
|
|
9
|
-
#from SwiftGUI.Widget_Elements.Separator import HorizontalSeparator
|
|
10
|
-
from SwiftGUI.Extended_Elements.Spacer import Spacer
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
# Advanced / Combined elements
|
|
14
|
-
class Form(BaseCombinedElement):
|
|
15
|
-
"""
|
|
16
|
-
Grid-Layout-Form with text-Input-combinations
|
|
17
|
-
|
|
18
|
-
It is WIP, but I'm adding more functionality regularely
|
|
19
|
-
I'll probably throw this whole class out of the window and redo it, since it is so unfathomly bad atm.
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
def __init__(
|
|
23
|
-
self,
|
|
24
|
-
texts:Iterable[str] | Iterable[tuple[str, str]], # Text = keys, or (Text, key)-pairs
|
|
25
|
-
*,
|
|
26
|
-
default_values: Iterable[Any] | dict[str, Any] = None,
|
|
27
|
-
key: Hashable = None,
|
|
28
|
-
key_function: Callable | Iterable[Callable] = None,
|
|
29
|
-
default_event: bool = None,
|
|
30
|
-
small_clear_buttons: bool = None,
|
|
31
|
-
big_clear_button: bool = None,
|
|
32
|
-
submit_button: bool = None,
|
|
33
|
-
#submit_key: Any = None,
|
|
34
|
-
return_submits: bool = None,
|
|
35
|
-
):
|
|
36
|
-
"""
|
|
37
|
-
|
|
38
|
-
:param texts:
|
|
39
|
-
:param default_values:
|
|
40
|
-
:param key:
|
|
41
|
-
:param key_function:
|
|
42
|
-
:param default_event:
|
|
43
|
-
:param small_clear_buttons:
|
|
44
|
-
:param big_clear_button:
|
|
45
|
-
:param submit_button: True, if there should be a submit-button that throws an event when clicked
|
|
46
|
-
:param return_submits: True, if pressing enter should be equal to pressing submit
|
|
47
|
-
"""
|
|
48
|
-
texts = list(texts)
|
|
49
|
-
|
|
50
|
-
if isinstance(texts[0], str):
|
|
51
|
-
self._texts = texts
|
|
52
|
-
self._input_keys = texts
|
|
53
|
-
else:
|
|
54
|
-
self._texts, self._input_keys = list(zip(*texts))
|
|
55
|
-
|
|
56
|
-
max_len = max(map(len,self._texts))
|
|
57
|
-
|
|
58
|
-
self._text_elements = [
|
|
59
|
-
Text(
|
|
60
|
-
line,
|
|
61
|
-
width=max_len + 1,
|
|
62
|
-
padding=2
|
|
63
|
-
)
|
|
64
|
-
for line in self._texts
|
|
65
|
-
]
|
|
66
|
-
|
|
67
|
-
self._input_elements = [
|
|
68
|
-
Input(
|
|
69
|
-
key_function= self.throw_default_event,
|
|
70
|
-
default_event= default_event,
|
|
71
|
-
key= t
|
|
72
|
-
)
|
|
73
|
-
for t in texts
|
|
74
|
-
]
|
|
75
|
-
|
|
76
|
-
self._clear_buttons = [
|
|
77
|
-
Button(
|
|
78
|
-
"x",
|
|
79
|
-
key_function= (
|
|
80
|
-
partial(lambda index: self._input_elements[index].set_value(""), n),
|
|
81
|
-
self.throw_default_event,
|
|
82
|
-
),
|
|
83
|
-
width=2,
|
|
84
|
-
) if small_clear_buttons else Text()
|
|
85
|
-
for n, _ in enumerate(self._input_elements)
|
|
86
|
-
]
|
|
87
|
-
|
|
88
|
-
self.layout = list(zip(self._text_elements, self._input_elements, self._clear_buttons))
|
|
89
|
-
|
|
90
|
-
# if Any((submit_button, big_clear_button)):
|
|
91
|
-
# self.layout.append([HorizontalSeparator()])
|
|
92
|
-
self.layout.append([Spacer(height=5)])
|
|
93
|
-
|
|
94
|
-
self.layout.append([])
|
|
95
|
-
if submit_button:
|
|
96
|
-
self._submit_button_element = Button(
|
|
97
|
-
"Submit",
|
|
98
|
-
#key= submit_key if submit_key is not None else None,
|
|
99
|
-
key_function=[self.throw_event, lambda v:self.done(v)]
|
|
100
|
-
#key_function= submit_key_function if submit_key_function else self.throw_event,
|
|
101
|
-
)
|
|
102
|
-
self.layout[-1].append(self._submit_button_element)
|
|
103
|
-
|
|
104
|
-
if big_clear_button:
|
|
105
|
-
self.layout[-1].append(Button(
|
|
106
|
-
"Clear",
|
|
107
|
-
key_function= (self.clear_all_values, self.throw_default_event)
|
|
108
|
-
))
|
|
109
|
-
|
|
110
|
-
if return_submits:
|
|
111
|
-
temp = self.throw_event
|
|
112
|
-
# if submit_button: # Looks cool, but slows down the code...
|
|
113
|
-
# temp = (self.throw_event, self._submit_button_element.flash)
|
|
114
|
-
|
|
115
|
-
for elem in self._input_elements:
|
|
116
|
-
elem.bind_event(Event.KeyEnter, key_function=temp)
|
|
117
|
-
|
|
118
|
-
super().__init__(Frame(self.layout), key=key, key_function=key_function, default_event=default_event)
|
|
119
|
-
|
|
120
|
-
if default_values:
|
|
121
|
-
self.set_value(default_values)
|
|
122
|
-
|
|
123
|
-
def _update_special_key(self,key:str,new_val:Any) -> bool|None:
|
|
124
|
-
match key:
|
|
125
|
-
case _:
|
|
126
|
-
return super()._update_special_key(key, new_val)
|
|
127
|
-
|
|
128
|
-
return True
|
|
129
|
-
|
|
130
|
-
@BaseCombinedElement._run_after_window_creation
|
|
131
|
-
def set_value(self, val: dict | Iterable) -> Self:
|
|
132
|
-
"""
|
|
133
|
-
Either pass a dict to overwrite specific items or an iterable to overwrite one after another
|
|
134
|
-
:param val:
|
|
135
|
-
:return:
|
|
136
|
-
"""
|
|
137
|
-
try:
|
|
138
|
-
val = list(val)
|
|
139
|
-
except TypeError:
|
|
140
|
-
super().set_value(val)
|
|
141
|
-
else:
|
|
142
|
-
for value, elem in zip(val, self._input_elements):
|
|
143
|
-
elem.value = value
|
|
144
|
-
|
|
145
|
-
def values(self) -> tuple:
|
|
146
|
-
"""
|
|
147
|
-
Return a tuple with all form-values one after the other
|
|
148
|
-
:return:
|
|
149
|
-
"""
|
|
150
|
-
return tuple(map(lambda a:a.value, self._input_elements))
|
|
151
|
-
|
|
152
|
-
@BaseElement._run_after_window_creation
|
|
153
|
-
def update_texts(self,**kwargs) -> Self:
|
|
154
|
-
"""
|
|
155
|
-
Evoke .update on every text-element
|
|
156
|
-
:param kwargs:
|
|
157
|
-
:return:
|
|
158
|
-
"""
|
|
159
|
-
for elem in self._text_elements:
|
|
160
|
-
elem._update_initial(**kwargs)
|
|
161
|
-
return self
|
|
162
|
-
|
|
163
|
-
@BaseElement._run_after_window_creation
|
|
164
|
-
def update_inputs(self,**kwargs) -> Self:
|
|
165
|
-
"""
|
|
166
|
-
Evoke .update on every text-element
|
|
167
|
-
:param kwargs:
|
|
168
|
-
:return:
|
|
169
|
-
"""
|
|
170
|
-
for elem in self._input_elements:
|
|
171
|
-
elem._update_initial(**kwargs)
|
|
172
|
-
return self
|
|
173
|
-
|
|
174
|
-
@BaseElement._run_after_window_creation
|
|
175
|
-
def update_submit_button(self, **kwargs) -> Self:
|
|
176
|
-
"""
|
|
177
|
-
Evoke .update on the submit-button
|
|
178
|
-
:param kwargs:
|
|
179
|
-
:return:
|
|
180
|
-
"""
|
|
181
|
-
self._submit_button_element._update_initial(**kwargs)
|
|
182
|
-
return self
|
|
183
|
-
|
|
184
|
-
def clear_all_values(self):
|
|
185
|
-
"""
|
|
186
|
-
Does what it says
|
|
187
|
-
:return:
|
|
188
|
-
"""
|
|
189
|
-
for elem in self._input_elements:
|
|
190
|
-
elem.value = ""
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|