Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example/button #1848

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions doc/gui/examples/controls/button_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2021-2024 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
# python <script>
# -----------------------------------------------------------------------------------------
from taipy.gui import Gui

text = None

def button_pressed(state, id: str, payload: dict):
# React to the button press action.
state.text = f"The button '{id}' was pressed and called action '{payload.get('action')}'."

page = """
<|Button Label|button|id=button1|on_action=button_pressed|>
<|{text}|>
"""

if __name__ == "__main__":
Gui(page).run(title="Button - Action")
25 changes: 25 additions & 0 deletions doc/gui/examples/controls/button_icon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2021-2024 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
# python <script>
# -----------------------------------------------------------------------------------------
from taipy.gui import Gui, Icon

icon = Icon("./charles-avatar.png", "charles")

page = """
<|{icon}|button|>
"""

if __name__ == "__main__":
Gui(page).run(title="Button - Icon")
26 changes: 26 additions & 0 deletions doc/gui/examples/controls/button_lambda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2021-2024 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
# python <script>
# -----------------------------------------------------------------------------------------
from taipy.gui import Gui

text = None

page = """
<|Button Label|button|id=button1|on_action={lambda s, i, p: s.assign("text", f"button '{i}': '{p.get('action')}'.")}|>
<|{text}|>
"""

if __name__ == "__main__":
Gui(page).run(title="Button - Lambda")
30 changes: 30 additions & 0 deletions doc/gui/examples/controls/button_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2021-2024 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
# python <script>
# -----------------------------------------------------------------------------------------
from taipy.gui import Gui

text = None

def on_action(state, id: str, payload: dict):
# React to the button press action.
state.text = f"The button '{id}' was pressed and called action '{payload.get('action')}'."

page = """
<|Button Label|button|>
<|{text}|>
"""

if __name__ == "__main__":
Gui(page).run(title="Button - Simple")
24 changes: 24 additions & 0 deletions doc/gui/examples/controls/button_stylekit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2021-2024 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
# python <script>
# -----------------------------------------------------------------------------------------
from taipy.gui import Gui

page = """
<|Error|button|class_name=error|>
<|Secondary|button|class_name=secondary|>
"""

if __name__ == "__main__":
Gui(page).run(title="Button - Stylekit")
26 changes: 26 additions & 0 deletions doc/gui/examples/controls/button_styling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2021-2024 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
# python <script>
# -----------------------------------------------------------------------------------------
from taipy.gui import Gui, Markdown

page = Markdown(
"""
<|Styled|button|class_name=my-style|>
""",
style={".taipy-button.my-style": {"border-radius": "0", "color": "green"}},
)

if __name__ == "__main__":
Gui(page).run(title="Button - Styling")
4 changes: 2 additions & 2 deletions taipy/gui/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def __init__(
self,
path: str,
text: t.Optional[str] = None,
light_path: t.Optional[bool] = None,
dark_path: t.Optional[bool] = None,
light_path: t.Optional[str] = None,
FredLL-Avaiga marked this conversation as resolved.
Show resolved Hide resolved
dark_path: t.Optional[str] = None,
) -> None:
"""Initialize a new Icon.

Expand Down
Loading