<s> import pyjd <EOL> from pyjamas . ui . RootPanel import RootPanel <EOL> from pyjamas . ui . Button import Button <EOL> from pyjamas . ui . HTML import HTML <EOL> from pyjamas . ui . HorizontalPanel import HorizontalPanel <EOL> from pyjamas . ui . VerticalPanel import VerticalPanel <EOL> from pyjamas . ui . DockPanel import DockPanel <EOL> from pyjamas . ui . ScrollPanel import ScrollPanel <EOL> from pyjamas . ui . Grid import Grid <EOL> from pyjamas . ui . DisclosurePanel import DisclosurePanel <EOL> class OddGridWidget ( DockPanel ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> DockPanel . __init__ ( self , ** kwargs ) <EOL> self . grid = Grid ( StyleName = "<STR_LIT>" ) <EOL> self . sp = ScrollPanel ( self . grid , Width = "<STR_LIT>" , Height = "<STR_LIT>" ) <EOL> self . header = Grid ( Height = "<STR_LIT>" ) <EOL> self . add ( self . header , DockPanel . NORTH ) <EOL> self . add ( self . sp , DockPanel . CENTER ) <EOL> cf = self . setCellHeight ( self . header , "<STR_LIT>" ) <EOL> cf = self . setCellHeight ( self . sp , "<STR_LIT>" ) <EOL> self . sortcol = <NUM_LIT:0> <EOL> def setData ( self , data ) : <EOL> self . data = data <EOL> self . redraw ( ) <EOL> def sortfn ( self , row1 , row2 ) : <EOL> return cmp ( row1 [ self . sortcol ] , row2 [ self . sortcol ] ) <EOL> def redraw ( self ) : <EOL> self . data . sort ( self . sortfn ) <EOL> rows = len ( self . data ) <EOL> cols = <NUM_LIT:0> <EOL> if rows > <NUM_LIT:0> : <EOL> cols = len ( self . data [ <NUM_LIT:0> ] ) <EOL> self . grid . resize ( rows , cols ) <EOL> self . header . resize ( <NUM_LIT:1> , cols ) <EOL> cf = self . grid . getCellFormatter ( ) <EOL> for ( nrow , row ) in enumerate ( self . data ) : <EOL> for ( ncol , item ) in enumerate ( row ) : <EOL> self . grid . setHTML ( nrow , ncol , str ( item ) ) <EOL> cf . setWidth ( nrow , ncol , "<STR_LIT>" ) <EOL> cf = self . header . getCellFormatter ( ) <EOL> self . sortbuttons = [ ] <EOL> for ncol in range ( cols ) : <EOL> sb = Button ( "<STR_LIT>" % ncol ) <EOL> sb . addClickListener ( self ) <EOL> self . header . setWidget ( <NUM_LIT:0> , ncol , sb ) <EOL> cf . setWidth ( <NUM_LIT:0> , ncol , "<STR_LIT>" ) <EOL> self . sortbuttons . append ( sb ) <EOL> def onClick ( self , sender ) : <EOL> for ( ncol , b ) in enumerate ( self . sortbuttons ) : <EOL> if sender == b : <EOL> self . sortcol = ncol <EOL> self . redraw ( ) <EOL> data = [ [ "<STR_LIT:hello>" , "<STR_LIT>" , <NUM_LIT> ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:0> ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:2> ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:5> ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:8> ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> ] <EOL> ] <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> pyjd . setup ( "<STR_LIT>" ) <EOL> ogw = OddGridWidget ( Width = "<STR_LIT>" , Height = "<STR_LIT>" , StyleName = "<STR_LIT>" ) <EOL> ogw . setData ( data ) <EOL> dp = DisclosurePanel ( "<STR_LIT>" , True , Width = "<STR_LIT>" ) <EOL> dp . add ( ogw ) <EOL> RootPanel ( ) . add ( dp ) <EOL> pyjd . run ( ) </s>
