Exemplo n.º 1
0
    def setUp(self):
        EnamlTestAssistant.setUp(self)

        enaml_source = """
from enaml.widgets.api import MainWindow
from traits_enaml.widgets.enable_canvas import EnableCanvas

enamldef MainView(MainWindow):
    attr editor

    initial_size = (400, 100)

    EnableCanvas:
        component << editor
"""

        editor = CtfEditor(bounds=(400, 100),
                           prompt_color_selection=get_color)

        function = editor.function.copy()
        function.color.insert(ColorNode(center=0.25, color=(1.0, 0.0, 0.0)))
        function.opacity.insert(OpacityNode(center=0.5, opacity=0.5))
        editor.function = function

        self.editor = editor
        self.view, _ = self.parse_and_create(enaml_source, editor=self.editor)

        with self.event_loop():
            self.view.show()
Exemplo n.º 2
0
    def setUp(self):

        EnamlTestAssistant.setUp(self)

        enaml_source = """
from enaml.widgets.api import Container
from ensemble.volren.volume_viewer_ui import VolumeViewerContainer

enamldef MainView(Container): view:
    attr viewer

    VolumeViewerContainer:
        viewer << view.viewer

"""
        volume = np.random.normal(size=(32, 32, 32))
        volume = (255*(volume-volume.min())/volume.ptp()).astype(np.uint8)
        volume_data = VolumeData(raw_data=volume)
        volume_axes = VolumeAxes(visible_axis_scales=(True, True, True))
        volume_bbox = VolumeBoundingBox()
        volume_cut_planes = VolumeCutPlanes()
        scene_members = {'axes': volume_axes, 'bbox': volume_bbox,
                         'cut_planes': volume_cut_planes}
        self.viewer = VolumeViewer(volume_data=volume_data,
                                   scene_members=scene_members,
                                   clip_bounds=CLIP_BOUNDS)
        self.view, _ = self.parse_and_create(enaml_source,
                                             viewer=self.viewer)

        with self.event_loop():
            self.view.show()
Exemplo n.º 3
0
    def setUp(self):
        EnamlTestAssistant.setUp(self)

        enaml_source = """
from enaml.widgets.api import MainWindow
from traits_enaml.widgets.enable_canvas import EnableCanvas

enamldef MainView(MainWindow):
    attr editor

    initial_size = (400, 100)

    EnableCanvas:
        component << editor
"""
        if six.PY2:
            enaml_source = enaml_source.encode('utf-8')
        editor = CtfEditor(bounds=(400, 100),
                           prompt_color_selection=get_color)

        function = editor.function.copy()
        function.color.insert(ColorNode(center=0.25, color=(1.0, 0.0, 0.0)))
        function.opacity.insert(OpacityNode(center=0.5, opacity=0.5))
        window_col = WindowColorNode(center=0.75, color=(0.0, 1.0, 1.0))
        window_op = WindowOpacityNode(center=0.75, opacity=0.5,
                                      window_type='hanning')
        function.add_linked_nodes(window_col, window_op)
        editor.function = function

        self.editor = editor
        self.view, _ = self.parse_and_create(enaml_source, editor=self.editor)

        with self.event_loop():
            self.view.show()
    def setUp(self):

        EnamlTestAssistant.setUp(self)

        enaml_source = """
from enaml.widgets.api import MainWindow, Field

enamldef MainView(MainWindow):
    attr model
    Field:
        name = 'test_op_delegate'
        text := model.value_delegate
    Field:
        name = 'test_op_subscribe'
        text << model.value_subscribe
    Field:
        name = 'test_op_update'
        text >> model.value_update
    Field:
        name = 'test_op_simple'
        text = model.value_simple
    Field:
        name = 'test_op_notify'
        text ::
            model.value_notify = True
    Field:
        name = 'test_list_subscribe'
        text << str(model.list_values)
    Field:
        name = 'test_dict_subscribe'
        text << str(model.dict_values)
    Field:
        name = 'test_set_subscribe'
        text << str(model.set_values)
    Field:
        name = 'test_property_subscribe'
        text << str(model.property_value)
    Field:
        name = 'test_typed_property_subscribe'
        text << str(model.typed_property_value)
    Field:
        name = 'test_collection_property_subscribe'
        text << str(model.collection_property_value)
"""
        self.model = TraitModel()
        view, toolkit_view = self.parse_and_create(
            enaml_source, model=self.model
        )

        self.view = view
Exemplo n.º 5
0
    def setUp(self):

        EnamlTestAssistant.setUp(self)

        enaml_source = """
from enaml.widgets.api import MainWindow, Field

enamldef MainView(MainWindow):
    attr model
    Field:
        name = 'test_op_delegate'
        text := model.value_delegate
    Field:
        name = 'test_op_subscribe'
        text << model.value_subscribe
    Field:
        name = 'test_op_update'
        text >> model.value_update
    Field:
        name = 'test_op_simple'
        text = model.value_simple
    Field:
        name = 'test_op_notify'
        text ::
            model.value_notify = True
    Field:
        name = 'test_list_subscribe'
        text << str(model.list_values)
    Field:
        name = 'test_dict_subscribe'
        text << str(model.dict_values)
    Field:
        name = 'test_set_subscribe'
        text << str(model.set_values)
    Field:
        name = 'test_property_subscribe'
        text << str(model.property_value)
    Field:
        name = 'test_typed_property_subscribe'
        text << str(model.typed_property_value)
    Field:
        name = 'test_collection_property_subscribe'
        text << str(model.collection_property_value)
"""
        self.model = TraitModel()
        view, toolkit_view = self.parse_and_create(enaml_source,
                                                   model=self.model)

        self.view = view
    def setUp(self):

        EnamlTestAssistant.setUp(self)

        enaml_source = """
from enaml.widgets.api import MainWindow
from enaml.core.api import Include

enamldef MainView(MainWindow): win:
    attr traits_view


    Include:
        objects << [traits_view] if traits_view is not None else []
"""

        view, toolkit_view = self.parse_and_create(enaml_source)
        self.view = view
Exemplo n.º 7
0
    def setUp(self):

        EnamlTestAssistant.setUp(self)

        enaml_source = """
from enaml.widgets.api import MainWindow
from traits_enaml.widgets.mayavi_canvas import MayaviCanvas

enamldef MainView(MainWindow):
    attr scene

    MayaviCanvas:
        scene << parent.scene

"""
        self.scene = MlabSceneModel()
        self.view, _ = self.parse_and_create(enaml_source, scene=self.scene)
        self.canvas = self.find_enaml_widget(self.view, 'MayaviCanvas')
Exemplo n.º 8
0
    def setUp(self):

        EnamlTestAssistant.setUp(self)

        enaml_source = """
from enaml.widgets.api import MainWindow
from enaml.core.api import Include

enamldef MainView(MainWindow): win:
    attr traits_view


    Include:
        objects << [traits_view] if traits_view is not None else []
"""

        view, toolkit_view = self.parse_and_create(enaml_source)
        self.view = view
class TestEnamlTestAssistant(unittest.TestCase):
    def setUp(self):
        self.test_assistant = EnamlTestAssistant()
        self.test_assistant.setUp()

    def tearDown(self):
        self.test_assistant.tearDown()

    def test_parse_and_create(self):
        # Check that parse_and_create is able to create enaml objects
        # which refer to other enaml files.
        assistant = self.test_assistant
        try:
            assistant.parse_and_create(ENAML_SOURCE)
        except ImportError:
            self.fail(msg="Failed to set up enaml class.")

    def test_parse_and_create_kwargs(self):
        # Test that parse_and_create correctly passes along kwargs.
        assistant = self.test_assistant
        attr_value = 123
        view, _ = assistant.parse_and_create(
            ENAML_SOURCE, some_attr=attr_value)

        with assistant.event_loop():
            main_view = assistant.find_enaml_widget(view, "MainView")
            self.assertEqual(attr_value, main_view.some_attr)

    def test_find_all_enaml_widgets(self):
        assistant = self.test_assistant

        with traits_enaml.imports():
            from traits_enaml.testing.tests.enaml_test_container import (
                EnamlTestContainer)

        view, _ = assistant.parse_and_create(ENAML_SOURCE)

        with assistant.event_loop():
            widgets = assistant.find_all_enaml_widgets(
                view, "EnamlTestContainer")

        self.assertEqual(len(widgets), 3)
        for widget in widgets:
            self.assertIsInstance(widget, EnamlTestContainer)
Exemplo n.º 10
0
class TestEnamlTestAssistant(unittest.TestCase):
    def setUp(self):
        self.test_assistant = EnamlTestAssistant()
        self.test_assistant.setUp()

    def tearDown(self):
        self.test_assistant.tearDown()

    def test_parse_and_create(self):
        # Check that parse_and_create is able to create enaml objects
        # which refer to other enaml files.
        assistant = self.test_assistant
        try:
            assistant.parse_and_create(ENAML_SOURCE)
        except ImportError:
            self.fail(msg="Failed to set up enaml class.")

    def test_parse_and_create_kwargs(self):
        # Test that parse_and_create correctly passes along kwargs.
        assistant = self.test_assistant
        attr_value = 123
        view, _ = assistant.parse_and_create(
            ENAML_SOURCE, some_attr=attr_value)

        with assistant.event_loop():
            main_view = assistant.find_enaml_widget(view, "MainView")
            self.assertEqual(attr_value, main_view.some_attr)

    def test_find_all_enaml_widgets(self):
        assistant = self.test_assistant

        with traits_enaml.imports():
            from traits_enaml.testing.tests.enaml_test_container import (
                EnamlTestContainer)

        view, _ = assistant.parse_and_create(ENAML_SOURCE)

        with assistant.event_loop():
            widgets = assistant.find_all_enaml_widgets(
                view, "EnamlTestContainer")

        self.assertEqual(len(widgets), 3)
        for widget in widgets:
            self.assertIsInstance(widget, EnamlTestContainer)
Exemplo n.º 11
0
    def setUp(self):

        EnamlTestAssistant.setUp(self)

        enaml_source = """
from OpenGL import GL

from enaml.widgets.api import MainWindow
from traits_enaml.widgets.gl_canvas import GLCanvas

enamldef MainView(MainWindow): main:
    GLCanvas: canvas:
        init_gl => ():
            GL.glClearColor(0.0, 1.0, 0.0, 1.0)
        draw_gl => ():
            GL.glClear(GL.GL_COLOR_BUFFER_BIT)
"""
        view, toolkit_view = self.parse_and_create(enaml_source)
        self.view = view
        view.show()
Exemplo n.º 12
0
    def setUp(self):

        EnamlTestAssistant.setUp(self)

        enaml_source = """
from OpenGL import GL

from enaml.widgets.api import MainWindow
from traits_enaml.widgets.gl_canvas import GLCanvas

enamldef MainView(MainWindow): main:
    GLCanvas: canvas:
        init_gl => ():
            GL.glClearColor(0.0, 1.0, 0.0, 1.0)
        draw_gl => ():
            GL.glClear(GL.GL_COLOR_BUFFER_BIT)
"""
        view, toolkit_view = self.parse_and_create(enaml_source)
        self.view = view
        view.show()
Exemplo n.º 13
0
    def setUp(self):

        EnamlTestAssistant.setUp(self)

        enaml_source = """
from enaml.widgets.api import MainWindow
from traits_enaml.widgets.enable_canvas import EnableCanvas

enamldef MainView(MainWindow):
    attr model

    EnableCanvas:
        name = 'canvas'
        component << model.component
"""
        self.component = Component()
        self.model = Model(component=self.component)

        view, toolkit_view = self.parse_and_create(enaml_source,
                                                   model=self.model)

        self.view = view
Exemplo n.º 14
0
    def setUp(self):

        EnamlTestAssistant.setUp(self)

        enaml_source = """
from enaml.widgets.api import MainWindow
from traits_enaml.widgets.traits_view import TraitsView

enamldef MainView(MainWindow): win:
    attr model

    TraitsView:
        model = win.model
"""

        self.model = Model()

        view, toolkit_view = self.parse_and_create(enaml_source,
                                                   model=self.model)

        self.view = view
        self.traits_view = self.find_enaml_widget(view, "TraitsView")
    def setUp(self):

        EnamlTestAssistant.setUp(self)

        enaml_source = """
from enaml.widgets.api import MainWindow
from traits_enaml.widgets.enable_canvas import EnableCanvas

enamldef MainView(MainWindow):
    attr model

    EnableCanvas:
        name = 'canvas'
        component << model.component
"""
        self.component = Component()
        self.model = Model(component=self.component)

        view, toolkit_view = self.parse_and_create(
            enaml_source, model=self.model
        )

        self.view = view
Exemplo n.º 16
0
    def setUp(self):

        EnamlTestAssistant.setUp(self)

        enaml_source = """
from enaml.widgets.api import Container
from ensemble.volren.volume_viewer_ui import VolumeViewerContainer

enamldef MainView(Container): view:
    attr viewer

    VolumeViewerContainer:
        viewer << view.viewer

"""
        if six.PY2:
            enaml_source = enaml_source.encode('utf-8')
        volume = np.random.normal(size=(32, 32, 32))
        volume = (255 * (volume - volume.min()) / volume.ptp()).astype(
            np.uint8)
        volume_data = VolumeData(raw_data=volume)
        volume_axes = VolumeAxes(visible_axis_scales=(True, True, True))
        volume_bbox = VolumeBoundingBox()
        volume_cut_planes = VolumeCutPlanes()
        scene_members = {
            'axes': volume_axes,
            'bbox': volume_bbox,
            'cut_planes': volume_cut_planes
        }
        self.viewer = VolumeViewer(volume_data=volume_data,
                                   scene_members=scene_members,
                                   clip_bounds=CLIP_BOUNDS)
        self.view, _ = self.parse_and_create(enaml_source, viewer=self.viewer)

        with self.event_loop():
            self.view.show()