/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/extensionregistry.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Thuban/UI/extensionregistry.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2580 - (hide annotations)
Thu Mar 10 22:39:11 2005 UTC (19 years, 11 months ago) by jan
Original Path: trunk/thuban/Thuban/UI/extensionregistry.py
File MIME type: text/x-python
File size: 3591 byte(s)
(ExtensionDesc.__init__): Added »···optional parameter init_callback.
ExtensionDesc.init_ext): New. Executes the callback and sets
a status.

1 jan 2580 # Copyright (C) 2004, 2005 by Intevation GmbH
2 jan 2353 # Authors:
3 jan 2580 # Jan-Oliver Wagner <[email protected]> (2004, 2005)
4 jan 2353 #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with Thuban for details.
7    
8     """
9     Registry for Extensions.
10    
11     This module defines a registry for Extensions.
12     This is basically used for displaying information on
13     the active Extensions in the general About-Dialog.
14     A registration is not mandatory to make a Extension
15     work, but any Extension should register to provide
16     a complete information in the Thuban About Dialog.
17    
18     A Extension should define a ExtensionDesc object
19     and apply ext_registry.add() to register it.
20     """
21    
22     __version__ = "$Revision$"
23     # $Source$
24     # $Id$
25    
26 jan 2580 from Thuban import _
27    
28 jan 2353 class ExtensionDesc:
29    
30     """
31     A description of a Thuban Extension.
32     """
33    
34 jan 2580 def __init__(self, name, version, authors, copyright, desc,
35     init_callback = None):
36 jan 2353 """
37     Initialize a new Thuban Extension information.
38    
39     name -- The name of the Thuban Extension.
40     Example: 'gns2shp'
41    
42     version -- The version number of the Thuban Extension.
43     Example: '1.0.0'
44    
45     authors -- List of authors.
46     Example: [ 'Jan-Oliver Wagner' ]
47    
48     copyright -- Copyright notice.
49     Example: '2003, 2004 Intevation GmbH'
50    
51     desc -- Short description of the Thuban Extension.
52     Example: _('''
53     Converts GNS (Geographical Name Service of NIMA)
54     to Shapefile format and displays the data.
55     ''')
56 jan 2580 init_callback -- a callback method that is executed if not
57     None. This method should contain gui specific
58     initializations of the extension.
59     Default is None.
60 jan 2353
61 jan 2580 This callback should return None if
62     the intialisation as successful. Else
63     a string describing the problems during
64     intialization.
65 jan 2353 """
66     self.name = name
67     self.version = version
68     self.authors = authors
69     self.copyright = copyright
70     self.desc = desc
71 jan 2580 self.init_callback = init_callback
72     self.status = _("Initialization not yet requested.")
73 jan 2353
74 jan 2580 def init_ext(self):
75     """Execute the init callback for the extension.
76    
77     Do nothing if the callback is None.
78    
79     It is expected that the callback function returns
80     None if all was OK and a string if something was wrong.
81     The string is believed to describe the problems.
82     """
83     if self.init_callback is not None:
84     result = self.init_callback()
85     if result is not None:
86     self.status = result
87     else:
88     self.status = _("Initialization successful.")
89    
90 jan 2353 class ExtensionRegistry:
91    
92     """
93     A ExtensionRegistry keeps information on the registered
94     Thuban Extensions.
95    
96     The registry will raise a exception either when the version
97     required for the Extensions exceeds the version of the currently
98     running Thuban or if the name of a registered extension already
99     is used for registering another extension.
100     """
101    
102     def __init__(self):
103     self.registry = []
104    
105     def __nonzero__(self):
106     return len(self.registry) <> 0
107    
108     def __iter__(self):
109     return iter(self.registry)
110    
111     def add(self, ext):
112     self.registry.append(ext)
113    
114    
115     # The central Thuban Extensions registry
116     ext_registry = ExtensionRegistry()

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26