Example #1
0
    def __init__(self, widgets):
        '''
        the constructor
        '''
        InfoExpander.__init__(self, _("General"), widgets)
        general_box = self.widgets.sp_general_box
        self.widgets.remove_parent(general_box)
        self.vbox.pack_start(general_box)
        self.widgets.sp_name_data.set_line_wrap(True)

        # make the check buttons read only
        def on_enter(button, *args):
            button.emit_stop_by_name("enter-notify-event")
            return True

        self.current_obj = None

        def on_nacc_clicked(*args):
            cmd = 'acc where species.id=%s' % self.current_obj.id
            bauble.gui.send_command(cmd)

        utils.make_label_clickable(self.widgets.sp_nacc_data, on_nacc_clicked)

        def on_nplants_clicked(*args):
            cmd = 'plant where accession.species.id=%s' % self.current_obj.id
            bauble.gui.send_command(cmd)

        utils.make_label_clickable(self.widgets.sp_nplants_data,
                                   on_nplants_clicked)
    def update(self, row):
        '''
        update the expander

        :param row: the row to get thevalues from
        '''
        syn_box = self.widgets.fam_synonyms_box
        # remove old labels
        syn_box.foreach(syn_box.remove)
        # use True comparison in case the preference isn't set
        self.set_expanded(prefs[self.expanded_pref] == True)
        if len(row.synonyms) == 0:
            self.set_sensitive(False)
        else:
            on_clicked = lambda l, e, syn: select_in_search_results(syn)
            for syn in row.synonyms:
                # create clickable label that will select the synonym
                # in the search results
                box = gtk.EventBox()
                label = gtk.Label()
                label.set_alignment(0, .5)
                label.set_markup(Family.str(syn))
                box.add(label)
                utils.make_label_clickable(label, on_clicked, syn)
                syn_box.pack_start(box, expand=False, fill=False)
            self.show_all()
            self.set_sensitive(True)
Example #3
0
    def __init__(self, widgets):
        """
        the constructor
        """
        InfoExpander.__init__(self, _("General"), widgets)
        general_box = self.widgets.sp_general_box
        self.widgets.remove_parent(general_box)
        self.vbox.pack_start(general_box)
        self.widgets.sp_name_data.set_line_wrap(True)

        # make the check buttons read only
        def on_enter(button, *args):
            button.emit_stop_by_name("enter-notify-event")
            return True

        self.current_obj = None

        def on_nacc_clicked(*args):
            cmd = "acc where species.id=%s" % self.current_obj.id
            bauble.gui.send_command(cmd)

        utils.make_label_clickable(self.widgets.sp_nacc_data, on_nacc_clicked)

        def on_nplants_clicked(*args):
            cmd = "plant where accession.species.id=%s" % self.current_obj.id
            bauble.gui.send_command(cmd)

        utils.make_label_clickable(self.widgets.sp_nplants_data, on_nplants_clicked)
Example #4
0
    def update(self, row):
        '''
        update the expander

        :param row: the row to get thevalues from
        '''
        syn_box = self.widgets.fam_synonyms_box
        # remove old labels
        syn_box.foreach(syn_box.remove)
        # use True comparison in case the preference isn't set
        self.set_expanded(prefs[self.expanded_pref] is True)
        if len(row.synonyms) == 0:
            self.set_sensitive(False)
        else:
            on_clicked = lambda l, e, syn: select_in_search_results(syn)
            for syn in row.synonyms:
                # create clickable label that will select the synonym
                # in the search results
                box = gtk.EventBox()
                label = gtk.Label()
                label.set_alignment(0, .5)
                label.set_markup(Family.str(syn))
                box.add(label)
                utils.make_label_clickable(label, on_clicked, syn)
                syn_box.pack_start(box, expand=False, fill=False)
            self.show_all()
            self.set_sensitive(True)
Example #5
0
    def update(self, row):
        '''
        update the expander

        :param row: the row to get thevalues from
        '''
        syn_box = self.widgets.sp_synonyms_box
        # remove old labels
        syn_box.foreach(syn_box.remove)
        logger.debug(row.synonyms)
        from sqlalchemy.orm.session import object_session
        self.session = object_session(row)
        syn = self.session.query(SpeciesSynonym).filter(
            SpeciesSynonym.synonym_id == row.id).first()
        accepted = syn and syn.species
        logger.debug("species %s is synonym of %s and has synonyms %s" %
                     (row, accepted, row.synonyms))
        self.set_label(_("Synonyms"))  # reset default value
        on_label_clicked = lambda l, e, syn: select_in_search_results(syn)
        if accepted is not None:
            self.set_label(_("Accepted name"))
            # create clickable label that will select the synonym
            # in the search results
            box = gtk.EventBox()
            label = gtk.Label()
            label.set_alignment(0, .5)
            label.set_markup(Species.str(accepted, markup=True, authors=True))
            box.add(label)
            utils.make_label_clickable(label, on_label_clicked, accepted)
            syn_box.pack_start(box, expand=False, fill=False)
            self.show_all()
            self.set_sensitive(True)
            self.set_expanded(True)
        elif len(row.synonyms) == 0:
            self.set_sensitive(False)
            self.set_expanded(False)
        else:
            # remove all the children
            syn_box.foreach(syn_box.remove)
            for syn in row.synonyms:
                # create clickable label that will select the synonym
                # in the search results
                box = gtk.EventBox()
                label = gtk.Label()
                label.set_alignment(0, .5)
                label.set_markup(Species.str(syn, markup=True, authors=True))
                box.add(label)
                utils.make_label_clickable(label, on_label_clicked, syn)
                syn_box.pack_start(box, expand=False, fill=False)
            self.show_all()
            self.set_sensitive(True)
            # TODO: get expanded state from prefs
            self.set_expanded(True)
Example #6
0
    def update(self, row):
        '''
        update the expander

        :param row: the row to get thevalues from
        '''
        syn_box = self.widgets.sp_synonyms_box
        # remove old labels
        syn_box.foreach(syn_box.remove)
        logger.debug(row.synonyms)
        from sqlalchemy.orm.session import object_session
        self.session = object_session(row)
        syn = self.session.query(SpeciesSynonym).filter(
            SpeciesSynonym.synonym_id == row.id).first()
        accepted = syn and syn.species
        logger.debug("species %s is synonym of %s and has synonyms %s" %
                     (row, accepted, row.synonyms))
        self.set_label(_("Synonyms"))  # reset default value
        on_label_clicked = lambda l, e, syn: select_in_search_results(syn)
        if accepted is not None:
            self.set_label(_("Accepted name"))
            # create clickable label that will select the synonym
            # in the search results
            box = gtk.EventBox()
            label = gtk.Label()
            label.set_alignment(0, .5)
            label.set_markup(Species.str(accepted, markup=True, authors=True))
            box.add(label)
            utils.make_label_clickable(label, on_label_clicked, accepted)
            syn_box.pack_start(box, expand=False, fill=False)
            self.show_all()
            self.set_sensitive(True)
            self.set_expanded(True)
        elif len(row.synonyms) == 0:
            self.set_sensitive(False)
            self.set_expanded(False)
        else:
            # remove all the children
            syn_box.foreach(syn_box.remove)
            for syn in row.synonyms:
                # create clickable label that will select the synonym
                # in the search results
                box = gtk.EventBox()
                label = gtk.Label()
                label.set_alignment(0, .5)
                label.set_markup(Species.str(syn, markup=True, authors=True))
                box.add(label)
                utils.make_label_clickable(label, on_label_clicked, syn)
                syn_box.pack_start(box, expand=False, fill=False)
            self.show_all()
            self.set_sensitive(True)
            # TODO: get expanded state from prefs
            self.set_expanded(True)
Example #7
0
    def __init__(self, widgets):
        '''
        '''
        InfoExpander.__init__(self, _("General"), widgets)
        general_box = self.widgets.loc_gen_box
        self.widgets.remove_parent(general_box)
        self.vbox.pack_start(general_box)
        self.current_obj = None

        def on_nplants_clicked(*args):
            cmd = 'plant where location.code="%s"' % self.current_obj.code
            bauble.gui.send_command(cmd)
        utils.make_label_clickable(self.widgets.loc_nplants_data,
                                   on_nplants_clicked)
Example #8
0
    def update(self, row):
        '''
        update the expander

        :param row: the row to get the values from
        '''
        syn_box = self.widgets.gen_synonyms_box
        # remove old labels
        syn_box.foreach(syn_box.remove)
        # use True comparison in case the preference isn't set
        self.set_expanded(prefs[self.expanded_pref] is True)
        self.session = object_session(row)
        logger.debug("genus %s is synonym of %s and has synonyms %s" %
                     (row, row.accepted, row.synonyms))
        self.set_label(_("Synonyms"))  # reset default value
        if row.accepted is not None:
            self.set_label(_("Accepted name"))
            on_clicked = lambda l, e, syn: select_in_search_results(syn)
            # create clickable label that will select the synonym
            # in the search results
            box = gtk.EventBox()
            label = gtk.Label()
            label.set_alignment(0, .5)
            label.set_markup(Genus.str(row.accepted, author=True))
            box.add(label)
            utils.make_label_clickable(label, on_clicked, row.accepted)
            syn_box.pack_start(box, expand=False, fill=False)
            self.show_all()
            self.set_sensitive(True)
        elif len(row.synonyms) == 0:
            self.set_sensitive(False)
        else:
            on_clicked = lambda l, e, syn: select_in_search_results(syn)
            for syn in row.synonyms:
                # create clickable label that will select the synonym
                # in the search results
                box = gtk.EventBox()
                label = gtk.Label()
                label.set_alignment(0, .5)
                label.set_markup(Genus.str(syn, author=True))
                box.add(label)
                utils.make_label_clickable(label, on_clicked, syn)
                syn_box.pack_start(box, expand=False, fill=False)
            self.show_all()
            self.set_sensitive(True)
Example #9
0
    def update(self, row):
        '''
        update the expander

        :param row: the row to get the values from
        '''
        syn_box = self.widgets.gen_synonyms_box
        # remove old labels
        syn_box.foreach(syn_box.remove)
        # use True comparison in case the preference isn't set
        self.set_expanded(prefs[self.expanded_pref] is True)
        self.session = object_session(row)
        logger.debug("genus %s is synonym of %s and has synonyms %s" %
                     (row, row.accepted, row.synonyms))
        self.set_label(_("Synonyms"))  # reset default value
        if row.accepted is not None:
            self.set_label(_("Accepted name"))
            on_clicked = lambda l, e, syn: select_in_search_results(syn)
            # create clickable label that will select the synonym
            # in the search results
            box = gtk.EventBox()
            label = gtk.Label()
            label.set_alignment(0, .5)
            label.set_markup(Genus.str(row.accepted, author=True))
            box.add(label)
            utils.make_label_clickable(label, on_clicked, row.accepted)
            syn_box.pack_start(box, expand=False, fill=False)
            self.show_all()
            self.set_sensitive(True)
        elif len(row.synonyms) == 0:
            self.set_sensitive(False)
        else:
            on_clicked = lambda l, e, syn: select_in_search_results(syn)
            for syn in row.synonyms:
                # create clickable label that will select the synonym
                # in the search results
                box = gtk.EventBox()
                label = gtk.Label()
                label.set_alignment(0, .5)
                label.set_markup(Genus.str(syn, author=True))
                box.add(label)
                utils.make_label_clickable(label, on_clicked, syn)
                syn_box.pack_start(box, expand=False, fill=False)
            self.show_all()
            self.set_sensitive(True)
Example #10
0
    def __init__(self, widgets):
        """

        Arguments:
        - `widgets`:
        """
        InfoExpander.__init__(self, _("General"), widgets)
        general_box = self.widgets.fam_general_box
        self.widgets.remove_parent(general_box)
        self.vbox.pack_start(general_box)

        def on_ngen_clicked(*args):
            f = self.current_obj
            cmd = 'genus where family.family="%s" and family.qualifier="%s"'\
                % (f.family, f.qualifier)
            bauble.gui.send_command(cmd)

        utils.make_label_clickable(self.widgets.fam_ngen_data, on_ngen_clicked)

        def on_nsp_clicked(*args):
            f = self.current_obj
            cmd = 'species where genus.family.family="%s" '\
                'and genus.family.qualifier="%s"' % (f.family, f.qualifier)
            bauble.gui.send_command(cmd)

        utils.make_label_clickable(self.widgets.fam_nsp_data, on_nsp_clicked)

        def on_nacc_clicked(*args):
            f = self.current_obj
            cmd = 'acc where species.genus.family.family="%s" ' \
                'and species.genus.family.qualifier="%s"' \
                % (f.family, f.qualifier)
            bauble.gui.send_command(cmd)

        utils.make_label_clickable(self.widgets.fam_nacc_data, on_nacc_clicked)

        def on_nplants_clicked(*args):
            f = self.current_obj
            cmd = 'plant where accession.species.genus.family.family="%s" ' \
                'and accession.species.genus.family.qualifier="%s"' \
                % (f.family, f.qualifier)
            bauble.gui.send_command(cmd)

        utils.make_label_clickable(self.widgets.fam_nplants_data,
                                   on_nplants_clicked)
    def __init__(self, widgets):
        """

        Arguments:
        - `widgets`:
        """
        InfoExpander.__init__(self, _("General"), widgets)
        general_box = self.widgets.fam_general_box
        self.widgets.remove_parent(general_box)
        self.vbox.pack_start(general_box)

        def on_ngen_clicked(*args):
            f = self.current_obj
            cmd = 'genus where family.family="%s" and family.qualifier="%s"'\
                % (f.family, f.qualifier)
            bauble.gui.send_command(cmd)
        utils.make_label_clickable(self.widgets.fam_ngen_data,
                                   on_ngen_clicked)

        def on_nsp_clicked(*args):
            f = self.current_obj
            cmd = 'species where genus.family.family="%s" '\
                'and genus.family.qualifier="%s"' % (f.family, f.qualifier)
            bauble.gui.send_command(cmd)
        utils.make_label_clickable(self.widgets.fam_nsp_data,
                                   on_nsp_clicked)

        def on_nacc_clicked(*args):
            f = self.current_obj
            cmd = 'acc where species.genus.family.family="%s" ' \
                'and species.genus.family.qualifier="%s"' \
                % (f.family, f.qualifier)
            bauble.gui.send_command(cmd)
        utils.make_label_clickable(self.widgets.fam_nacc_data,
                                   on_nacc_clicked)

        def on_nplants_clicked(*args):
            f = self.current_obj
            cmd = 'plant where accession.species.genus.family.family="%s" ' \
                'and accession.species.genus.family.qualifier="%s"' \
                % (f.family, f.qualifier)
            bauble.gui.send_command(cmd)
        utils.make_label_clickable(self.widgets.fam_nplants_data,
                                   on_nplants_clicked)
Example #12
0
    def __init__(self, widgets):
        '''
        the constructor
        '''
        InfoExpander.__init__(self, _("General"), widgets)
        general_box = self.widgets.gen_general_box
        self.widgets.remove_parent(general_box)
        self.vbox.pack_start(general_box)

        self.current_obj = None

        def on_family_clicked(*args):
            select_in_search_results(self.current_obj.family)

        utils.make_label_clickable(self.widgets.gen_fam_data,
                                   on_family_clicked)

        def on_nsp_clicked(*args):
            g = self.current_obj
            cmd = 'species where genus.genus="%s" and genus.qualifier="%s"' \
                % (g.genus, g.qualifier)
            bauble.gui.send_command(cmd)

        utils.make_label_clickable(self.widgets.gen_nsp_data, on_nsp_clicked)

        def on_nacc_clicked(*args):
            g = self.current_obj
            cmd = 'acc where species.genus.genus="%s" ' \
                'and species.genus.qualifier="%s"' \
                % (g.genus, g.qualifier)
            bauble.gui.send_command(cmd)

        utils.make_label_clickable(self.widgets.gen_nacc_data, on_nacc_clicked)

        def on_nplants_clicked(*args):
            g = self.current_obj
            cmd = 'plant where accession.species.genus.genus="%s" and ' \
                'accession.species.genus.qualifier="%s"' \
                % (g.genus, g.qualifier)
            bauble.gui.send_command(cmd)

        utils.make_label_clickable(self.widgets.gen_nplants_data,
                                   on_nplants_clicked)
    def __init__(self, widgets):
        '''
        the constructor
        '''
        InfoExpander.__init__(self, _("General"), widgets)
        general_box = self.widgets.gen_general_box
        self.widgets.remove_parent(general_box)
        self.vbox.pack_start(general_box)

        self.current_obj = None
        def on_family_clicked(*args):
            select_in_search_results(self.current_obj.family)
        utils.make_label_clickable(self.widgets.gen_fam_data,
                                   on_family_clicked)

        def on_nsp_clicked(*args):
            g = self.current_obj
            cmd = 'species where genus.genus="%s" and genus.qualifier="%s"' \
                % (g.genus, g.qualifier)
            bauble.gui.send_command(cmd)
        utils.make_label_clickable(self.widgets.gen_nsp_data,
                                   on_nsp_clicked)

        def on_nacc_clicked(*args):
            g = self.current_obj
            cmd = 'acc where species.genus.genus="%s" ' \
                'and species.genus.qualifier="%s"' \
                % (g.genus, g.qualifier)
            bauble.gui.send_command(cmd)
        utils.make_label_clickable(self.widgets.gen_nacc_data,
                                   on_nacc_clicked)

        def on_nplants_clicked(*args):
            g = self.current_obj
            cmd = 'plant where accession.species.genus.genus="%s" and ' \
                'accession.species.genus.qualifier="%s"' \
                % (g.genus, g.qualifier)
            bauble.gui.send_command(cmd)
        utils.make_label_clickable(self.widgets.gen_nplants_data,
                                   on_nplants_clicked)
    def __init__(self, widgets):
        '''
        '''
        super(GeneralPlantExpander, self).__init__(_("General"), widgets)
        general_box = self.widgets.general_box
        self.widgets.remove_parent(general_box)
        self.vbox.pack_start(general_box)
        self.current_obj = None

        def on_acc_code_clicked(*args):
            select_in_search_results(self.current_obj.accession)
        utils.make_label_clickable(self.widgets.acc_code_data,
                                   on_acc_code_clicked)

        def on_species_clicked(*args):
            select_in_search_results(self.current_obj.accession.species)
        utils.make_label_clickable(self.widgets.name_data, on_species_clicked)

        def on_location_clicked(*args):
            select_in_search_results(self.current_obj.location)
        utils.make_label_clickable(self.widgets.location_data,
                                   on_location_clicked)
Example #15
0
    def __init__(self):
        '''
        '''
        logger.debug('SplashInfoBox::__init__')
        super(SplashInfoBox, self).__init__()
        filename = os.path.join(paths.lib_dir(), 'plugins', 'plants',
                                'infoboxes.glade')
        self.widgets = utils.load_widgets(filename)
        self.widgets.remove_parent(self.widgets.splash_vbox)
        self.pack_start(self.widgets.splash_vbox, expand=False, padding=8)

        utils.make_label_clickable(
            self.widgets.splash_nfamuse, lambda *a: bauble.gui.send_command(
                'family where genera.species.id != 0'))

        utils.make_label_clickable(
            self.widgets.splash_ngenuse, lambda *a: bauble.gui.send_command(
                'genus where not species = Empty'))

        utils.make_label_clickable(
            self.widgets.splash_nspctot,
            lambda *a: bauble.gui.send_command('species like %'))

        utils.make_label_clickable(
            self.widgets.splash_nspcuse, lambda *a: bauble.gui.send_command(
                'species where not accessions = Empty'))

        utils.make_label_clickable(
            self.widgets.splash_nspcnot, lambda *a: bauble.gui.send_command(
                'species where accessions = Empty'))

        utils.make_label_clickable(
            self.widgets.splash_nacctot,
            lambda *a: bauble.gui.send_command('accession like %'))

        utils.make_label_clickable(
            self.widgets.splash_naccuse, lambda *a: bauble.gui.send_command(
                'accession where sum(plants.quantity)>0'))

        utils.make_label_clickable(
            self.widgets.splash_naccnot, lambda *a: bauble.gui.send_command(
                'accession where plants = Empty or sum(plants.quantity)=0'))

        utils.make_label_clickable(
            self.widgets.splash_nplttot,
            lambda *a: bauble.gui.send_command('plant like %'))

        utils.make_label_clickable(
            self.widgets.splash_npltuse,
            lambda *a: bauble.gui.send_command('plant where sum(quantity)>0'))

        utils.make_label_clickable(
            self.widgets.splash_npltnot,
            lambda *a: bauble.gui.send_command('plant where sum(quantity)=0'))

        utils.make_label_clickable(
            self.widgets.splash_nloctot,
            lambda *a: bauble.gui.send_command('location like %'))

        utils.make_label_clickable(
            self.widgets.splash_nlocuse, lambda *a: bauble.gui.send_command(
                'location where sum(plants.quantity)>0'))

        utils.make_label_clickable(
            self.widgets.splash_nlocnot, lambda *a: bauble.gui.send_command(
                'location where plants is Empty or sum(plants.quantity)=0'))

        for i in range(1, 11):
            wname = "stqr_%02d_button" % i
            widget = getattr(self.widgets, wname)
            widget.connect('clicked', partial(self.on_sqb_clicked, i))
        wname = "splash_stqr_button"
        widget = getattr(self.widgets, wname)
        widget.connect('clicked', self.on_splash_stqr_button_clicked)
Example #16
0
    def __init__(self):
        '''
        '''
        logger.debug('SplashInfoBox::__init__')
        super(SplashInfoBox, self).__init__()
        filename = os.path.join(paths.lib_dir(), 'plugins', 'plants',
                                'infoboxes.glade')
        self.widgets = utils.load_widgets(filename)
        self.widgets.remove_parent(self.widgets.splash_vbox)
        self.pack_start(self.widgets.splash_vbox,
                        expand=False, padding=8)

        utils.make_label_clickable(
            self.widgets.splash_nfamuse,
            lambda *a: bauble.gui.send_command(
                'family where genera.species.id != 0'))

        utils.make_label_clickable(
            self.widgets.splash_ngenuse,
            lambda *a: bauble.gui.send_command(
                'genus where not species = Empty'))

        utils.make_label_clickable(
            self.widgets.splash_nspctot,
            lambda *a: bauble.gui.send_command(
                'species like %'))

        utils.make_label_clickable(
            self.widgets.splash_nspcuse,
            lambda *a: bauble.gui.send_command(
                'species where not accessions = Empty'))

        utils.make_label_clickable(
            self.widgets.splash_nspcnot,
            lambda *a: bauble.gui.send_command(
                'species where accessions = Empty'))

        utils.make_label_clickable(
            self.widgets.splash_nacctot,
            lambda *a: bauble.gui.send_command(
                'accession like %'))

        utils.make_label_clickable(
            self.widgets.splash_naccuse,
            lambda *a: bauble.gui.send_command(
                'accession where sum(plants.quantity)>0'))

        utils.make_label_clickable(
            self.widgets.splash_naccnot,
            lambda *a: bauble.gui.send_command(
                'accession where plants = Empty or sum(plants.quantity)=0'))

        utils.make_label_clickable(
            self.widgets.splash_nplttot,
            lambda *a: bauble.gui.send_command(
                'plant like %'))

        utils.make_label_clickable(
            self.widgets.splash_npltuse,
            lambda *a: bauble.gui.send_command(
                'plant where sum(quantity)>0'))

        utils.make_label_clickable(
            self.widgets.splash_npltnot,
            lambda *a: bauble.gui.send_command(
                'plant where sum(quantity)=0'))

        utils.make_label_clickable(
            self.widgets.splash_nloctot,
            lambda *a: bauble.gui.send_command(
                'location like %'))

        utils.make_label_clickable(
            self.widgets.splash_nlocuse,
            lambda *a: bauble.gui.send_command(
                'location where sum(plants.quantity)>0'))

        utils.make_label_clickable(
            self.widgets.splash_nlocnot,
            lambda *a: bauble.gui.send_command(
                'location where plants is Empty or sum(plants.quantity)=0'))

        for i in range(1, 11):
            wname = "stqr_%02d_button" % i
            widget = getattr(self.widgets, wname)
            widget.connect('clicked', partial(self.on_sqb_clicked, i))
        wname = "splash_stqr_button"
        widget = getattr(self.widgets, wname)
        widget.connect('clicked', self.on_splash_stqr_button_clicked)
Example #17
0
    def update(self, row):
        '''
        update the expander

        :param row: the row to get the values from
        '''
        self.current_obj = row
        session = object_session(row)
        # link function
        on_label_clicked = lambda l, e, x: select_in_search_results(x)
        # Link to family
        self.widget_set_value('sp_fam_data', '<small>(%s)</small>' %
                              row.genus.family.family, markup=True)
        utils.make_label_clickable(
            self.widgets.sp_fam_data, on_label_clicked, row.genus.family)
        # link to genus
        self.widget_set_value('sp_gen_data', '<big><i>%s</i></big>' %
                              row.genus.genus, markup=True)
        utils.make_label_clickable(
            self.widgets.sp_gen_data, on_label_clicked, row.genus)
        # epithet (full binomial but missing genus)
        self.widget_set_value('sp_epithet_data', '<big>%s</big>' %
                              row.markup(authors=True, genus=False),
                              markup=True)

        awards = ''
        if row.awards:
            awards = utils.utf8(row.awards)
        self.widget_set_value('sp_awards_data', awards)

        logger.debug('setting cites data from row %s' % row)
        cites = ''
        if row.cites:
            cites = utils.utf8(row.cites)
        self.widget_set_value('sp_cites_data', cites)

        # zone = ''
        # if row.hardiness_zone:
        #     awards = utils.utf8(row.hardiness_zone)
        # self.widget_set_value('sp_hardiness_data', zone)

        habit = ''
        if row.habit:
            habit = utils.utf8(row.habit)
        self.widget_set_value('sp_habit_data', habit)

        dist = ''
        if row.distribution:
            dist = utils.utf8(row.distribution_str())
        self.widget_set_value('sp_dist_data', dist)

        dist = ''
        if row.label_distribution:
            dist = row.label_distribution
        self.widget_set_value('sp_labeldist_data', dist)

        # stop here if not GardenPluin
        if 'GardenPlugin' not in pluginmgr.plugins:
            return

        from bauble.plugins.garden.accession import Accession
        from bauble.plugins.garden.plant import Plant

        nacc = session.query(Accession).join('species').\
            filter_by(id=row.id).count()
        self.widget_set_value('sp_nacc_data', nacc)

        nplants = session.query(Plant).join('accession', 'species').\
            filter_by(id=row.id).count()
        if nplants == 0:
            self.widget_set_value('sp_nplants_data', nplants)
        else:
            nacc_in_plants = session.query(Plant.accession_id).\
                join('accession', 'species').\
                filter_by(id=row.id).distinct().count()
            self.widget_set_value('sp_nplants_data', '%s in %s accessions'
                                  % (nplants, nacc_in_plants))
    def update(self, row):
        '''
        '''
        self.table.foreach(self.table.remove)
        if not row.changes:
            return
        nrows = len(row.changes)
        self.table.resize(nrows, 2)
        date_format = prefs.prefs[prefs.date_format_pref]
        current_row = 0

        def _cmp(x, y):
            """
            Sort by change.date and then change._created.  If they are
            equal then removals sort before transfers.
            """
            if x.date < y.date:
                return -1
            elif x.date > y.date:
                return 1
            elif x.date == y.date and x._created < y._created:
                return -1
            elif x.date == y.date and x._created > y._created:
                return 1
            elif x.quantity < 0:
                return -1
            else:
                return 1

        for change in sorted(row.changes, cmp=_cmp, reverse=True):
            date = change.date.strftime(date_format)
            label = gtk.Label('%s:' % date)
            label.set_alignment(0, 0)
            self.table.attach(label, 0, 1, current_row, current_row+1,
                              xoptions=gtk.FILL)
            if change.to_location and change.from_location:
                s = '%(quantity)s Transferred from %(from_loc)s to %(to)s' % \
                    dict(quantity=change.quantity,
                         from_loc=change.from_location, to=change.to_location)
            elif change.quantity < 0:
                s = '%(quantity)s Removed from %(location)s' % \
                    dict(quantity=-change.quantity,
                         location=change.from_location)
            elif change.quantity > 0:
                s = '%(quantity)s Added to %(location)s' % \
                    dict(quantity=change.quantity, location=change.to_location)
            else:
                s = '%s: %s -> %s' % (change.quantity, change.from_location,
                                      change.to_location)
            if change.reason is not None:
                s += '\n%s' % change_reasons[change.reason]
            label = gtk.Label(s)
            label.set_alignment(0, .5)
            self.table.attach(label, 1, 2, current_row, current_row+1,
                              xoptions=gtk.FILL)
            current_row += 1
            if change.parent_plant:
                s = _('<i>Branched from %(plant)s</i>') % \
                    dict(plant=utils.xml_safe_utf8(change.parent_plant))
                label = gtk.Label()
                label.set_alignment(0, .5)
                label.set_markup(s)
                eb = gtk.EventBox()
                eb.add(label)
                self.table.attach(eb, 1, 2, current_row, current_row+1,
                                  xoptions=gtk.FILL)
                def on_clicked(widget, event, parent):
                    select_in_search_results(parent)
                utils.make_label_clickable(label, on_clicked,
                                           change.parent_plant)
                current_row += 1

        self.vbox.show_all()
Example #19
0
    def update(self, row):
        '''
        update the expander

        :param row: the row to get the values from
        '''
        self.current_obj = row
        session = object_session(row)
        # link function
        on_label_clicked = lambda l, e, x: select_in_search_results(x)
        # Link to family
        self.widget_set_value('sp_fam_data',
                              '<small>(%s)</small>' % row.genus.family.epithet,
                              markup=True)
        utils.make_label_clickable(self.widgets.sp_fam_data, on_label_clicked,
                                   row.genus.family)
        # link to genus
        if row.hybrid_marker != u'H':
            self.widget_set_value('sp_gen_data',
                                  '<big><i>%s</i></big> ' %
                                  row.genus.str(use_hybrid_marker=True),
                                  markup=True)
            utils.make_label_clickable(self.widgets.sp_gen_data,
                                       on_label_clicked, row.genus)
        else:
            self.widget_set_value('sp_gen_data', '')
        # epithet (full binomial but missing genus)
        self.widget_set_value('sp_epithet_data',
                              '<big>%s</big>' %
                              row.markup(authors=True, genus=False),
                              markup=True)

        awards = ''
        if row.awards:
            awards = utils.utf8(row.awards)
        self.widget_set_value('sp_awards_data', awards)

        logger.debug('setting cites data from row %s' % row)
        cites = ''
        if row.cites:
            cites = utils.utf8(row.cites)
        self.widget_set_value('sp_cites_data', cites)

        # zone = ''
        # if row.hardiness_zone:
        #     awards = utils.utf8(row.hardiness_zone)
        # self.widget_set_value('sp_hardiness_data', zone)

        habit = ''
        if row.habit:
            habit = utils.utf8(row.habit)
        self.widget_set_value('sp_habit_data', habit)

        dist = ''
        if row.distribution:
            dist = utils.utf8(row.distribution_str())
        self.widget_set_value('sp_dist_data', dist)

        dist = ''
        if row.label_distribution:
            dist = row.label_distribution
        self.widget_set_value('sp_labeldist_data', dist)

        # stop here if not GardenPluin
        if 'GardenPlugin' not in pluginmgr.plugins:
            return

        from bauble.plugins.garden.accession import Accession
        from bauble.plugins.garden.plant import Plant

        nacc = session.query(Accession).join('species').\
            filter_by(id=row.id).count()
        self.widget_set_value('sp_nacc_data', nacc)

        nplants = session.query(Plant).join('accession', 'species').\
            filter_by(id=row.id).count()
        if nplants == 0:
            self.widget_set_value('sp_nplants_data', nplants)
        else:
            nacc_in_plants = session.query(Plant.accession_id).\
                join('accession', 'species').\
                filter_by(id=row.id).distinct().count()
            self.widget_set_value(
                'sp_nplants_data',
                '%s in %s accessions' % (nplants, nacc_in_plants))