1 import warnings
2 from turbojson.jsonify import encode
3 from turbogears.widgets.base import CSSLink, JSLink, CSSSource, JSSource, \
4 Widget, CoreWD, static, js_location
5 from turbogears.widgets.forms import SelectionField
6
7 try:
8 set
9 except NameError:
10 from sets import Set as set
11
12 __all__ = ["Tabber", "SyntaxHighlighter", "JumpMenu"]
13
15 """This widget includes the tabber js and css into your rendered
16 page so you can create tabbed divs by assigning them the 'tabber'
17 and 'tabbertab' classes.
18 """
19 css = [CSSLink(static,"tabber/tabber.css", media="screen")]
20 - def __init__(self, tabber_options={}, use_cookie=False, hide_on_load=True,
21 *args, **kw):
22 super(Tabber, self).__init__(*args, **kw)
23 js = []
24
25 if use_cookie and (tabber_options.has_key('onLoad') or
26 tabber_options.has_key('onClick')):
27 warnings.warn("Cannot use cookies if overriden by "
28 "tabber_options['onClick'] or "
29 "tabber_options['onLoad']. Undefined behavior.")
30
31 if use_cookie:
32 js.append(JSLink(static, "tabber/tabber_cookie.js"))
33 if tabber_options:
34 js.append(JSSource("var tabberOptions = %s;" %
35 encode(tabber_options)))
36 if use_cookie:
37 js.append(JSSource("""
38 try {
39 tabberOptions
40 } catch(e){
41 tabberOptions = {};
42 }
43 tabberOptions['onLoad'] = tabber_onload;
44 tabberOptions['onClick'] = tabber_onclick;
45 tabberOptions['cookie'] = 'TGTabber';"""))
46 if hide_on_load:
47 js.append(JSSource("document.write('%s');"
48 % '<style type="text/css">.tabber{display:none;}</style>'))
49 js.append(JSLink(static, "tabber/tabber-minimized.js",
50 location=js_location.bodytop))
51 self.javascript = js
52
53
55 name = "Tabber"
56 for_widget = Tabber()
57 template = """<div class="tabber">
58 <div class="tabbertab"><h2>Tab 1</h2><p>This is page 1.</p></div>
59 <div class="tabbertab"><h2>Tab 2</h2><p>This is page 2.</p></div>
60 <div class="tabbertab"><h2>Tab 3</h2><p>This is page 3.</p></div>
61 </div>"""
62
64 """This widget includes the syntax highlighter js and css into your
65 rendered page to syntax-hightlight textareas named 'code'. The supported
66 languages can be listed at the 'languages' __init__ parameter.
67 """
68 available_langs = set([
69 'CSharp',
70 'Css',
71 'Delphi',
72 'Java',
73 'JScript',
74 'Php',
75 'Python',
76 'Ruby',
77 'Sql',
78 'Vb',
79 'Xml',
80 ])
81 css = [CSSLink(static,"sh/SyntaxHighlighter.css")]
82
83 - def __init__(self, languages=['Python', 'Xml']):
103
112
114 """
115 Choose a link from the menu,
116 the page will be redirect to the selected link.
117 """
118 js = JSSource("""
119 <!--
120 function TG_jumpMenu(targ,f,restore){
121 eval(targ+".location='"+f.options[f.selectedIndex].value+"'");
122 if (restore) f.selectedIndex=0;
123 }
124 //-->
125 """)
126
127 template = """
128 <select xmlns:py="http://purl.org/kid/ns#"
129 name="${name}"
130 class="${field_class}"
131 id="${field_id}"
132 onchange="TG_jumpMenu('parent',this,0)"
133 py:attrs="attrs"
134 >
135 <optgroup py:for="group, options in grouped_options"
136 label="${group}"
137 py:strip="not group"
138 >
139 <option py:for="value, desc, attrs in options"
140 value="${value}"
141 py:attrs="attrs"
142 py:content="desc"
143 />
144 </optgroup>
145 </select>
146 """
147 javascript = [js]
148 _selected_verb = 'selected'
149 params = ["attrs"]
150 params_doc = {'attrs' : 'Dictionary containing extra (X)HTML attributes for'
151 ' the select tag'}
152 attrs = {}
153
155 name = "Jump Menu"
156 for_widget = JumpMenu("your_jump_menu_field",
157 options=[('http://www.python.org', "Python"),
158 ('http://www.turbogears.org', "TurboGears"),
159 ('http://www.python.org/pypi', "Cheese Shop"),
160 ('http://www.pythonware.com/daily/', "Daily Python")],
161
162 )
163