<s> import pyjd <EOL> from pyjamas . ui . RootPanel import RootPanel <EOL> from pyjamas . ui . HTML import HTML <EOL> from pyjamas . ui . Label import Label <EOL> from pyjamas . ui . Button import Button <EOL> from pyjamas . ui . HorizontalPanel import HorizontalPanel <EOL> from pyjamas . ui . AbsolutePanel import AbsolutePanel <EOL> from pyjamas . ui . ScrollPanel import ScrollPanel <EOL> from pyjamas . ui . Grid import Grid <EOL> from pyjamas . ui . SimplePanel import SimplePanel <EOL> from pyjamas . ui . FlexTable import FlexTable <EOL> from pyjamas . ui . Image import Image <EOL> from pyjamas . ui . DockPanel import DockPanel <EOL> from pyjamas . ui import HasHorizontalAlignment <EOL> from pyjamas . ui import HasVerticalAlignment <EOL> from pyjamas . ui import HasAlignment <EOL> from pyjamas import Window <EOL> from pyjamas . JSONService import JSONProxy <EOL> from Trees import Trees <EOL> from pyjamas . Timer import Timer <EOL> class CollapserPanel ( SimplePanel ) : <EOL> def __init__ ( self , sink ) : <EOL> SimplePanel . __init__ ( self ) <EOL> self . sink = sink <EOL> self . caption = HTML ( ) <EOL> self . child = None <EOL> self . showing = False <EOL> self . dragging = False <EOL> self . dragStartX = <NUM_LIT:0> <EOL> self . dragStartY = <NUM_LIT:0> <EOL> self . panel = FlexTable ( ) <EOL> self . collapse = Image ( "<STR_LIT>" ) <EOL> self . collapse . addClickListener ( self ) <EOL> dock = DockPanel ( ) <EOL> dock . setSpacing ( <NUM_LIT:0> ) <EOL> dock . add ( self . collapse , DockPanel . EAST ) <EOL> dock . add ( self . caption , DockPanel . WEST ) <EOL> dock . setCellHorizontalAlignment ( self . collapse , HasAlignment . ALIGN_RIGHT ) <EOL> dock . setCellVerticalAlignment ( self . collapse , HasAlignment . ALIGN_TOP ) <EOL> dock . setCellHorizontalAlignment ( self . caption , HasAlignment . ALIGN_LEFT ) <EOL> dock . setCellWidth ( self . caption , "<STR_LIT>" ) <EOL> dock . setWidth ( "<STR_LIT>" ) <EOL> dock . setHeight ( "<STR_LIT>" ) <EOL> self . panel . setWidget ( <NUM_LIT:0> , <NUM_LIT:0> , dock ) <EOL> self . panel . setHeight ( "<STR_LIT>" ) <EOL> self . panel . setWidth ( "<STR_LIT>" ) <EOL> self . panel . setBorderWidth ( <NUM_LIT:0> ) <EOL> self . panel . setCellPadding ( <NUM_LIT:0> ) <EOL> self . panel . setCellSpacing ( <NUM_LIT:0> ) <EOL> self . panel . getCellFormatter ( ) . setHeight ( <NUM_LIT:1> , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> self . panel . getCellFormatter ( ) . setWidth ( <NUM_LIT:1> , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> self . panel . getCellFormatter ( ) . setAlignment ( <NUM_LIT:1> , <NUM_LIT:0> , HasHorizontalAlignment . ALIGN_LEFT , HasVerticalAlignment . ALIGN_TOP ) <EOL> SimplePanel . setWidget ( self , self . panel ) <EOL> self . setStyleName ( "<STR_LIT>" ) <EOL> self . caption . setStyleName ( "<STR_LIT>" ) <EOL> self . collapse . setStyleName ( "<STR_LIT>" ) <EOL> dock . setStyleName ( "<STR_LIT>" ) <EOL> self . collapsed = False <EOL> self . collapsed_width = "<STR_LIT>" <EOL> self . uncollapsed_width = "<STR_LIT>" <EOL> def setInitialWidth ( self , width ) : <EOL> self . uncollapsed_width = width <EOL> SimplePanel . setWidth ( self , width ) <EOL> self . sink . setCollapserWidth ( self , width ) <EOL> def setHeight ( self , height ) : <EOL> SimplePanel . setHeight ( self , height ) <EOL> def onClick ( self , sender ) : <EOL> if self . collapsed == False : <EOL> self . collapse . setUrl ( "<STR_LIT>" ) <EOL> self . collapsed = True <EOL> self . caption . setVisible ( False ) <EOL> if self . child : <EOL> self . child . setVisible ( False ) <EOL> self . setWidth ( self . collapsed_width ) <EOL> self . sink . setCollapserWidth ( self , self . collapsed_width ) <EOL> else : <EOL> self . collapse . setUrl ( "<STR_LIT>" ) <EOL> self . collapsed = False <EOL> self . caption . setVisible ( True ) <EOL> if self . child : <EOL> self . child . setVisible ( True ) <EOL> self . setWidth ( self . uncollapsed_width ) <EOL> self . sink . setCollapserWidth ( self , self . uncollapsed_width ) <EOL> def setHTML ( self , html ) : <EOL> self . caption . setHTML ( html ) <EOL> def setText ( self , text ) : <EOL> self . caption . setText ( text ) <EOL> def remove ( self , widget ) : <EOL> if self . child != widget : <EOL> return False <EOL> self . panel . remove ( widget ) <EOL> return True <EOL> def doAttachChildren ( self ) : <EOL> SimplePanel . doAttachChildren ( self ) <EOL> self . caption . onAttach ( ) <EOL> def doDetachChildren ( self ) : <EOL> SimplePanel . doDetachChildren ( self ) <EOL> self . caption . onDetach ( ) <EOL> def setWidget ( self , widget ) : <EOL> if self . child is not None : <EOL> self . panel . remove ( self . child ) <EOL> if widget is not None : <EOL> self . panel . setWidget ( <NUM_LIT:1> , <NUM_LIT:0> , widget ) <EOL> self . child = widget <EOL> def space_split ( data ) : <EOL> res = [ ] <EOL> idx = data . find ( "<STR_LIT:U+0020>" ) <EOL> res . append ( data [ : idx ] ) <EOL> res . append ( data [ idx + <NUM_LIT:1> : ] ) <EOL> return res <EOL> class RightGrid ( DockPanel ) : <EOL> def __init__ ( self , title ) : <EOL> DockPanel . __init__ ( self ) <EOL> self . grid = FlexTable ( ) <EOL> title = HTML ( title ) <EOL> self . add ( title , DockPanel . NORTH ) <EOL> self . setCellHorizontalAlignment ( title , <EOL> HasHorizontalAlignment . ALIGN_LEFT ) <EOL> self . add ( self . grid , DockPanel . CENTER ) <EOL> self . grid . setBorderWidth ( "<STR_LIT>" ) <EOL> self . grid . setCellSpacing ( "<STR_LIT>" ) <EOL> self . grid . setCellPadding ( "<STR_LIT>" ) <EOL> self . formatCell ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . grid . setHTML ( <NUM_LIT:0> , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> def clear_items ( self ) : <EOL> self . index = <NUM_LIT:0> <EOL> self . items = { } <EOL> def set_items ( self , items ) : <EOL> self . items = items <EOL> self . index = <NUM_LIT:0> <EOL> self . max_rows = <NUM_LIT:0> <EOL> self . max_cols = <NUM_LIT:0> <EOL> Timer ( <NUM_LIT:1> , self ) <EOL> def onTimer ( self , timer ) : <EOL> count = <NUM_LIT:0> <EOL> while count < <NUM_LIT:10> and self . index < len ( self . items ) : <EOL> self . _add_items ( self . index ) <EOL> self . index += <NUM_LIT:1> <EOL> count += <NUM_LIT:1> <EOL> if self . index < len ( self . items ) : <EOL> timer . schedule ( <NUM_LIT:1> ) <EOL> def _add_items ( self , i ) : <EOL> item = self . items [ i ] <EOL> command = item [ <NUM_LIT:0> ] <EOL> col = item [ <NUM_LIT:1> ] <EOL> row = item [ <NUM_LIT:2> ] <EOL> data = item [ <NUM_LIT:3> ] <EOL> format_row = - <NUM_LIT:1> <EOL> format_col = - <NUM_LIT:1> <EOL> if col + <NUM_LIT:1> > self . max_cols : <EOL> format_col = self . max_cols <EOL> self . max_cols = col + <NUM_LIT:1> <EOL> if row + <NUM_LIT:1> >= self . max_rows : <EOL> format_row = self . max_rows <EOL> self . max_rows = row + <NUM_LIT:1> <EOL> if format_row >= <NUM_LIT:0> : <EOL> for k in range ( format_row , self . max_rows ) : <EOL> self . formatCell ( k , <NUM_LIT:0> ) <EOL> self . formatCell ( row , col ) <EOL> cf = self . grid . getCellFormatter ( ) <EOL> if command == '<STR_LIT:data>' : <EOL> self . grid . setHTML ( row , col , data ) <EOL> elif command == '<STR_LIT>' : <EOL> data = space_split ( data ) <EOL> attr = data [ <NUM_LIT:0> ] <EOL> val = data [ <NUM_LIT:1> ] <EOL> cf . setStyleAttr ( row , col , attr , val ) <EOL> elif command == '<STR_LIT>' : <EOL> data = space_split ( data ) <EOL> vert = data [ <NUM_LIT:0> ] <EOL> horiz = data [ <NUM_LIT:1> ] <EOL> if vert != '<STR_LIT:->' : <EOL> cf . setVerticalAlignment ( row , col , vert ) <EOL> if horiz != '<STR_LIT:->' : <EOL> cf . setHorizontalAlignment ( row , col , horiz ) <EOL> elif command == '<STR_LIT>' : <EOL> data = space_split ( data ) <EOL> rowspan = data [ <NUM_LIT:0> ] <EOL> colspan = data [ <NUM_LIT:1> ] <EOL> if colspan != '<STR_LIT:->' : <EOL> cf . setColSpan ( row , col , colspan ) <EOL> if rowspan != '<STR_LIT:->' : <EOL> cf . setRowSpan ( row , col , rowspan ) <EOL> def formatCell ( self , row , col ) : <EOL> self . grid . prepareCell ( row , col ) <EOL> if col == <NUM_LIT:0> and row != <NUM_LIT:0> : <EOL> self . grid . setHTML ( row , col , "<STR_LIT>" % row ) <EOL> if row != <NUM_LIT:0> and col != <NUM_LIT:0> : <EOL> fmt = "<STR_LIT>" <EOL> if col == <NUM_LIT:0> and row == <NUM_LIT:0> : <EOL> fmt = "<STR_LIT>" <EOL> elif row == <NUM_LIT:0> : <EOL> fmt = "<STR_LIT>" <EOL> elif col == <NUM_LIT:0> : <EOL> fmt = "<STR_LIT>" <EOL> self . grid . getCellFormatter ( ) . setStyleName ( row , col , fmt ) <EOL> class RightPanel ( DockPanel ) : <EOL> def __init__ ( self ) : <EOL> DockPanel . __init__ ( self ) <EOL> self . grids = { } <EOL> self . g = Grid ( ) <EOL> self . g . setCellSpacing ( "<STR_LIT>" ) <EOL> self . g . setCellPadding ( "<STR_LIT>" ) <EOL> self . title = HTML ( "<STR_LIT>" ) <EOL> self . title . setStyleName ( "<STR_LIT>" ) <EOL> self . add ( self . title , DockPanel . NORTH ) <EOL> self . setCellWidth ( self . title , "<STR_LIT>" ) <EOL> self . setCellHorizontalAlignment ( self . title , <EOL> HasHorizontalAlignment . ALIGN_LEFT ) <EOL> self . add ( self . g , DockPanel . CENTER ) <EOL> def setTitle ( self , title ) : <EOL> self . title . setHTML ( title ) <EOL> def clear_items ( self ) : <EOL> for i in range ( len ( self . grids ) ) : <EOL> g = self . grids [ i ] <EOL> if hasattr ( g , "<STR_LIT>" ) : <EOL> g . clear_items ( ) <EOL> self . grids = { } <EOL> self . g . resize ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> def setup_panels ( self , datasets ) : <EOL> self . grids = { } <EOL> self . data = { } <EOL> self . names = { } <EOL> self . loaded = { } <EOL> size = len ( datasets ) <EOL> self . g . resize ( size , <NUM_LIT:1> ) <EOL> def add_html ( self , html , name , index ) : <EOL> self . data [ index ] = html <EOL> self . names [ index ] = name <EOL> self . grids [ index ] = HTML ( html ) <EOL> self . g . setWidget ( index , <NUM_LIT:0> , self . grids [ index ] ) <EOL> def add_items ( self , items , name , index ) : <EOL> self . data [ index ] = items <EOL> self . names [ index ] = name <EOL> self . grids [ index ] = RightGrid ( "<STR_LIT>" ) <EOL> self . grids [ index ] . set_items ( items ) <EOL> self . g . setWidget ( index , <NUM_LIT:0> , self . grids [ index ] ) <EOL> class MidPanel ( Grid ) : <EOL> def __init__ ( self , sink ) : <EOL> Grid . __init__ ( self ) <EOL> self . resize ( <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . addTableListener ( self ) <EOL> self . sink = sink <EOL> self . selected_row = - <NUM_LIT:1> <EOL> def set_items ( self , items ) : <EOL> if self . selected_row != - <NUM_LIT:1> : <EOL> self . styleRow ( self . selected_row , False ) <EOL> self . item_names = [ ] <EOL> self . item_locations = [ ] <EOL> self . resizeRows ( len ( items ) ) <EOL> for i in range ( len ( items ) ) : <EOL> item = items [ i ] <EOL> name = item [ <NUM_LIT:0> ] <EOL> location = item [ <NUM_LIT:1> ] <EOL> self . setHTML ( i , <NUM_LIT:0> , name ) <EOL> self . item_names . append ( name ) <EOL> self . item_locations . append ( location ) <EOL> def onCellClicked ( self , sender , row , col ) : <EOL> self . styleRow ( self . selected_row , False ) <EOL> self . selected_row = row <EOL> self . styleRow ( self . selected_row , True ) <EOL> self . sink . select_right_grid ( self . item_locations [ row ] , <EOL> self . item_names [ row ] ) <EOL> def styleRow ( self , row , selected ) : <EOL> if ( row != - <NUM_LIT:1> ) : <EOL> if ( selected ) : <EOL> self . getRowFormatter ( ) . addStyleName ( row , "<STR_LIT>" ) <EOL> else : <EOL> self . getRowFormatter ( ) . removeStyleName ( row , "<STR_LIT>" ) <EOL> class InfoDirectory : <EOL> def onModuleLoad ( self ) : <EOL> self . remote = InfoServicePython ( ) <EOL> self . tree_width = <NUM_LIT:200> <EOL> self . tp = HorizontalPanel ( ) <EOL> self . tp . setWidth ( "<STR_LIT>" % ( self . tree_width ) ) <EOL> self . treeview = Trees ( ) <EOL> self . treeview . fTree . addTreeListener ( self ) <EOL> self . sp = ScrollPanel ( ) <EOL> self . tp . add ( self . treeview ) <EOL> self . sp . add ( self . tp ) <EOL> self . sp . setHeight ( "<STR_LIT>" ) <EOL> self . horzpanel1 = HorizontalPanel ( ) <EOL> self . horzpanel1 . setSize ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . horzpanel1 . setBorderWidth ( <NUM_LIT:1> ) <EOL> self . horzpanel1 . setSpacing ( "<STR_LIT>" ) <EOL> self . rp = RightPanel ( ) <EOL> self . rps = ScrollPanel ( ) <EOL> self . rps . add ( self . rp ) <EOL> self . rps . setWidth ( "<STR_LIT>" ) <EOL> self . rp . setWidth ( "<STR_LIT>" ) <EOL> self . cp1 = CollapserPanel ( self ) <EOL> self . cp1 . setWidget ( self . sp ) <EOL> self . cp1 . setHTML ( "<STR_LIT>" ) <EOL> self . midpanel = MidPanel ( self ) <EOL> self . cp2 = CollapserPanel ( self ) <EOL> self . cp2 . setWidget ( self . midpanel ) <EOL> self . cp2 . setHTML ( "<STR_LIT>" ) <EOL> self . horzpanel1 . add ( self . cp1 ) <EOL> self . horzpanel1 . add ( self . cp2 ) <EOL> self . horzpanel1 . add ( self . rps ) <EOL> self . cp1 . setInitialWidth ( "<STR_LIT>" % self . tree_width ) <EOL> self . cp2 . setInitialWidth ( "<STR_LIT>" ) <EOL> RootPanel ( ) . add ( self . horzpanel1 ) <EOL> width = Window . getClientWidth ( ) <EOL> height = Window . getClientHeight ( ) <EOL> self . onWindowResized ( width , height ) <EOL> Window . addWindowResizeListener ( self ) <EOL> def setCollapserWidth ( self , widget , width ) : <EOL> self . horzpanel1 . setCellWidth ( widget , width ) <EOL> def onWindowResized ( self , width , height ) : <EOL> self . cp1 . setHeight ( "<STR_LIT>" % ( height - <NUM_LIT:30> ) ) <EOL> self . cp2 . setHeight ( "<STR_LIT>" % ( height - <NUM_LIT:30> ) ) <EOL> self . rps . setHeight ( "<STR_LIT>" % ( height - <NUM_LIT:30> ) ) <EOL> self . horzpanel1 . setHeight ( "<STR_LIT>" % ( height - <NUM_LIT:20> ) ) <EOL> def onTreeItemStateChanged ( self , item ) : <EOL> if item . isSelected ( ) : <EOL> self . onTreeItemSelected ( item ) <EOL> def onTreeItemSelected ( self , item ) : <EOL> obj = item . getUserObject ( ) <EOL> if len ( obj . children ) != <NUM_LIT:0> : <EOL> self . clear_mid_panel ( ) <EOL> return <EOL> self . remote . get_midpanel_data ( obj . root + "<STR_LIT:/>" + obj . text , self ) <EOL> self . cp2 . setHTML ( obj . text ) <EOL> self . clear_right_panel ( ) <EOL> def clear_right_panel ( self ) : <EOL> self . horzpanel1 . remove ( <NUM_LIT:2> ) <EOL> self . horzpanel1 . insert ( HTML ( "<STR_LIT>" ) , <NUM_LIT:2> ) <EOL> self . rp . setTitle ( "<STR_LIT>" ) <EOL> def clear_mid_panel ( self ) : <EOL> self . clear_right_panel ( ) <EOL> def set_mid_panel ( self , response ) : <EOL> self . midpanel . set_items ( response ) <EOL> self . cp2 . setWidget ( self . midpanel ) <EOL> def select_right_grid ( self , location , name ) : <EOL> self . horzpanel1 . remove ( <NUM_LIT:2> ) <EOL> self . horzpanel1 . insert ( self . rps , <NUM_LIT:2> ) <EOL> self . rp . setTitle ( name ) <EOL> self . remote . get_rightpanel_datanames ( location , self ) <EOL> def get_rightpanel_datasets ( self , datasets ) : <EOL> self . rp . clear_items ( ) <EOL> self . rp . setup_panels ( datasets ) <EOL> for i in range ( len ( datasets ) ) : <EOL> item = datasets [ i ] <EOL> fname = item [ <NUM_LIT:0> ] <EOL> self . remote . get_rightpanel_data ( fname , fname , i , self ) <EOL> def fill_right_grid ( self , data ) : <EOL> index = data . get ( '<STR_LIT:index>' ) <EOL> name = data . get ( '<STR_LIT:name>' ) <EOL> if data . has_key ( '<STR_LIT>' ) : <EOL> self . rp . add_items ( data . get ( '<STR_LIT>' ) , name , index ) <EOL> elif data . has_key ( '<STR_LIT:html>' ) : <EOL> self . rp . add_html ( data . get ( '<STR_LIT:html>' ) , name , index ) <EOL> def onRemoteResponse ( self , response , request_info ) : <EOL> method = request_info . method <EOL> if method == "<STR_LIT>" : <EOL> self . set_mid_panel ( response ) <EOL> elif method == "<STR_LIT>" : <EOL> self . get_rightpanel_datasets ( response ) <EOL> elif method == "<STR_LIT>" : <EOL> self . fill_right_grid ( response ) <EOL> def onRemoteError ( self , code , message , request_info ) : <EOL> RootPanel ( ) . add ( HTML ( "<STR_LIT>" + code ) ) <EOL> RootPanel ( ) . add ( HTML ( message ) ) <EOL> class InfoServicePython ( JSONProxy ) : <EOL> def __init__ ( self ) : <EOL> JSONProxy . __init__ ( self , "<STR_LIT>" , <EOL> [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> pyjd . setup ( "<STR_LIT>" ) <EOL> app = InfoDirectory ( ) <EOL> app . onModuleLoad ( ) <EOL> pyjd . run ( ) </s>
