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

reset file selector input after upload #2280

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

FredLL-Avaiga
Copy link
Member

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

  • Reset file selector input after upload so that the user can select the same file
  • disable number input arrows when the input is disabled

Related Tickets & Documents

How to reproduce the issue

from PIL import Image

import taipy.gui.builder as tgb
from taipy.gui import Gui, notify

path_upload = ""
original_image = None
image = None
fixed_image = None
fixed = False
num_val = 1
num_active = True


def clear_images(state):
    """
    Clears the currently displayed images by setting `original_image` and `fixed_image` to None.
    """
    state.original_image = None
    state.fixed_image = None
    state.fixed = False
    state.image = None
    state.path_upload = ""
    print("Images cleared.")
    notify(state, "info", "Images have been cleared.")


def upload_image(state):
    """
    Handles image upload and prepares the state for displaying the image.
    Resets variables to ensure the new upload is recognized.
    """
    state.original_image = Image.open(state.path_upload)
    state.fixed = False
    print(f"Image successfully loaded from {state.path_upload}.")
    notify(state, "success", "Image uploaded successfully!")


# Create the Taipy GUI layout
with tgb.Page() as page:
    tgb.text(
        lambda original_image: "Is there an image? " + str(original_image is not None)
    )
    tgb.file_selector(
        "{path_upload}",
        extensions=".webp",
        drop_message="Drop Image here",
        label="Upload image",
        on_action=upload_image,
    )

    tgb.button(
        label="Clear Images",
        on_action=clear_images,
        active="{original_image is not None}",
    )

    tgb.number("{num_val}", active="{num_active}")
    tgb.button(label="active number", on_action=lambda s: s.assign("num_active", not s.num_active))


if __name__ == "__main__":
    Gui(page=page).run(title="2103 WebP to PNG Converter")

disable number input arrows
resolves #2103
@FredLL-Avaiga FredLL-Avaiga self-assigned this Nov 25, 2024
@FredLL-Avaiga FredLL-Avaiga added 💥Malfunction Addresses an identified problem. 🟧 Priority: High Must be addressed as soon GUI: Front-End 📝Release Notes Impacts the Release Notes or the Documentation in general labels Nov 25, 2024
Copy link
Contributor

github-actions bot commented Nov 25, 2024

Coverage report for ./frontend/taipy-gui

Caution

Coverage does not meet threshold
Branches coverage not met for global: expected >=80%, but got 69.45668135095447%

St.
Category Percentage Covered / Total
🟢 Statements
87.51% (+0.02% 🔼)
3460/3954
🟡 Branches
69.46% (+0.05% 🔼)
2365/3405
🟢 Functions
83.22% (+0.02% 🔼)
640/769
🟢 Lines
87.99% (+0.02% 🔼)
3203/3640

Test suite run success

698 tests passing in 47 suites.

Report generated by 🧪jest coverage report action from 1a4b005

Copy link
Contributor

Coverage report for ./frontend/taipy

Caution

Coverage does not meet threshold
Statements coverage not met for global: expected >=80%, but got 52.07920792079208%

St.
Category Percentage Covered / Total
🔴 Statements 52.08% 263/505
🔴 Branches 21.75% 67/308
🔴 Functions 14.66% 17/116
🔴 Lines 53.42% 242/453

Test suite run success

7 tests passing in 1 suite.

Report generated by 🧪jest coverage report action from 1a4b005

Copy link
Contributor

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
19331 16806 87% 0% 🟢

New Files

No new covered files...

Modified Files

No covered modified files...

updated for commit: 1a4b005 by action🐍

Copy link
Member

@dinhlongviolin1 dinhlongviolin1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI: Front-End 💥Malfunction Addresses an identified problem. 🟧 Priority: High Must be addressed as soon 📝Release Notes Impacts the Release Notes or the Documentation in general
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with using file_selector to upload an image file second time around.
2 participants