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
=== modified file 'a4lib/app.py'
--- a4lib/app.py 2010-05-27 14:23:58 +0000
+++ a4lib/app.py 2010-05-28 14:36:37 +0000
@@ -6,7 +6,7 @@
6import optparse6import optparse
7import os7import os
8import gtk8import gtk
9from a4lib.svgimage import SVGImage, SVGImageError9from a4lib.presentation import Presentation, PresentationError
1010
11class WindowMain(object):11class WindowMain(object):
12 """The main window of the application."""12 """The main window of the application."""
@@ -32,8 +32,8 @@
32 self.set_status('Loading {0}...'.format(file_name))32 self.set_status('Loading {0}...'.format(file_name))
33 try:33 try:
34 # Try to open a file.34 # Try to open a file.
35 image = SVGImage(file_name)35 image = Presentation(file_name)
36 except SVGImageError as error:36 except PresentationError as error:
37 # The file doesn't exist, or is not an SVG file. Show an error37 # The file doesn't exist, or is not an SVG file. Show an error
38 # dialog and don't do anything else.38 # dialog and don't do anything else.
39 dialog = gtk.MessageDialog(39 dialog = gtk.MessageDialog(
4040
=== renamed file 'a4lib/svgimage.py' => 'a4lib/presentation.py'
--- a4lib/svgimage.py 2010-05-27 13:58:29 +0000
+++ a4lib/presentation.py 2010-05-28 14:36:37 +0000
@@ -3,16 +3,18 @@
33
4"""Code to deal with SVG images."""4"""Code to deal with SVG images."""
55
6import json
7from xml.dom import minidom
6import rsvg8import rsvg
7from glib import GError9from glib import GError
810
911
10class SVGImageError(StandardError):12class PresentationError(StandardError):
11 """Error raised when an operation with an image fails."""13 """Error raised when an operation with an image fails."""
1214
1315
14class SVGImage(object):16class Presentation(object):
15 """An object that represents an image contained in a SVG file."""17 """An object that represents a presentation."""
1618
17 def __init__(self, file_name):19 def __init__(self, file_name):
18 self.file_name = file_name20 self.file_name = file_name
@@ -20,9 +22,24 @@
20 svg_data = open(file_name).read()22 svg_data = open(file_name).read()
21 self._svg_handler = rsvg.Handle(data=svg_data)23 self._svg_handler = rsvg.Handle(data=svg_data)
22 except IOError as error:24 except IOError as error:
23 raise SVGImageError(error.args[1])25 raise PresentationError(error.args[1])
24 except GError as error:26 except GError as error:
25 raise SVGImageError('Unknown file type')27 raise PresentationError('Unknown file type')
26 self.width = self._svg_handler.get_property('width')28
27 self.height = self._svg_handler.get_property('height')29 dom = minidom.parseString(svg_data)
30 for node in dom.getElementsByTagName('metadata'):
31 if node.getAttribute('id') == 'a4-presentation-information':
32 data = u''.join(
33 child.data for child in node.childNodes
34 if child.nodeType == node.TEXT_NODE)
35 try:
36 self.information = json.loads(data)
37 except ValueError:
38 raise PresentationError('File corrupted')
39 break
40 else:
41 raise PresentationError('Not a presentation')
42
43 self.width = self._svg_handler.props.width
44 self.height = self._svg_handler.props.height
28 self.render_cairo = self._svg_handler.render_cairo45 self.render_cairo = self._svg_handler.render_cairo

Subscribers

People subscribed via source and target branches