16 |
# write to the Free Software Foundation, Inc., 59 Temple Place |
# write to the Free Software Foundation, Inc., 59 Temple Place |
17 |
# - Suite 330, Boston, MA 02111-1307, USA. |
# - Suite 330, Boston, MA 02111-1307, USA. |
18 |
# |
# |
19 |
# Copyright 2001-2002 Free Software Foundation |
# Copyright 2001-2003 Free Software Foundation |
20 |
# |
# |
21 |
# FILE: |
# FILE: |
22 |
# reports/Incubator.py |
# reports/Incubator.py |
27 |
# NOTES: |
# NOTES: |
28 |
# |
# |
29 |
|
|
30 |
from gnue.common import GDebug |
from gnue.common import GDebug, GParserHelpers |
31 |
from gnue.reports import GRParser, GRReport, GRLayout |
from gnue.reports.base import GRParser, GRReport |
32 |
from gnue.designer.Incubator import * |
from gnue.reports.base import layout as GRLayout |
33 |
|
from gnue.designer.base.Incubator import BaseIncubator |
34 |
def createObject(instance, report, tag, type=None, parent=None, |
|
35 |
parentHint=None, attributes={}): |
class Incubator(BaseIncubator): |
36 |
|
|
37 |
|
elements = GRParser.getXMLelements() |
38 |
GDebug.printMesg(3,'Creating a "%s" object' % tag) |
|
39 |
GDebug.printMesg(6,"Object's parent is %s" % parentHint) |
def createObject(self, rootObject, tag, parent, attributes={}, select=1): |
40 |
|
# Handle GRPassThru |
41 |
try: |
if tag.find(':')+1: |
42 |
name = attributes['name'] |
o = self._handlePassThru(rootObject, tag, parent, attributes, select) |
43 |
except KeyError: |
if o: |
44 |
name = instance.getNextGenericName(tag) |
self.instance.dispatchEvent('ObjectCreated',object=o, originator=__name__) |
45 |
|
if select: |
46 |
try: |
self.instance.dispatchEvent('ObjectSelected',object=object, originator=__name__) |
47 |
objclass = elements[tag]['BaseClass'] |
return o |
|
if elements[tag].has_key('Attributes'): |
|
|
attrs = elements[tag]['Attributes'] |
|
48 |
else: |
else: |
49 |
attrs = {} |
return BaseIncubator.createObject(self, rootObject, tag, parent, attributes, select) |
|
except KeyError: |
|
|
GDebug.printMesg(1, "Attempted to create a '%s', " |
|
|
"but I don't know what to do!" % tag) |
|
|
return |
|
|
|
|
|
|
|
|
parent = None |
|
|
if tag in ('layout',): |
|
|
parent = report |
|
|
|
|
|
o = objclass(parent or parentHint) |
|
|
|
|
|
# Pull default values for any attributes not supplied |
|
|
for attr in attrs.keys(): |
|
|
if not attributes.has_key(attr): |
|
|
if attrs[attr].has_key('Default'): |
|
|
attributes[attr] = attrs[attr]['Typecast'](attrs[attr]['Default']) |
|
|
|
|
|
for attr in attributes.keys(): |
|
|
if attrs.has_key(attr): |
|
|
o.__dict__[attr] = attributes[attr] |
|
|
o.name = name |
|
|
instance.nameMappings[o.name] = o |
|
|
o._buildObject() |
|
|
instance.onCreateObject(o, __name__) |
|
|
instance.onSetCurrentObject(o, __name__) |
|
|
return o |
|
|
|
|
|
|
|
|
def reparentObject(instance, report, object, newParent): |
|
|
if object._parent == newParent: |
|
|
return |
|
|
|
|
|
# TODO |
|
|
pass |
|
|
|
|
|
|
|
|
def deleteObject(instance, report, object, newCurrentObject=None, firstRun=1): |
|
|
|
|
|
if firstRun: |
|
|
newCurrentObject = object._parent |
|
|
parent = object._parent |
|
|
|
|
|
for child in object._children: |
|
|
child.deleteObject(instance, report, child, firstRun=0) |
|
|
|
|
|
instance.onDeleteObject(object, __name__) |
|
|
|
|
|
if firstRun: |
|
|
o = parent |
|
|
while not isinstance(o, GRReport.GRReport): |
|
|
o._buildObject() |
|
|
o = o._parent |
|
|
|
|
|
if newCurrentObject: |
|
|
instance.onSetCurrentObject(newCurrentObject, __name__) |
|
|
|
|
|
|
|
|
|
|
|
# |
|
|
# Figure out tag dependencies |
|
|
# |
|
|
elements = GRParser.getXMLelements() |
|
|
elementMapping = {} |
|
|
calcDependencies(elements, elementMapping) |
|
50 |
|
|
51 |
|
|
52 |
|
def _handlePassThru(self, rootObject, tag, parent, |
53 |
|
attributes={}, select=1): |
54 |
|
# handle <out:region name="primary"> when |
55 |
|
# xmlns:out="GNUe:Reports:Labels" |
56 |
|
try: |
57 |
|
name = attributes['name'] |
58 |
|
except KeyError: |
59 |
|
name = tag[tag.find(':')+1:] |
60 |
|
|
61 |
|
objclass = GRLayout.GRPassThru |
62 |
|
o = objclass(parent) |
63 |
|
|
64 |
|
# Add any GContent |
65 |
|
try: |
66 |
|
GParserHelpers.GContent(o, attributes['_content_']) |
67 |
|
except KeyError: |
68 |
|
pass |
69 |
|
|
70 |
|
o.__dict__.update(attributes) |
71 |
|
o._xmltag = tag[tag.find(':')+1:] |
72 |
|
o._listedAttributes = attributes.keys() |
73 |
|
o._xmlnamespace = rootObject.findChildOfType('GRLayout')._xmlchildnamespace |
74 |
|
|
75 |
|
o.name = name |
76 |
|
self.instance.nameMappings[o.name] = o |
77 |
|
o._buildObject() |
78 |
|
return o |