1 |
jan |
195 |
# Copyright (c) 2001, 2002 by Intevation GmbH |
2 |
|
|
# Authors: |
3 |
|
|
# Jan-Oliver Wagner <[email protected]> |
4 |
|
|
# |
5 |
|
|
# This program is free software under the GPL (>=v2) |
6 |
|
|
# Read the file COPYING coming with Thuban for details. |
7 |
|
|
|
8 |
|
|
__version__ = "$Revision$" |
9 |
|
|
|
10 |
|
|
from messages import EXTENSION_CHANGED, EXTENSION_OBJECTS_CHANGED |
11 |
|
|
|
12 |
|
|
from base import TitledObject, Modifiable |
13 |
|
|
|
14 |
|
|
|
15 |
|
|
class Extension(TitledObject, Modifiable): |
16 |
|
|
|
17 |
|
|
"""Represent a extension. A extension is a package of additional |
18 |
|
|
functionality to Thuban and contains a number of Objects |
19 |
|
|
that can be freely defined in an extension. |
20 |
|
|
Each object must a a TitleObject with additional set "object.name". |
21 |
|
|
|
22 |
|
|
Extension objects send the following message types: |
23 |
|
|
|
24 |
|
|
EXTENSION_CHANGED -- Something in the extension has changed. |
25 |
|
|
|
26 |
|
|
EXTENSION_OBJECTS_CHANGED -- Something in the objects has changed. |
27 |
|
|
|
28 |
|
|
""" |
29 |
|
|
|
30 |
|
|
forwarded_channels = (EXTENSION_CHANGED, EXTENSION_OBJECTS_CHANGED) |
31 |
|
|
|
32 |
|
|
def __init__(self, title): |
33 |
|
|
"""Initialize the extension.""" |
34 |
|
|
TitledObject.__init__(self, title) |
35 |
|
|
self.objects = [] |
36 |
|
|
|
37 |
|
|
def Destroy(self): |
38 |
|
|
for object in self.objects: |
39 |
|
|
object.Destroy() |
40 |
|
|
Modifiable.Destroy(self) |
41 |
|
|
|
42 |
|
|
def AddObject(self, object): |
43 |
|
|
self.objects.append(object) |
44 |
|
|
for channel in self.forwarded_channels: |
45 |
|
|
object.Subscribe(channel, self.forward, channel) |
46 |
|
|
self.changed(EXTENSION_OBJECTS_CHANGED, self) |
47 |
|
|
|
48 |
|
|
def RemoveObject(self, object): |
49 |
|
|
for channel in self.forwarded_channels: |
50 |
|
|
object.Unsubscribe(channel, self.forward, channel) |
51 |
|
|
self.layers.remove(layer) |
52 |
|
|
self.changed(EXTENSION_OBJECTS_CHANGED, self) |
53 |
|
|
object.Destroy() |
54 |
|
|
|
55 |
|
|
def Objects(self): |
56 |
|
|
return self.objects |
57 |
|
|
|
58 |
|
|
def HasObjects(self): |
59 |
|
|
return len(self.objects) > 0 |
60 |
|
|
|
61 |
|
|
def FindObject(self, title): |
62 |
|
|
"""Find an object by title. If found, return it, else return None.""" |
63 |
|
|
for object in self.objects: |
64 |
|
|
if object.title == title: |
65 |
|
|
return object |
66 |
|
|
return None |
67 |
|
|
|
68 |
|
|
def forward(self, *args): |
69 |
|
|
"""Reissue events""" |
70 |
|
|
if len(args) > 1: |
71 |
|
|
args = (args[-1],) + args[:-1] |
72 |
|
|
apply(self.issue, args) |
73 |
|
|
|
74 |
|
|
def WasModified(self): |
75 |
|
|
"""Return true if something of the extension was modified""" |
76 |
|
|
if self.modified: |
77 |
|
|
return 1 |
78 |
|
|
else: |
79 |
|
|
return 0 |
80 |
|
|
|
81 |
|
|
def UnsetModified(self): |
82 |
|
|
"""Unset the modified flag of the extension""" |
83 |
|
|
Modifiable.UnsetModified(self) |
84 |
bh |
217 |
|
85 |
|
|
def TreeInfo(self): |
86 |
|
|
return ("Extension: %s" % self.title, |
87 |
|
|
["%s: %s" % (object.title, object.name) |
88 |
|
|
for object in self.objects]) |