<s> from __future__ import absolute_import , division , print_function <EOL> from glue . viewers . common . qt . mpl_widget import MplWidget <EOL> from glue . viewers . common . qt . mouse_mode import MouseMode <EOL> from glue . icons . qt import get_icon <EOL> from . . toolbar import GlueToolbar <EOL> class MouseModeTest ( MouseMode ) : <EOL> def __init__ ( self , axes , release_callback = None ) : <EOL> super ( MouseModeTest , self ) . __init__ ( axes , release_callback = release_callback ) <EOL> self . icon = get_icon ( '<STR_LIT>' ) <EOL> self . mode_id = '<STR_LIT>' <EOL> self . action_text = '<STR_LIT>' <EOL> self . tool_tip = '<STR_LIT>' <EOL> self . last_mode = None <EOL> def press ( self , event ) : <EOL> self . last_mode = '<STR_LIT>' <EOL> def move ( self , event ) : <EOL> self . last_mode = '<STR_LIT>' <EOL> class TestToolbar ( object ) : <EOL> def setup_method ( self , method ) : <EOL> from glue . external . qt import QtGui <EOL> assert QtGui . QApplication . instance ( ) is not None <EOL> self . win = QtGui . QMainWindow ( ) <EOL> widget , axes = self . _make_plot_widget ( self . win ) <EOL> self . canvas = widget . canvas <EOL> self . axes = axes <EOL> self . tb = GlueToolbar ( self . canvas , self . win ) <EOL> self . mode = MouseModeTest ( self . axes , release_callback = self . callback ) <EOL> self . tb . add_mode ( self . mode ) <EOL> self . win . addToolBar ( self . tb ) <EOL> self . _called_back = False <EOL> def teardown_method ( self , method ) : <EOL> self . win . close ( ) <EOL> def _make_plot_widget ( self , parent ) : <EOL> widget = MplWidget ( parent ) <EOL> ax = widget . canvas . fig . add_subplot ( <NUM_LIT> ) <EOL> p = ax . plot ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) [ <NUM_LIT:0> ] <EOL> return widget , ax <EOL> def callback ( self , mode ) : <EOL> self . _called_back = True <EOL> def assert_valid_mode_state ( self , target_mode ) : <EOL> for mode in self . tb . buttons : <EOL> if mode == target_mode and self . tb . buttons [ mode ] . isCheckable ( ) : <EOL> assert self . tb . buttons [ mode ] . isChecked ( ) <EOL> self . tb . _active == target_mode <EOL> else : <EOL> assert not self . tb . buttons [ mode ] . isChecked ( ) <EOL> def test_callback ( self ) : <EOL> self . tb . buttons [ '<STR_LIT>' ] . trigger ( ) <EOL> self . mode . release ( None ) <EOL> assert self . _called_back </s>
