Esempio n. 1
0
def test_update_theme(
    mock_add_theme,
    mock_remove_theme,
    mock_icon_changed,
    make_napari_viewer,
    qapp,
):
    viewer = make_napari_viewer()

    blue = get_theme("dark", False)
    blue.name = "blue"
    register_theme("blue", blue)

    # triggered when theme was added
    mock_add_theme.assert_called()
    mock_remove_theme.assert_not_called()

    unregister_theme("blue")
    # triggered when theme was removed
    mock_remove_theme.assert_called()

    mock_icon_changed.assert_not_called()
    viewer.theme = "light"
    theme = _themes["light"]
    theme.icon = "#FF0000"
    mock_icon_changed.assert_called()
Esempio n. 2
0
def test_register_theme():
    # Check that blue theme is not listed in available themes
    themes = available_themes()
    assert 'test_blue' not in themes

    # Create new blue theme based on dark theme
    blue_theme = get_theme('dark')
    blue_theme.update(
        background='rgb(28, 31, 48)',
        foreground='rgb(45, 52, 71)',
        primary='rgb(80, 88, 108)',
        current='rgb(184, 112, 0)',
    )

    # Register blue theme
    register_theme('test_blue', blue_theme)

    # Check that blue theme is listed in available themes
    themes = available_themes()
    assert 'test_blue' in themes

    # Check that the dark theme has not been overwritten
    dark_theme = get_theme('dark')
    assert not dark_theme['background'] == blue_theme['background']

    # Check that blue theme can be gotten from available themes
    theme = get_theme('test_blue')
    assert theme['background'] == blue_theme['background']
Esempio n. 3
0
def test_rebuild_theme_settings():
    settings = get_settings()
    assert "another-theme" not in available_themes()
    # theme is not updated
    with pytest.raises(ValidationError):
        settings.appearance.theme = "another-theme"
    blue_theme = get_theme("dark")
    register_theme("another-theme", blue_theme)
    settings.appearance.theme = "another-theme"
Esempio n. 4
0
def test_custom_theme_settings(settings):
    # See: https://github.com/napari/napari/issues/2340
    custom_theme_name = "blue"

    # No theme registered yet, this should fail
    with pytest.raises(pydantic.error_wrappers.ValidationError):
        settings.appearance.theme = custom_theme_name

    blue_theme = get_theme('dark')
    blue_theme.update(
        background='rgb(28, 31, 48)',
        foreground='rgb(45, 52, 71)',
        primary='rgb(80, 88, 108)',
        current='rgb(184, 112, 0)',
    )
    register_theme(custom_theme_name, custom_theme_name)

    # Theme registered, should pass validation
    settings.appearance.theme = custom_theme_name
Esempio n. 5
0
def test_unregister_theme():
    # Create new blue theme based on dark theme
    blue_theme = get_theme('dark')
    blue_theme.update(
        background='rgb(28, 31, 48)',
        foreground='rgb(45, 52, 71)',
        primary='rgb(80, 88, 108)',
        current='rgb(184, 112, 0)',
    )

    # Register blue theme
    register_theme('test_blue', blue_theme)

    # Check that blue theme is listed in available themes
    themes = available_themes()
    assert 'test_blue' in themes

    # Remove theme from available themes
    unregister_theme("test_blue")
    themes = available_themes()
    assert 'test_blue' not in themes
Esempio n. 6
0
"""
Displays an image and sets the theme to new custom theme.
"""

from skimage import data
import napari
from napari.utils.theme import available_themes, get_theme, register_theme

with napari.gui_qt():
    # create the viewer with an image
    viewer = napari.view_image(data.astronaut(), rgb=True, name='astronaut')

    # List themes
    print('Originally themes', available_themes())

    blue_theme = get_theme('dark')
    blue_theme.update(
        background='rgb(28, 31, 48)',
        foreground='rgb(45, 52, 71)',
        primary='rgb(80, 88, 108)',
        current='rgb(184, 112, 0)',
    )

    register_theme('blue', blue_theme)

    # List themes
    print('New themes', available_themes())

    # Set theme
    viewer.theme = 'blue'