PyPDFForm 2.5.0__py3-none-any.whl → 3.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of PyPDFForm might be problematic. Click here for more details.

@@ -1,11 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
- """Provides middleware for PDF checkbox widgets.
2
+ """
3
+ Module representing a checkbox widget.
3
4
 
4
- This module contains the Checkbox class which handles:
5
- - Checkbox state management (checked/unchecked)
6
- - Button style customization
7
- - Value validation and conversion
8
- - Schema generation for form validation
5
+ This module defines the Checkbox class, which is a subclass of the
6
+ Widget class. It represents a checkbox form field in a PDF document.
9
7
  """
10
8
 
11
9
  from typing import Union
@@ -14,88 +12,59 @@ from .base import Widget
14
12
 
15
13
 
16
14
  class Checkbox(Widget):
17
- """Middleware for PDF checkbox widgets.
18
-
19
- Handles all aspects of checkbox processing including:
20
- - State management (checked/unchecked)
21
- - Button style customization (check, cross, circle)
22
- - Value validation
23
- - PDF form field integration
15
+ """
16
+ Represents a checkbox widget.
24
17
 
25
- Inherits from Widget base class and extends it with checkbox-specific features.
18
+ The Checkbox class provides a concrete implementation for
19
+ checkbox form fields. It inherits from the Widget class and
20
+ implements the schema_definition and sample_value properties.
26
21
  """
27
22
 
28
23
  SET_ATTR_TRIGGER_HOOK_MAP = {
29
24
  "size": "update_check_radio_size",
30
25
  }
31
26
 
32
- BUTTON_STYLE_MAPPING = {
33
- "check": "4",
34
- "cross": "5",
35
- "circle": "l",
36
- }
37
-
38
27
  def __init__(
39
28
  self,
40
29
  name: str,
41
30
  value: bool = None,
42
31
  ) -> None:
43
- """Initializes a new checkbox widget.
32
+ """
33
+ Initializes a checkbox widget.
44
34
 
45
35
  Args:
46
- name: Field name/key for the checkbox
47
- value: Initial checked state (default: None)
48
- """
36
+ name (str): The name of the checkbox.
37
+ value (bool): The initial value of the checkbox. Defaults to None.
49
38
 
39
+ Attributes:
40
+ size (int): The size of the checkbox. Defaults to None.
41
+ """
50
42
  super().__init__(name, value)
51
43
 
52
44
  self.size = None
53
- self._button_style = self.BUTTON_STYLE_MAPPING["check"]
54
45
 
55
46
  @property
56
47
  def schema_definition(self) -> dict:
57
- """Generates a JSON schema definition for the checkbox.
48
+ """
49
+ Returns the schema definition for the checkbox.
50
+
51
+ The schema definition is a dictionary that describes the
52
+ data type and other constraints for the checkbox value.
58
53
 
59
54
  Returns:
60
- dict: Schema properties including:
61
- - type: boolean
62
- - description (if available from base class)
55
+ dict: A dictionary representing the schema definition.
63
56
  """
64
-
65
57
  return {"type": "boolean", **super().schema_definition}
66
58
 
67
59
  @property
68
60
  def sample_value(self) -> Union[bool, int]:
69
- """Generates a sample value for the checkbox.
70
-
71
- Returns:
72
- Union[bool, int]: Always returns True as the sample checked state
73
61
  """
62
+ Returns a sample value for the checkbox.
74
63
 
75
- return True
76
-
77
- @property
78
- def button_style(self) -> Union[str, None]:
79
- """Gets the current button style identifier.
64
+ The sample value is used to generate example data for the
65
+ checkbox field.
80
66
 
81
67
  Returns:
82
- Union[str, None]: The button style code used in PDF form fields
83
- """
84
-
85
- return self._button_style
86
-
87
- @button_style.setter
88
- def button_style(self, value) -> None:
89
- """Sets the button style for the checkbox.
90
-
91
- Accepts either style names ('check', 'cross', 'circle') or
92
- direct PDF button style codes ('4', '5', 'l').
93
-
94
- Args:
95
- value: Button style name or code to set
68
+ Union[bool, int]: A sample value for the checkbox.
96
69
  """
97
-
98
- if value in self.BUTTON_STYLE_MAPPING:
99
- self._button_style = self.BUTTON_STYLE_MAPPING[value]
100
- elif value in self.BUTTON_STYLE_MAPPING.values():
101
- self._button_style = value
70
+ return True
@@ -1,58 +1,68 @@
1
1
  # -*- coding: utf-8 -*-
2
- """Provides middleware for PDF dropdown/combobox widgets.
2
+ """
3
+ Module representing a dropdown widget.
3
4
 
4
- This module contains the Dropdown class which handles:
5
- - Dropdown option management
6
- - Selection index tracking
7
- - Value validation
8
- - Schema generation for form validation
5
+ This module defines the Dropdown class, which is a subclass of the
6
+ Widget class. It represents a dropdown form field in a PDF document.
9
7
  """
10
8
 
11
9
  from .base import Widget
12
10
 
13
11
 
14
12
  class Dropdown(Widget):
15
- """Middleware for PDF dropdown/combobox widgets.
13
+ """
14
+ Represents a dropdown widget in a PDF form.
15
+
16
+ Inherits from the Widget class and provides specific functionality
17
+ for handling dropdown form fields.
16
18
 
17
- Handles all aspects of dropdown processing including:
18
- - Option list management
19
- - Selection index validation
20
- - Value conversion
21
- - PDF form field integration
19
+ Key attributes:
20
+ font (str): The font of the dropdown field.
21
+ choices (List[str]): The list of available options in the dropdown.
22
+ value (int): The index of the selected choice in the choices list.
22
23
 
23
- Inherits from Widget base class and extends it with dropdown-specific features.
24
+ Methods:
25
+ schema_definition: Returns a schema definition for the dropdown's value.
26
+ sample_value: Returns a sample value for the dropdown.
24
27
  """
25
28
 
29
+ SET_ATTR_TRIGGER_HOOK_MAP = {
30
+ "font": "update_text_field_font",
31
+ "choices": "update_dropdown_choices",
32
+ }
33
+
26
34
  def __init__(
27
35
  self,
28
36
  name: str,
29
37
  value: int = None,
30
38
  ) -> None:
31
- """Initializes a new dropdown widget.
39
+ """
40
+ Initializes a dropdown widget.
32
41
 
33
42
  Args:
34
- name: Field name/key for the dropdown
35
- value: Initial selected option index (default: None)
36
- """
43
+ name (str): The name of the dropdown.
44
+ value (int): The initial value of the dropdown. Defaults to None.
37
45
 
46
+ Attributes:
47
+ font (str): The font of the dropdown field.
48
+ choices (List[str]): The list of choices for the dropdown.
49
+ """
38
50
  super().__init__(name, value)
39
51
 
40
- self.choices = []
41
- self.desc = None
52
+ self.font = None
53
+ self.choices = None
42
54
 
43
55
  @property
44
56
  def schema_definition(self) -> dict:
45
- """Generates a JSON schema definition for the dropdown.
57
+ """
58
+ Returns the schema definition for the dropdown.
46
59
 
47
- Includes:
48
- - Type constraint (integer)
49
- - Maximum valid option index
50
- - Any inherited schema properties
60
+ The schema definition is a dictionary that describes the
61
+ data type and other constraints for the dropdown value.
51
62
 
52
63
  Returns:
53
- dict: Complete JSON schema definition
64
+ dict: A dictionary representing the schema definition.
54
65
  """
55
-
56
66
  return {
57
67
  "type": "integer",
58
68
  "maximum": len(self.choices) - 1,
@@ -61,12 +71,13 @@ class Dropdown(Widget):
61
71
 
62
72
  @property
63
73
  def sample_value(self) -> int:
64
- """Generates a sample value for the dropdown.
74
+ """
75
+ Returns a sample value for the dropdown.
65
76
 
66
- Returns the index of the last option by default.
77
+ The sample value is used to generate example data for the
78
+ dropdown field.
67
79
 
68
80
  Returns:
69
- int: Index of the last option in the dropdown
81
+ int: A sample value for the dropdown.
70
82
  """
71
-
72
83
  return len(self.choices) - 1
@@ -1,34 +1,22 @@
1
1
  # -*- coding: utf-8 -*-
2
- """Provides middleware for PDF image field widgets.
3
-
4
- This module contains the Image class which handles:
5
- - Image field processing for common formats (JPEG, PNG)
6
- - Aspect ratio preservation when scaling
7
- - PDF form field integration
8
- - Image rotation and positioning
9
-
10
- Supports image data from:
11
- - Raw bytes
12
- - File paths
13
- - File-like objects
2
+ """
3
+ Module representing an image widget.
14
4
 
15
- Note: Inherits core functionality from Signature middleware since
16
- PDF image fields are technically signature fields with images.
5
+ This module defines the Image class, which is a subclass of the
6
+ Signature class. It represents an image form field in a PDF document,
7
+ allowing users to add images to the form.
17
8
  """
18
9
 
19
10
  from .signature import Signature
20
11
 
21
12
 
22
13
  class Image(Signature):
23
- """Middleware for PDF image field widgets.
24
-
25
- Handles all aspects of image field processing including:
26
- - Image data handling
27
- - Aspect ratio control
28
- - PDF form field integration
14
+ """
15
+ Represents an image widget.
29
16
 
30
- Inherits from Signature class and extends it with image-specific features.
17
+ The Image class provides a concrete implementation for
18
+ image form fields. It inherits from the Signature class and
19
+ sets the preserve_aspect_ratio attribute to False by default.
31
20
  """
32
21
 
33
22
  preserve_aspect_ratio = False
34
- """Whether to preserve the original image's aspect ratio when scaling."""
@@ -1,26 +1,22 @@
1
1
  # -*- coding: utf-8 -*-
2
- """Provides middleware for PDF radio button widgets.
2
+ """
3
+ Module representing a radio button widget.
3
4
 
4
- This module contains the Radio class which handles:
5
- - Radio button group state management
6
- - Option selection tracking
7
- - Value validation and conversion
8
- - Schema generation for form validation
5
+ This module defines the Radio class, which is a subclass of the
6
+ Checkbox class. It represents a radio button form field in a PDF
7
+ document, allowing users to select one option from a group of choices.
9
8
  """
10
9
 
11
10
  from .checkbox import Checkbox
12
11
 
13
12
 
14
13
  class Radio(Checkbox):
15
- """Middleware for PDF radio button widgets.
16
-
17
- Handles all aspects of radio button processing including:
18
- - Group selection management
19
- - Option counting and validation
20
- - Button style customization
21
- - PDF form field integration
14
+ """
15
+ Represents a radio button widget.
22
16
 
23
- Inherits from Checkbox class and extends it with radio-specific features.
17
+ The Radio class provides a concrete implementation for radio button
18
+ form fields. It inherits from the Checkbox class and implements
19
+ the schema_definition and sample_value properties.
24
20
  """
25
21
 
26
22
  def __init__(
@@ -28,32 +24,33 @@ class Radio(Checkbox):
28
24
  name: str,
29
25
  value: int = None,
30
26
  ) -> None:
31
- """Initializes a new radio button widget.
27
+ """
28
+ Initializes a radio button widget.
32
29
 
33
30
  Args:
34
- name: Field name/key for the radio button group
35
- value: Initial selected option index (default: None)
36
- """
31
+ name (str): The name of the radio button.
32
+ value (int): The initial value of the radio button. Defaults to None.
37
33
 
34
+ Attributes:
35
+ number_of_options (int): The number of options for the radio button.
36
+ """
38
37
  super().__init__(name, value)
39
38
 
40
- self.size = None
41
39
  self.number_of_options = 0
42
- self._button_style = self.BUTTON_STYLE_MAPPING["circle"]
43
40
 
44
41
  @property
45
42
  def schema_definition(self) -> dict:
46
- """Generates a JSON schema definition for the radio button group.
43
+ """
44
+ Returns the schema definition for the radio button.
47
45
 
48
- Includes:
49
- - Type constraint (integer)
50
- - Maximum valid option index
51
- - Any inherited schema properties
46
+ The schema definition is a dictionary that describes the
47
+ data type and other constraints for the radio button value,
48
+ which is expected to be an integer representing the index
49
+ of the selected option.
52
50
 
53
51
  Returns:
54
- dict: Complete JSON schema definition
52
+ dict: A dictionary representing the schema definition.
55
53
  """
56
-
57
54
  return {
58
55
  "maximum": self.number_of_options - 1,
59
56
  **super().schema_definition,
@@ -62,12 +59,14 @@ class Radio(Checkbox):
62
59
 
63
60
  @property
64
61
  def sample_value(self) -> int:
65
- """Generates a sample value for the radio button group.
62
+ """
63
+ Returns a sample value for the radio button.
66
64
 
67
- Returns the index of the last option by default.
65
+ The sample value is used to generate example data for the
66
+ radio button field. It returns the index of the last option
67
+ in the group.
68
68
 
69
69
  Returns:
70
- int: Index of the last option in the group
70
+ int: A sample value for the radio button.
71
71
  """
72
-
73
72
  return self.number_of_options - 1
@@ -1,86 +1,71 @@
1
1
  # -*- coding: utf-8 -*-
2
- """Provides middleware for PDF signature field widgets.
2
+ """
3
+ Module representing a signature widget.
3
4
 
4
- This module contains the Signature class which handles:
5
- - Signature image processing
6
- - Aspect ratio preservation
7
- - File path resolution
8
- - PDF form field integration
5
+ This module defines the Signature class, which is a subclass of the
6
+ Widget class. It represents a signature form field in a PDF document,
7
+ allowing users to add their signature as an image.
9
8
  """
10
9
 
11
10
  from os.path import expanduser
12
- from typing import BinaryIO, Union
11
+ from typing import Union
13
12
 
14
13
  from ..adapter import fp_or_f_obj_or_stream_to_stream
15
14
  from .base import Widget
16
15
 
17
16
 
18
17
  class Signature(Widget):
19
- """Middleware for PDF signature field widgets.
20
-
21
- Handles all aspects of signature field processing including:
22
- - Signature image handling
23
- - Aspect ratio control
24
- - File path resolution
25
- - PDF form field integration
18
+ """
19
+ Represents a signature widget.
26
20
 
27
- Inherits from Widget base class and extends it with signature-specific features.
21
+ The Signature class provides a concrete implementation for
22
+ signature form fields. It inherits from the Widget class and
23
+ implements the schema_definition, sample_value, and stream
24
+ properties.
28
25
  """
29
26
 
30
27
  preserve_aspect_ratio = True
31
- """Whether to preserve the original image's aspect ratio when scaling."""
32
-
33
- def __init__(
34
- self,
35
- name: str,
36
- value: Union[bytes, str, BinaryIO] = None,
37
- ) -> None:
38
- """Initializes a new signature field widget.
39
-
40
- Args:
41
- name: Field name/key for the signature
42
- value: Signature image as bytes, file path, or file object (default: None)
43
- """
44
-
45
- super().__init__(name, value)
46
28
 
47
29
  @property
48
30
  def schema_definition(self) -> dict:
49
- """Generates a JSON schema definition for the signature field.
31
+ """
32
+ Returns the schema definition for the signature.
33
+
34
+ The schema definition is a dictionary that describes the
35
+ data type and other constraints for the signature value,
36
+ which is expected to be a string representing the path to
37
+ the signature image.
50
38
 
51
39
  Returns:
52
- dict: Schema properties including:
53
- - type: string (file path)
54
- - description (if available from base class)
40
+ dict: A dictionary representing the schema definition.
55
41
  """
56
-
57
- return {"type": "string"}
42
+ return {"type": "string", **super().schema_definition}
58
43
 
59
44
  @property
60
45
  def sample_value(self) -> str:
61
- """Generates a sample value for the signature field.
46
+ """
47
+ Returns a sample value for the signature.
62
48
 
63
- Returns a default sample image path from the user's Downloads folder.
49
+ The sample value is used to generate example data for the
50
+ signature field. It returns the path to a sample image file.
64
51
 
65
52
  Returns:
66
- str: Path to sample image file
53
+ str: A sample value for the signature.
67
54
  """
68
-
69
55
  return expanduser("~/Downloads/sample_image.jpg")
70
56
 
71
57
  @property
72
58
  def stream(self) -> Union[bytes, None]:
73
- """Converts the signature image to a byte stream.
59
+ """
60
+ Returns the stream of the signature image.
74
61
 
75
- Handles conversion of:
76
- - Raw image bytes
77
- - File paths
78
- - File-like objects
62
+ This method reads the signature image from the file path
63
+ specified in the value attribute and returns the image data
64
+ as a stream of bytes.
79
65
 
80
66
  Returns:
81
- Union[bytes, None]: Image data as bytes, or None if no value set
67
+ Union[bytes, None]: The stream of the signature image.
82
68
  """
83
-
84
69
  return (
85
70
  fp_or_f_obj_or_stream_to_stream(self.value)
86
71
  if self.value is not None