-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
182 additions
and
75 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Experimental | ||
::: mininterface.experimental | ||
options: | ||
members: | ||
- SubmitButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,6 +264,11 @@ m.form(my_dictionary) | |
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,55 @@ | ||
|
||
# class SubmitToTrue(bool): | ||
# pass | ||
# SubmitButton = TypeVar("SubmitButton") | ||
|
||
from types import FunctionType | ||
|
||
|
||
class SubmitButton: | ||
""" Create a button. When clicked, the form submits. | ||
If submission succeeds (validation checks pass), its value becomes True. | ||
```python | ||
from pathlib import Path | ||
from mininterface import run, Tag | ||
from mininterface.experimental import SubmitButton | ||
m = run(interface="gui") | ||
out = m.form({ | ||
"File name": Tag("/tmp", annotation=Path), | ||
"Append text": { | ||
"My text": "", | ||
"Append now": SubmitButton() | ||
}, | ||
"Duplicate": { | ||
"Method": Tag("twice", choices=["twice", "thrice"]), | ||
"Duplicate now": SubmitButton() | ||
} | ||
}) | ||
# Clicking on 'Append now' button | ||
print(out) | ||
# {'File name': PosixPath('/tmp'), | ||
# 'Append text': {'My text': '', 'Append now': True}, | ||
# 'Duplicate': {'Method': 'twice', 'Duplicate now': False}} | ||
``` | ||
![Submit button](asset/submitButton.avif) | ||
""" | ||
pass | ||
# NOTE I would prefer this is a mere type, not a class. | ||
|
||
|
||
# FunctionType is not acceptable base type | ||
class FacetCallback(): | ||
""" This type denotes the Tag value is a function. | ||
A button should be created. When clicked, it gets the facet as the argument. | ||
""" | ||
pass | ||
# TODO, not complete | ||
|
||
# NOTE EXPERIMENTAL | ||
# def SubmitToTrue(name=None, description=""): | ||
# """ Create a button. When click, the form submits. If submission succeeds, its value becomes True. """ | ||
# def SubmitButton(name=None, description=""): | ||
# """ Create a button. When clicked, the form submits. | ||
# If submission succeeds (validation checks pass), its value becomes True. | ||
# """ | ||
# from .tag import Tag | ||
# return Tag(val=False, description=description, name=None, annotation=SubmitToTrue) | ||
# return Tag(val=False, description=description, name=None, annotation=SubmitButton) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from textual.widgets import Button, Checkbox, Input, RadioSet | ||
|
||
from ..tag import Tag | ||
|
||
|
||
class Changeable: | ||
""" Widget that can implement on_change method. """ | ||
|
||
_link: Tag | ||
|
||
def trigger_change(self): | ||
if tag := self._link: | ||
tag: Tag | ||
tag._on_change_trigger(self.get_ui_value()) | ||
|
||
def get_ui_value(self): | ||
if isinstance(self, RadioSet): | ||
if self.pressed_button: | ||
return str(self.pressed_button.label) | ||
else: | ||
return None | ||
elif isinstance(self, Button): | ||
return None | ||
else: | ||
return self.value | ||
|
||
|
||
class MySubmitButton(Button, Changeable): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self._val = False | ||
|
||
def on_button_pressed(self): | ||
self._val = True | ||
self._link.facet.submit() | ||
|
||
def get_ui_value(self): | ||
return self._val | ||
|
||
|
||
class MyInput(Input, Changeable): | ||
async def on_blur(self): | ||
return self.trigger_change() | ||
|
||
|
||
class MyCheckbox(Checkbox, Changeable): | ||
def on_checkbox_changed(self): | ||
return self.trigger_change() | ||
|
||
|
||
class MyRadioSet(RadioSet, Changeable): | ||
def on_radio_set_changed(self): | ||
return self.trigger_change() | ||
|
||
|
||
class MyButton(Button, Changeable): | ||
|
||
def on_button_pressed(self): | ||
return self._link.val() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters