DEP: Replace PdfWriter method add_js - #3979
Conversation
Replace add_js with add_action. The more generic name gives extensibility if more action types are implemented.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3979 +/- ##
==========================================
+ Coverage 98.11% 98.13% +0.01%
==========================================
Files 59 59
Lines 11489 11513 +24
Branches 2150 2149 -1
==========================================
+ Hits 11273 11298 +25
Misses 122 122
+ Partials 94 93 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
This method would be better called The value of OpenAction (2.0 specification):
Thus this would be better, with the method having different paths on which type it is given (using @stefan6419846 as well as your code review, welcome guidance on the above changes. |
stefan6419846
left a comment
There was a problem hiding this comment.
This method would be better called
open_action.add_actionis used for the AA key entry in a page object. There is also an AA key entry in the catalog dictionary.
I am sorry, but I have some trouble following what you try to say here.
Thus this would be better, with the method having different paths on which type it is given (using
isinstance):
open_action(self, action: Action | Destination)
open_action sounds like a property and not like a method to change/add something here. A Destination is no action, thus the name would be confusing.
Put implementation in Action class.
Fix code style issues
How about |
So we would need |
The will close action is not part of the open action; it is part of the additional-actions dictionary. From the 2.0 specification: The |
|
My confusion is still growing here: We have If this is not the case, I guess we should go back to the design phase and properly document what the writer/whole document itself supports and how a corresponding API can look like, including where we could re-use existing code and where we need new one. |
No, this is associated with the OpenAction key of the Catalog dictionary. The analog of what has already been implemented in the PageObject is the AA key of the Catalog dictionary.
We can use API we have from what is already implemented; |
|
@stefan6419846 further discussion about this below.
These "other circumstances" are by an additional-actions dictionary in these object types:
The page object additional-actions dictionary we added: Annotations and the document catalog can have actions attached in two ways, for the document catalog these are the OpenAction and AA keys. This means that for the document catalog we need two methods to attach to |
|
After some more back-and-forth and research, I now start to further understand the topic. A document itself can apparently have "regular" actions and one open action, which either is a action like we know from pages or a destination to jump to. The current PR focuses on the open action itself. As I can only do one thing, the current implementation with always appending seems wrong, although Are my remarks correct or did I misrepresent/miss something? |
Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
|
Yes this is my understanding also. I think the way you steered the design of the Action class was excellent. Keeping the Having
Agree. I copied the I will make |
|
OpenAction Value
PDF 2.0 specification. @stefan6419846, action is used in a broader sense like in the specification, meaning the action is either do an actual action or to jump to a specific destination: I think we should do this because users wanting to add an action will easily find this, and those knowing the specification and wanting to add a destination using OpenAction can do so also. It works for either use case. |
Code review changes.
Fix errors.
Change comment.
Move tests to test_actions.py and delete test_javascript.py.
Fix error.
Replace add_js with add_action. The more generic name gives
extensibility if more action types are implemented.
Closes #3776.