/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/extension.py
ViewVC logotype

Contents of /branches/WIP-pyshapelib-bramz/Thuban/Model/extension.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 374 - (show annotations)
Mon Jan 27 14:20:02 2003 UTC (22 years, 1 month ago) by jan
Original Path: trunk/thuban/Thuban/Model/extension.py
File MIME type: text/x-python
File size: 2701 byte(s)
Replace user string by _() for i18n.

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

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26