Package muntjac :: Package addon :: Package refresher :: Module refresher
[hide private]
[frames] | no frames]

Source Code for Module muntjac.addon.refresher.refresher

  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  from muntjac.ui.abstract_component import AbstractComponent 
 17  from muntjac.addon.refresher.ui.v_refresher import VRefresher 
 18   
 19   
20 -class Refresher(AbstractComponent):
21 """A Refresher is an non-visual component that polls the server for 22 GUI updates. 23 24 This makes asynchronous UI changes possible, that will be rendered even 25 if the user doesn't initiate a server-cycle explicitly. 26 27 @author Henrik Paul 28 """ 29 30 CLIENT_WIDGET = None #ClientWidget(com.github.wolfie.refresher.client.ui.VRefresher) 31 32 TYPE_MAPPING = 'com.github.wolfie.refresher.Refresher' 33 34 _DEFAULT_REFRESH_INTERVAL = 1000 35
36 - def __init__(self):
37 """Creates a new L{Refresher} instance, with a default refresh interval 38 of L{Refresher.DEFAULT_REFRESH_INTERVAL}. 39 """ 40 super(Refresher, self).__init__() 41 42 self._refreshListeners = list() 43 self._refreshIntervalInMillis = self._DEFAULT_REFRESH_INTERVAL
44 45
46 - def paintContent(self, target):
47 target.addAttribute('pollinginterval', self._refreshIntervalInMillis)
48 49
50 - def setRefreshInterval(self, intervalInMillis):
51 """Define a refresh interval. 52 53 @param intervalInMillis: 54 The desired refresh interval in milliseconds. An interval 55 of zero or less temporarily inactivates the refresh. 56 """ 57 self._refreshIntervalInMillis = intervalInMillis 58 self.requestRepaint()
59 60
61 - def getRefreshInterval(self):
62 """Get the currently used refreshing interval. 63 64 @return: The refresh interval in milliseconds. A result of zero or 65 less means that the refresher is currently inactive. 66 """ 67 return self._refreshIntervalInMillis
68 69
70 - def changeVariables(self, source, variables):
71 super(Refresher, self).changeVariables(source, variables) 72 73 if VRefresher.VARIABLE_REFRESH_EVENT in variables: 74 self.fireRefreshEvents()
75 76
77 - def fireRefreshEvents(self):
78 for listener in self._refreshListeners: 79 listener.refresh(self)
80 81
82 - def addListener(self, listener, iface=None):
83 """Add a listener that will be triggered whenever this instance 84 refreshes itself 85 86 @param listener: 87 the listener 88 @return: C{True} if the adding was successful. C{False} if the 89 adding was unsuccessful, or C{listener} is C{None}. 90 """ 91 if isinstance(listener, RefreshListener): 92 self._refreshListeners.append(listener) 93 else: 94 super(Refresher, self).addListener(listener, iface)
95 96
97 - def removeListener(self, listener, iface=None):
98 """Removes a L{RefreshListener} from this instance. 99 100 @param listener: 101 the listener to be removed. 102 @return: C{True} if removal was successful. A C{False} most often 103 means that C{listener} wasn't added to this instance to 104 begin with. 105 """ 106 if isinstance(listener, RefreshListener): 107 self._refreshListeners.remove(listener) 108 else: 109 super(Refresher, self).removeListener(listener, iface)
110 111
112 -class RefreshListener(object):
113
114 - def refresh(self, source):
115 pass
116