<s> import datetime <EOL> import xml . sax . saxutils <EOL> from pyglet . gl import * <EOL> from wydget import element , event , layouts , loadxml , util <EOL> from wydget . widgets . frame import Frame , ContainerFrame <EOL> from wydget . widgets . slider import VerticalSlider , HorizontalSlider <EOL> from wydget . widgets . label import Label <EOL> class Table ( element . Element ) : <EOL> name = '<STR_LIT>' <EOL> h_slider = None <EOL> v_slider = None <EOL> def __init__ ( self , parent , size = None , is_exclusive = False , <EOL> color = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) , bgcolor = ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> alt_bgcolor = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1> ) , active_bgcolor = ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1> ) , <EOL> x = <NUM_LIT:0> , y = <NUM_LIT:0> , z = <NUM_LIT:0> , width = '<STR_LIT>' , height = None , ** kw ) : <EOL> font_size = parent . getStyle ( ) . font_size <EOL> size = util . parse_value ( size , None ) <EOL> if size is not None : <EOL> height = ( size + <NUM_LIT:1> ) * font_size <EOL> self . is_exclusive = is_exclusive <EOL> super ( Table , self ) . __init__ ( parent , x , y , z , width , height , <EOL> bgcolor = bgcolor , ** kw ) <EOL> self . contents = ContainerFrame ( self ) <EOL> self . contents . layout = layouts . Layout ( self . contents ) <EOL> self . contents . checkForScrollbars ( ) <EOL> self . color = util . parse_color ( color ) <EOL> self . base_bgcolor = self . bgcolor <EOL> self . alt_bgcolor = util . parse_color ( alt_bgcolor ) <EOL> self . active_bgcolor = util . parse_color ( active_bgcolor ) <EOL> def get_inner_rect ( self ) : <EOL> p = self . padding <EOL> font_size = self . getStyle ( ) . font_size <EOL> return util . Rect ( p , p , self . width - p * <NUM_LIT:2> , self . height - p * <NUM_LIT:2> - font_size ) <EOL> inner_rect = property ( get_inner_rect ) <EOL> def layoutDimensionsChanged ( self , layout ) : <EOL> pass <EOL> @ classmethod <EOL> def fromXML ( cls , element , parent ) : <EOL> '''<STR_LIT>''' <EOL> kw = loadxml . parseAttributes ( element ) <EOL> obj = cls ( parent , ** kw ) <EOL> for child in element . getchildren ( ) : <EOL> if child . tag == '<STR_LIT>' : <EOL> Row . fromXML ( child , obj . contents ) <EOL> elif child . tag == '<STR_LIT>' : <EOL> obj . heading = Heading . fromXML ( child , obj ) <EOL> obj . heading . layout . layout ( ) <EOL> else : <EOL> raise ValueError , '<STR_LIT>' % child . tag <EOL> obj . contents . layout . layout ( ) <EOL> return obj <EOL> class Heading ( Frame ) : <EOL> name = '<STR_LIT>' <EOL> def __init__ ( self , parent , width = '<STR_LIT>' , bgcolor = '<STR_LIT>' , ** kw ) : <EOL> kw [ '<STR_LIT:y>' ] = parent . height - parent . getStyle ( ) . font_size <EOL> super ( Heading , self ) . __init__ ( parent , width = width , ** kw ) <EOL> self . layout = layouts . Horizontal ( self , valign = '<STR_LIT>' , halign = '<STR_LIT>' , <EOL> padding = <NUM_LIT:2> ) <EOL> class Row ( Frame ) : <EOL> name = '<STR_LIT>' <EOL> def __init__ ( self , parent , border = None , color = None , bgcolor = None , <EOL> active_bgcolor = None , is_active = False , width = '<STR_LIT>' , ** kw ) : <EOL> self . is_active = is_active <EOL> n = len ( parent . children ) <EOL> table = parent . parent <EOL> if color is None : <EOL> color = table . color <EOL> if bgcolor is None : <EOL> bgcolor = ( table . bgcolor , table . alt_bgcolor ) [ n % <NUM_LIT:2> ] <EOL> if active_bgcolor is None : <EOL> self . active_bgcolor = table . active_bgcolor <EOL> else : <EOL> self . active_bgcolor = util . parse_color ( active_bgcolor ) <EOL> font_size = parent . getStyle ( ) . font_size <EOL> kw [ '<STR_LIT:y>' ] = n * font_size <EOL> kw [ '<STR_LIT>' ] = font_size <EOL> super ( Row , self ) . __init__ ( parent , border = border , bgcolor = bgcolor , <EOL> width = width , ** kw ) <EOL> self . base_bgcolor = bgcolor <EOL> def renderBackground ( self , clipped ) : <EOL> '''<STR_LIT>''' <EOL> if self . is_active and self . active_bgcolor : <EOL> self . bgcolor = self . active_bgcolor <EOL> else : <EOL> self . bgcolor = self . base_bgcolor <EOL> super ( Row , self ) . renderBackground ( clipped ) <EOL> class Cell ( Label ) : <EOL> name = '<STR_LIT>' <EOL> def __init__ ( self , parent , value , type = '<STR_LIT:string>' , ** kw ) : <EOL> self . value = value <EOL> self . type = type <EOL> self . column = len ( parent . children ) <EOL> kw [ '<STR_LIT:x>' ] = parent . parent . parent . heading . children [ self . column ] . x <EOL> if type == '<STR_LIT:time>' : <EOL> if value . hour : <EOL> text = '<STR_LIT>' % ( value . hour , value . minute , value . second ) <EOL> else : <EOL> text = '<STR_LIT>' % ( value . minute , value . second ) <EOL> else : <EOL> text = str ( value ) <EOL> super ( Cell , self ) . __init__ ( parent , text , ** kw ) <EOL> @ classmethod <EOL> def fromXML ( cls , element , parent ) : <EOL> '''<STR_LIT>''' <EOL> kw = loadxml . parseAttributes ( element ) <EOL> text = xml . sax . saxutils . unescape ( element . text ) <EOL> t = kw . get ( '<STR_LIT:type>' ) <EOL> if t == '<STR_LIT>' : <EOL> value = int ( text ) <EOL> elif t == '<STR_LIT:time>' : <EOL> if '<STR_LIT::>' in text : <EOL> value = map ( int , text . split ( '<STR_LIT::>' ) ) <EOL> if len ( value ) == <NUM_LIT:2> : m , s = value [ <NUM_LIT:0> ] , value [ <NUM_LIT:1> ] <EOL> else : h , m , s = value [ <NUM_LIT:0> ] , value [ <NUM_LIT:1> ] , value [ <NUM_LIT:2> ] <EOL> else : <EOL> value = int ( text ) <EOL> s = value % <NUM_LIT> <EOL> m = ( value / <NUM_LIT> ) % <NUM_LIT> <EOL> h = value / <NUM_LIT> <EOL> value = datetime . time ( h , m , s ) <EOL> else : <EOL> value = text <EOL> obj = cls ( parent , value , ** kw ) <EOL> return obj </s>
