<s> from __future__ import absolute_import , division , print_function <EOL> import os <EOL> from glue . external . qt import QtGui <EOL> from glue import core <EOL> from glue . plugins . dendro_viewer . client import DendroClient <EOL> from glue . viewers . common . qt . toolbar import GlueToolbar <EOL> from glue . viewers . common . qt . mouse_mode import PickMode <EOL> from glue . utils . qt import load_ui <EOL> from glue . utils . qt . widget_properties import ( ButtonProperty , CurrentComboProperty , <EOL> connect_bool_button , connect_current_combo ) <EOL> from glue . viewers . common . qt . data_viewer import DataViewer <EOL> from glue . viewers . common . qt . mpl_widget import MplWidget , defer_draw <EOL> from glue . utils import nonpartial <EOL> class DendroWidget ( DataViewer ) : <EOL> """<STR_LIT>""" <EOL> LABEL = '<STR_LIT>' <EOL> _property_set = DataViewer . _property_set + '<STR_LIT>' . split ( ) <EOL> ylog = ButtonProperty ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> height = CurrentComboProperty ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> parent = CurrentComboProperty ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> order = CurrentComboProperty ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , session , parent = None ) : <EOL> super ( DendroWidget , self ) . __init__ ( session , parent ) <EOL> self . central_widget = MplWidget ( ) <EOL> self . option_widget = QtGui . QWidget ( ) <EOL> self . setCentralWidget ( self . central_widget ) <EOL> self . ui = load_ui ( '<STR_LIT>' , self . option_widget , <EOL> directory = os . path . dirname ( __file__ ) ) <EOL> self . client = DendroClient ( self . _data , <EOL> self . central_widget . canvas . fig , <EOL> layer_artist_container = self . _layer_artist_container ) <EOL> self . _connect ( ) <EOL> self . make_toolbar ( ) <EOL> self . statusBar ( ) . setSizeGripEnabled ( False ) <EOL> @ staticmethod <EOL> def _get_default_tools ( ) : <EOL> return [ ] <EOL> def _connect ( self ) : <EOL> ui = self . ui <EOL> cl = self . client <EOL> connect_bool_button ( cl , '<STR_LIT>' , ui . ylog ) <EOL> connect_current_combo ( cl , '<STR_LIT>' , ui . parentCombo ) <EOL> connect_current_combo ( cl , '<STR_LIT>' , ui . heightCombo ) <EOL> connect_current_combo ( cl , '<STR_LIT>' , ui . orderCombo ) <EOL> def make_toolbar ( self ) : <EOL> result = GlueToolbar ( self . central_widget . canvas , self , <EOL> name = '<STR_LIT>' ) <EOL> for mode in self . _mouse_modes ( ) : <EOL> result . add_mode ( mode ) <EOL> self . addToolBar ( result ) <EOL> return result <EOL> def _mouse_modes ( self ) : <EOL> axes = self . client . axes <EOL> def apply_mode ( mode ) : <EOL> self . client . apply_roi ( mode . roi ( ) ) <EOL> def on_move ( mode ) : <EOL> if mode . _drag : <EOL> self . client . apply_roi ( mode . roi ( ) ) <EOL> return [ PickMode ( axes , <EOL> move_callback = on_move , <EOL> roi_callback = apply_mode ) ] <EOL> def _update_combos ( self , data = None ) : <EOL> data = data or self . client . display_data <EOL> if data is None : <EOL> return <EOL> for combo in [ self . ui . heightCombo , <EOL> self . ui . parentCombo , <EOL> self . ui . orderCombo ] : <EOL> combo . blockSignals ( True ) <EOL> ids = [ ] <EOL> idx = combo . currentIndex ( ) <EOL> old = combo . itemData ( idx ) if idx > <NUM_LIT:0> else None <EOL> combo . clear ( ) <EOL> for cid in data . components : <EOL> if cid . hidden and cid is not data . pixel_component_ids [ <NUM_LIT:0> ] : <EOL> continue <EOL> combo . addItem ( cid . label , userData = cid ) <EOL> ids . append ( cid ) <EOL> try : <EOL> combo . setCurrentIndex ( ids . index ( old ) ) <EOL> except ValueError : <EOL> combo . setCurrentIndex ( <NUM_LIT:0> ) <EOL> combo . blockSignals ( False ) <EOL> def add_data ( self , data ) : <EOL> """<STR_LIT>""" <EOL> if data in self . client : <EOL> return <EOL> self . _update_combos ( data ) <EOL> self . client . add_layer ( data ) <EOL> return True <EOL> def add_subset ( self , subset ) : <EOL> """<STR_LIT>""" <EOL> self . add_data ( subset . data ) <EOL> if subset . data in self . client : <EOL> self . client . add_layer ( subset ) <EOL> return True <EOL> def register_to_hub ( self , hub ) : <EOL> super ( DendroWidget , self ) . register_to_hub ( hub ) <EOL> self . client . register_to_hub ( hub ) <EOL> hub . subscribe ( self , core . message . ComponentsChangedMessage , <EOL> nonpartial ( self . _update_combos ( ) ) ) <EOL> def unregister ( self , hub ) : <EOL> super ( DendroWidget , self ) . unregister ( hub ) <EOL> hub . unsubscribe_all ( self . client ) <EOL> hub . unsubscribe_all ( self ) <EOL> def options_widget ( self ) : <EOL> return self . option_widget <EOL> @ defer_draw <EOL> def restore_layers ( self , rec , context ) : <EOL> from glue . core . callback_property import delay_callback <EOL> with delay_callback ( self . client , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) : <EOL> self . client . restore_layers ( rec , context ) <EOL> self . _update_combos ( ) </s>
