Commits

Ralph Bean  committed 4edfe4d

big initial commit -- works

  • Participants
  • Parent commits f1d519d

Comments (0)

Files changed (13)

 *.swp
 ez_setup
 devdata.db
-tw2*
 virtualenv-apply
 devdata.db*
 data
 apply.egg-info
 somedb.db
 apply/templates/usr
+tw2.tipster.egg-info
+recursive-include tw2/tipster/static *
+recursive-include tw2/tipster/templates *
+include README.rst
+Cute little tip widget for your websites!
+[egg_info]
+
+[nosetests]
+where = tests
+from setuptools import setup, find_packages
+
+setup(
+    name='tw2.tipster',
+    version='2.0b1',
+    description='Tips for your website :)',
+    author='Ralph Bean',
+    author_email='ralph.bean@gmail.com',
+    license='MIT',
+    url='',
+    install_requires=[
+        "tw2.jquery.plugins.ui",
+        ## Add other requirements here
+        # "Genshi",
+        ],
+    packages=find_packages(exclude=['ez_setup', 'tests']),
+    namespace_packages = ['tw2'],
+    zip_safe=False,
+    include_package_data=True,
+    test_suite = 'nose.collector',
+    entry_points="""
+        [tw2.widgets]
+        # Register your widgets so they can be listed in the WidgetBrowser
+        widgets = tw2.tipster
+    """,
+    keywords = [
+        'toscawidgets.widgets',
+    ],
+    classifiers = [
+        'Development Status :: 3 - Alpha',
+        'Environment :: Web Environment',
+        'Environment :: Web Environment :: ToscaWidgets',
+        'Topic :: Software Development :: Libraries :: Python Modules',
+        'Topic :: Software Development :: Widget Sets',
+        'Intended Audience :: Developers',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+    ],
+)

File tw2/__init__.py

+__import__('pkg_resources').declare_namespace(__name__)

File tw2/tipster/__init__.py

+from widgets import *

File tw2/tipster/base.py

+
+import tw2.core as twc
+
+tipster_js = twc.JSLink(filename='static/js/tipster.js', modname='tw2.tipster')

File tw2/tipster/samples.py

+"""
+Here you can create samples of your widgets by providing default parameters,
+inserting them in a container widget, mixing them with other widgets, etc...
+These samples will appear in the WidgetBrowser
+
+See http://toscawidgets.org/documentation/WidgetBrowser for more information
+"""
+
+import widgets
+
+class DemoTipsterWidget(widgets.TipsterWidget):
+    tips = [
+        "Here's a tip:  Wash your face!",
+        "No really, wash your face!",
+        "You know... if you specify a stopTipsURL you can stop tips.",
+        "blah",
+    ]
+    stopTipsURL = 'this-url-doesnot-exist____you-are-responsible-for-backend'

File tw2/tipster/static/js/tipster.js

+function setupTipster(selector, tips, stopTipsURL) {
+        $(document).ready( function() {
+                if ( window._tipster === undefined ) { window._tipster = {}; }
+                if ( window._tipster[selector] === undefined ) {
+                        window._tipster[selector] = {};
+                }
+                window._tipster[selector]['tips'] = tips;
+                window._tipster[selector]['stopTipsURL'] = stopTipsURL;
+                window._tipster[selector]['i'] = Math.floor(
+                        Math.random()*tips.length);
+
+                nextTip(selector);
+
+        });
+}
+function closeTip(selector) {
+        $('#'+selector).slideUp('slow');
+}
+function stopTips(selector) {
+        closeTip(selector);
+        console.log('trying');
+        console.log(window._tipster[selector]['stopTipsURL']);
+        $.getJSON(window._tipster[selector]['stopTipsURL']);
+}
+function nextTip(selector) {
+        window._tipster[selector]['i'] += 1;
+        var i = window._tipster[selector]['i'] %= window._tipster[selector]['tips'].length;
+
+        var stopTipsURL = window._tipster[selector]['stopTipsURL'];
+        var content = window._tipster[selector]['tips'][i];
+
+        var controls = '<div style="font-size: 75%; padding-bottom: 5px; padding-right: 5px; text-align: right;">';
+        if ( stopTipsURL ) {
+                controls += '<a href="javascript:stopTips(\'' + selector.replace(/:/g, '\\:') + '\');">(don\'t show me tips)</a>&nbsp;';
+        }
+        controls += '<a href="javascript:closeTip(\'' + selector.replace(/:/g, '\\:') + '\');">(close tip)</a>&nbsp;';
+        controls += '<a href="javascript:nextTip(\'' + selector.replace(/:/g, '\\:') + '\');">(next tip)</a>&nbsp;';
+        controls += '</div>';
+
+
+        var span = '<span class="ui-icon ui-icon-info" style="float: left; margin-left: .3em; margin-right: .3em;"></span>';
+        $('#'+selector).html('<p>' + span + '<strong>Tip:</strong> ' + content + '</p>' + controls);
+
+}

File tw2/tipster/templates/__init__.py

Empty file added.

File tw2/tipster/templates/tipster.mak

+<%namespace name="tw" module="tw2.core.mako_util"/>
+<div class="ui-widget">
+<div ${tw.attrs(attrs=w.attrs)} class="ui-state-highlight ui-corner-all"></div>
+<script type="text/javascript">
+setupTipster('${w.selector}', ${w._tips}, '${w.stopTipsURL}');
+</script>
+</div>

File tw2/tipster/widgets.py

+from tw2.core.resources import encoder
+import tw2.core as twc
+
+import tw2.jquery
+import tw2.jquery.base as tw2_jq_c_b
+import tw2.jquery.plugins.ui.base as tw2_jq_ui
+
+import formencode.validators as fv
+import base
+
+_pager_defaults = {'enableSearch': True, 'enableClear': True, 'gridModel': True}
+
+
+class TipsterWidget(tw2_jq_ui.JQueryUIWidget):
+    resources = [
+        tw2.jquery.jquery_js,
+        tw2_jq_ui.jquery_ui_js, tw2_jq_ui.jquery_ui_css,
+        base.tipster_js
+    ]
+    template = "mako:tw2.tipster.templates.tipster"
+
+    tips = twc.Param(
+        "A list of tips.", default=["Here's a tip.  Wash your face!"])
+
+    stopTipsURL = twc.Param(
+        "URL to stop tips from showing up for this user.", default="")
+
+    def prepare(self):
+        self._tips = encoder.encode(self.tips)
+        super(TipsterWidget, self).prepare()
+