<s> from __future__ import absolute_import , division , print_function <EOL> from glue . external . qt import QtGui <EOL> from glue . core . hub import HubListener <EOL> from glue . core . message import ComponentsChangedMessage <EOL> class ComponentIDCombo ( QtGui . QComboBox , HubListener ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , data = None , parent = None , visible_only = True ) : <EOL> QtGui . QComboBox . __init__ ( self , parent ) <EOL> self . _data = data <EOL> self . _visible_only = visible_only <EOL> @ property <EOL> def data ( self ) : <EOL> return self . _data <EOL> @ data . setter <EOL> def data ( self , value ) : <EOL> if value is None : <EOL> return <EOL> self . _data = value <EOL> if value . hub is not None : <EOL> self . register_to_hub ( value . hub ) <EOL> self . refresh_components ( ) <EOL> @ property <EOL> def component ( self ) : <EOL> return self . itemData ( self . currentIndex ( ) ) <EOL> @ component . setter <EOL> def component ( self , value ) : <EOL> for i in range ( self . count ( ) ) : <EOL> if self . itemData ( i ) is value : <EOL> self . setCurrentIndex ( i ) <EOL> return <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % value ) <EOL> def refresh_components ( self ) : <EOL> if self . data is None : <EOL> return <EOL> self . blockSignals ( True ) <EOL> old_data = self . itemData ( self . currentIndex ( ) ) <EOL> self . clear ( ) <EOL> if self . _visible_only : <EOL> fields = self . data . visible_components <EOL> else : <EOL> fields = self . data . components <EOL> index = <NUM_LIT:0> <EOL> for i , f in enumerate ( fields ) : <EOL> self . addItem ( f . label , userData = f ) <EOL> if f == old_data : <EOL> index = i <EOL> self . blockSignals ( False ) <EOL> self . setCurrentIndex ( index ) <EOL> def register_to_hub ( self , hub ) : <EOL> hub . subscribe ( self , <EOL> ComponentsChangedMessage , <EOL> handler = lambda x : self . refresh_components , <EOL> filter = lambda x : x . data is self . _data ) </s>
