root/trunk/RBRapier/RBRapier/Formats/SVG/SVGSkin/SVGItems/Groups.py

Revision 671, 2.9 kB (checked in by sholloway, 5 years ago)

*** empty log message ***

Line 
1 #!/usr/bin/env python
2 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 ##~ License
4 ##~
5 ##- The RuneBlade Foundation library is intended to ease some
6 ##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.)
7 ##- applications, while providing the flexibility to modularly change the
8 ##- architecture. Enjoy.
9 ##~
10 ##~ Copyright (C) 2002  TechGame Networks, LLC.
11 ##~
12 ##~ This library is free software; you can redistribute it and/or
13 ##~ modify it under the terms of the BSD style License as found in the
14 ##~ LICENSE file included with this distribution.
15 ##~
16 ##~ TechGame Networks, LLC can be reached at:
17 ##~ 3578 E. Hartsel Drive #211
18 ##~ Colorado Springs, Colorado, USA, 80920
19 ##~
20 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21
22 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 #~ Imports
24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25
26 from Styled import StyledSVGItem
27
28 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29 #~ Definitions
30 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31
32 class GroupSVGItem(StyledSVGItem):
33     pass
34
35 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36
37 class ContainerSVGItem(GroupSVGItem):
38     def InterpretSettings(self, settings):
39         GroupSVGItem.InterpretSettings(self, settings)
40
41         width = settings.get('width', None)
42         if width is not None:
43             width = self._asCoord(width)
44             if width < 0 and width is not None:
45                 raise ValueError, '"width" attribute can not be negative"'
46         height = settings.get('height', None)
47         if height is not None:
48             height = self._asCoord(height)
49             if height < 0 and height is not None:
50                 raise ValueError, '"height" attribute can not be negative"'
51         self.object.SetDimensions(width, height)
52
53         viewBox = settings.get('viewBox', None)
54         if 'viewBox' in settings:
55             viewBox = self._asViewBox(viewBox)
56         self.object.SetViewBox(viewBox)
57
58         alignment = self._asAlignmentList(settings.get('preserveAspectRatio', ''))
59         self.object.SetAlignment(*alignment) # xalign, yalign, alignstyle
60
61     #~ helper methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62
63     def _asAlignmentList(self, alignment):
64         alignment = alignment.strip()
65         if alignment.lower() == 'none':
66             return (None, None, None)
67         else:
68             alignment = alignment.replace(',', ' ')
69             if ' ' in alignment:
70                 alignment, specifier = alignment.split()
71             else: specifier = 'meet'
72             return (alignment[0:4], alignment[4:8], specifier.lower())
73
74     def _asViewBox(self, viewBox):
75         if not isinstance(viewBox, (list, tuple)):
76             viewBox = map(self._asCoord, viewBox.replace(',', ' ').split())
77         if len(viewBox) != 4:
78             raise ValueError, "viewBox must have four elements, but value has %s (%r)" % (len(viewBox), viewBox)
79         return list(viewBox)
80
Note: See TracBrowser for help on using the browser.