Esempio n. 1
0
def test_disconnecting_signal_stops_emitting_to_slot():
    signal = Signal()
    fun = Mock()
    signal.connect(callback=fun)
    signal.emit()
    fun.assert_called_once()

    signal.disconnect(callback=fun)
    signal.emit()
    fun.assert_called_once()
Esempio n. 2
0
def test_signal_emits_keyword_argments_to_slot():
    signal = Signal()
    fun = Mock()
    signal.connect(callback=fun)
    signal.emit(hello="world")
    fun.assert_called_with(hello="world")

    signal.emit(data=3)
    fun.assert_called_with(data=3)

    signal.emit(data1=10, data2="Hi")
    fun.assert_called_with(data1=10, data2="Hi")
Esempio n. 3
0
class UpdateSectionTransformCommand(BaseCommand):
    _section_repo: BaseSectionRepo
    _atlas_repo: BaseAtlasRepo
    section_moved: Signal = Signal()

    def __call__(self, **dims):  # type: ignore
        for dim in dims:
            if dim not in [
                    'right', 'superior', 'anterior', 'rot_lateral',
                    'rot_axial', 'rot_median'
            ]:
                raise TypeError(f'Unknown dimension "{dim}"')

        sections = self._section_repo.sections
        atlas = self._atlas_repo.get_atlas()
        if not sections:
            raise RuntimeError('Section is not loaded yet')
        if not atlas:
            raise RuntimeError('Atlas is not loaded yet')
        section = sections[0]

        new_section = section.set_plane_3d(**dims)
        atlas_section = register(section=new_section, atlas=atlas)
        self._section_repo.save_section(new_section)
        self.section_moved.emit(
            transform=new_section.affine_transform,
            atlas_slice_image=atlas_section.image.channels[0])
Esempio n. 4
0
class SelectChannelCommand(BaseCommand):
    _repo: BaseSectionRepo
    channel_changed: Signal = Signal()

    def __call__(self, channel: int):  # type: ignore
        section = self._repo.sections[0]
        # if section is None:
        #     self._presenter.show_error("No section loaded yet.")
        # try:
        image = section.image.channels[channel - 1]
        self.channel_changed.emit(channel=channel, image=image)
Esempio n. 5
0
class GetPixelRegistrationDataCommand(BaseCommand):
    _repo: BaseSectionRepo
    coord_data_requested: Signal = Signal()

    def __call__(self, i: int, j: int):  # type: ignore
        sections = self._repo.sections
        if not sections:
            return
        section = sections[0]
        x, y, z = section.pos_from_coord(i=i, j=j)
        self.coord_data_requested.emit(image_coords=ImageCoord(i=i, j=j),
                                       atlas_coords=AtlasCoord(x=x, y=y, z=z))
Esempio n. 6
0
def test_signal_calls_slot_when_emitted():
    signal = Signal()
    fun = Mock()
    signal.connect(callback=fun)
    fun.assert_not_called()
    signal.emit()
    fun.assert_called_once()
Esempio n. 7
0
class MoveSectionCommand(BaseCommand):
    _section_repo: BaseSectionRepo
    _atlas_repo: BaseAtlasRepo
    section_moved: Signal = Signal()

    def __call__(self, x=0., y=0., z=0., rx=0., ry=0., rz=0.):
        sections = self._section_repo.sections
        atlas = self._atlas_repo.get_atlas()
        if not sections or not atlas:
            print("not atlas", atlas)
            return
        section = sections[0]
        new_section = section.translate(dx=x, dy=y, dz=z).rotate(dx=rx,
                                                                 dy=ry,
                                                                 dz=rz)

        atlas_section = atlas.slice(plane=new_section.plane_3d)
        assert atlas_section.image.num_channels == 1, f"{atlas_section.image.num_channels, atlas_section.image.shape}"
        atlas_slice_image = atlas_section.image.channels[0]

        self._section_repo.save_section(new_section)
        self.section_moved.emit(transform=new_section.affine_transform,
                                atlas_slice_image=atlas_slice_image)
Esempio n. 8
0
class MoveSectionCommand(BaseCommand):
    _section_repo: BaseSectionRepo
    _atlas_repo: BaseAtlasRepo
    section_moved: Signal = Signal()

    def __call__(self,
                 right=0.,
                 superior=0.,
                 anterior=0.,
                 rot_lateral=0.,
                 rot_axial=0.,
                 rot_median=0.):  # type: ignore
        section = \
            self._section_repo.sections[0] \
            .translate(right=right, superior=superior, anterior=anterior) \
            .rotate(rot_lateral=rot_lateral, rot_axial=rot_axial, rot_median=rot_median)

        atlas = self._atlas_repo.get_atlas()
        atlas_section = register(section=section, atlas=atlas)

        self._section_repo.save_section(section)
        self.section_moved.emit(
            transform=section.affine_transform,
            atlas_slice_image=atlas_section.image.channels[0])
Esempio n. 9
0
def test_signal_emits_to_multiple_slots():
    signal = Signal()
    fun1, fun2 = Mock(), Mock()
    signal.connect(fun1)
    signal.connect(fun2)
    signal.emit()
    assert fun1.call_count == 1
    assert fun2.call_count == 1

    fun3 = Mock()
    signal.connect(fun3)
    signal.emit()
    assert fun1.call_count == 2
    assert fun2.call_count == 2
    assert fun3.call_count == 1

    signal.disconnect(fun2)
    signal.emit()
    assert fun1.call_count == 3
    assert fun2.call_count == 2
    assert fun3.call_count == 2