Skip to content

Commit

Permalink
Update template.py
Browse files Browse the repository at this point in the history
  • Loading branch information
freaksie authored Dec 3, 2024
1 parent 7c622aa commit 730a55a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions PyPDFForm/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,31 @@ def widget_rect_watermarks(pdf: bytes) -> List[bytes]:
return watermarks


# def dropdown_to_text(dropdown: Dropdown) -> Text:
# """Converts a dropdown widget to a text widget."""

# result = Text(dropdown.name)

# if dropdown.value is not None:
# result.value = (
# dropdown.choices[dropdown.value]
# if dropdown.value < len(dropdown.choices)
# else ""
# )

# return result
def dropdown_to_text(dropdown: Dropdown) -> Text:
"""Converts a dropdown widget to a text widget."""

result = Text(dropdown.name)

if dropdown.value is not None:
result.value = (
dropdown.choices[dropdown.value]
if dropdown.value < len(dropdown.choices)
else ""
dropdown.value
)

return result


def update_text_field_attributes(
template_stream: bytes,
widgets: Dict[str, WIDGET_TYPES],
Expand Down

0 comments on commit 730a55a

Please sign in to comment.