Commits

megamahi  committed f772bb7

Added really-useless(except for Moksha) text widget

  • Participants
  • Parent commits 988e4ab

Comments (0)

Files changed (3)

File tw2/dyntext/__init__.py

-from widgets import DynamicTextWidget
+from widgets import DynamicTextWidget, PollingDynamicTextWidget

File tw2/dyntext/samples.py

 import webob
 
 class DemoDynamicTextWidget(widgets.DynamicTextWidget):
+    initial_value = "I don't really do anything unless you call setDynamicText()."
+
+class DemoPollingDynamicTextWidget(widgets.PollingDynamicTextWidget):
     # Provide default parameters, value, etc... here
     # default = <some-default-value>
     data_url = '/dynamic_text_demo'
     
-    pass
-
     @classmethod
     def request(cls, req):
         lottery_numbers = ", ".join([str(random.randint(1,100)) for x in range(5)])

File tw2/dyntext/widgets.py

 from tw2.jquery import jquery_js
 import json
 
-setup_call = twc.js_function('setupPollingDynText')
-
 class DynamicTextWidget(twc.Widget):
     template = "mako:tw2.dyntext.templates.dyntext"
 
-    # declare static resources here
-    # you can remove either or both of these, if not needed
     resources = [
         twc.JSLink(modname=__name__, filename='static/dyntext.js'),
         jquery_js
     ]
 
+    initial_text = twc.Param('Initial text to place in the widget', default='')
+
+    def prepare(self):
+        super(DynamicTextWidget, self).prepare()
+        # put code here to run just before the widget is displayed
+        self.selector = self.attrs['id'].replace(':', '\\:')
+
+
+setup_call = twc.js_function('setupPollingDynText')
+
+class PollingDynamicTextWidget(DynamicTextWidget):
     data_url = twc.Param('(str) URL where JSON data should be pulled from', default=None)
 
     interval = twc.Param('(int) Polling interval in milliseconds', default=5000)
 
-    initial_text = twc.Param('Initial text to place in the widget', default='')
-
     def prepare(self):
         if self.data_url is None:
             raise ValueError, "DynamicTextWidget data_url parameter must be set"
         elif 'str' not in str(type(self.data_url)):
             raise ValueError, "DynamicTextWidget data_url parameter must be a string"
 
-        super(DynamicTextWidget, self).prepare()
+        super(PollingDynamicTextWidget, self).prepare()
         # put code here to run just before the widget is displayed
-        self.selector = self.attrs['id'].replace(':', '\\:')
         self.add_call(setup_call(self.selector, self.data_url, self.interval))