A4

Merge lp:~andrea.corbellini/a4/parser into lp:a4

Proposed by Andrea Corbellini
Status: Merged
Merged at revision: 4
Proposed branch: lp:~andrea.corbellini/a4/parser
Merge into: lp:a4
Diff against target: 78 lines (+27/-10)
2 files modified
a4lib/app.py (+3/-3)
a4lib/presentation.py (+24/-7)
To merge this branch: bzr merge lp:~andrea.corbellini/a4/parser
Reviewer Review Type Date Requested Status
Andrea Colangelo Approve
Review via email: mp+26311@code.launchpad.net

Commit message

Parse the SVG file to look for presentation information.

Description of the change

This code looks for a <metadata> tag with the id "a4-presentation-information" into the SVG file. This tag will contain all the information about the presentation (e.g. the path and the sequence of animations).

Here's how you can test this change:

1. with your favorite editor, create an SVG document;
2. open it with a text editor and put into the root element (<svg>) the following code:

  <metadata id="a4-presentation-information">{"key": "value"}</metadata>

3. save and open the file with A4.

Now, if you introspect the a4lib.presentation.Presentation object you should see that its `information` attribute contains exactly this value:

  {u'key': u'value'}

See also my mail to the mailing list.

To post a comment you must log in.
Revision history for this message
Andrea Colangelo (warp10) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'a4lib/app.py'
2--- a4lib/app.py 2010-05-27 14:23:58 +0000
3+++ a4lib/app.py 2010-05-28 14:36:37 +0000
4@@ -6,7 +6,7 @@
5 import optparse
6 import os
7 import gtk
8-from a4lib.svgimage import SVGImage, SVGImageError
9+from a4lib.presentation import Presentation, PresentationError
10
11 class WindowMain(object):
12 """The main window of the application."""
13@@ -32,8 +32,8 @@
14 self.set_status('Loading {0}...'.format(file_name))
15 try:
16 # Try to open a file.
17- image = SVGImage(file_name)
18- except SVGImageError as error:
19+ image = Presentation(file_name)
20+ except PresentationError as error:
21 # The file doesn't exist, or is not an SVG file. Show an error
22 # dialog and don't do anything else.
23 dialog = gtk.MessageDialog(
24
25=== renamed file 'a4lib/svgimage.py' => 'a4lib/presentation.py'
26--- a4lib/svgimage.py 2010-05-27 13:58:29 +0000
27+++ a4lib/presentation.py 2010-05-28 14:36:37 +0000
28@@ -3,16 +3,18 @@
29
30 """Code to deal with SVG images."""
31
32+import json
33+from xml.dom import minidom
34 import rsvg
35 from glib import GError
36
37
38-class SVGImageError(StandardError):
39+class PresentationError(StandardError):
40 """Error raised when an operation with an image fails."""
41
42
43-class SVGImage(object):
44- """An object that represents an image contained in a SVG file."""
45+class Presentation(object):
46+ """An object that represents a presentation."""
47
48 def __init__(self, file_name):
49 self.file_name = file_name
50@@ -20,9 +22,24 @@
51 svg_data = open(file_name).read()
52 self._svg_handler = rsvg.Handle(data=svg_data)
53 except IOError as error:
54- raise SVGImageError(error.args[1])
55+ raise PresentationError(error.args[1])
56 except GError as error:
57- raise SVGImageError('Unknown file type')
58- self.width = self._svg_handler.get_property('width')
59- self.height = self._svg_handler.get_property('height')
60+ raise PresentationError('Unknown file type')
61+
62+ dom = minidom.parseString(svg_data)
63+ for node in dom.getElementsByTagName('metadata'):
64+ if node.getAttribute('id') == 'a4-presentation-information':
65+ data = u''.join(
66+ child.data for child in node.childNodes
67+ if child.nodeType == node.TEXT_NODE)
68+ try:
69+ self.information = json.loads(data)
70+ except ValueError:
71+ raise PresentationError('File corrupted')
72+ break
73+ else:
74+ raise PresentationError('Not a presentation')
75+
76+ self.width = self._svg_handler.props.width
77+ self.height = self._svg_handler.props.height
78 self.render_cairo = self._svg_handler.render_cairo

Subscribers

People subscribed via source and target branches