ia64/xen-unstable

view tools/python/xen/sv/GenTabbed.py @ 6552:a9873d384da4

Merge.
author adsharma@los-vmm.sc.intel.com
date Thu Aug 25 12:24:48 2005 -0700 (2005-08-25)
parents 112d44270733 fa0754a9f64f
children dfaf788ab18c
line source
1 import types
3 from xen.sv.HTMLBase import HTMLBase
4 from xen.sv.util import getVar
6 class GenTabbed( HTMLBase ):
8 def __init__( self, title, urlWriter, tabStrings, tabObjects ):
9 HTMLBase.__init__(self)
10 self.tabStrings = tabStrings
11 self.tabObjects = tabObjects
12 self.urlWriter = urlWriter
13 self.title = title
15 def write_BODY( self, request ):
16 if not self.__dict__.has_key( "tab" ):
17 try:
18 self.tab = int( getVar( 'tab', request, 0 ) )
19 except:
20 self.tab = 0
22 request.write( "\n<div class='title'>%s</div>" % self.title )
24 TabView( self.tab, self.tabStrings, self.urlWriter ).write_BODY( request )
26 try:
27 request.write( "\n<div class='tab'>" )
28 render_tab = self.tabObjects[ self.tab ]
29 render_tab( self.urlWriter ).write_BODY( request )
30 request.write( "\n</div>" )
31 except Exception, e:
32 request.write( "\n<p>Error Rendering Tab</p>" )
33 request.write( "\n<p>%s</p>" % str( e ) )
35 request.write( "\n<input type=\"hidden\" name=\"tab\" value=\"%d\">" % self.tab )
37 def perform( self, request ):
38 request.write( "Tab> perform" )
39 request.write( "<br/>op: " + str( getVar( 'op', request ) ) )
40 request.write( "<br/>args: " + str( getVar( 'args', request ) ) )
41 request.write( "<br/>tab: " + str( getVar( 'tab', request ) ) )
43 try:
44 action = getVar( 'op', request, 0 )
45 if action == "tab":
46 self.tab = int( getVar( 'args', request ) )
47 else:
48 this.tab = int( getVar( 'tab', request, 0 ) )
49 self.tabObjects[ self.tab ]( self.urlWriter ).perform( request )
50 except:
51 pass
53 class PreTab( HTMLBase ):
55 def __init__( self, source ):
56 HTMLBase.__init__( self )
57 self.source = source
59 def write_BODY( self, request ):
60 request.write( "\n<pre>" )
61 request.write( self.source )
62 request.write( "\n</pre>" )
64 class GeneralTab( HTMLBase ):
66 def __init__( self, dict, titles ):
67 HTMLBase.__init__( self )
68 self.dict = dict
69 self.titles = titles
71 def write_BODY( self, request ):
73 request.write( "\n<table width='100%' cellspacing='0' cellpadding='0' border='0'>" )
75 def writeAttr( niceName, attr, formatter=None ):
76 if type( attr ) is types.TupleType:
77 ( attr, formatter ) = attr
79 if attr in self.dict:
80 if formatter:
81 temp = formatter( self.dict[ attr ] )
82 else:
83 temp = str( self.dict[ attr ] )
84 request.write( "\n<tr><td width='50%%'><p>%s:</p></td><td width='50%%'><p>%s</p></td></tr>" % ( niceName, temp ) )
86 for niceName, attr in self.titles.items():
87 writeAttr( niceName, attr )
89 request.write( "</table>" )
91 class NullTab( HTMLBase ):
93 def __init__( self, title="Null Tab" ):
94 HTMLBase.__init__( self )
95 self.title = title
97 def write_BODY( self, request ):
98 request.write( "\n<p>%s</p>" % self.title )
100 class ActionTab( HTMLBase ):
102 def __init__( self, actions ):
103 self.actions = actions
104 HTMLBase.__init__( self )
106 def write_BODY( self, request ):
107 for item in self.actions.items():
108 try:
109 ((op, attr), title) = item
110 except:
111 (op, title) = item
112 attr = ""
113 request.write( "\n<div class='button' onclick=\"doOp2( '%s', '%s' )\">%s</a></div>" % (op, attr, title) )
115 class CompositeTab( HTMLBase ):
117 def __init__( self, tabs, urlWriter ):
118 HTMLBase.__init__( self )
119 self.tabs = tabs
120 self.urlWriter = urlWriter
122 def write_BODY( self, request ):
123 for tab in self.tabs:
124 tab( self.urlWriter ).write_BODY( request )
126 def perform( self, request ):
127 for tab in self.tabs:
128 tab( self.urlWriter ).perform( request )
130 class TabView( HTMLBase ):
132 # tab - int, id into tabs of selected tab
133 # tabs - list of strings, tab names
134 # urlWriter -
135 def __init__( self, tab, tabs, urlWriter ):
136 HTMLBase.__init__(self)
137 self.tab = tab
138 self.tabs = tabs
139 self.urlWriter = urlWriter
141 def write_BODY( self, request ):
142 for i in range( len( self.tabs ) ):
143 if self.tab == i:
144 at = " id='activeTab'"
145 else:
146 at = ""
147 request.write( "\n<div%s class='tabButton' onclick=\"doOp2( 'tab', '%d' )\">%s</div>" % ( at, i, self.tabs[ i ] ) )