Ejemplo n.º 1
0
    def __call__(self):
        """ block execution and start the event handler """
        self.mode = 'select'
        self.seed_select = None
        _BlockInput.__call__(self, n=0, timeout=0)

        return None
Ejemplo n.º 2
0
    def __call__(self, timeout=-1):
        """
        Blocking call to retrieve a single key click
        Returns key or None if timeout
        """
        self.ev = None

        BlockingInput.__call__(self, n=1, timeout=timeout)

        return self.ev
Ejemplo n.º 3
0
    def __call__(self, timeout=30):
        """
        Blocking call to retrieve a single mouse click or key press.

        Returns ``True`` if key press, ``False`` if mouse click, or ``None`` if
        timed out.
        """
        self.keyormouse = None
        BlockingInput.__call__(self, n=1, timeout=timeout)

        return self.event_key
Ejemplo n.º 4
0
    def __init__(self, seed_map_editor, fig=1):
        if fig:
            _plt.ion()
            _plt.figure(fig)
        fig = _plt.gcf()

        self.editor = seed_map_editor

        self.display()

        _BlockInput.__init__(
            self,
            fig=fig,
            eventslist=('key_press_event', 'button_press_event',
                        'motion_notify_event', 'button_release_event'))
Ejemplo n.º 5
0
    def post_event(self):
        """ Dispatch event """
        assert len(self.events) > 0, "No events yet"

        update_display = False
        event = self.events[-1]
        if event.name == 'key_press_event':
            self.key_event(event)
        elif self.mode == 'pause':
            if self.n > 0:
                self.n += 1
            _BlockInput.post_event(self)
            return
        else:
            button = event.button
            x, y = event.xdata, event.ydata
            if x is None:
                return

            if button == 1:
                if self.mode == 'select':
                    self.mode = 'draw'
                    self.polygon = [[x, y]]
                elif self.mode == 'draw':
                    self.polygon.append([x, y])
                    if event.name == 'button_release_event':
                        try:
                            self.mode = 'wait'
                            self.editor.append(action='add',
                                               point=self.polygon)  # add seed
                            update_display = True
                            self.polygon = None
                        finally:
                            self.mode = 'select'
                    self.update_polygon()

            elif button == 3:
                if self.mode == 'select':
                    self.mode = 'wait'
                    self.editor.append(action='delete',
                                       point=[x, y])  # delete seed
                    update_display = True
                    self.mode = 'select'

        if update_display:
            self.update_display()
Ejemplo n.º 6
0
    def _initialize_fig_show(self):
        # fig_save will be resized to image size, only fig_show needs fig_size.
        fig = plt.figure(**self.fig_show_cfg)
        ax = fig.add_subplot()

        # remove white edges by set subplot margin
        fig.subplots_adjust(left=0, right=1, bottom=0, top=1)

        self.fig_show, self.ax_show = fig, ax
        self.blocking_input = BlockingInput(self.fig_show,
                                            eventslist=('key_press_event',
                                                        'close_event'))
Ejemplo n.º 7
0
    def __init__(self, ax=None):
        if ax is None: ax = gca()
        self.ax = ax

        # drawtype is 'box' or 'line' or 'none'
        self.selector = RectangleSelector(self.ax,
                                          self._callback,
                                          drawtype='box',
                                          useblit=True,
                                          minspanx=5,
                                          minspany=5,
                                          spancoords='pixels')
        self.selector.set_active(False)
        self.block = BlockingInput(self.ax.figure)
Ejemplo n.º 8
0
    def cleanup(self, event=None):
        # clean the figure, when input is done
        if self.show_clicks:
            if event:
                # make sure we don't mess with the axes zoom
                xlim = event.inaxes.get_xlim()
                ylim = event.inaxes.get_ylim()

            for mark in self.marks:
                mark.remove()
            self.marks = []
            for line in self.lines:
                line.remove()
            self.lines = []

            if event:
                # before we draw, make sure to reset the limits
                event.inaxes.set_xlim(xlim)
                event.inaxes.set_ylim(ylim)

            self.fig.canvas.draw()
            # Call base class to remove callbacks
            _BlockInput.cleanup(self)
Ejemplo n.º 9
0
    def __init__(self, fig):
        """Create a BlockingKeyInput

        \param fig The figure to monitor for keyboard events
        """
        BlockingInput.__init__(self, fig=fig, eventslist=('key_press_event', ))
Ejemplo n.º 10
0
 def stop(self, event):
     """
     Stop block, ending user interaction
     """
     _BlockInput.pop(self, -1)
     self.fig.canvas.stop_event_loop()
Ejemplo n.º 11
0
 def __init__(self, fig):
     # BlockingInput.__init__(self, fig=fig, eventslist=(
     #     'button_press_event', 'key_press_event'))
     BlockingInput.__init__(self, fig=fig, eventslist=('key_press_event', ))
     self.event_key = None