Skip to content

Commit

Permalink
Multiple fixes for assistant: add_image && add_file_input (#1122)
Browse files Browse the repository at this point in the history
* Multiple fixes for assistant: add_image && add_file_input

* small fix

* update version and releanotes

* fix lint

* Update releasenotes.rst

---------

Co-authored-by: Mika Hänninen <[email protected]>
  • Loading branch information
Bogdan Condurache and mikahanninen authored Nov 1, 2023
1 parent d3b25fa commit ea06ec3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
4 changes: 4 additions & 0 deletions docs/source/releasenotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Latest versions
`Upcoming release <https://github.com/robocorp/rpaframework/projects/3#column-16713994>`_
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

- Library **RPA.Assistant** (:pr:`1122`; ``rpaframework-assistant`` **3.0.2**): Show
files selected with ``Add File Input`` to make it easier for users to know it has
been used. Also shows a warning if the image path for ``Add Image`` is not valid or
file does not exist.

`Released <https://pypi.org/project/rpaframework/#history>`_
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down
2 changes: 1 addition & 1 deletion packages/assistant/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "rpaframework-assistant"
version = "3.0.1"
version = "3.0.2"
description = "Interactive UI library for RPA Framework"
authors = ["RPA Framework <[email protected]>"]
license = "Apache-2.0"
Expand Down
49 changes: 35 additions & 14 deletions packages/assistant/src/RPA/Assistant/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def add_image(
Adds an inline image to the dialog, which can either
point to a local file path on the executing machine or to
a remote URL.
a remote URL. If it's a local file path it has to be absolute path.
By default the image is resized to fit the width of the dialog
window, but the width and/or height can be explicitly defined
Expand All @@ -444,24 +444,33 @@ def add_image(
*** Keywords ***
Display image
Add image company-logo.png
Add image C:\\Users\\me\\company-logo.png
Add heading To start, please press the Continue button size=Small
Add submit buttons Continue
Run dialog
.. code-block:: python
def display_image():
assistant = Assistant()
assistant.add_image("company-logo.png")
assistant.add_image("C:\\Users\\me\\company-logo.png")
assistant.add_heading("To start, please press the Continue button", size="small")
assistant.add_submit_buttons("Continue")
assistant.run_dialog()
""" # noqa: E501

self._client.add_element(
Container(content=Image(src=url_or_path, width=width, height=height))
)
is_url = url_or_path.startswith(("http://", "https://"))
is_absolute_path = os.path.isabs(url_or_path)
is_absolute_and_file_exists = is_absolute_path and os.path.isfile(url_or_path)

if is_url or is_absolute_and_file_exists:
self._client.add_element(
Container(content=Image(src=url_or_path, width=width, height=height))
)
else:
self.logger.warning(
"The image path you specified should be a valid URL or absolute path "
+ f" to an existing file. The value provided: {url_or_path}"
)

@keyword
def add_file(
Expand Down Expand Up @@ -980,9 +989,16 @@ def multiple_file_selections():
def on_pick_result(event: FilePickerResultEvent):
if event.files:
self._client.results[str(name)] = [f.path for f in event.files]
selected_files.value = (
", ".join(map(lambda f: f.name, event.files))
if event.files
else "Cancelled!"
)
selected_files.update()

file_picker = FilePicker(on_result=on_pick_result)
self._client.add_invisible_element(file_picker)
selected_files = Text()

options = {
"source": optional_str(source),
Expand All @@ -996,13 +1012,18 @@ def on_pick_result(event: FilePickerResultEvent):
options["file_type"] = options["file_type"].split(",")

self._client.add_element(
ElevatedButton(
label or "Choose files...",
on_click=lambda _: file_picker.pick_files(
allow_multiple=bool(multiple),
initial_directory=options["source"],
allowed_extensions=options["file_type"],
),
Row(
[
ElevatedButton(
label or "Choose files...",
on_click=lambda _: file_picker.pick_files(
allow_multiple=bool(multiple),
initial_directory=options["source"],
allowed_extensions=options["file_type"],
),
),
selected_files,
]
)
)

Expand Down

0 comments on commit ea06ec3

Please sign in to comment.