support for accessing Action fields

Bug #351316 reported by Martin Luessi
14
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Poppler Python Bindings
Fix Released
Undecided
Daniel
python-poppler (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Currently python poppler does not support accessing the fields of the various poppler action structs. Poppler uses action structs for various things such as links to external files, links within the PDF, launching external applications, etc.

The attached patch adds several member functions to the Action class to allow accessing the struct fields. Note that poppler uses a different struct for each action type, while the python poppler bindings only use one Action class. If a member function to obtain a field that does not exist in the corresponding struct is called, a None object is returned.

The additional member functions are the following:

Action.get_action_type() : returns the action type, which is an object of type ActionType

Action.get_title(): returns the title of the action (string or None)

Action.get_uri(): returns the URI (string or None)

Action.get_dest(): returns the destination (object of type Dest or None)

Action.named_dest(): returns the named destinatin (string or None)

Action.get_file_name(): returns the file name (string or None)

Action.get_params(): returns the parameters (string or None)

Best,

Martin

Revision history for this message
Martin Luessi (mluessi) wrote :
Revision history for this message
Gian Mario Tagliaretti (gianmt) wrote :

Hi Martin, sorry for the huge delay.

Being the Action an union makes things a lot more complicated of course, what about we create different objects (inheriting from gpointer) and we return the right one instead?

Does it make any sense to you or it will just complicate things more than necessary? Beware that I didn't look carefully at poppler code so it can be a nonsense what I just wrote.

Revision history for this message
Martin Luessi (mluessi) wrote : Re: [Bug 351316] Re: support for accessing Action fields

Hi Gian,

I agree that having different objects would be nicer. However, I'm not
sure on how to that with inheriting from gpointer, as I don't have a
lot of experience with creating python wrappers for GTK based
libraries. Can you give me any tips regarding this?

Thanks,

Martin

On Fri, Apr 10, 2009 at 4:21 PM, Gian Mario Tagliaretti
<email address hidden> wrote:
> Hi Martin, sorry for the huge delay.
>
> Being the Action an union makes things a lot more complicated of course,
> what about we create different objects (inheriting from gpointer) and we
> return the right one instead?
>
> Does it make any sense to you or it will just complicate things more
> than necessary? Beware that I didn't look carefully at poppler code so
> it can be a nonsense what I just wrote.
>
> --
> support for accessing Action fields
> https://bugs.launchpad.net/bugs/351316
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in Poppler Python Bindings: New
>
> Bug description:
> Currently python poppler does not support accessing the fields of the various poppler action structs. Poppler uses action structs for various things such as links to external files, links within the PDF, launching external applications, etc.
>
> The attached patch adds several member functions to the Action class to allow accessing the struct fields. Note that poppler uses a different struct for each action type, while the python poppler bindings only use one Action class. If a member function to obtain a field that does not exist in the corresponding struct is called, a None object is returned.
>
> The additional member functions are the following:
>
> Action.get_action_type() : returns the action type, which is an object of type ActionType
>
> Action.get_title(): returns the title of the action (string or None)
>
> Action.get_uri(): returns the URI (string or None)
>
> Action.get_dest(): returns the destination (object of type Dest or None)
>
> Action.named_dest(): returns the named destinatin (string or None)
>
> Action.get_file_name(): returns the file name (string or None)
>
> Action.get_params(): returns the parameters (string or None)
>
> Best,
>
> Martin
>

Revision history for this message
Gian Mario Tagliaretti (gianmt) wrote :

Hi Martin sorry for the delay again.

basically is something like the following commit if it's a boxed type:
http://git.gnome.org/cgit/pygobject/commit/?id=90cd8b7c4a25cd2ecb751f8337b401c98538272b

or like the following for a gpointer
http://git.gnome.org/cgit/pygobject/tree/gio/unix.override

Revision history for this message
Martin Luessi (mluessi) wrote :

On Wed, May 27, 2009 at 5:26 PM, Gian Mario Tagliaretti
<email address hidden> wrote:
> Hi Martin sorry for the delay again.
>
> basically is something like the following commit if it's a boxed type:
> http://git.gnome.org/cgit/pygobject/commit/?id=90cd8b7c4a25cd2ecb751f8337b401c98538272b
>
> or like the following for a gpointer
> http://git.gnome.org/cgit/pygobject/tree/gio/unix.override
>
> --

Gian,

Thanks for your reply. I'm still not sure how this could be done using
different objects. I understand how one can wrap a GObject in a boxed
type, as it is currently done for the "Action" object and many others
in pypoppler. However, poppler itself only defines a single
PopplerAction type. Do you recommend that I define new types for all
actions in poppler, e.g. ActionURI for URI actions? If so, should I
add a member function "getAction" to the LinkMapping object? The
LinkMapping object has a pointer to the PopplerAction object
(LinkMapping.action), the new member function would create an Action
object of the appropriate type and return it.

best,

Martin

Revision history for this message
Daniel (daniel-jacobs) wrote :

Hello Martin!

>Do you recommend that I define new types for all
>actions in poppler, e.g. ActionURI for URI actions?

I understood Gian the same way.

Yesterday, I started to work on this.
Here is my progress:
-Create a class for each ActionType with access to all corresponding fields (except type): Done
-Add a method called "to_typed_action" to PopplerAction,
    which returns the Action as ActionGotoDest, ActionUri whatever, depending on PopplerAction.type: Done
This function can be used from within Python.

To have easier access to the typed actions, I will override the getter of LinkMapping action attribute of as you suggested, so that it returns the typed action directly and do the same for IndexIter.get_action.
This will be finished this weekend, I hope.

I'm looking forward to see this lack of function closed, soon.

Bye Daniel

Revision history for this message
Daniel (daniel-jacobs) wrote :

Hello!

This is the patch, I've written.
If you find some bugs or know a better way to implement this, please let me know.
If the code is OK, I hope to see it soon in pypoppler.

Thanks in advance.

Revision history for this message
Daniel (daniel-jacobs) wrote :
Revision history for this message
Martin Luessi (mluessi) wrote :

Daniel,

Thanks a lot for your work! It looks good to me, I think this is what Gian had in mind. I tested your code today and it works as expected. I recommend that Daniels changes are merged asap.

thanks,

Martin

Changed in poppler-python:
status: New → In Progress
Revision history for this message
Gian Mario Tagliaretti (gianmt) wrote :

I've committed Daniel's patch, can you guys test the trunk and give feedback? thanks in advance

Changed in poppler-python:
assignee: nobody → Daniel (daniel-jacobs)
status: In Progress → Fix Committed
Revision history for this message
Daniel (daniel-jacobs) wrote :

Hi Gian,

http://launchpadlibrarian.net/28707365/poppler.defs.diff

is missing in trunk.
Can you please merge it.

Thanks.

Revision history for this message
Gian Mario Tagliaretti (gianmt) wrote :

oops... sorry Daniel I've committed the changes on poppler.defs as well.

Revision history for this message
Thomas Jost (schnouki) wrote :

Hi everybody,

Rev. 62 works perfectly fine for me (I already use it for pympress -- www.pympress.org). Thanks a lot, it is very useful!

Revision history for this message
Daniel (daniel-jacobs) wrote :

Hi Gian,

I could only check it with
 - ActionGotoDest
 - ActionUri
since I don't have any PDF-files using other action types.

For those actions it's working well and I couldn't imagine why it should not run with other action types.

Have a nice day and thanks for merging it so quick.

Daniel

Revision history for this message
Gian Mario Tagliaretti (gianmt) wrote :

Daniel thanks a lot for the patch and thanks everybody for testing, I'll make a release today or tomorrow.

Changed in poppler-python:
status: Fix Committed → Fix Released
Revision history for this message
Daniel (daniel-jacobs) wrote :

It would be nice to have the updated package in Ubuntu.

Thanks

Revision history for this message
Daniel (daniel-jacobs) wrote :

The latest version (0.12.1) is in debian!
Thus it will be in Lucid Lynx automatically!

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

Thank you for taking the time to report this bug and helping to make Ubuntu better. However, I am closing it because the bug has been fixed in the latest development version of Ubuntu - Lucid Lynx.

If you need a fix for the bug in previous versions of Ubuntu, please follow the instructions for "How to request new packages" at https://help.ubuntu.com/community/UbuntuBackports#request-new-packages

fixed in latest upload 0.12.1-1

Changed in python-poppler (Ubuntu):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.