Merge lp:~tomasgroth/openlp/mupdf into lp:openlp

Proposed by Tomas Groth
Status: Superseded
Proposed branch: lp:~tomasgroth/openlp/mupdf
Merge into: lp:openlp
Diff against target: 897 lines (+644/-41)
9 files modified
openlp/core/ui/slidecontroller.py (+2/-2)
openlp/plugins/presentations/lib/mediaitem.py (+83/-35)
openlp/plugins/presentations/lib/messagelistener.py (+31/-1)
openlp/plugins/presentations/lib/pdfcontroller.py (+306/-0)
openlp/plugins/presentations/lib/presentationtab.py (+98/-1)
openlp/plugins/presentations/presentationplugin.py (+3/-0)
resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py (+2/-1)
tests/functional/openlp_plugins/presentations/test_mediaitem.py (+10/-1)
tests/functional/openlp_plugins/presentations/test_pdfcontroller.py (+109/-0)
To merge this branch: bzr merge lp:~tomasgroth/openlp/mupdf
Reviewer Review Type Date Requested Status
Tim Bentley Needs Fixing
Raoul Snyman Pending
Review via email: mp+200161@code.launchpad.net

This proposal supersedes a proposal from 2013-11-14.

This proposal has been superseded by a proposal from 2013-12-31.

Description of the change

Support for presenting PDF using mupdf or ghostscript.

To post a comment you must log in.
Revision history for this message
Dmitriy Marmyshev (marmyshev) wrote : Posted in a previous version of this proposal

Looks good!
Really expecting function for us! Keep develop it!

1Q: Does it works on OS X?
2Q: I didnt get the point with PdfViewer class. Dont you use slide's system in OpenLP? Do I correctly understand that you just convert PDF to images and then show them like images? May be it will be easier to use image plugin for showing images after conversion.

And 1 more suggestion: may be it is better to use this:

os.path.isfile(os.path.join(self.get_temp_folder(), u'mainslide001.png'))

instead of this:

os.path.isfile(self.get_temp_folder() + u'/mainslide001.png')

Revision history for this message
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal

>And 1 more suggestion: may be it is better to use this:
>
>os.path.isfile(os.path.join(self.get_temp_folder(),
>u'mainslide001.png'))
>
>instead of this:
>
>os.path.isfile(self.get_temp_folder() + u'/mainslide001.png')

Good catch Dmitriy!

--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

Revision history for this message
Tomas Groth (tomasgroth) wrote : Posted in a previous version of this proposal

> 1Q: Does it works on OS X?
Yea, provided that either ghostscript or mupdf is available.

> 2Q: I didnt get the point with PdfViewer class. Dont you use slide's system in
> OpenLP? Do I correctly understand that you just convert PDF to images and then
> show them like images? May be it will be easier to use image plugin for
> showing images after conversion.
I've thought of the same thing, but I have to admit that I'm yet to find a way to bend the system to my need. I'd like the service-item to be a pdf-presentation, but presenting that using the same aproach as the image plugin isn't easy. But maybe I just don't understand the structure of OpenLP yet.

> And 1 more suggestion: may be it is better to use this:
> os.path.isfile(os.path.join(self.get_temp_folder(), u'mainslide001.png'))
> instead of this:
> os.path.isfile(self.get_temp_folder() + u'/mainslide001.png')
I'll change this in the next push.

Revision history for this message
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal

Hum
The conversion to images is done on importing the PDF so all the images are
in the file system.
You could then add the images as image items to the service instead of
presentation file.

That would be a clean cross over Services would work as images but added as
a PDF.

On 21 July 2013 15:16, Tomas Groth <email address hidden> wrote:

> > 1Q: Does it works on OS X?
> Yea, provided that either ghostscript or mupdf is available.
>
> > 2Q: I didnt get the point with PdfViewer class. Dont you use slide's
> system in
> > OpenLP? Do I correctly understand that you just convert PDF to images
> and then
> > show them like images? May be it will be easier to use image plugin for
> > showing images after conversion.
> I've thought of the same thing, but I have to admit that I'm yet to find a
> way to bend the system to my need. I'd like the service-item to be a
> pdf-presentation, but presenting that using the same aproach as the image
> plugin isn't easy. But maybe I just don't understand the structure of
> OpenLP yet.
>
> > And 1 more suggestion: may be it is better to use this:
> > os.path.isfile(os.path.join(self.get_temp_folder(), u'mainslide001.png'))
> > instead of this:
> > os.path.isfile(self.get_temp_folder() + u'/mainslide001.png')
> I'll change this in the next push.
> --
> https://code.launchpad.net/~tomasgroth/openlp/mupdf/+merge/174849
> Your team OpenLP Core is requested to review the proposed merge of
> lp:~tomasgroth/openlp/mupdf into lp:openlp.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~openlp-core
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~openlp-core
> More help : https://help.launchpad.net/ListHelp
>

--
Tim and Alison Bentley
<email address hidden>

Revision history for this message
Andreas Preikschat (googol-deactivatedaccount) wrote : Posted in a previous version of this proposal

And please add docstrings to *all* methods/functions

Revision history for this message
Dmitriy Marmyshev (marmyshev) wrote : Posted in a previous version of this proposal

> Hum
> The conversion to images is done on importing the PDF so all the images are
> in the file system.
> You could then add the images as image items to the service instead of
> presentation file.
>
> That would be a clean cross over Services would work as images but added as
> a PDF.
>

Let me not to agree with this. We should not to make life of OpenLP operator (user) harder by changing visually a "PDF file" to a "group of imageses". If I (as user) add PDF presentation to OpenLP - i'd like to see PDF in the list.
Upper, I mean that create new class (PdfViewer) just to show images may be is not the easiest way, may be it is better simply to use classes from ImagePlugin to show images from PDF controller.

Revision history for this message
Jonathan Corwin (j-corwin) wrote : Posted in a previous version of this proposal

(Note comment only, I've not looked at the code)

I too think it is nice to keep it in the Presentation plugin. The user is dealing with a PDF file as far as they are concerned and transporting the PDF in the service file rather than lots of images is in my view the correct way of doing this. Importing a PDF in Presentations and having to look for it in the image plugin would confuse many. Also by moving the PDF around it protects us from adding it on one computer with a 640x480 resolution moving to a 1900x1080 system and ending up having to deal with images in an resolution that don't scale nicely.

In the future some other app (e.g. Impress) might support the opening of PDF files and in this case the user would then be able to choose between mupdf or something else. If we're only storing the images then that wouldn't be so easy.

Yes it would be nice if we could just hook into the already existing image handling functionality of OpenLP for the display, but I wouldn't want us to tear the code base to pieces to get this to work. (I don't know the difficulties of this). I don't see any harm in making it a two phase task anyway and to do this later if we find a nice way to do it.

Finally an idea has just come to mind that in the future we could also support an "Export to Images" function on the presentation whereby we could copy the thumbnail images (created at output resolution) to the an Image Plugin group, to at least cater for those situations where the user knows the presentation application isn't installed at the destination system. However this would be outside the scope of this particular branch and would be a whole new feature.

Revision history for this message
Dave Warnock (dave-warnock) wrote : Posted in a previous version of this proposal

Just wanted to add my support to what Jonathon suggests.

On 22 July 2013 10:18, Jonathan Corwin <email address hidden> wrote:

> (Note comment only, I've not looked at the code)
>
> I too think it is nice to keep it in the Presentation plugin. The user is
> dealing with a PDF file as far as they are concerned and transporting the
> PDF in the service file rather than lots of images is in my view the
> correct way of doing this. Importing a PDF in Presentations and having to
> look for it in the image plugin would confuse many. Also by moving the PDF
> around it protects us from adding it on one computer with a 640x480
> resolution moving to a 1900x1080 system and ending up having to deal with
> images in an resolution that don't scale nicely.
>
> In the future some other app (e.g. Impress) might support the opening of
> PDF files and in this case the user would then be able to choose between
> mupdf or something else. If we're only storing the images then that
> wouldn't be so easy.
>
> Yes it would be nice if we could just hook into the already existing image
> handling functionality of OpenLP for the display, but I wouldn't want us to
> tear the code base to pieces to get this to work. (I don't know the
> difficulties of this). I don't see any harm in making it a two phase task
> anyway and to do this later if we find a nice way to do it.
>
> Finally an idea has just come to mind that in the future we could also
> support an "Export to Images" function on the presentation whereby we could
> copy the thumbnail images (created at output resolution) to the an Image
> Plugin group, to at least cater for those situations where the user knows
> the presentation application isn't installed at the destination system.
> However this would be outside the scope of this particular branch and would
> be a whole new feature.
> --
> https://code.launchpad.net/~tomasgroth/openlp/mupdf/+merge/174849
> You are subscribed to branch lp:openlp.
>

--
Dave Warnock: http://42.blogs.warnock.me.uk
Cycling Blog: http://42bikes.warnock.me.uk

Revision history for this message
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal
Download full text (3.5 KiB)

Ok so I worded it in a clumsy manner.

PDF gets added to the presentation plugin no problems. It generates images
of the pages like the presentation plugins do.

The difference suggested and echoed by Jonathan is we use the image
processing part of the serviceitem to do the displays instead of writing
and managing an 8th player within the architecture.

It will look like a PDF, quack like a PDF display like a set of images.

The changes suggested will be constrained to the Presentations plugin so
easier to implement and test with less disruption.

Adding a new player is not a small job and with the issues we have had in
the past (4 months to sort out media after 5 months getting it in) and the
migrations going on it will be a challenge.

BTW are the PDF libraries fully python3 compliant and have versions
available for all the distros we support. That would also be a merge
requirement.

Tim

On 22 July 2013 11:35, Dave Warnock <email address hidden> wrote:

> Just wanted to add my support to what Jonathon suggests.
>
> On 22 July 2013 10:18, Jonathan Corwin <email address hidden> wrote:
>
> > (Note comment only, I've not looked at the code)
> >
> > I too think it is nice to keep it in the Presentation plugin. The user is
> > dealing with a PDF file as far as they are concerned and transporting the
> > PDF in the service file rather than lots of images is in my view the
> > correct way of doing this. Importing a PDF in Presentations and having to
> > look for it in the image plugin would confuse many. Also by moving the
> PDF
> > around it protects us from adding it on one computer with a 640x480
> > resolution moving to a 1900x1080 system and ending up having to deal with
> > images in an resolution that don't scale nicely.
> >
> > In the future some other app (e.g. Impress) might support the opening of
> > PDF files and in this case the user would then be able to choose between
> > mupdf or something else. If we're only storing the images then that
> > wouldn't be so easy.
> >
> > Yes it would be nice if we could just hook into the already existing
> image
> > handling functionality of OpenLP for the display, but I wouldn't want us
> to
> > tear the code base to pieces to get this to work. (I don't know the
> > difficulties of this). I don't see any harm in making it a two phase task
> > anyway and to do this later if we find a nice way to do it.
> >
> > Finally an idea has just come to mind that in the future we could also
> > support an "Export to Images" function on the presentation whereby we
> could
> > copy the thumbnail images (created at output resolution) to the an Image
> > Plugin group, to at least cater for those situations where the user knows
> > the presentation application isn't installed at the destination system.
> > However this would be outside the scope of this particular branch and
> would
> > be a whole new feature.
> > --
> > https://code.launchpad.net/~tomasgroth/openlp/mupdf/+merge/174849
> > You are subscribed to branch lp:openlp.
> >
>
>
>
> --
> Dave Warnock: http://42.blogs.warnock.me.uk
> Cycling Blog: http://42bikes.warnock.me.uk
>
> https://code.launchpad.net/~tomasgroth/openlp/mupdf/+merge/174849
> Your team OpenL...

Read more...

Revision history for this message
Tomas Groth (tomasgroth) wrote : Posted in a previous version of this proposal

Ok, here is some more thoughts...
The challenge as I see it is that the presentation plugin has been build around the fact the PowerPoint, PowerPoint Viewer and Impress all have their own "players", which means that since this pdf-presentation extensions is inside the presentation plugin, it is expected to provide a player, which is what I implemented in this first revision by adding the simple PdfViewer class. As some of you noted it might not be a great idea to add another "player", but the problem then is how to bend OpenLP into presenting images, even though it is a presentation...
I've looked around a bit and for now my best idea is to remove my PdfViewer class, and instead use my own instance of the MainDisplay class, which can present images. This way I reuse a "player", and avoid having to hack various parts too much. I haven't tried it yet, but I think it could work.
About python3, that shouldn't be an issue since I call the ghostscript or mupdf programs directly, not via python libs.

Revision history for this message
Jonathan Corwin (j-corwin) wrote : Posted in a previous version of this proposal

Tim, I don't understand why adding a new player /here/ will be a big problem. Yes it was a problem for media because that was all integrated with songs, the toolbar, etc and there was a lot of overlap across plugins.

However the Presentations plugin is completely designed to deal with third party apps. All they need to be able to do is blank, and the plugin will deal with the rest. Having a simple Window that can go full screen is not going to have the problems that we had with media. In fact I personally think trying to tie this in to use the existing display would make the code more complicated and error prone that keeping it standalone.

Revision history for this message
Tomas Groth (tomasgroth) wrote : Posted in a previous version of this proposal

Hi guys,
I've now also made a version which uses the approach Tim mentioned. It works quite well, but I haven't pushed it yet.
So how do we figure out which version should be used?

Revision history for this message
Jonathan Corwin (j-corwin) wrote : Posted in a previous version of this proposal

Push it and get it reviewed :)

Revision history for this message
Tomas Groth (tomasgroth) wrote : Posted in a previous version of this proposal

Ok, so I've just pushed the player-less version, where the image-presentation functionality is used instead. There is still a few issues. For example it tries to load the first image added to the serviceitem as a pdf-presentation when going live/preview. Haven't figured out why.

Revision history for this message
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal

That is because you have set the ServiceItem.processor.
You have code in the pdf route which is not needed.

On 27 July 2013 10:52, Tomas Groth <email address hidden> wrote:

> Ok, so I've just pushed the player-less version, where the
> image-presentation functionality is used instead. There is still a few
> issues. For example it tries to load the first image added to the
> serviceitem as a pdf-presentation when going live/preview. Haven't figured
> out why.
> --
> https://code.launchpad.net/~tomasgroth/openlp/mupdf/+merge/174849
> Your team OpenLP Core is requested to review the proposed merge of
> lp:~tomasgroth/openlp/mupdf into lp:openlp.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~openlp-core
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~openlp-core
> More help : https://help.launchpad.net/ListHelp
>

--
Tim and Alison Bentley
<email address hidden>

Revision history for this message
Tomas Groth (tomasgroth) wrote : Posted in a previous version of this proposal

I've now added the possibility for pointing to ghostscript or mudraw if autodetection isn't working. Also minor fixes for the pdf-presentation code.

Revision history for this message
Tomas Groth (tomasgroth) wrote : Posted in a previous version of this proposal

Hi guys, I was wondering if you think something more should be added before this is ready to be merged into trunk? Does it make sense to make tests for presentation plugins?

Revision history for this message
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal

Looks good but these need to be fixed.

* settings screen the grouping has moved from the left side to the middle.
* settings screen "binary" has the "y" half chopped off.
* showing an image live / preview does not work when loaded from the service manager. Fine from the media manager. Have not tried to save / reload but guess that is broken.
* blank lines in functions please remove (general)
* questions in comments please removed.
* check_binary why is this outside the class as a standalone function?
* if os.name != u'nt': swap logic round so is positive and less chance of a miss read.
* 320 would this be better to have in the code a file instead of writing to a file each run?
* if self.pdf_program_path.text() != u'': should be if not self.pdf_program_path.text(): - General point.
* setting do not need "given" in the string.
* img should be image (old bad code copied!
* no tests.
* line 53 far too long.
* lines 52-64 do we need all this. if the images are generated then it would be a case of just loading them not processing them again?

review: Needs Fixing
Revision history for this message
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal

Please resubmit due to the age of this request and additionally it will need converting to Python 3 as on 1/9/2013 truck will be converted.

review: Needs Resubmitting
Revision history for this message
Tomas Groth (tomasgroth) wrote : Posted in a previous version of this proposal

I need some feedback/guidance/help to finish this implementation...
The basic idea is to use mupdf or ghostscript to create a picture for each page in the PDF, and when going to live/preview mode, then replace the service_item with an image-based service_item. I've made it work when going to live/preview from the mediamanager, but I can't figure out how/where to do it from the servicemanager - any hints would be appreciated! As an alternative it can be implemented as the other presentation-backends, with a "player".

I'd also like some directions as to what tests to include? I couldn't find any tests for the other presentation backends...

And finally, I've added some extra fields to the presentation-settings-tab, and for some reason now all fields has moved a bit to the right instead for being to the far left - any hints as to why?

Revision history for this message
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal

Hi Tomas, in it's current state your merge proposal has some conflicts. Can you merge from trunk and fix those please?

review: Needs Fixing
Revision history for this message
Tomas Groth (tomasgroth) wrote : Posted in a previous version of this proposal

Merged with trunk to resolve conflicts. Last set of questions still applies.

Revision history for this message
Tomas Groth (tomasgroth) wrote :

I think I've resolved most problems now and even added some simple tests.
The basic idea is to (still) use mupdf or ghostscript to create a picture for each page in the PDF, and when going to live/preview mode the service_item is replaced with an image-based service_item on the fly.

Revision history for this message
Tim Bentley (trb143) wrote :

Conflicts with head.

lines 8-13 why. This needs a good explanation as it looks like a botch.
lines 52-53 - fix for PEP8 - have a look at other places as well.
line 77 - why not service?

Linn 200+ Confused. If generated from plugin we have a image service item. Good. If started from Service Manager we need to convert. Why? How did it get to the service manager cos the plugin would have created an image service item not a presentation one. Also not sure about exposing the innards of the serviceitem in this could. could it be a new method on the service item?

tmpFile = tmp_file

484 - 498 Line lengths.
611, 668, 675 etc tabbing
650 space

review: Needs Fixing
lp:~tomasgroth/openlp/mupdf updated
2291. By Tomas Groth

Changed the way a serviceitem from the servicemanager is copied and converted. Also fixed for PEP8.

2292. By Tomas Groth

merged with trunk

2293. By Tomas Groth

Added some docstring documentation.

2294. By Tomas Groth

Moved PS script into separate file.

2295. By Tomas Groth

Make the PdfController reload backend if setting changes.

2296. By Tomas Groth

Only allow pdf-program selection using filedialog.

2297. By Tomas Groth

merged with trunk

2298. By Tomas Groth

fixed an exception

2299. By Tomas Groth

merged with head

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/core/ui/slidecontroller.py'
2--- openlp/core/ui/slidecontroller.py 2013-12-28 21:33:38 +0000
3+++ openlp/core/ui/slidecontroller.py 2013-12-31 12:36:15 +0000
4@@ -436,7 +436,7 @@
5 # "V1" was the slide we wanted to go.
6 self.preview_widget.change_slide(self.slide_list[self.current_shortcut])
7 self.slide_selected()
8- # Reset the shortcut.
9+ # Reset the shortcut.
10 self.current_shortcut = ''
11
12 def set_live_hot_keys(self, parent=None):
13@@ -730,7 +730,7 @@
14 if old_item and self.is_live and old_item.is_capable(ItemCapabilities.ProvidesOwnDisplay):
15 self._reset_blank()
16 Registry().execute(
17- '%s_start' % service_item.name.lower(), [service_item, self.is_live, self.hide_mode(), slide_no])
18+ '%s_start' % service_item.name.lower(), [self.service_item, self.is_live, self.hide_mode(), slide_no])
19 self.slide_list = {}
20 if self.is_live:
21 self.song_menu.menu().clear()
22
23=== modified file 'openlp/plugins/presentations/lib/mediaitem.py'
24--- openlp/plugins/presentations/lib/mediaitem.py 2013-12-28 21:33:38 +0000
25+++ openlp/plugins/presentations/lib/mediaitem.py 2013-12-31 12:36:15 +0000
26@@ -116,7 +116,7 @@
27 self.display_type_label = QtGui.QLabel(self.presentation_widget)
28 self.display_type_label.setObjectName('display_type_label')
29 self.display_type_combo_box = create_horizontal_adjusting_combo_box(self.presentation_widget,
30- 'display_type_combo_box')
31+ 'display_type_combo_box')
32 self.display_type_label.setBuddy(self.display_type_combo_box)
33 self.display_layout.addRow(self.display_type_label, self.display_type_combo_box)
34 # Add the Presentation widget to the page layout.
35@@ -177,9 +177,8 @@
36 if titles.count(filename) > 0:
37 if not initial_load:
38 critical_error_message_box(translate('PresentationPlugin.MediaItem', 'File Exists'),
39- translate('PresentationPlugin.MediaItem',
40- 'A presentation with that filename already exists.')
41- )
42+ translate('PresentationPlugin.MediaItem',
43+ 'A presentation with that filename already exists.'))
44 continue
45 controller_name = self.findControllerByType(filename)
46 if controller_name:
47@@ -203,7 +202,8 @@
48 icon = build_icon(':/general/general_delete.png')
49 else:
50 critical_error_message_box(UiStrings().UnsupportedFile,
51- translate('PresentationPlugin.MediaItem', 'This type of presentation is not supported.'))
52+ translate('PresentationPlugin.MediaItem',
53+ 'This type of presentation is not supported.'))
54 continue
55 item_name = QtGui.QListWidgetItem(filename)
56 item_name.setData(QtCore.Qt.UserRole, file)
57@@ -238,7 +238,7 @@
58 Settings().setValue(self.settings_section + '/presentations files', self.get_file_list())
59
60 def generate_slide_data(self, service_item, item=None, xml_version=False,
61- remote=False, context=ServiceItemContext.Service):
62+ remote=False, context=ServiceItemContext.Service, presentation_file=None):
63 """
64 Load the relevant information for displaying the presentation in the slidecontroller. In the case of
65 powerpoints, an image for each slide.
66@@ -249,45 +249,93 @@
67 items = self.list_view.selectedItems()
68 if len(items) > 1:
69 return False
70- service_item.processor = self.display_type_combo_box.currentText()
71- service_item.add_capability(ItemCapabilities.ProvidesOwnDisplay)
72+ filename = presentation_file
73+ if filename is None:
74+ filename = items[0].data(QtCore.Qt.UserRole)
75+ file_type = os.path.splitext(filename)[1][1:]
76 if not self.display_type_combo_box.currentText():
77 return False
78- for bitem in items:
79- filename = bitem.data(QtCore.Qt.UserRole)
80- (path, name) = os.path.split(filename)
81- service_item.title = name
82- if os.path.exists(filename):
83- if service_item.processor == self.automatic:
84- service_item.processor = self.findControllerByType(filename)
85- if not service_item.processor:
86+ if (file_type == 'pdf' or file_type == 'xps') and context != ServiceItemContext.Service:
87+ service_item.add_capability(ItemCapabilities.CanMaintain)
88+ service_item.add_capability(ItemCapabilities.CanPreview)
89+ service_item.add_capability(ItemCapabilities.CanLoop)
90+ service_item.add_capability(ItemCapabilities.CanAppend)
91+ # force a nonexistent theme
92+ service_item.theme = -1
93+ for bitem in items:
94+ filename = presentation_file
95+ if filename is None:
96+ filename = bitem.data(QtCore.Qt.UserRole)
97+ (path, name) = os.path.split(filename)
98+ service_item.title = name
99+ if os.path.exists(filename):
100+ processor = self.findControllerByType(filename)
101+ if not processor:
102 return False
103- controller = self.controllers[service_item.processor]
104- doc = controller.add_document(filename)
105- if doc.get_thumbnail_path(1, True) is None:
106- doc.load_presentation()
107- i = 1
108- img = doc.get_thumbnail_path(i, True)
109- if img:
110- while img:
111- service_item.add_from_command(path, name, img)
112+ controller = self.controllers[processor]
113+ service_item.processor = None
114+ doc = controller.add_document(filename)
115+ if doc.get_thumbnail_path(1, True) is None or not os.path.isfile(
116+ os.path.join(doc.get_temp_folder(), 'mainslide001.png')):
117+ doc.load_presentation()
118+ i = 1
119+ imagefile = 'mainslide%03d.png' % i
120+ image = os.path.join(doc.get_temp_folder(), imagefile)
121+ while os.path.isfile(image):
122+ service_item.add_from_image(image, name)
123 i += 1
124- img = doc.get_thumbnail_path(i, True)
125+ imagefile = 'mainslide%03d.png' % i
126+ image = os.path.join(doc.get_temp_folder(), imagefile)
127 doc.close_presentation()
128 return True
129 else:
130 # File is no longer present
131 if not remote:
132 critical_error_message_box(translate('PresentationPlugin.MediaItem', 'Missing Presentation'),
133- translate('PresentationPlugin.MediaItem',
134- 'The presentation %s is incomplete, please reload.') % filename)
135- return False
136- else:
137- # File is no longer present
138- if not remote:
139- critical_error_message_box(translate('PresentationPlugin.MediaItem', 'Missing Presentation'),
140- translate('PresentationPlugin.MediaItem', 'The presentation %s no longer exists.') % filename)
141- return False
142+ translate('PresentationPlugin.MediaItem',
143+ 'The presentation %s no longer exists.') % filename)
144+ return False
145+ else:
146+ service_item.processor = self.display_type_combo_box.currentText()
147+ service_item.add_capability(ItemCapabilities.ProvidesOwnDisplay)
148+ for bitem in items:
149+ filename = bitem.data(QtCore.Qt.UserRole)
150+ (path, name) = os.path.split(filename)
151+ service_item.title = name
152+ if os.path.exists(filename):
153+ if service_item.processor == self.automatic:
154+ service_item.processor = self.findControllerByType(filename)
155+ if not service_item.processor:
156+ return False
157+ controller = self.controllers[service_item.processor]
158+ doc = controller.add_document(filename)
159+ if doc.get_thumbnail_path(1, True) is None:
160+ doc.load_presentation()
161+ i = 1
162+ img = doc.get_thumbnail_path(i, True)
163+ if img:
164+ while img:
165+ service_item.add_from_command(path, name, img)
166+ i += 1
167+ img = doc.get_thumbnail_path(i, True)
168+ doc.close_presentation()
169+ return True
170+ else:
171+ # File is no longer present
172+ if not remote:
173+ critical_error_message_box(translate('PresentationPlugin.MediaItem',
174+ 'Missing Presentation'),
175+ translate('PresentationPlugin.MediaItem',
176+ 'The presentation %s is incomplete, please reload.')
177+ % filename)
178+ return False
179+ else:
180+ # File is no longer present
181+ if not remote:
182+ critical_error_message_box(translate('PresentationPlugin.MediaItem', 'Missing Presentation'),
183+ translate('PresentationPlugin.MediaItem',
184+ 'The presentation %s no longer exists.') % filename)
185+ return False
186
187 def findControllerByType(self, filename):
188 """
189
190=== modified file 'openlp/plugins/presentations/lib/messagelistener.py'
191--- openlp/plugins/presentations/lib/messagelistener.py 2013-12-28 21:33:38 +0000
192+++ openlp/plugins/presentations/lib/messagelistener.py 2013-12-31 12:36:15 +0000
193@@ -28,11 +28,13 @@
194 ###############################################################################
195
196 import logging
197+import copy
198
199 from PyQt4 import QtCore
200
201 from openlp.core.common import Registry
202 from openlp.core.ui import HideMode
203+from openlp.core.lib import ServiceItemContext, ServiceItem
204
205 log = logging.getLogger(__name__)
206
207@@ -69,6 +71,7 @@
208 return
209 self.doc.slidenumber = slide_no
210 self.hide_mode = hide_mode
211+ log.debug('add_handler, slidenumber: %d' % slide_no)
212 if self.is_live:
213 if hide_mode == HideMode.Screen:
214 Registry().execute('live_display_hide', HideMode.Screen)
215@@ -316,6 +319,28 @@
216 hide_mode = message[2]
217 file = item.get_frame_path()
218 self.handler = item.processor
219+ # When starting presentation from the servicemanager we convert
220+ # PDF/XPS-serviceitems into image-serviceitems. When started from the mediamanager
221+ # the conversion has already been done at this point.
222+ if file.endswith('.pdf') or file.endswith('.xps'):
223+ log.debug('Converting from pdf/xps to images for serviceitem with file %s', file)
224+ # Create a copy of the original item, and then clear the original item so it can be filled with images
225+ item_cpy = copy.copy(item)
226+ item.__init__(None)
227+ if is_live:
228+ self.media_item.generate_slide_data(item, item_cpy, False, False, ServiceItemContext.Live, file)
229+ else:
230+ self.media_item.generate_slide_data(item, item_cpy, False, False, ServiceItemContext.Preview, file)
231+ # Some of the original serviceitem attributes is needed in the new serviceitem
232+ item.footer = item_cpy.footer
233+ item.from_service = item_cpy.from_service
234+ item.iconic_representation = item_cpy.iconic_representation
235+ item.image_border = item_cpy.image_border
236+ item.main = item_cpy.main
237+ item.theme_data = item_cpy.theme_data
238+ # When presenting PDF or XPS, we are using the image presentation code,
239+ # so handler & processor is set to None, and we skip adding the handler.
240+ self.handler = None
241 if self.handler == self.media_item.automatic:
242 self.handler = self.media_item.findControllerByType(file)
243 if not self.handler:
244@@ -324,7 +349,12 @@
245 controller = self.live_handler
246 else:
247 controller = self.preview_handler
248- controller.add_handler(self.controllers[self.handler], file, hide_mode, message[3])
249+ # When presenting PDF or XPS, we are using the image presentation code,
250+ # so handler & processor is set to None, and we skip adding the handler.
251+ if self.handler is None:
252+ self.controller = controller
253+ else:
254+ controller.add_handler(self.controllers[self.handler], file, hide_mode, message[3])
255
256 def slide(self, message):
257 """
258
259=== added file 'openlp/plugins/presentations/lib/pdfcontroller.py'
260--- openlp/plugins/presentations/lib/pdfcontroller.py 1970-01-01 00:00:00 +0000
261+++ openlp/plugins/presentations/lib/pdfcontroller.py 2013-12-31 12:36:15 +0000
262@@ -0,0 +1,306 @@
263+# -*- coding: utf-8 -*-
264+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
265+
266+###############################################################################
267+# OpenLP - Open Source Lyrics Projection #
268+# --------------------------------------------------------------------------- #
269+# Copyright (c) 2008-2014 Raoul Snyman #
270+# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
271+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
272+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
273+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
274+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
275+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
276+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
277+# --------------------------------------------------------------------------- #
278+# This program is free software; you can redistribute it and/or modify it #
279+# under the terms of the GNU General Public License as published by the Free #
280+# Software Foundation; version 2 of the License. #
281+# #
282+# This program is distributed in the hope that it will be useful, but WITHOUT #
283+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
284+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
285+# more details. #
286+# #
287+# You should have received a copy of the GNU General Public License along #
288+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
289+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
290+###############################################################################
291+
292+import os
293+import logging
294+from tempfile import NamedTemporaryFile
295+import re
296+from subprocess import check_output, CalledProcessError, STDOUT
297+
298+from openlp.core.utils import AppLocation
299+from openlp.core.common import Settings
300+from openlp.core.lib import ScreenList
301+from .presentationcontroller import PresentationController, PresentationDocument
302+
303+log = logging.getLogger(__name__)
304+
305+
306+class PdfController(PresentationController):
307+ """
308+ Class to control PDF presentations
309+ """
310+ log.info('PdfController loaded')
311+
312+ def __init__(self, plugin):
313+ """
314+ Initialise the class
315+ """
316+ log.debug('Initialising')
317+ self.process = None
318+ PresentationController.__init__(self, plugin, 'Pdf', PdfDocument)
319+ self.supports = ['pdf']
320+ self.mudrawbin = ''
321+ self.gsbin = ''
322+ if self.check_installed() and self.mudrawbin:
323+ self.also_supports = ['xps']
324+
325+ @staticmethod
326+ def check_binary(program_path):
327+ """
328+ Function that checks whether a binary is either ghostscript or mudraw or neither.
329+ Is also used from presentationtab.py
330+ """
331+ program_type = None
332+ runlog = ''
333+ log.debug('testing program_path: %s', program_path)
334+ try:
335+ runlog = check_output([program_path, '--help'], stderr=STDOUT)
336+ except CalledProcessError as e:
337+ runlog = e.output
338+ except Exception:
339+ runlog = ''
340+ # Analyse the output to see it the program is mudraw, ghostscript or neither
341+ for line in runlog.splitlines():
342+ decoded_line = line.decode()
343+ found_mudraw = re.search('usage: mudraw.*', decoded_line)
344+ if found_mudraw:
345+ program_type = 'mudraw'
346+ break
347+ found_gs = re.search('GPL Ghostscript.*', decoded_line)
348+ if found_gs:
349+ program_type = 'gs'
350+ break
351+ log.debug('in check_binary, found: %s', program_type)
352+ return program_type
353+
354+ def check_available(self):
355+ """
356+ PdfController is able to run on this machine.
357+ """
358+ log.debug('check_available Pdf')
359+ return self.check_installed()
360+
361+ def check_installed(self):
362+ """
363+ Check the viewer is installed.
364+ """
365+ log.debug('check_installed Pdf')
366+ # Use the user defined program if given
367+ if (Settings().value('presentations/enable_pdf_program')):
368+ pdf_program = Settings().value('presentations/pdf_program')
369+ program_type = self.check_binary(pdf_program)
370+ if program_type == 'gs':
371+ self.gsbin = pdf_program
372+ return True
373+ elif program_type == 'mudraw':
374+ self.mudrawbin = pdf_program
375+ return True
376+ # Fallback to autodetection
377+ application_path = AppLocation.get_directory(AppLocation.AppDir)
378+ if os.name == 'nt':
379+ # for windows we only accept mudraw.exe in the base folder
380+ application_path = AppLocation.get_directory(AppLocation.AppDir)
381+ if os.path.isfile(application_path + '/../mudraw.exe'):
382+ self.mudrawbin = application_path + '/../mudraw.exe'
383+ else:
384+ # First try to find mupdf
385+ try:
386+ self.mudrawbin = check_output(['which', 'mudraw']).decode(encoding='UTF-8').rstrip('\n')
387+ except CalledProcessError:
388+ self.mudrawbin = ''
389+ # if mupdf isn't installed, fallback to ghostscript
390+ if not self.mudrawbin:
391+ try:
392+ self.gsbin = check_output(['which', 'gs']).rstrip('\n')
393+ except CalledProcessError:
394+ self.gsbin = ''
395+ # Last option: check if mudraw is placed in OpenLP base folder
396+ if not self.mudrawbin and not self.gsbin:
397+ application_path = AppLocation.get_directory(AppLocation.AppDir)
398+ if os.path.isfile(application_path + '/../mudraw'):
399+ self.mudrawbin = application_path + '/../mudraw'
400+ if not self.mudrawbin and not self.gsbin:
401+ return False
402+ else:
403+ return True
404+
405+ def kill(self):
406+ """
407+ Called at system exit to clean up any running presentations
408+ """
409+ log.debug('Kill pdfviewer')
410+ while self.docs:
411+ self.docs[0].close_presentation()
412+
413+
414+class PdfDocument(PresentationDocument):
415+ """
416+ Class which holds information of a single presentation.
417+ This class is not actually used to present the PDF, instead we convert to
418+ image-serviceitem on the fly and present as such. Therefore some of the 'playback'
419+ functions is not implemented.
420+ """
421+ def __init__(self, controller, presentation):
422+ """
423+ Constructor, store information about the file and initialise.
424+ """
425+ log.debug('Init Presentation Pdf')
426+ PresentationDocument.__init__(self, controller, presentation)
427+ self.presentation = None
428+ self.blanked = False
429+ self.hidden = False
430+ self.image_files = []
431+ self.num_pages = -1
432+
433+ def gs_get_resolution(self, size):
434+ """
435+ Only used when using ghostscript
436+ Ghostscript can't scale automaticly while keeping aspect like mupdf, so we need
437+ to get the ratio bewteen the screen size and the PDF to scale
438+ """
439+ # Use a postscript script to get size of the pdf. It is assumed that all pages have same size
440+ postscript = '%!PS \n\
441+() = \n\
442+File dup (r) file runpdfbegin \n\
443+1 pdfgetpage dup \n\
444+/MediaBox pget { \n\
445+aload pop exch 4 1 roll exch sub 3 1 roll sub \n\
446+( Size: x: ) print =print (, y: ) print =print (\n) print \n\
447+} if \n\
448+flush \n\
449+quit \n\
450+'
451+ # Put postscript into tempfile
452+ tmp_file = NamedTemporaryFile(delete=False)
453+ tmp_file.write(postscript)
454+ tmp_file.close()
455+ # Run the script on the pdf to get the size
456+ runlog = []
457+ try:
458+ runlog = check_output([self.controller.gsbin, '-dNOPAUSE', '-dNODISPLAY', '-dBATCH',
459+ '-sFile=' + self.filepath, tmp_file.name])
460+ except CalledProcessError as e:
461+ log.debug(' '.join(e.cmd))
462+ log.debug(e.output)
463+ os.unlink(tmp_file.name)
464+ # Extract the pdf resolution from output, the format is " Size: x: <width>, y: <height>"
465+ width = 0
466+ height = 0
467+ for line in runlog.splitlines():
468+ try:
469+ width = re.search('.*Size: x: (\d+\.?\d*), y: \d+.*', line).group(1)
470+ height = re.search('.*Size: x: \d+\.?\d*, y: (\d+\.?\d*).*', line).group(1)
471+ break
472+ except AttributeError:
473+ pass
474+ # Calculate the ratio from pdf to screen
475+ if width > 0 and height > 0:
476+ width_ratio = size.right() / float(width)
477+ height_ratio = size.bottom() / float(height)
478+ # return the resolution that should be used. 72 is default.
479+ if width_ratio > height_ratio:
480+ return int(height_ratio * 72)
481+ else:
482+ return int(width_ratio * 72)
483+ else:
484+ return 72
485+
486+ def load_presentation(self):
487+ """
488+ Called when a presentation is added to the SlideController. It generates images from the PDF.
489+ """
490+ log.debug('load_presentation pdf')
491+ # Check if the images has already been created, and if yes load them
492+ if os.path.isfile(os.path.join(self.get_temp_folder(), 'mainslide001.png')):
493+ created_files = sorted(os.listdir(self.get_temp_folder()))
494+ for fn in created_files:
495+ if os.path.isfile(os.path.join(self.get_temp_folder(), fn)):
496+ self.image_files.append(os.path.join(self.get_temp_folder(), fn))
497+ self.num_pages = len(self.image_files)
498+ return True
499+ size = ScreenList().current['size']
500+ # Generate images from PDF that will fit the frame.
501+ runlog = ''
502+ try:
503+ if not os.path.isdir(self.get_temp_folder()):
504+ os.makedirs(self.get_temp_folder())
505+ if self.controller.mudrawbin:
506+ runlog = check_output([self.controller.mudrawbin, '-w', str(size.right()), '-h', str(size.bottom()),
507+ '-o', os.path.join(self.get_temp_folder(), 'mainslide%03d.png'), self.filepath])
508+ elif self.controller.gsbin:
509+ resolution = self.gs_get_resolution(size)
510+ runlog = check_output([self.controller.gsbin, '-dSAFER', '-dNOPAUSE', '-dBATCH', '-sDEVICE=png16m',
511+ '-r' + str(resolution), '-dTextAlphaBits=4', '-dGraphicsAlphaBits=4',
512+ '-sOutputFile=' + os.path.join(self.get_temp_folder(), 'mainslide%03d.png'),
513+ self.filepath])
514+ created_files = sorted(os.listdir(self.get_temp_folder()))
515+ for fn in created_files:
516+ if os.path.isfile(os.path.join(self.get_temp_folder(), fn)):
517+ self.image_files.append(os.path.join(self.get_temp_folder(), fn))
518+ except Exception as e:
519+ log.debug(e)
520+ log.debug(runlog)
521+ return False
522+ self.num_pages = len(self.image_files)
523+ # Create thumbnails
524+ self.create_thumbnails()
525+ return True
526+
527+ def create_thumbnails(self):
528+ """
529+ Generates thumbnails
530+ """
531+ log.debug('create_thumbnails pdf')
532+ if self.check_thumbnails():
533+ return
534+ # use builtin function to create thumbnails from generated images
535+ index = 1
536+ for image in self.image_files:
537+ self.convert_thumbnail(image, index)
538+ index += 1
539+
540+ def close_presentation(self):
541+ """
542+ Close presentation and clean up objects. Triggered by new object being added to SlideController or OpenLP being
543+ shut down.
544+ """
545+ log.debug('close_presentation pdf')
546+ self.controller.remove_doc(self)
547+
548+ def is_loaded(self):
549+ """
550+ Returns true if a presentation is loaded.
551+ """
552+ log.debug('is_loaded pdf')
553+ if self.num_pages < 0:
554+ return False
555+ return True
556+
557+ def is_active(self):
558+ """
559+ Returns true if a presentation is currently active.
560+ """
561+ log.debug('is_active pdf')
562+ return self.is_loaded() and not self.hidden
563+
564+ def get_slide_count(self):
565+ """
566+ Returns total number of slides
567+ """
568+ return self.num_pages
569
570=== modified file 'openlp/plugins/presentations/lib/presentationtab.py'
571--- openlp/plugins/presentations/lib/presentationtab.py 2013-12-24 08:56:50 +0000
572+++ openlp/plugins/presentations/lib/presentationtab.py 2013-12-31 12:36:15 +0000
573@@ -30,7 +30,9 @@
574 from PyQt4 import QtGui
575
576 from openlp.core.common import Settings, UiStrings, translate
577-from openlp.core.lib import SettingsTab
578+from openlp.core.lib import SettingsTab, build_icon
579+from openlp.core.lib.ui import critical_error_message_box
580+from .pdfcontroller import PdfController
581
582
583 class PresentationTab(SettingsTab):
584@@ -64,6 +66,7 @@
585 self.presenter_check_boxes[controller.name] = checkbox
586 self.controllers_layout.addWidget(checkbox)
587 self.left_layout.addWidget(self.controllers_group_box)
588+ # Advanced
589 self.advanced_group_box = QtGui.QGroupBox(self.left_column)
590 self.advanced_group_box.setObjectName('advanced_group_box')
591 self.advanced_layout = QtGui.QVBoxLayout(self.advanced_group_box)
592@@ -72,8 +75,35 @@
593 self.override_app_check_box.setObjectName('override_app_check_box')
594 self.advanced_layout.addWidget(self.override_app_check_box)
595 self.left_layout.addWidget(self.advanced_group_box)
596+ # Pdf options
597+ self.pdf_group_box = QtGui.QGroupBox(self.left_column)
598+ self.pdf_group_box.setObjectName('pdf_group_box')
599+ self.pdf_layout = QtGui.QFormLayout(self.pdf_group_box)
600+ self.pdf_layout.setObjectName('pdf_layout')
601+ self.pdf_program_check_box = QtGui.QCheckBox(self.pdf_group_box)
602+ self.pdf_program_check_box.setObjectName('pdf_program_check_box')
603+ self.pdf_layout.addRow(self.pdf_program_check_box)
604+ self.pdf_program_path_layout = QtGui.QHBoxLayout()
605+ self.pdf_program_path_layout.setObjectName('pdf_program_path_layout')
606+ self.pdf_program_path = QtGui.QLineEdit(self.pdf_group_box)
607+ self.pdf_program_path.setObjectName('pdf_program_path')
608+ self.pdf_program_path.setReadOnly(True)
609+ self.pdf_program_path.setPalette(self.get_grey_text_palette(True))
610+ self.pdf_program_path_layout.addWidget(self.pdf_program_path)
611+ self.pdf_program_browse_button = QtGui.QToolButton(self.pdf_group_box)
612+ self.pdf_program_browse_button.setObjectName('pdf_program_browse_button')
613+ self.pdf_program_browse_button.setIcon(build_icon(':/general/general_open.png'))
614+ self.pdf_program_browse_button.setEnabled(False)
615+ self.pdf_program_path_layout.addWidget(self.pdf_program_browse_button)
616+ self.pdf_layout.addRow(self.pdf_program_path_layout)
617+ self.left_layout.addWidget(self.pdf_group_box)
618 self.left_layout.addStretch()
619+ self.right_column.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred)
620 self.right_layout.addStretch()
621+ # Signals and slots
622+ self.pdf_program_path.editingFinished.connect(self.on_pdf_program_path_edit_finished)
623+ self.pdf_program_browse_button.clicked.connect(self.on_pdf_program_browse_button_clicked)
624+ self.pdf_program_check_box.clicked.connect(self.on_pdf_program_check_box_clicked)
625
626 def retranslateUi(self):
627 """
628@@ -85,8 +115,11 @@
629 checkbox = self.presenter_check_boxes[controller.name]
630 self.set_controller_text(checkbox, controller)
631 self.advanced_group_box.setTitle(UiStrings().Advanced)
632+ self.pdf_group_box.setTitle(translate('PresentationPlugin.PresentationTab', 'PDF options'))
633 self.override_app_check_box.setText(
634 translate('PresentationPlugin.PresentationTab', 'Allow presentation application to be overridden'))
635+ self.pdf_program_check_box.setText(
636+ translate('PresentationPlugin.PresentationTab', 'Use given full path for mudraw or ghostscript binary:'))
637
638 def set_controller_text(self, checkbox, controller):
639 if checkbox.isEnabled():
640@@ -103,6 +136,15 @@
641 checkbox = self.presenter_check_boxes[controller.name]
642 checkbox.setChecked(Settings().value(self.settings_section + '/' + controller.name))
643 self.override_app_check_box.setChecked(Settings().value(self.settings_section + '/override app'))
644+ # load pdf-program settings
645+ enable_pdf_program = Settings().value(self.settings_section + '/enable_pdf_program')
646+ self.pdf_program_check_box.setChecked(enable_pdf_program)
647+ self.pdf_program_path.setReadOnly(not enable_pdf_program)
648+ self.pdf_program_path.setPalette(self.get_grey_text_palette(not enable_pdf_program))
649+ self.pdf_program_browse_button.setEnabled(enable_pdf_program)
650+ pdf_program = Settings().value(self.settings_section + '/pdf_program')
651+ if pdf_program:
652+ self.pdf_program_path.setText(pdf_program)
653
654 def save(self):
655 """
656@@ -128,6 +170,18 @@
657 if Settings().value(setting_key) != self.override_app_check_box.checkState():
658 Settings().setValue(setting_key, self.override_app_check_box.checkState())
659 changed = True
660+ # Save pdf-settings
661+ pdf_program = self.pdf_program_path.text()
662+ enable_pdf_program = self.pdf_program_check_box.checkState()
663+ # If the given program is blank disable using the program
664+ if pdf_program == '':
665+ enable_pdf_program = 0
666+ if pdf_program != Settings().value(self.settings_section + '/pdf_program'):
667+ Settings().setValue(self.settings_section + '/pdf_program', pdf_program)
668+ changed = True
669+ if enable_pdf_program != Settings().value(self.settings_section + '/enable_pdf_program'):
670+ Settings().setValue(self.settings_section + '/enable_pdf_program', enable_pdf_program)
671+ changed = True
672 if changed:
673 self.settings_form.register_post_process('mediaitem_suffix_reset')
674 self.settings_form.register_post_process('mediaitem_presentation_rebuild')
675@@ -143,3 +197,46 @@
676 checkbox = self.presenter_check_boxes[controller.name]
677 checkbox.setEnabled(controller.is_available())
678 self.set_controller_text(checkbox, controller)
679+
680+ def on_pdf_program_path_edit_finished(self):
681+ """
682+ After selecting/typing in a program it is validated that it is a actually ghostscript or mudraw
683+ """
684+ program_type = None
685+ if self.pdf_program_path.text() != '':
686+ program_type = PdfController.check_binary(self.pdf_program_path.text())
687+ if not program_type:
688+ critical_error_message_box(UiStrings().Error,
689+ translate('PresentationPlugin.PresentationTab',
690+ 'The program is not ghostscript or mudraw which is required.'))
691+ self.pdf_program_path.setFocus()
692+
693+ def on_pdf_program_browse_button_clicked(self):
694+ """
695+ Select the mudraw or ghostscript binary that should be used.
696+ """
697+ filename = QtGui.QFileDialog.getOpenFileName(self, translate('PresentationPlugin.PresentationTab',
698+ 'Select mudraw or ghostscript binary.'))
699+ if filename:
700+ self.pdf_program_path.setText(filename)
701+ self.pdf_program_path.setFocus()
702+
703+ def on_pdf_program_check_box_clicked(self, checked):
704+ """
705+ When checkbox for manual entering pdf-program is clicked,
706+ enable or disable the textbox for the programpath and the browse-button.
707+ """
708+ self.pdf_program_path.setReadOnly(not checked)
709+ self.pdf_program_path.setPalette(self.get_grey_text_palette(not checked))
710+ self.pdf_program_browse_button.setEnabled(checked)
711+
712+ def get_grey_text_palette(self, greyed):
713+ """
714+ Returns a QPalette with greyed out text as used for placeholderText.
715+ """
716+ palette = QtGui.QPalette()
717+ color = self.palette().color(QtGui.QPalette.Active, QtGui.QPalette.Text)
718+ if greyed:
719+ color.setAlpha(128)
720+ palette.setColor(QtGui.QPalette.Active, QtGui.QPalette.Text, color)
721+ return palette
722
723=== modified file 'openlp/plugins/presentations/presentationplugin.py'
724--- openlp/plugins/presentations/presentationplugin.py 2013-12-24 08:56:50 +0000
725+++ openlp/plugins/presentations/presentationplugin.py 2013-12-31 12:36:15 +0000
726@@ -45,9 +45,12 @@
727
728 __default_settings__ = {
729 'presentations/override app': QtCore.Qt.Unchecked,
730+ 'presentations/enable_pdf_program': QtCore.Qt.Unchecked,
731+ 'presentations/pdf_program': '',
732 'presentations/Impress': QtCore.Qt.Checked,
733 'presentations/Powerpoint': QtCore.Qt.Checked,
734 'presentations/Powerpoint Viewer': QtCore.Qt.Checked,
735+ 'presentations/Pdf': QtCore.Qt.Checked,
736 'presentations/presentations files': []
737 }
738
739
740=== modified file 'resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py'
741--- resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py 2013-12-24 08:56:50 +0000
742+++ resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py 2013-12-31 12:36:15 +0000
743@@ -29,4 +29,5 @@
744
745 hiddenimports = ['openlp.plugins.presentations.lib.impresscontroller',
746 'openlp.plugins.presentations.lib.powerpointcontroller',
747- 'openlp.plugins.presentations.lib.pptviewcontroller']
748+ 'openlp.plugins.presentations.lib.pptviewcontroller',
749+ 'openlp.plugins.presentations.lib.pdfcontroller']
750
751=== modified file 'tests/functional/openlp_plugins/presentations/test_mediaitem.py'
752--- tests/functional/openlp_plugins/presentations/test_mediaitem.py 2013-12-28 21:33:38 +0000
753+++ tests/functional/openlp_plugins/presentations/test_mediaitem.py 2013-12-31 12:36:15 +0000
754@@ -75,11 +75,16 @@
755 presentation_controller.also_supports = []
756 presentation_viewer_controller = MagicMock()
757 presentation_viewer_controller.enabled.return_value = False
758+ pdf_controller = MagicMock()
759+ pdf_controller.enabled.return_value = True
760+ pdf_controller.supports = ['pdf']
761+ pdf_controller.also_supports = ['xps']
762 # Mock the controllers.
763 self.media_item.controllers = {
764 'Impress': impress_controller,
765 'Powerpoint': presentation_controller,
766- 'Powerpoint Viewer': presentation_viewer_controller
767+ 'Powerpoint Viewer': presentation_viewer_controller,
768+ 'Pdf': pdf_controller
769 }
770
771 # WHEN: Build the file mask.
772@@ -92,3 +97,7 @@
773 'The file mask should contain the odp extension')
774 self.assertIn('*.ppt', self.media_item.on_new_file_masks,
775 'The file mask should contain the ppt extension')
776+ self.assertIn('*.pdf', self.media_item.on_new_file_masks,
777+ 'The file mask should contain the pdf extension')
778+ self.assertIn('*.xps', self.media_item.on_new_file_masks,
779+ 'The file mask should contain the xps extension')
780
781=== added file 'tests/functional/openlp_plugins/presentations/test_pdfcontroller.py'
782--- tests/functional/openlp_plugins/presentations/test_pdfcontroller.py 1970-01-01 00:00:00 +0000
783+++ tests/functional/openlp_plugins/presentations/test_pdfcontroller.py 2013-12-31 12:36:15 +0000
784@@ -0,0 +1,109 @@
785+# -*- coding: utf-8 -*-
786+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
787+
788+###############################################################################
789+# OpenLP - Open Source Lyrics Projection #
790+# --------------------------------------------------------------------------- #
791+# Copyright (c) 2008-2014 Raoul Snyman #
792+# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
793+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
794+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
795+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
796+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
797+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
798+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
799+# --------------------------------------------------------------------------- #
800+# This program is free software; you can redistribute it and/or modify it #
801+# under the terms of the GNU General Public License as published by the Free #
802+# Software Foundation; version 2 of the License. #
803+# #
804+# This program is distributed in the hope that it will be useful, but WITHOUT #
805+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
806+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
807+# more details. #
808+# #
809+# You should have received a copy of the GNU General Public License along #
810+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
811+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
812+###############################################################################
813+"""
814+This module contains tests for the PdfController
815+"""
816+import os
817+import shutil
818+from unittest import TestCase, SkipTest
819+from tempfile import mkstemp, mkdtemp
820+
821+from PyQt4 import QtGui
822+
823+from openlp.plugins.presentations.lib.pdfcontroller import PdfController, PdfDocument
824+from tests.functional import MagicMock
825+from openlp.core.common import Settings
826+from openlp.core.lib import ScreenList
827+from tests.utils.constants import TEST_RESOURCES_PATH
828+
829+__default_settings__ = {
830+ 'presentations/enable_pdf_program': False
831+}
832+
833+
834+class TestPdfController(TestCase):
835+ """
836+ Test the PdfController.
837+ """
838+ def setUp(self):
839+ """
840+ Set up the components need for all tests.
841+ """
842+ self.fd, self.ini_file = mkstemp('.ini')
843+ Settings().set_filename(self.ini_file)
844+ self.application = QtGui.QApplication.instance()
845+ ScreenList.create(self.application.desktop())
846+ Settings().extend_default_settings(__default_settings__)
847+ self.temp_folder = mkdtemp()
848+ self.thumbnail_folder = mkdtemp()
849+
850+ def tearDown(self):
851+ """
852+ Delete all the C++ objects at the end so that we don't have a segfault
853+ """
854+ del self.application
855+ try:
856+ os.unlink(self.ini_file)
857+ shutil.rmtree(self.thumbnail_folder)
858+ shutil.rmtree(self.temp_folder)
859+ except OSError:
860+ pass
861+
862+ def constructor_test(self):
863+ """
864+ Test the Constructor
865+ """
866+ # GIVEN: No presentation controller
867+ controller = None
868+
869+ # WHEN: The presentation controller object is created
870+ controller = PdfController(plugin=MagicMock())
871+
872+ # THEN: The name of the presentation controller should be correct
873+ self.assertEqual('Pdf', controller.name, 'The name of the presentation controller should be correct')
874+
875+ def load_pdf_test(self):
876+ """
877+ Test loading of a Pdf
878+ """
879+ # GIVEN: A Pdf-file
880+ test_file = os.path.join(TEST_RESOURCES_PATH, 'presentations', 'pdf_test1.pdf')
881+
882+ # WHEN: The Pdf is loaded
883+ controller = PdfController(plugin=MagicMock())
884+ if not controller.check_available():
885+ raise SkipTest('Could not detect mudraw or ghostscript, so skipping PDF test')
886+ controller.temp_folder = self.temp_folder
887+ controller.thumbnail_folder = self.thumbnail_folder
888+ document = PdfDocument(controller, test_file)
889+ loaded = document.load_presentation()
890+
891+ # THEN: The load should succeed and we should be able to get a pagecount
892+ self.assertTrue(loaded, 'The loading of the PDF should succeed.')
893+ self.assertEqual(3, document.get_slide_count(), 'The pagecount of the PDF should be 3.')
894
895=== added directory 'tests/resources/presentations'
896=== added file 'tests/resources/presentations/pdf_test1.pdf'
897Binary files tests/resources/presentations/pdf_test1.pdf 1970-01-01 00:00:00 +0000 and tests/resources/presentations/pdf_test1.pdf 2013-12-31 12:36:15 +0000 differ