<s> import os <EOL> from skimage import data , img_as_float , io , img_as_uint <EOL> from skimage . viewer import ImageViewer <EOL> from skimage . viewer . qt import QtGui , QtCore , has_qt <EOL> from skimage . viewer . widgets import ( <EOL> Slider , OKCancelButtons , SaveButtons , ComboBox , CheckBox , Text ) <EOL> from skimage . viewer . plugins . base import Plugin <EOL> from numpy . testing import assert_almost_equal , assert_equal <EOL> from numpy . testing . decorators import skipif <EOL> from skimage . _shared . _warnings import expected_warnings <EOL> def get_image_viewer ( ) : <EOL> image = data . coins ( ) <EOL> viewer = ImageViewer ( img_as_float ( image ) ) <EOL> viewer += Plugin ( ) <EOL> return viewer <EOL> @ skipif ( not has_qt ) <EOL> def test_check_box ( ) : <EOL> viewer = get_image_viewer ( ) <EOL> cb = CheckBox ( '<STR_LIT:hello>' , value = True , alignment = '<STR_LIT:left>' ) <EOL> viewer . plugins [ <NUM_LIT:0> ] += cb <EOL> assert_equal ( cb . val , True ) <EOL> cb . val = False <EOL> assert_equal ( cb . val , False ) <EOL> cb . val = <NUM_LIT:1> <EOL> assert_equal ( cb . val , True ) <EOL> cb . val = <NUM_LIT:0> <EOL> assert_equal ( cb . val , False ) <EOL> @ skipif ( not has_qt ) <EOL> def test_combo_box ( ) : <EOL> viewer = get_image_viewer ( ) <EOL> cb = ComboBox ( '<STR_LIT:hello>' , ( '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ) ) <EOL> viewer . plugins [ <NUM_LIT:0> ] += cb <EOL> assert_equal ( str ( cb . val ) , '<STR_LIT:a>' ) <EOL> assert_equal ( cb . index , <NUM_LIT:0> ) <EOL> cb . index = <NUM_LIT:2> <EOL> assert_equal ( str ( cb . val ) , '<STR_LIT:c>' ) , <EOL> assert_equal ( cb . index , <NUM_LIT:2> ) <EOL> @ skipif ( not has_qt ) <EOL> def test_text_widget ( ) : <EOL> viewer = get_image_viewer ( ) <EOL> txt = Text ( '<STR_LIT:hello>' , '<STR_LIT>' ) <EOL> viewer . plugins [ <NUM_LIT:0> ] += txt <EOL> assert_equal ( str ( txt . text ) , '<STR_LIT>' ) <EOL> txt . text = '<STR_LIT>' <EOL> assert_equal ( str ( txt . text ) , '<STR_LIT>' ) <EOL> @ skipif ( not has_qt ) <EOL> def test_slider_int ( ) : <EOL> viewer = get_image_viewer ( ) <EOL> sld = Slider ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:10> , value_type = '<STR_LIT:int>' ) <EOL> viewer . plugins [ <NUM_LIT:0> ] += sld <EOL> assert_equal ( sld . val , <NUM_LIT:4> ) <EOL> sld . val = <NUM_LIT:6> <EOL> assert_equal ( sld . val , <NUM_LIT:6> ) <EOL> sld . editbox . setText ( '<STR_LIT:5>' ) <EOL> sld . _on_editbox_changed ( ) <EOL> assert_equal ( sld . val , <NUM_LIT:5> ) <EOL> @ skipif ( not has_qt ) <EOL> def test_slider_float ( ) : <EOL> viewer = get_image_viewer ( ) <EOL> sld = Slider ( '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , value = <NUM_LIT> , value_type = '<STR_LIT:float>' , <EOL> orientation = '<STR_LIT>' , update_on = '<STR_LIT>' ) <EOL> viewer . plugins [ <NUM_LIT:0> ] += sld <EOL> assert_equal ( sld . val , <NUM_LIT> ) <EOL> sld . val = <NUM_LIT> <EOL> assert_almost_equal ( sld . val , <NUM_LIT> , <NUM_LIT:2> ) <EOL> sld . editbox . setText ( '<STR_LIT>' ) <EOL> sld . _on_editbox_changed ( ) <EOL> assert_almost_equal ( sld . val , <NUM_LIT> , <NUM_LIT:2> ) <EOL> @ skipif ( not has_qt ) <EOL> def test_save_buttons ( ) : <EOL> viewer = get_image_viewer ( ) <EOL> sv = SaveButtons ( ) <EOL> viewer . plugins [ <NUM_LIT:0> ] += sv <EOL> import tempfile <EOL> fid , filename = tempfile . mkstemp ( suffix = '<STR_LIT>' ) <EOL> os . close ( fid ) <EOL> timer = QtCore . QTimer ( ) <EOL> timer . singleShot ( <NUM_LIT:100> , QtGui . QApplication . quit ) <EOL> sv . save_stack . click ( ) <EOL> sv . save_file . click ( ) <EOL> sv . save_to_stack ( ) <EOL> with expected_warnings ( [ '<STR_LIT>' ] ) : <EOL> sv . save_to_file ( filename ) <EOL> img = data . imread ( filename ) <EOL> with expected_warnings ( [ '<STR_LIT>' ] ) : <EOL> assert_almost_equal ( img , img_as_uint ( viewer . image ) ) <EOL> img = io . pop ( ) <EOL> assert_almost_equal ( img , viewer . image ) <EOL> os . remove ( filename ) <EOL> @ skipif ( not has_qt ) <EOL> def test_ok_buttons ( ) : <EOL> viewer = get_image_viewer ( ) <EOL> ok = OKCancelButtons ( ) <EOL> viewer . plugins [ <NUM_LIT:0> ] += ok <EOL> ok . update_original_image ( ) , <EOL> ok . close_plugin ( ) </s>
