Ejemplo n.º 1
0
    def run(self, session):
        from spyderlib import spyder
        from spyderlib.config import CONF

        cs.exit_if_not_exists(session)
        app = spyder.initialize()

        # This should come from our command line parser, however, Spyder does
        # not provide a way to get the argument parser but only the parsed
        # arguments.
        opts = {
            'working_directory': cs.path(),
            'debug': False,
            'profile': False,
            'multithreaded': False,
            'light': False
        }

        # The python executable is set explicitly here, because Spyder tends
        # not to pick up the one used in a virtualenv. This should be set in a
        # profile in order to not mess with the user's settings.
        CONF.set('console', 'pythonexecutable', sys.executable)

        main = spyder.MainWindow(Bunch(opts))
        main.setup()
        main.show()
        main.open_file(cs.path(session))

        app.exec_()
Ejemplo n.º 2
0
        def get_enum_bunch(enum):
            enum_map = {}

            for key, value in enum.__enum_values__.items():
                name = value.value_nick.upper().replace('-', '_')
                enum_map[name] = key

            return Bunch(enum_map)
Ejemplo n.º 3
0
class Camera(Device):
    """Base class for remotely controllable cameras.

    .. py:attribute:: frame-rate

        Frame rate of acquisition in q.count per time unit.
    """

    trigger_sources = Bunch(['AUTO', 'SOFTWARE', 'EXTERNAL'])
    trigger_types = Bunch(['EDGE', 'LEVEL'])
    state = State(default='standby')
    frame_rate = Quantity(1 / q.second, help="Frame frequency")
    trigger_source = Parameter(help="Trigger source")

    def __init__(self):
        super(Camera, self).__init__()
        self.convert = identity

    @background
    @check(source='standby', target='recording')
    async def start_recording(self):
        """
        start_recording()

        Start recording frames.
        """
        await self._record_real()

    @background
    @check(source='recording', target='standby')
    async def stop_recording(self):
        """
        stop_recording()

        Stop recording frames.
        """
        await self._stop_real()

    @contextlib.asynccontextmanager
    async def recording(self):
        """
        recording()

        A context manager for starting and stopping the camera.

        In general it is used with the ``async with`` keyword like this::

            async with camera.recording():
                frame = await camera.grab()
        """
        await self.start_recording()
        try:
            yield
        finally:
            LOG.log(AIODEBUG, 'stop recording in recording()')
            await self.stop_recording()

    @background
    async def trigger(self):
        """Trigger a frame if possible."""
        await self._trigger_real()

    @background
    async def grab(self):
        """Return a NumPy array with data of the current frame."""
        return self.convert(await self._grab_real())

    async def stream(self):
        """
        stream()

        Grab frames continuously yield them. This is an async generator.
        """
        await self.set_trigger_source(self.trigger_sources.AUTO)
        await self.start_recording()

        while await self.get_state() == 'recording':
            yield await self.grab()

    async def _get_trigger_source(self):
        raise AccessorNotImplementedError

    async def _set_trigger_source(self, source):
        raise AccessorNotImplementedError

    async def _record_real(self):
        raise AccessorNotImplementedError

    async def _stop_real(self):
        raise AccessorNotImplementedError

    async def _trigger_real(self):
        raise AccessorNotImplementedError

    async def _grab_real(self):
        raise AccessorNotImplementedError
Ejemplo n.º 4
0
class Camera(Device):

    """Base class for remotely controllable cameras.

    .. py:attribute:: frame-rate

        Frame rate of acquisition in q.count per time unit.
    """

    trigger_modes = Bunch(['AUTO', 'SOFTWARE', 'EXTERNAL'])
    state = State(default='standby')
    frame_rate = Quantity(1.0 / q.second, help="Frame frequency")
    trigger_mode = Parameter(help="Trigger mode")

    def __init__(self):
        super(Camera, self).__init__()
        self.convert = identity

    @check(source='standby', target='recording')
    def start_recording(self):
        """Start recording frames."""
        self._record_real()

    @check(source='recording', target='standby')
    def stop_recording(self):
        """Stop recording frames."""
        self._stop_real()

    @contextlib.contextmanager
    def recording(self):
        """
        A context manager for starting and stopping the camera.

        In general it is used with the ``with`` keyword like this::

            with camera.recording():
                frame = camera.grab()
        """
        self.start_recording()
        try:
            yield
        finally:
            self.stop_recording()

    def trigger(self):
        """Trigger a frame if possible."""
        self._trigger_real()

    def grab(self):
        """Return a NumPy array with data of the current frame."""
        return self.convert(self._grab_real())

    @async
    def grab_async(self):
        return self.grab()

    @async
    def stream(self, consumer):
        """Grab frames continuously and send them to *consumer*, which
        is a coroutine.
        """
        self.trigger_mode = self.trigger_modes.AUTO
        self.start_recording()

        while self.state == 'recording':
            consumer.send(self.grab())

    def _get_trigger_mode(self):
        raise AccessorNotImplementedError

    def _set_trigger_mode(self, mode):
        raise AccessorNotImplementedError

    def _record_real(self):
        raise AccessorNotImplementedError

    def _stop_real(self):
        raise AccessorNotImplementedError

    def _trigger_real(self):
        raise AccessorNotImplementedError

    def _grab_real(self):
        raise AccessorNotImplementedError