Package muntjac :: Package terminal :: Module theme_resource
[hide private]
[frames] | no frames]

Source Code for Module muntjac.terminal.theme_resource

 1  # Copyright (C) 2012 Vaadin Ltd.  
 2  # Copyright (C) 2012 Richard Lincoln 
 3  #  
 4  # Licensed under the Apache License, Version 2.0 (the "License");  
 5  # you may not use this file except in compliance with the License.  
 6  # You may obtain a copy of the License at  
 7  #  
 8  #     http://www.apache.org/licenses/LICENSE-2.0  
 9  #  
10  # Unless required by applicable law or agreed to in writing, software  
11  # distributed under the License is distributed on an "AS IS" BASIS,  
12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
13  # See the License for the specific language governing permissions and  
14  # limitations under the License. 
15   
16  """A named theme dependent resource.""" 
17   
18  from muntjac.terminal.resource import IResource 
19   
20   
21 -class ThemeResource(IResource):
22 """C{ThemeResource} is a named theme dependent resource 23 provided and managed by a theme. The actual resource contents are 24 dynamically resolved to comply with the used theme by the terminal 25 adapter. This is commonly used to provide static images, flash, 26 java-applets, etc for the terminals. 27 28 @author: Vaadin Ltd. 29 @author: Richard Lincoln 30 @version: 1.1.2 31 """ 32
33 - def __init__(self, resourceId):
34 """Creates a resource. 35 36 @param resourceId: 37 the Id of the resource. 38 """ 39 # Id of the terminal managed resource. 40 self._resourceID = None 41 42 if resourceId is None: 43 raise ValueError, 'IResource ID must not be null' 44 45 if len(resourceId) == 0: 46 raise ValueError, 'IResource ID can not be empty' 47 48 if resourceId[0] == '/': 49 raise ValueError, \ 50 'IResource ID must be relative (can not begin with /)' 51 52 self._resourceID = resourceId
53 54
55 - def __eq__(self, obj):
56 """Tests if the given object equals this IResource. 57 58 @param obj: 59 the object to be tested for equality. 60 @return: C{True} if the given object equals this Icon, 61 C{False} if not. 62 """ 63 return (isinstance(obj, ThemeResource) 64 and self._resourceID == obj.resourceID)
65 66
67 - def __ne__(self, obj):
68 return (not isinstance(obj, ThemeResource) 69 or self._resourceID != obj.resourceID)
70 71
72 - def __hash__(self):
73 return hash(self._resourceID)
74 75
76 - def __str__(self):
77 return str(self._resourceID)
78 79
80 - def getResourceId(self):
81 """Gets the resource id. 82 83 @return: the resource id. 84 """ 85 return self._resourceID
86 87
88 - def getMIMEType(self):
89 """@see: L{IResource.getMIMEType}""" 90 91 # FIXME: circular import 92 from muntjac.service.file_type_resolver import FileTypeResolver 93 94 return FileTypeResolver.getMIMEType(self.getResourceId())
95