def append_button(self, text, divider=None, rect=None, callback=None,
                      size='9%', location='bottom', ax=None, **kwargs):
        """ Adds a button to the current page """

        if rect is not None:
            new_ax = df2.plt.axes(rect)
        if rect is None and divider is None:
            if ax is None:
                ax = df2.gca()
            divider = df2.ensure_divider(ax)
        if divider is not None:
            new_ax = divider.append_axes(location, size=size, pad=.05)
        if callback is not None:
            color, hovercolor = u'.85', u'.95'
        else:
            color, hovercolor = u'.88', u'.88'
            #color, hovercolor = u'.45', u'.45'
        #if isinstance(text, six.text_type):
        new_but = mpl.widgets.Button(
            new_ax, text, color=color, hovercolor=hovercolor)
        #elif isinstance(text, (list, tuple)):
        #    labels = [False] * len(text)
        #    labels[0] = True
        #    new_but = mpl.widgets.CheckButtons(new_ax, text, labels)
        #else:
        #    raise ValueError('bad input')

        if callback is not None:
            new_but.on_clicked(callback)
        else:
            button_text = new_but.ax.texts[0]
            button_text.set_color('.6')
            #button_text.set_color('r')
            #ut.embed()
            #print('new_but.color = %r' % (new_but.color,))
        #else:
        # TODO: figure ou how to gray out these buttons
        #    new_but.color = u'.1'
        #    new_but.hovercolor = u'.1'
        #    new_but.active = False
        #    print('new_but.color = %r' % (new_but.color,))
        ph.set_plotdat(new_ax, 'viztype', 'button')
        ph.set_plotdat(new_ax, 'text', text)
        #ph.set_plotdat(new_ax, 'parent_axes', ax)
        if ax is not None:
            child_axes = ph.get_plotdat(ax, 'child_axes', [])
            child_axes.append(new_ax)
            ph.set_plotdat(ax, 'child_axes', child_axes)
        for key, val in six.iteritems(kwargs):
            ph.set_plotdat(new_ax, key, val)
        # Keep buttons from losing scrop
        tup = (new_but, new_ax)
        self.scope.append(tup)
        return tup
Exemple #2
0
    def plot_annotationmatch(self, index, draw=True, make_buttons=True):
        self.select_candidate_match(index)
        # Get index relative to the page
        px = index - self.start_index
        pnum = self.pnum_(px)
        # Setup figure
        fnum = self.fnum
        fig = df2.figure(fnum=fnum, pnum=pnum, docla=True, doclf=False)
        fig
        #self.ax = ax = df2.gca()
        # Get viz params
        qres = self.current_qres
        aid1, aid2 = self.current_match_aids
        ibs = self.ibs
        kwargs = self.interactkw
        # Vizualize
        ax = viz_matches.show_matches(ibs,
                                      qres,
                                      aid2,
                                      self_fm=[],
                                      fnum=fnum,
                                      pnum=pnum,
                                      **kwargs)[0]

        divider = df2.ensure_divider(ax)

        name1, name2 = ibs.get_annot_names([aid1, aid2])
        #truth = self.ibs.get_match_truth(aid1, aid2)

        if make_buttons:
            butkw = {
                'divider': divider,
                'callback': self.match_reviewed,
                'index': index,
            }
            if name1 == name2 and not name1.startswith('____'):
                self.append_button(BREAK_MATCH_PREF, **butkw)
            else:
                if not name1.startswith('____'):
                    self.append_button(RENAME2_PREF + name1, **butkw)
                if not name2.startswith('____'):
                    self.append_button(RENAME1_PREF + name2, **butkw)
                if name1.startswith('____') and name2.startswith('____'):
                    self.append_button(NEW_MATCH_PREF, **butkw)

        if draw:
            vh.draw()
Exemple #3
0
    def plot_annotationmatch(self, index, draw=True, make_buttons=True):
        printDBG('[ishow_qres] starting interaction')
        self.select_candidate_match(index)
        # Get index relative to the page
        px = index - self.start_index
        pnum = self.pnum_(px)
        #fnum = df2.kwargs_fnum(kwargs)
        #printDBG('[inter] starting %s interaction' % type_)
        # Setup figure
        fnum = self.fnum
        printDBG('\n<<<<  BEGIN %s INTERACTION >>>>' % (str('qres').upper()))
        fig = df2.figure(fnum=fnum, pnum=pnum, docla=True, doclf=False)
        printDBG(fig)
        #self.ax = ax = df2.gca()
        # Get viz params
        qres = self.current_qres
        aid1, aid2 = self.current_match_aids
        ibs = self.ibs
        kwargs = self.interactkw
        # Vizualize
        ax = viz_matches.show_matches(ibs, qres, aid2, self_fm=[], fnum=fnum,
                                      pnum=pnum, **kwargs)[0]

        divider = df2.ensure_divider(ax)

        name1, name2 = ibs.get_annot_names([aid1, aid2])
        #truth = self.ibs.get_match_truth(aid1, aid2)

        if make_buttons:
            butkw = {
                'divider': divider,
                'callback': self.match_reviewed,
                'index': index,
            }
            if name1 == name2 and not name1.startswith('____'):
                self.append_button(BREAK_MATCH_PREF, **butkw)
            else:
                if not name1.startswith('____'):
                    self.append_button(RENAME2_PREF + name1, **butkw)
                if not name2.startswith('____'):
                    self.append_button(RENAME1_PREF + name2, **butkw)
                if name1.startswith('____') and name2.startswith('____'):
                    self.append_button(NEW_MATCH_PREF, **butkw)

        if draw:
            vh.draw()
Exemple #4
0
    def append_button(self,
                      text,
                      divider=None,
                      rect=None,
                      callback=None,
                      size='9%',
                      location='bottom',
                      ax=None,
                      **kwargs):
        """ Adds a button to the current page """

        if rect is not None:
            new_ax = df2.plt.axes(rect)
        if rect is None and divider is None:
            if ax is None:
                ax = df2.gca()
            divider = df2.ensure_divider(ax)
        if divider is not None:
            new_ax = divider.append_axes(location, size=size, pad=.05)
        if callback is not None:
            color, hovercolor = u'.85', u'.95'
        else:
            color, hovercolor = u'.88', u'.88'
            #color, hovercolor = u'.45', u'.45'
        #if isinstance(text, six.text_type):
        new_but = mpl.widgets.Button(new_ax,
                                     text,
                                     color=color,
                                     hovercolor=hovercolor)
        #elif isinstance(text, (list, tuple)):
        #    labels = [False] * len(text)
        #    labels[0] = True
        #    new_but = mpl.widgets.CheckButtons(new_ax, text, labels)
        #else:
        #    raise ValueError('bad input')

        if callback is not None:
            new_but.on_clicked(callback)
        else:
            button_text = new_but.ax.texts[0]
            button_text.set_color('.6')
            #button_text.set_color('r')
            #ut.embed()
            #print('new_but.color = %r' % (new_but.color,))
        #else:
        # TODO: figure ou how to gray out these buttons
        #    new_but.color = u'.1'
        #    new_but.hovercolor = u'.1'
        #    new_but.active = False
        #    print('new_but.color = %r' % (new_but.color,))
        ph.set_plotdat(new_ax, 'viztype', 'button')
        ph.set_plotdat(new_ax, 'text', text)
        #ph.set_plotdat(new_ax, 'parent_axes', ax)
        if ax is not None:
            child_axes = ph.get_plotdat(ax, 'child_axes', [])
            child_axes.append(new_ax)
            ph.set_plotdat(ax, 'child_axes', child_axes)
        for key, val in six.iteritems(kwargs):
            ph.set_plotdat(new_ax, key, val)
        # Keep buttons from losing scrop
        tup = (new_but, new_ax)
        self.scope.append(tup)
        return tup