Pārlūkot izejas kodu

Example/button (#1848)

* button examples

* fix types

---------

Co-authored-by: Fred Lefévère-Laoide <Fred.Lefevere-Laoide@Taipy.io>
Fred Lefévère-Laoide 7 mēneši atpakaļ
vecāks
revīzija
a30ce0fc66

+ 30 - 0
doc/gui/examples/controls/button_action.py

@@ -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 - 0
doc/gui/examples/controls/button_icon.py

@@ -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 - 0
doc/gui/examples/controls/button_lambda.py

@@ -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 - 0
doc/gui/examples/controls/button_simple.py

@@ -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 - 0
doc/gui/examples/controls/button_stylekit.py

@@ -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 - 0
doc/gui/examples/controls/button_styling.py

@@ -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")

+ 2 - 2
taipy/gui/icon.py

@@ -35,8 +35,8 @@ class Icon:
         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,
+        dark_path: t.Optional[str] = None,
     ) -> None:
         """Initialize a new Icon.