Changeset 5955 for main/waeup.sirp/trunk/src/waeup/sirp
- Timestamp:
- 22 Apr 2011, 01:35:13 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py
r5899 r5955 9 9 # BBB 10 10 from zope.app.catalog.interfaces import ICatalog 11 from zope.interface import Interface, Attribute 11 from zope.interface import Interface, Attribute, implements 12 12 from zope import schema 13 13 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm 14 14 from waeup.sirp.permissions import RoleSource 15 15 16 class IThemeProvider(Interface): 17 """A component that delivers all themes defined. 18 19 We normally do not deal with browser-related stuff in `waeup.sirp` 20 but leave that to the `browser` subpackage. With themes (aka 21 skins) we cannot follow that path because we need a theme as an 22 attribute of each `University` instance. 23 24 Therefore we must tell the browser subpackage how we expect themes 25 to be announced code-wise. 26 27 What we tell here is that we might ask for a utility providing 28 IThemeProvider and that this component then should be callable to 29 give us a list of themes and their respective internal names. 30 """ 31 def __call__(): 32 """Get a list of all themes available. 33 34 Returns a list of ``(<NAME>, <THEME>)`` tuples where 35 ``<NAME>`` is the internal name under which a theme was 36 registered and ``<THEME>`` is the real theme. 37 """ 38 39 class ThemeSource(BasicSourceFactory): 40 """A source for themes. 41 """ 42 def getValues(self): 43 """Get names of themes. 44 """ 45 theme_provider = getUtility(IThemeProvider, name="default") 46 return [x for x, y in theme_provider()] 47 48 def getTitle(self, value): 49 """Get a user-presentable description for a theme. 50 """ 51 theme_provider = getUtility(IThemeProvider, name="default") 52 for name, theme in theme_provider(): 53 if name == value: 54 return theme.description 55 return u'unnamed' 56 57 class ThemeSourceBinder(object): 58 """A source binder for the `ThemeSource`. 59 60 Normally, we can pass instances of a source (like `ThemeSource`) 61 directly to fields in interfaces (writing something like ``source 62 = ThemeSource()``. With `ThemeSource` we cannot do this, because 63 the set of available themes is not available before the whole 64 `waeup.sirp` package was grokked (and parsed). 65 66 We bypass that problem by defining this trivial source-binder, 67 which is asked for themes only when the values of the source are 68 really needed and after the process of grokking and parsing 69 everything on startup. 70 71 So, although this binder binds to some context (`IUniversity` is 72 currently the only interface making use of this source, so 73 `University` instances are the only context used), the context 74 does not really matter. 75 """ 76 implements(schema.interfaces.IContextSourceBinder) 77 78 def __call__(self, context): 79 return ThemeSource() 80 16 81 class FatalCSVError(Exception): 17 82 """Some row could not be processed. … … 26 91 SimpleTerm(value, value, title) for title, value in terms]) 27 92 93 28 94 class IWAeUPObject(Interface): 29 95 """A WAeUP object. … … 40 106 required = True, 41 107 ) 42 108 109 43 110 skin = schema.Choice( 44 111 title = u'Skin', 45 112 default = u'waeuptheme-gray1.css', 46 #values = ['waeuptheme-gray1.css', 'waeuptheme-red1.css'], 47 vocabulary = SimpleWAeUPVocabulary( 48 ('Henrik\'s Gray Theme', 'waeuptheme-gray1.css'), ('Uli\'s Red Theme', 'waeuptheme-red1.css')), 113 source = ThemeSourceBinder(), 49 114 required = True, 50 115 )
Note: See TracChangeset for help on using the changeset viewer.