| 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 |
import re |
|---|
| 27 |
import TransformBuilder |
|---|
| 28 |
|
|---|
| 29 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 30 |
#~ Constants / Variables / Etc. |
|---|
| 31 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 32 |
|
|---|
| 33 |
_re_coordwithunits = re.compile(r'([-+]?(?:\d+(?:\.\d*)?|\d*\.\d+)(?:[eE][-+]?\d+)?)(\D*)') |
|---|
| 34 |
|
|---|
| 35 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 36 |
#~ Definitions |
|---|
| 37 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 38 |
|
|---|
| 39 |
class SVGItem(object): |
|---|
| 40 |
def InterpretSettings(self, settings): |
|---|
| 41 |
pass |
|---|
| 42 |
|
|---|
| 43 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 44 |
|
|---|
| 45 |
class TransformableSVGItem(SVGItem): |
|---|
| 46 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 47 |
#~ Constants / Variables / Etc. |
|---|
| 48 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 49 |
|
|---|
| 50 |
transformbuilder = TransformBuilder.TransformCommandBuilder() |
|---|
| 51 |
transformfactoryfactory = TransformBuilder.SaveTransformFactory |
|---|
| 52 |
|
|---|
| 53 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 54 |
#~ Public Methods |
|---|
| 55 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 56 |
|
|---|
| 57 |
def InterpretSettings(self, settings): |
|---|
| 58 |
SVGItem.InterpretSettings(self, settings) |
|---|
| 59 |
transform = settings.get('transform', None) |
|---|
| 60 |
if transform: |
|---|
| 61 |
transform = self._asTransform(transform) |
|---|
| 62 |
self.object.SetTransform(transform) |
|---|
| 63 |
|
|---|
| 64 |
x = settings.get('x', None) |
|---|
| 65 |
y = settings.get('y', None) |
|---|
| 66 |
if x is not None or y is not None: |
|---|
| 67 |
x = self._asCoord(x or 0.) |
|---|
| 68 |
y = self._asCoord(y or 0.) |
|---|
| 69 |
self.object.SetPosition((x, y)) |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
#~ helpers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 73 |
|
|---|
| 74 |
def _asCoord(self, coord): |
|---|
| 75 |
try: |
|---|
| 76 |
return float(coord) |
|---|
| 77 |
except ValueError: |
|---|
| 78 |
match = _re_coordwithunits.match(coord) |
|---|
| 79 |
if match: |
|---|
| 80 |
value, units = match.groups() |
|---|
| 81 |
# FIXME |
|---|
| 82 |
print "Warning: unit %r found in coordinate %r" % (units, coord) |
|---|
| 83 |
if units == '%': |
|---|
| 84 |
return None |
|---|
| 85 |
else: |
|---|
| 86 |
return float(value) |
|---|
| 87 |
else: |
|---|
| 88 |
raise |
|---|
| 89 |
|
|---|
| 90 |
def _asCoordList(self, coords): |
|---|
| 91 |
return [self._asCoord(each) for each in coords] |
|---|
| 92 |
|
|---|
| 93 |
def _asCoordTuple(self, coords): |
|---|
| 94 |
return tuple([self._asCoord(each) for each in coords]) |
|---|
| 95 |
|
|---|
| 96 |
def _asTransform(self, transform): |
|---|
| 97 |
return self.transformbuilder.Build(transform, self.transformfactoryfactory()) |
|---|
| 98 |
|
|---|