<s> import gtk <EOL> import pango <EOL> from event import * <EOL> class InfoBarGtk ( gtk . EventBox ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , text = "<STR_LIT>" ) : <EOL> gtk . EventBox . __init__ ( self ) <EOL> self . modify_bg ( gtk . STATE_NORMAL , gtk . gdk . color_parse ( "<STR_LIT>" ) ) <EOL> self . _label = gtk . Label ( ) <EOL> self . _label . set_property ( '<STR_LIT>' , pango . ELLIPSIZE_END ) <EOL> self . _label . set_text ( text ) <EOL> self . _label . set_tooltip_text ( text ) <EOL> self . _label . set_size_request ( - <NUM_LIT:1> , <NUM_LIT> ) <EOL> self . _hbox1 = gtk . HBox ( ) <EOL> self . _hbox2 = gtk . HBox ( ) <EOL> self . add ( self . _hbox1 ) <EOL> self . _icon_bin = gtk . Alignment ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . _hbox1 . pack_start ( self . _icon_bin , False , True , <NUM_LIT:5> ) <EOL> self . _hbox1 . pack_start ( self . _label , True , True , <NUM_LIT:5> ) <EOL> self . _hbox1 . pack_start ( self . _hbox2 , False , True , <NUM_LIT:5> ) <EOL> self . _hbox1 . show_all ( ) <EOL> self . _has_close_button = False <EOL> self . _after_button_pressed = Event ( ) <EOL> def set_icon ( self , image ) : <EOL> if image == None : <EOL> self . _icon_bin . remove ( gtk . _icon_bin . get_children ( ) [ <NUM_LIT:0> ] ) <EOL> else : <EOL> self . _icon_bin . add ( image ) <EOL> def set_stock_icon ( self , stock ) : <EOL> if stock == None : <EOL> self . _icon_bin . remove ( gtk . _icon_bin . get_children ( ) [ <NUM_LIT:0> ] ) <EOL> else : <EOL> image = gtk . image_new_from_stock ( stock , gtk . ICON_SIZE_SMALL_TOOLBAR ) <EOL> self . _icon_bin . add ( image ) <EOL> def add_button ( self , label , cb , * userdata ) : <EOL> bn = gtk . Button ( label ) <EOL> bn . set_property ( '<STR_LIT>' , False ) <EOL> self . _hbox2 . pack_start ( self . _mka ( bn ) , False , False , <NUM_LIT:2> ) <EOL> def on_click ( * args ) : <EOL> cb ( * userdata ) <EOL> self . _after_button_pressed . fire ( ) <EOL> bn . connect ( '<STR_LIT>' , on_click ) <EOL> def add_close_button ( self , cb = None , * userdata ) : <EOL> assert self . _has_close_button == False <EOL> self . _has_close_button = True <EOL> bn = gtk . Button ( ) <EOL> bn . set_property ( '<STR_LIT>' , gtk . RELIEF_NONE ) <EOL> bn . set_property ( '<STR_LIT>' , False ) <EOL> bn . set_image ( gtk . image_new_from_stock ( gtk . STOCK_CLOSE , gtk . ICON_SIZE_SMALL_TOOLBAR ) ) <EOL> bn . modify_bg ( gtk . STATE_PRELIGHT , gtk . gdk . color_parse ( "<STR_LIT>" ) ) <EOL> bn . modify_bg ( gtk . STATE_NORMAL , gtk . gdk . color_parse ( "<STR_LIT>" ) ) <EOL> self . _hbox1 . pack_end ( self . _mka ( bn ) , False , False , <NUM_LIT:2> ) <EOL> def on_click ( * args ) : <EOL> if cb : <EOL> cb ( * userdata ) <EOL> self . _after_button_pressed . fire ( ) <EOL> bn . connect ( '<STR_LIT>' , on_click ) <EOL> @ property <EOL> def after_button_pressed ( self ) : <EOL> return self . _after_button_pressed <EOL> @ property <EOL> def has_close_button ( self ) : <EOL> return self . _has_close_button <EOL> @ property <EOL> def has_buttons ( self ) : <EOL> return len ( self . _hbox2 . get_children ( ) ) != <NUM_LIT:0> <EOL> @ property <EOL> def text ( self ) : <EOL> return self . _label . get_text ( ) <EOL> @ text . setter <EOL> def text ( self , text ) : <EOL> self . _label . set_text ( text ) <EOL> def _mka ( self , bn ) : <EOL> a = gtk . Alignment ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:0> , <NUM_LIT:0.0> ) <EOL> a . add ( bn ) <EOL> return a <EOL> class _BSeparator ( gtk . EventBox ) : <EOL> def __init__ ( self ) : <EOL> gtk . EventBox . __init__ ( self ) <EOL> self . modify_bg ( gtk . STATE_NORMAL , gtk . gdk . color_parse ( "<STR_LIT>" ) ) <EOL> self . add ( gtk . HSeparator ( ) ) <EOL> class InfoBarGtkCollection ( gtk . VBox ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> gtk . VBox . __init__ ( self ) <EOL> self . _num_bars = <NUM_LIT:0> <EOL> def has_bar ( self , bar ) : <EOL> return bar . get_parent ( ) in self . get_children ( ) <EOL> def close_bar ( self , bar ) : <EOL> self . remove ( bar . get_parent ( ) ) <EOL> self . _num_bars -= <NUM_LIT:1> <EOL> if self . _num_bars > <NUM_LIT:0> : <EOL> grp0 = self . get_children ( ) [ <NUM_LIT:0> ] <EOL> c0 = grp0 . get_children ( ) [ <NUM_LIT:0> ] <EOL> if isinstance ( c0 , _BSeparator ) : <EOL> grp0 . remove ( c0 ) <EOL> def add_bar ( self , bar ) : <EOL> assert isinstance ( bar , InfoBarGtk ) <EOL> if bar . has_close_button == False : <EOL> bar . add_close_button ( lambda : True ) <EOL> def close_bar ( ) : <EOL> if bar . get_parent ( ) : <EOL> self . close_bar ( bar ) <EOL> bar . after_button_pressed . add_listener ( close_bar ) <EOL> grp = gtk . VBox ( ) <EOL> if self . _num_bars >= <NUM_LIT:1> : <EOL> sep = _BSeparator ( ) <EOL> grp . pack_start ( sep ) <EOL> grp . pack_start ( bar ) <EOL> self . pack_start ( grp ) <EOL> grp . show_all ( ) <EOL> self . _num_bars += <NUM_LIT:1> <EOL> def __len__ ( self ) : <EOL> return self . _num_bars <EOL> def __getitem__ ( self , i ) : <EOL> grp = self . get_children ( ) [ i ] <EOL> if isinstance ( grp . get_children ( ) [ <NUM_LIT:0> ] , InfoBarGtk ) : <EOL> return grp . get_children ( ) [ <NUM_LIT:0> ] <EOL> else : <EOL> return grp . get_children ( ) [ <NUM_LIT:1> ] <EOL> if __name__ == "<STR_LIT:__main__>" and False : <EOL> w = gtk . Window ( ) <EOL> w . set_size_request ( <NUM_LIT> , - <NUM_LIT:1> ) <EOL> b = InfoBarGtk ( ) <EOL> b . text = "<STR_LIT>" <EOL> w . add ( b ) <EOL> w . show_all ( ) <EOL> gtk . main ( ) <EOL> if __name__ == "<STR_LIT:__main__>" and True : <EOL> w = gtk . Window ( ) <EOL> w . set_size_request ( <NUM_LIT> , - <NUM_LIT:1> ) <EOL> bbc = InfoBarGtkCollection ( ) <EOL> bb = InfoBarGtk ( "<STR_LIT>" ) <EOL> bbc . add_bar ( bb ) <EOL> bb = InfoBarGtk ( "<STR_LIT>" ) <EOL> bb . set_stock_icon ( gtk . STOCK_DIALOG_INFO ) <EOL> bbc . add_bar ( bb ) <EOL> bb = InfoBarGtk ( "<STR_LIT>" ) <EOL> bb . add_button ( "<STR_LIT>" , lambda : True ) <EOL> bbc . add_bar ( bb ) <EOL> bb = InfoBarGtk ( "<STR_LIT>" ) <EOL> bb . set_stock_icon ( gtk . STOCK_DIALOG_WARNING ) <EOL> bb . add_button ( "<STR_LIT>" , lambda : True ) <EOL> bb . add_close_button ( lambda : True ) <EOL> bbc . add_bar ( bb ) <EOL> w . add ( bbc ) <EOL> w . show_all ( ) <EOL> gtk . main ( ) </s>
