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: 652 lines (+487/-23) (has conflicts)
6 files modified
openlp/plugins/presentations/lib/mediaitem.py (+72/-21)
openlp/plugins/presentations/lib/messagelistener.py (+17/-1)
openlp/plugins/presentations/lib/pdfcontroller.py (+290/-0)
openlp/plugins/presentations/lib/presentationtab.py (+103/-0)
openlp/plugins/presentations/presentationplugin.py (+3/-0)
resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py (+2/-1)
Text conflict in openlp/plugins/presentations/lib/mediaitem.py
Text conflict in openlp/plugins/presentations/lib/presentationtab.py
To merge this branch: bzr merge lp:~tomasgroth/openlp/mupdf
Reviewer Review Type Date Requested Status
Tim Bentley Needs Resubmitting
Review via email: mp+182009@code.launchpad.net

This proposal supersedes a proposal from 2013-07-15.

This proposal has been superseded by a proposal from 2013-11-14.

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 :

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 :

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
lp:~tomasgroth/openlp/mupdf updated
2282. By Tomas Groth

Merge with python3 changes.

2283. By Tomas Groth

Made branch work with python3.

2284. By Tomas Groth

Mostly code cleanup of PDF support code.

2285. By Tomas Groth

Merged with trunk to resolve conflicts.

2286. By Tomas Groth

Made presenting PDF from the servicemanager work

2287. By Tomas Groth

Merged with trunk

2288. By Tomas Groth

Fixes for the presentation setting tab

2289. By Tomas Groth

Added tests for the PdfController.

2290. By Tomas Groth

Merged with trunk.

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/plugins/presentations/lib/mediaitem.py'
2--- openlp/plugins/presentations/lib/mediaitem.py 2013-10-13 21:07:28 +0000
3+++ openlp/plugins/presentations/lib/mediaitem.py 2013-11-14 16:44:06 +0000
4@@ -249,10 +249,11 @@
5 items = self.list_view.selectedItems()
6 if len(items) > 1:
7 return False
8- service_item.processor = self.display_type_combo_box.currentText()
9- service_item.add_capability(ItemCapabilities.ProvidesOwnDisplay)
10+ filename = items[0].data(QtCore.Qt.UserRole)
11+ file_type = os.path.splitext(filename)[1][1:]
12 if not self.display_type_combo_box.currentText():
13 return False
14+<<<<<<< TREE
15 for bitem in items:
16 filename = bitem.data(QtCore.Qt.UserRole)
17 (path, name) = os.path.split(filename)
18@@ -261,33 +262,83 @@
19 if service_item.processor == self.automatic:
20 service_item.processor = self.findControllerByType(filename)
21 if not service_item.processor:
22+=======
23+ if (file_type == 'pdf' or file_type == 'xps') and context != ServiceItemContext.Service:
24+ service_item.add_capability(ItemCapabilities.CanMaintain)
25+ service_item.add_capability(ItemCapabilities.CanPreview)
26+ service_item.add_capability(ItemCapabilities.CanLoop)
27+ service_item.add_capability(ItemCapabilities.CanAppend)
28+ # force a nonexistent theme
29+ service_item.theme = -1
30+ for bitem in items:
31+ filename = bitem.data(QtCore.Qt.UserRole)
32+ (path, name) = os.path.split(filename)
33+ service_item.title = name
34+ if os.path.exists(filename):
35+ processor = self.findControllerByType(filename)
36+ if not processor:
37+>>>>>>> MERGE-SOURCE
38 return False
39- controller = self.controllers[service_item.processor]
40- doc = controller.add_document(filename)
41- if doc.get_thumbnail_path(1, True) is None:
42- doc.load_presentation()
43- i = 1
44- img = doc.get_thumbnail_path(i, True)
45- if img:
46- while img:
47- service_item.add_from_command(path, name, img)
48+ controller = self.controllers[processor]
49+ service_item.processor = None
50+ doc = controller.add_document(filename)
51+ if doc.get_thumbnail_path(1, True) is None or not os.path.isfile(
52+ os.path.join(doc.get_temp_folder(), 'mainslide001.png')):
53+ doc.load_presentation()
54+ i = 1
55+ imagefile = 'mainslide%03d.png' % i
56+ image = os.path.join(doc.get_temp_folder(), imagefile)
57+ while os.path.isfile(image):
58+ service_item.add_from_image(image, name)
59 i += 1
60- img = doc.get_thumbnail_path(i, True)
61+ imagefile = 'mainslide%03d.png' % i
62+ image = os.path.join(doc.get_temp_folder(), imagefile)
63 doc.close_presentation()
64 return True
65 else:
66 # File is no longer present
67 if not remote:
68 critical_error_message_box(translate('PresentationPlugin.MediaItem', 'Missing Presentation'),
69- translate('PresentationPlugin.MediaItem',
70- 'The presentation %s is incomplete, please reload.') % filename)
71- return False
72- else:
73- # File is no longer present
74- if not remote:
75- critical_error_message_box(translate('PresentationPlugin.MediaItem', 'Missing Presentation'),
76- translate('PresentationPlugin.MediaItem', 'The presentation %s no longer exists.') % filename)
77- return False
78+ translate('PresentationPlugin.MediaItem', 'The presentation %s no longer exists.') % filename)
79+ return False
80+ else:
81+ service_item.processor = self.display_type_combo_box.currentText()
82+ service_item.add_capability(ItemCapabilities.ProvidesOwnDisplay)
83+ for bitem in items:
84+ filename = bitem.data(QtCore.Qt.UserRole)
85+ (path, name) = os.path.split(filename)
86+ service_item.title = name
87+ if os.path.exists(filename):
88+ if service_item.processor == self.Automatic:
89+ service_item.processor = self.findControllerByType(filename)
90+ if not service_item.processor:
91+ return False
92+ controller = self.controllers[service_item.processor]
93+ doc = controller.add_document(filename)
94+ if doc.get_thumbnail_path(1, True) is None:
95+ doc.load_presentation()
96+ i = 1
97+ img = doc.get_thumbnail_path(i, True)
98+ if img:
99+ while img:
100+ service_item.add_from_command(path, name, img)
101+ i += 1
102+ img = doc.get_thumbnail_path(i, True)
103+ doc.close_presentation()
104+ return True
105+ else:
106+ # File is no longer present
107+ if not remote:
108+ critical_error_message_box(translate('PresentationPlugin.MediaItem', 'Missing Presentation'),
109+ translate('PresentationPlugin.MediaItem',
110+ 'The presentation %s is incomplete, please reload.') % filename)
111+ return False
112+ else:
113+ # File is no longer present
114+ if not remote:
115+ critical_error_message_box(translate('PresentationPlugin.MediaItem', 'Missing Presentation'),
116+ translate('PresentationPlugin.MediaItem', 'The presentation %s no longer exists.') % filename)
117+ return False
118
119 def findControllerByType(self, filename):
120 """
121
122=== modified file 'openlp/plugins/presentations/lib/messagelistener.py'
123--- openlp/plugins/presentations/lib/messagelistener.py 2013-08-31 18:17:38 +0000
124+++ openlp/plugins/presentations/lib/messagelistener.py 2013-11-14 16:44:06 +0000
125@@ -33,6 +33,7 @@
126
127 from openlp.core.lib import Registry
128 from openlp.core.ui import HideMode
129+from openlp.core.lib import ServiceItemContext
130
131 log = logging.getLogger(__name__)
132
133@@ -69,6 +70,7 @@
134 return
135 self.doc.slidenumber = slide_no
136 self.hide_mode = hide_mode
137+ log.debug('add_handler, slidenumber: %d' % slide_no)
138 if self.is_live:
139 if hide_mode == HideMode.Screen:
140 Registry().execute('live_display_hide', HideMode.Screen)
141@@ -316,6 +318,14 @@
142 hide_mode = message[2]
143 file = item.get_frame_path()
144 self.handler = item.processor
145+ #self.media_item.generate_slide_data(self, service_item, item=None, xml_version=False,remote=False, context=ServiceItemContext.Service)
146+ if file.endswith('.pdf') or file.endswith('.xps'):
147+ log.debug('Trying to convert from pdf to images for service-item')
148+ if is_live:
149+ self.media_item.generate_slide_data(self, item, None, False, False, ServiceItemContext.Live)
150+ else:
151+ self.media_item.generate_slide_data(self, item, None, False, False, ServiceItemContext.Preview)
152+
153 if self.handler == self.media_item.Automatic:
154 self.handler = self.media_item.findControllerByType(file)
155 if not self.handler:
156@@ -324,7 +334,13 @@
157 controller = self.live_handler
158 else:
159 controller = self.preview_handler
160- controller.add_handler(self.controllers[self.handler], file, hide_mode, message[3])
161+ # when presenting PDF, we're using the image presentation code,
162+ # so handler & processor is set to None, and we skip adding the handler.
163+ log.debug('file: %s' % file)
164+ if self.handler == None:
165+ self.controller = controller
166+ else:
167+ controller.add_handler(self.controllers[self.handler], file, hide_mode, message[3])
168
169 def slide(self, message):
170 """
171
172=== added file 'openlp/plugins/presentations/lib/pdfcontroller.py'
173--- openlp/plugins/presentations/lib/pdfcontroller.py 1970-01-01 00:00:00 +0000
174+++ openlp/plugins/presentations/lib/pdfcontroller.py 2013-11-14 16:44:06 +0000
175@@ -0,0 +1,290 @@
176+# -*- coding: utf-8 -*-
177+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
178+
179+###############################################################################
180+# OpenLP - Open Source Lyrics Projection #
181+# --------------------------------------------------------------------------- #
182+# Copyright (c) 2008-2013 Raoul Snyman #
183+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
184+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
185+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
186+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
187+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
188+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
189+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
190+# --------------------------------------------------------------------------- #
191+# This program is free software; you can redistribute it and/or modify it #
192+# under the terms of the GNU General Public License as published by the Free #
193+# Software Foundation; version 2 of the License. #
194+# #
195+# This program is distributed in the hope that it will be useful, but WITHOUT #
196+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
197+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
198+# more details. #
199+# #
200+# You should have received a copy of the GNU General Public License along #
201+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
202+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
203+###############################################################################
204+
205+import os
206+import logging
207+from tempfile import NamedTemporaryFile
208+import re
209+from subprocess import check_output, CalledProcessError, STDOUT
210+#from PyQt4 import QtCore, QtGui
211+
212+from openlp.core.utils import AppLocation
213+from openlp.core.lib import ScreenList, Settings
214+from .presentationcontroller import PresentationController, PresentationDocument
215+
216+
217+log = logging.getLogger(__name__)
218+
219+
220+class PdfController(PresentationController):
221+ """
222+ Class to control PDF presentations
223+ """
224+ log.info('PdfController loaded')
225+
226+ def __init__(self, plugin):
227+ """
228+ Initialise the class
229+ """
230+ log.debug('Initialising')
231+ self.process = None
232+ PresentationController.__init__(self, plugin, 'Pdf', PdfDocument)
233+ self.supports = ['pdf']
234+ self.mudrawbin = ''
235+ self.gsbin = ''
236+ if self.check_installed() and self.mudrawbin:
237+ self.also_supports = ['xps']
238+
239+ def check_binary(program_path):
240+ """
241+ Function that checks whether a binary is either ghostscript or mudraw or neither.
242+ """
243+ program_type = None
244+ runlog = ''
245+ try:
246+ runlog = check_output([program_path, '--help'], stderr=STDOUT)
247+ except CalledProcessError as e:
248+ runlog = e.output
249+ except Exception:
250+ runlog = ''
251+ # Analyse the output to see it the program is mudraw, ghostscript or neither
252+ for line in runlog.splitlines():
253+ found_mudraw = re.search('usage: mudraw.*', line)
254+ if found_mudraw:
255+ program_type = 'mudraw'
256+ break
257+ found_gs = re.search('GPL Ghostscript.*', line)
258+ if found_gs:
259+ program_type = 'gs'
260+ break
261+ log.info('in check_binary, found: ' + program_type)
262+ return program_type
263+
264+ def check_available(self):
265+ """
266+ PdfController is able to run on this machine.
267+ """
268+ log.debug('check_available Pdf')
269+ return self.check_installed()
270+
271+ def check_installed(self):
272+ """
273+ Check the viewer is installed.
274+ """
275+ log.debug('check_installed Pdf')
276+ # Use the user defined program if given
277+ if (Settings().value('presentations/enable_pdf_program')):
278+ pdf_program = Settings().value('presentations/pdf_program')
279+ type = self.check_binary(pdf_program)
280+ if type == 'gs':
281+ self.gsbin = pdf_program
282+ return True
283+ elif type == 'mudraw':
284+ self.mudrawbin = pdf_program
285+ return True
286+ # Fallback to autodetection
287+ application_path = AppLocation.get_directory(AppLocation.AppDir)
288+ if os.name == 'nt':
289+ # for windows we only accept mudraw.exe in the base folder
290+ application_path = AppLocation.get_directory(AppLocation.AppDir)
291+ if os.path.isfile(application_path + '/../mudraw.exe'):
292+ self.mudrawbin = application_path + '/../mudraw.exe'
293+ else:
294+ # First try to find mupdf
295+ try:
296+ self.mudrawbin = check_output(['which', 'mudraw']).decode(encoding='UTF-8').rstrip('\n')
297+ except CalledProcessError:
298+ self.mudrawbin = ''
299+ # if mupdf isn't installed, fallback to ghostscript
300+ if not self.mudrawbin:
301+ try:
302+ self.gsbin = check_output(['which', 'gs']).rstrip('\n')
303+ except CalledProcessError:
304+ self.gsbin = ''
305+ # Last option: check if mudraw is placed in OpenLP base folder
306+ if not self.mudrawbin and not self.gsbin:
307+ application_path = AppLocation.get_directory(AppLocation.AppDir)
308+ if os.path.isfile(application_path + '/../mudraw'):
309+ self.mudrawbin = application_path + '/../mudraw'
310+ if not self.mudrawbin and not self.gsbin:
311+ return False
312+ else:
313+ return True
314+
315+ def kill(self):
316+ """
317+ Called at system exit to clean up any running presentations
318+ """
319+ log.debug('Kill pdfviewer')
320+ while self.docs:
321+ self.docs[0].close_presentation()
322+
323+
324+class PdfDocument(PresentationDocument):
325+ """
326+ Class which holds information of a single presentation.
327+ """
328+ def __init__(self, controller, presentation):
329+ """
330+ Constructor, store information about the file and initialise.
331+ """
332+ log.debug('Init Presentation Pdf')
333+ PresentationDocument.__init__(self, controller, presentation)
334+ self.presentation = None
335+ self.blanked = False
336+ self.hidden = False
337+ self.image_files = []
338+ self.num_pages = -1
339+
340+ def gs_get_resolution(self, size):
341+ """
342+ Only used when using ghostscript
343+ Ghostscript can't scale automaticly while keeping aspect like mupdf, so we need
344+ to get the ratio bewteen the screen size and the PDF to scale
345+ """
346+ # Use a postscript script to get size of the pdf. It is assumed that all pages have same size
347+ postscript = '%!PS \n\
348+() = \n\
349+File dup (r) file runpdfbegin \n\
350+1 pdfgetpage dup \n\
351+/MediaBox pget { \n\
352+aload pop exch 4 1 roll exch sub 3 1 roll sub \n\
353+( Size: x: ) print =print (, y: ) print =print (\n) print \n\
354+} if \n\
355+flush \n\
356+quit \n\
357+'
358+ # Put postscript into tempfile
359+ tmpfile = NamedTemporaryFile(delete=False)
360+ tmpfile.write(postscript)
361+ tmpfile.close()
362+ # Run the script on the pdf to get the size
363+ runlog = []
364+ try:
365+ runlog = check_output([self.controller.gsbin, '-dNOPAUSE', '-dNODISPLAY', '-dBATCH', '-sFile=' + self.filepath, tmpfile.name])
366+ except CalledProcessError as e:
367+ log.debug(' '.join(e.cmd))
368+ log.debug(e.output)
369+ os.unlink(tmpfile.name)
370+ # Extract the pdf resolution from output, the format is " Size: x: <width>, y: <height>"
371+ width = 0
372+ height = 0
373+ for line in runlog.splitlines():
374+ try:
375+ width = re.search('.*Size: x: (\d+\.?\d*), y: \d+.*', line).group(1)
376+ height = re.search('.*Size: x: \d+\.?\d*, y: (\d+\.?\d*).*', line).group(1)
377+ break;
378+ except AttributeError:
379+ pass
380+ # Calculate the ratio from pdf to screen
381+ if width > 0 and height > 0:
382+ width_ratio = size.right() / float(width)
383+ height_ratio = size.bottom() / float(height)
384+ # return the resolution that should be used. 72 is default.
385+ if width_ratio > height_ratio:
386+ return int(height_ratio * 72)
387+ else:
388+ return int(width_ratio * 72)
389+ else:
390+ return 72
391+
392+ def load_presentation(self):
393+ """
394+ Called when a presentation is added to the SlideController. It generates images from the PDF.
395+ """
396+ log.debug('load_presentation pdf')
397+ # Check if the images has already been created, and if yes load them
398+ if os.path.isfile(os.path.join(self.get_temp_folder(), 'mainslide001.png')):
399+ created_files = sorted(os.listdir(self.get_temp_folder()))
400+ for fn in created_files:
401+ if os.path.isfile(os.path.join(self.get_temp_folder(), fn)):
402+ self.image_files.append(os.path.join(self.get_temp_folder(), fn))
403+ self.num_pages = len(self.image_files)
404+ return True
405+ size = ScreenList().current['size']
406+ # Generate images from PDF that will fit the frame.
407+ runlog = ''
408+ try:
409+ if not os.path.isdir(self.get_temp_folder()):
410+ os.makedirs(self.get_temp_folder())
411+ if self.controller.mudrawbin:
412+ runlog = check_output([self.controller.mudrawbin, '-w', str(size.right()), '-h', str(size.bottom()), '-o', os.path.join(self.get_temp_folder(), 'mainslide%03d.png'), self.filepath])
413+ elif self.controller.gsbin:
414+ resolution = self.gs_get_resolution(size)
415+ runlog = check_output([self.controller.gsbin, '-dSAFER', '-dNOPAUSE', '-dBATCH', '-sDEVICE=png16m', '-r' + str(resolution), '-dTextAlphaBits=4', '-dGraphicsAlphaBits=4', '-sOutputFile=' + os.path.join(self.get_temp_folder(), 'mainslide%03d.png'), self.filepath])
416+ created_files = sorted(os.listdir(self.get_temp_folder()))
417+ for fn in created_files:
418+ if os.path.isfile(os.path.join(self.get_temp_folder(), fn)):
419+ self.image_files.append(os.path.join(self.get_temp_folder(), fn))
420+ except Exception as e:
421+ log.debug(e)
422+ log.debug(runlog)
423+ return False
424+ self.num_pages = len(self.image_files)
425+ # Create thumbnails
426+ self.create_thumbnails()
427+ return True
428+
429+ def create_thumbnails(self):
430+ """
431+ Generates thumbnails
432+ """
433+ log.debug('create_thumbnails pdf')
434+ if self.check_thumbnails():
435+ return
436+ # use builtin function to create thumbnails from generated images
437+ index = 1
438+ for image in self.image_files:
439+ self.convert_thumbnail(image, index)
440+ index += 1
441+
442+ def close_presentation(self):
443+ """
444+ Close presentation and clean up objects. Triggered by new object being added to SlideController or OpenLP being
445+ shut down.
446+ """
447+ log.debug('close_presentation pdf')
448+ self.controller.remove_doc(self)
449+
450+ def is_loaded(self):
451+ """
452+ Returns true if a presentation is loaded.
453+ """
454+ log.debug('is_loaded pdf')
455+ if self.num_pages < 0:
456+ return False
457+ return True
458+
459+ def is_active(self):
460+ """
461+ Returns true if a presentation is currently active.
462+ """
463+ log.debug('is_active pdf')
464+ return self.is_loaded() and not self.hidden
465+
466
467=== modified file 'openlp/plugins/presentations/lib/presentationtab.py'
468--- openlp/plugins/presentations/lib/presentationtab.py 2013-10-13 20:36:42 +0000
469+++ openlp/plugins/presentations/lib/presentationtab.py 2013-11-14 16:44:06 +0000
470@@ -29,9 +29,17 @@
471
472 from PyQt4 import QtGui
473
474+<<<<<<< TREE
475 from openlp.core.common import Settings, UiStrings, translate
476 from openlp.core.lib import SettingsTab
477
478+=======
479+from openlp.core.lib import Settings, SettingsTab, UiStrings, translate, build_icon
480+from openlp.core.lib.ui import critical_error_message_box
481+from .pdfcontroller import PdfController
482+#from openlp.plugins.presentations.lib.pdfcontroller import PdfController
483+#from pdfcontroller import check_binary
484+>>>>>>> MERGE-SOURCE
485
486 class PresentationTab(SettingsTab):
487 """
488@@ -64,6 +72,7 @@
489 self.presenter_check_boxes[controller.name] = checkbox
490 self.controllers_layout.addWidget(checkbox)
491 self.left_layout.addWidget(self.controllers_group_box)
492+ # Advanced
493 self.advanced_group_box = QtGui.QGroupBox(self.left_column)
494 self.advanced_group_box.setObjectName('advanced_group_box')
495 self.advanced_layout = QtGui.QVBoxLayout(self.advanced_group_box)
496@@ -71,7 +80,33 @@
497 self.override_app_check_box = QtGui.QCheckBox(self.advanced_group_box)
498 self.override_app_check_box.setObjectName('override_app_check_box')
499 self.advanced_layout.addWidget(self.override_app_check_box)
500+
501+ # Pdf options
502+ self.pdf_group_box = QtGui.QGroupBox(self.left_column)
503+ self.pdf_group_box.setObjectName('pdf_group_box')
504+ self.pdf_layout = QtGui.QFormLayout(self.pdf_group_box)
505+ self.pdf_layout.setObjectName('pdf_layout')
506+ self.pdf_program_check_box = QtGui.QCheckBox(self.pdf_group_box)
507+ self.pdf_program_check_box.setObjectName('pdf_program_check_box')
508+ self.pdf_layout.addWidget(self.pdf_program_check_box)
509+ self.pdf_program_path_layout = QtGui.QHBoxLayout()
510+ self.pdf_program_path_layout.setObjectName('pdf_program_path_layout')
511+ self.pdf_program_path = QtGui.QLineEdit(self.pdf_group_box)
512+ self.pdf_program_path.setObjectName('pdf_program_path')
513+ self.pdf_program_path.setReadOnly(True)
514+ self.pdf_program_path.setPalette(self.get_grey_text_palette(True))
515+ self.pdf_program_path_layout.addWidget(self.pdf_program_path)
516+ self.pdf_program_browse_button = QtGui.QToolButton(self.pdf_group_box)
517+ self.pdf_program_browse_button.setObjectName('pdf_program_browse_button')
518+ self.pdf_program_browse_button.setIcon(build_icon(':/general/general_open.png'))
519+ self.pdf_program_browse_button.setEnabled(False)
520+ self.pdf_program_path_layout.addWidget(self.pdf_program_browse_button)
521+ self.pdf_layout.addRow(self.pdf_program_path_layout)
522+ self.pdf_program_path.editingFinished.connect(self.on_pdf_program_path_edit_finished)
523+ self.pdf_program_browse_button.clicked.connect(self.on_pdf_program_browse_button_clicked)
524+ self.pdf_program_check_box.clicked.connect(self.on_pdf_program_check_box_clicked)
525 self.left_layout.addWidget(self.advanced_group_box)
526+ self.left_layout.addWidget(self.pdf_group_box)
527 self.left_layout.addStretch()
528 self.right_layout.addStretch()
529
530@@ -85,8 +120,12 @@
531 checkbox = self.presenter_check_boxes[controller.name]
532 self.set_controller_text(checkbox, controller)
533 self.advanced_group_box.setTitle(UiStrings().Advanced)
534+ self.pdf_group_box.setTitle(translate('PresentationPlugin.PresentationTab', 'PDF options'))
535 self.override_app_check_box.setText(
536 translate('PresentationPlugin.PresentationTab', 'Allow presentation application to be overridden'))
537+ self.pdf_program_check_box.setText(
538+ translate('PresentationPlugin.PresentationTab', 'Use given full path for mudraw or ghostscript binary:'))
539+
540
541 def set_controller_text(self, checkbox, controller):
542 if checkbox.isEnabled():
543@@ -103,6 +142,15 @@
544 checkbox = self.presenter_check_boxes[controller.name]
545 checkbox.setChecked(Settings().value(self.settings_section + '/' + controller.name))
546 self.override_app_check_box.setChecked(Settings().value(self.settings_section + '/override app'))
547+ # load pdf-program settings
548+ enable_pdf_program = Settings().value(self.settings_section + '/enable_pdf_program')
549+ self.pdf_program_check_box.setChecked(enable_pdf_program)
550+ self.pdf_program_path.setReadOnly(not enable_pdf_program)
551+ self.pdf_program_path.setPalette(self.get_grey_text_palette(not enable_pdf_program))
552+ self.pdf_program_browse_button.setEnabled(enable_pdf_program)
553+ pdf_program = Settings().value(self.settings_section + '/pdf_program')
554+ if pdf_program:
555+ self.pdf_program_path.setText(pdf_program)
556
557 def save(self):
558 """
559@@ -128,6 +176,20 @@
560 if Settings().value(setting_key) != self.override_app_check_box.checkState():
561 Settings().setValue(setting_key, self.override_app_check_box.checkState())
562 changed = True
563+
564+ # Save pdf-settings
565+ pdf_program = self.pdf_program_path.text()
566+ enable_pdf_program = self.pdf_program_check_box.checkState()
567+ # If the given program is blank disable using the program
568+ if pdf_program == '':
569+ enable_pdf_program = 0
570+ if pdf_program != Settings().value(self.settings_section + '/pdf_program'):
571+ Settings().setValue(self.settings_section + '/pdf_program', pdf_program)
572+ changed = True
573+ if enable_pdf_program != Settings().value(self.settings_section + '/enable_pdf_program'):
574+ Settings().setValue(self.settings_section + '/enable_pdf_program', enable_pdf_program)
575+ changed = True
576+
577 if changed:
578 self.settings_form.register_post_process('mediaitem_suffix_reset')
579 self.settings_form.register_post_process('mediaitem_presentation_rebuild')
580@@ -143,3 +205,44 @@
581 checkbox = self.presenter_check_boxes[controller.name]
582 checkbox.setEnabled(controller.is_available())
583 self.set_controller_text(checkbox, controller)
584+
585+ def on_pdf_program_path_edit_finished(self):
586+ """
587+ After selecting/typing in a program it is validated that it is a actually ghostscript or mudraw
588+ """
589+ type = None
590+ if self.pdf_program_path.text() != '':
591+ type = PdfController.check_binary(self.pdf_program_path.text())
592+ if not type:
593+ critical_error_message_box(UiStrings().Error,
594+ translate('PresentationPlugin.PresentationTab', 'The program is not ghostscript or mudraw which is required.'))
595+ self.pdf_program_path.setFocus()
596+
597+ def on_pdf_program_browse_button_clicked(self):
598+ """
599+ Select the mudraw or ghostscript binary that should be used.
600+ """
601+ filename = QtGui.QFileDialog.getOpenFileName(self, translate('PresentationPlugin.PresentationTab', 'Select mudraw or ghostscript binary.'))
602+ if filename:
603+ self.pdf_program_path.setText(filename)
604+ self.pdf_program_path.setFocus()
605+
606+ def on_pdf_program_check_box_clicked(self, checked):
607+ """
608+ When checkbox for manual entering pdf-program is clicked,
609+ enable or disable the textbox for the programpath and the browse-button.
610+ """
611+ self.pdf_program_path.setReadOnly(not checked)
612+ self.pdf_program_path.setPalette(self.get_grey_text_palette(not checked))
613+ self.pdf_program_browse_button.setEnabled(checked)
614+
615+ def get_grey_text_palette(self, greyed):
616+ """
617+ Returns a QPalette with greyed out text as used for placeholderText.
618+ """
619+ palette = QtGui.QPalette()
620+ color = self.palette().color(QtGui.QPalette.Active, QtGui.QPalette.Text)
621+ if greyed:
622+ color.setAlpha(128)
623+ palette.setColor(QtGui.QPalette.Active, QtGui.QPalette.Text, color)
624+ return palette
625
626=== modified file 'openlp/plugins/presentations/presentationplugin.py'
627--- openlp/plugins/presentations/presentationplugin.py 2013-10-13 21:07:28 +0000
628+++ openlp/plugins/presentations/presentationplugin.py 2013-11-14 16:44:06 +0000
629@@ -45,9 +45,12 @@
630
631 __default_settings__ = {
632 'presentations/override app': QtCore.Qt.Unchecked,
633+ 'presentations/enable_pdf_program': QtCore.Qt.Unchecked,
634+ 'presentations/pdf_program': '',
635 'presentations/Impress': QtCore.Qt.Checked,
636 'presentations/Powerpoint': QtCore.Qt.Checked,
637 'presentations/Powerpoint Viewer': QtCore.Qt.Checked,
638+ 'presentations/Pdf': QtCore.Qt.Checked,
639 'presentations/presentations files': []
640 }
641
642
643=== modified file 'resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py'
644--- resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py 2013-07-18 19:28:35 +0000
645+++ resources/pyinstaller/hook-openlp.plugins.presentations.presentationplugin.py 2013-11-14 16:44:06 +0000
646@@ -29,4 +29,5 @@
647
648 hiddenimports = ['openlp.plugins.presentations.lib.impresscontroller',
649 'openlp.plugins.presentations.lib.powerpointcontroller',
650- 'openlp.plugins.presentations.lib.pptviewcontroller']
651+ 'openlp.plugins.presentations.lib.pptviewcontroller',
652+ 'openlp.plugins.presentations.lib.pdfcontroller']