def __init__(self):
     super(SourceDetailInfoBox, self).__init__()
     filename = os.path.join(paths.lib_dir(), "plugins", "garden",
                             "source_detail_infobox.glade")
     self.widgets = utils.load_widgets(filename)
     self.general = GeneralSourceDetailExpander(self.widgets)
     self.add_expander(self.general)
Esempio n. 2
0
    def init(cls):
        """copy default template files to appdata_dir

        we do this in the initialization instead of installation
        because new version of plugin might provide new templates.

        """
        cls.install()  # plugins still not versioned...

        templates = ['example_accession.csv',
                     'example_accession-es.csv',
                     'example_plant.csv',
                     'example_plant-es.csv',
                     'example_species.csv',
                     'example_species-es.csv',
                     'bgci-upload.csv',
                     'label.ps',
                     'labels.html',
                     'labels_small.html',
                     'label-engraving.svg',
        ]
        src_dir = os.path.join(paths.lib_dir(), "plugins", "report", 'mako')
        for template in templates:
            src = os.path.join(src_dir, template)
            dst = os.path.join(cls.plugin_dir, template)
            if not os.path.exists(dst) and os.path.exists(src):
                shutil.copy(src, dst)
Esempio n. 3
0
 def __init__(self, parent=None):
     """
     """
     super(PropagationEditorView, self).__init__(
         os.path.join(paths.lib_dir(), "plugins", "garden", "prop_editor.glade"), parent=parent
     )
     self.init_translatable_combo("prop_type_combo", prop_type_values)
Esempio n. 4
0
    def __init__(self):
        button_defs = [
            {'name': 'GoogleButton', '_base_uri': "http://www.google.com/search?q=%s", '_space': '+', 'title': "Search Google", 'tooltip': None, },
            {'name': 'GBIFButton', '_base_uri': "http://www.gbif.org/species/search?q=%s", '_space': '+', 'title': _("Search GBIF"), 'tooltip': _("Search the Global Biodiversity Information Facility"), },
            {'name': 'ITISButton', '_base_uri': "http://www.itis.gov/servlet/SingleRpt/SingleRpt?search_topic=Scientific_Name&search_value=%s&search_kingdom=Plant&search_span=containing&categories=All&source=html&search_credRating=All", '_space': '%20', 'title': _("Search ITIS"), 'tooltip': _("Search the Intergrated Taxonomic Information System"), },
            {'name': 'GRINButton', '_base_uri': "http://www.ars-grin.gov/cgi-bin/npgs/swish/accboth?query=%s&submit=Submit+Text+Query&si=0", '_space': '+', 'title': _("Search NPGS/GRIN"), 'tooltip': _('Search National Plant Germplasm System'), },
            {'name': 'ALAButton', '_base_uri': "http://bie.ala.org.au/search?q=%s", '_space': '+', 'title': _("Search ALA"), 'tooltip': _("Search the Atlas of Living Australia"), },
            {'name': 'IPNIButton', '_base_uri': "http://www.ipni.org/ipni/advPlantNameSearch.do?find_genus=%(genus)s&find_isAPNIRecord=on& find_isGCIRecord=on&find_isIKRecord=on&output_format=normal", '_space': ' ', 'title': _("Search IPNI"), 'tooltip': _("Search the International Plant Names Index"), },
            {'name': 'BGCIButton', '_base_uri': "http://www.bgci.org/plant_search.php?action=Find&ftrGenus=%(genus)s&ftrRedList=&ftrRedList1997=&ftrEpithet=&ftrCWR=&x=0&y=0#results", '_space': ' ', 'title': _("Search BGCI"), 'tooltip': _("Search Botanic Gardens Conservation International"), },
            {'name': 'TPLButton', '_base_uri': "http://www.theplantlist.org/tpl1.1/search?q=%(genus)s", '_space': '+', 'title': _("Search TPL"), 'tooltip': _("Search The Plant List online database"), },
            {'name': 'TropicosButton', '_base_uri': "http://tropicos.org/NameSearch.aspx?name=%(genus)s", '_space': '+', 'title': _("Search Tropicos"), 'tooltip': _("Search Tropicos (MissouriBG) online database"), },
            ]
        InfoBox.__init__(self)
        filename = os.path.join(paths.lib_dir(), 'plugins', 'plants',
                                'infoboxes.glade')
        self.widgets = utils.load_widgets(filename)
        self.general = GeneralGenusExpander(self.widgets)
        self.add_expander(self.general)
        self.synonyms = SynonymsExpander(self.widgets)
        self.add_expander(self.synonyms)
        self.links = view.LinksExpander('notes', button_defs)
        self.add_expander(self.links)
        self.props = PropertiesExpander()
        self.add_expander(self.props)

        if 'GardenPlugin' not in pluginmgr.plugins:
            self.widgets.remove_parent('gen_nacc_label')
            self.widgets.remove_parent('gen_nacc_data')
            self.widgets.remove_parent('gen_nplants_label')
            self.widgets.remove_parent('gen_nplants_data')
Esempio n. 5
0
def setup_date_button(view, entry, button, date_func=None):
    """
    Associate a button with entry so that when the button is clicked a
    date is inserted into the entry.

    :param view: a bauble.editor.GenericEditorView

    :param entry: the entry that the data goes into

    :param button: the button that enters the data in entry

    :param date_func: the function that returns a string represention
      of the date
    """
    if isinstance(entry, basestring):
        entry = view.widgets[entry]
    if isinstance(button, basestring):
        button = view.widgets[button]
    icon = os.path.join(paths.lib_dir(), 'images', 'calendar.png')
    image = gtk.Image()
    image.set_from_file(icon)
    button.set_tooltip_text(_("Today's date"))
    button.set_image(image)

    def on_clicked(b):
        s = ''
        if date_func:
            s = date_func()
        else:
            s = today_str()
        entry.set_text(s)
    if view and hasattr(view, 'connect'):
        view.connect(button, 'clicked', on_clicked)
    else:
        button.connect('clicked', on_clicked)
Esempio n. 6
0
    def __init__(self):
        '''
        the constructor
        '''
        super(SearchView, self).__init__()
        filename = os.path.join(paths.lib_dir(), 'bauble.glade')
        self.widgets = utils.load_widgets(filename)

        self.create_gui()

        import pictures_view
        pictures_view.floating_window = pictures_view.PicturesView(
            parent=self.widgets.search_h2pane)

        # we only need this for the timeout version of populate_results
        self.populate_callback_id = None

        # the context menu cache holds the context menus by type in the results
        # view so that we don't have to rebuild them every time
        self.context_menu_cache = {}
        self.infobox_cache = {}
        self.infobox = None

        # keep all the search results in the same session, this should
        # be cleared when we do a new search
        self.session = db.Session()
Esempio n. 7
0
def start_taxonomy_check():
    '''run the batch taxonomy check (BTC)
    '''

    view = GenericEditorView(
        os.path.join(paths.lib_dir(), 'plugins', 'plants',
                     'taxonomy_check.glade'),
        parent=None,
        root_widget_name='dialog1')
    model = type('BTCStatus', (object,), {})()
    model.page = 1
    model.selection = view.get_selection()
    model.tick_off = None
    model.report = None
    model.file_path = ''

    if model.selection is None:
        return
    from sqlalchemy.orm import object_session
    presenter = BatchTaxonomicCheckPresenter(
        model, view, refresh_view=True,
        session=object_session(model.selection[0]))
    error_state = presenter.start()
    if error_state:
        presenter.session.rollback()
    else:
        presenter.commit_changes()
        from bauble import gui
        view = gui.get_view()
        if hasattr(view, 'update'):
            view.update()
    presenter.cleanup()
    return error_state
Esempio n. 8
0
 def __init__(self):
     super(SourceDetailInfoBox, self).__init__()
     filename = os.path.join(paths.lib_dir(), "plugins", "garden",
                             "source_detail_infobox.glade")
     self.widgets = utils.load_widgets(filename)
     self.general = GeneralSourceDetailExpander(self.widgets)
     self.add_expander(self.general)
Esempio n. 9
0
    def init(cls):
        """copy default template files to appdata_dir

        we do this in the initialization instead of installation
        because new version of plugin might provide new templates.

        """
        cls.install()  # plugins still not versioned...

        templates = [
            'example_accession.csv',
            'example_accession-es.csv',
            'example_plant.csv',
            'example_plant-es.csv',
            'example_species.csv',
            'example_species-es.csv',
            'bgci-upload.csv',
            'label.ps',
            'labels.html',
            'labels_small.html',
            'label-engraving.svg',
        ]
        src_dir = os.path.join(paths.lib_dir(), "plugins", "report", 'mako')
        for template in templates:
            src = os.path.join(src_dir, template)
            dst = os.path.join(cls.plugin_dir, template)
            if not os.path.exists(dst) and os.path.exists(src):
                shutil.copy(src, dst)
    def test_add_widget(self):
        import gtk

        filename = os.path.join(paths.lib_dir(), "bauble.glade")
        view = GenericEditorView(filename)
        label = gtk.Label("testing")
        view.widget_add("statusbar", label)
Esempio n. 11
0
def start_institution_editor():
    glade_path = os.path.join(paths.lib_dir(), "plugins", "garden", "institution.glade")
    from bauble import prefs
    from bauble.editor import GenericEditorView, MockView

    if prefs.testing:
        view = MockView()
    else:
        view = GenericEditorView(glade_path, parent=None, root_widget_name="inst_dialog")
    view._tooltips = {
        "inst_name": _("The full name of the institution."),
        "inst_abbr": _("The standard abbreviation of the " "institution."),
        "inst_code": _("The intitution code should be unique among " "all institions."),
        "inst_contact": _("The name of the person to contact for " "information related to the institution."),
        "inst_tech": _(
            "The email address or phone number of the "
            "person to contact for technical "
            "information related to the institution."
        ),
        "inst_email": _("The email address of the institution."),
        "inst_tel": _("The telephone number of the institution."),
        "inst_fax": _("The fax number of the institution."),
        "inst_addr": _("The mailing address of the institition."),
    }

    o = Institution()
    inst_pres = InstitutionPresenter(o, view)
    response = inst_pres.start()
    if response == gtk.RESPONSE_OK:
        o.write()
        inst_pres.commit_changes()
    else:
        inst_pres.session.rollback()
    inst_pres.session.close()
Esempio n. 12
0
    def __init__(self, parent, model, view, session):
        self.parent_ref = weakref.ref(parent)
        self.parent_session = session
        try:
            view.widgets.prop_main_box
        except:
            # only add the propagation editor widgets to the view
            # widgets if the widgets haven't yet been added
            filename = os.path.join(paths.lib_dir(), 'plugins', 'garden',
                                    'prop_editor.glade')
            view.widgets.builder.add_from_file(filename)
        prop_main_box = view.widgets.prop_main_box
        view.widgets.remove_parent(prop_main_box)
        view.widgets.acc_prop_box_parent.add(prop_main_box)

        # since the view here will be an AccessionEditorView and not a
        # PropagationEditorView then we need to do anything here that
        # PropagationEditorView would do
        view.init_translatable_combo('prop_type_combo', prop_type_values)
        # add None to the prop types which is specific to
        # SourcePropagationPresenter since we might also need to
        # remove the propagation...this will need to be called before
        # the PropagationPresenter.on_prop_type_changed or it won't work
        view.widgets.prop_type_combo.get_model().append([None, ''])

        # create a temporary Propagation that we'll connect to the
        # source when the prop_type_combo changes
        # self.source = model
        # if not self.source.propagation:
        #     self.source.propagation = Propagation()
        #     view.widgets.prop_details_box.props.visible=False
        self._dirty = False
        super(SourcePropagationPresenter, self).__init__(model, view)
Esempio n. 13
0
 def test_set_sensitive(self):
     filename = os.path.join(paths.lib_dir(), 'connmgr.glade')
     view = GenericEditorView(filename, root_widget_name='main_dialog')
     view.widget_set_sensitive('cancel_button', True)
     self.assertTrue(view.widgets.cancel_button.get_sensitive())
     view.widget_set_sensitive('cancel_button', False)
     self.assertFalse(view.widgets.cancel_button.get_sensitive())
Esempio n. 14
0
    def __init__(self):
        '''
        the constructor
        '''
        super(SpeciesInfoPage, self).__init__()
        filename = os.path.join(paths.lib_dir(), 'plugins', 'plants',
                                'infoboxes.glade')
        # load the widgets directly instead of using load_widgets()
        # because the caching that load_widgets() does can mess up
        # displaying the SpeciesInfoBox sometimes if you try to show
        # the infobox while having a vernacular names selected in
        # the search results and then a species name
        self.widgets = utils.BuilderWidgets(filename)
        self.general = GeneralSpeciesExpander(self.widgets)
        self.add_expander(self.general)
        self.vernacular = VernacularExpander(self.widgets)
        self.add_expander(self.vernacular)
        self.synonyms = SynonymsExpander(self.widgets)
        self.add_expander(self.synonyms)
        self.links = LinksExpander()
        self.add_expander(self.links)
        self.props = PropertiesExpander()
        self.add_expander(self.props)
        self.label = _('General')

        if 'GardenPlugin' not in pluginmgr.plugins:
            self.widgets.remove_parent('sp_nacc_label')
            self.widgets.remove_parent('sp_nacc_data')
            self.widgets.remove_parent('sp_nplants_label')
            self.widgets.remove_parent('sp_nplants_data')
Esempio n. 15
0
 def __init__(self, parent=None):
     filename = os.path.join(paths.lib_dir(), 'plugins', 'garden',
                             'acc_editor.glade')
     super(SourceDetailEditorView, self).__init__(filename, parent=parent)
     self.set_accept_buttons_sensitive(False)
     self.init_translatable_combo(
         'source_type_combo', source_type_values)
Esempio n. 16
0
def start_taxonomy_check():
    """run the batch taxonomy check (BTC)
    """

    view = GenericEditorView(
        os.path.join(paths.lib_dir(), "plugins", "plants", "taxonomy_check.glade"),
        parent=None,
        root_widget_name="dialog1",
    )
    model = type("BTCStatus", (object,), {})()
    model.page = 1
    model.selection = view.get_selection()
    model.tick_off = None
    model.report = None
    model.file_path = ""

    if model.selection is None:
        return
    from sqlalchemy.orm import object_session

    presenter = BatchTaxonomicCheckPresenter(model, view, refresh_view=True, session=object_session(model.selection[0]))
    error_state = presenter.start()
    if error_state:
        presenter.session.rollback()
    else:
        presenter.commit_changes()
        from bauble import gui

        view = gui.get_view()
        if hasattr(view, "update"):
            view.update()
    presenter.cleanup()
    return error_state
Esempio n. 17
0
    def itest_editor(self):
        # import default geography data
        import bauble.paths as paths
        default_path = os.path.join(paths.lib_dir(), "plugins", "plants",
                                "default")
        filenames = [os.path.join(default_path, f) for f in 'geography.txt',
                     'habit.txt']
        from bauble.plugins.imex.csv_ import CSVImporter
        importer = CSVImporter()
        importer.start(filenames, force=True)

        f = Family(family=u'family')
        g2 = Genus(genus=u'genus2', family=f)
        g = Genus(genus=u'genus', family=f)
        g2.synonyms.append(g)
        self.session.add(f)
        self.session.commit()
        sp = Species(genus=g, sp=u'sp')
        e = SpeciesEditor(model=sp)
        e.start()
        del e
        assert utils.gc_objects_by_type('SpeciesEditor') == [], \
            'SpeciesEditor not deleted'
        assert utils.gc_objects_by_type('SpeciesEditorPresenter') == [], \
            'SpeciesEditorPresenter not deleted'
        assert utils.gc_objects_by_type('SpeciesEditorView') == [], \
            'SpeciesEditorView not deleted'
 def test_set_sensitive(self):
     filename = os.path.join(paths.lib_dir(), "connmgr.glade")
     view = GenericEditorView(filename, root_widget_name="main_dialog")
     view.widget_set_sensitive("cancel_button", True)
     self.assertTrue(view.widgets.cancel_button.get_sensitive())
     view.widget_set_sensitive("cancel_button", False)
     self.assertFalse(view.widgets.cancel_button.get_sensitive())
    def __init__(self, parent, model, view, session):
        self.parent_ref = weakref.ref(parent)
        self.parent_session = session
        try:
            view.widgets.prop_main_box
        except:
            # only add the propagation editor widgets to the view
            # widgets if the widgets haven't yet been added
            filename = os.path.join(paths.lib_dir(), 'plugins', 'garden',
                                    'prop_editor.glade')
            view.widgets.builder.add_from_file(filename)
        prop_main_box = view.widgets.prop_main_box
        view.widgets.remove_parent(prop_main_box)
        view.widgets.acc_prop_box_parent.add(prop_main_box)

        # since the view here will be an AccessionEditorView and not a
        # PropagationEditorView then we need to do anything here that
        # PropagationEditorView would do
        view.init_translatable_combo('prop_type_combo', prop_type_values)
        # add None to the prop types which is specific to
        # SourcePropagationPresenter since we might also need to
        # remove the propagation...this will need to be called before
        # the PropagationPresenter.on_prop_type_changed or it won't work
        view.widgets.prop_type_combo.get_model().append([None, ''])

        # create a temporary Propagation that we'll connect to the
        # source when the prop_type_combo changes
        # self.source = model
        # if not self.source.propagation:
        #     self.source.propagation = Propagation()
        #     view.widgets.prop_details_box.props.visible=False
        self._dirty = False
        super(SourcePropagationPresenter, self).__init__(model, view)
Esempio n. 20
0
    def __init__(self):
        """
        the constructor
        """
        super(SpeciesInfoPage, self).__init__()
        filename = os.path.join(paths.lib_dir(), "plugins", "plants", "infoboxes.glade")
        # load the widgets directly instead of using load_widgets()
        # because the caching that load_widgets() does can mess up
        # displaying the SpeciesInfoBox sometimes if you try to show
        # the infobox while having a vernacular names selected in
        # the search results and then a species name
        self.widgets = utils.BuilderWidgets(filename)
        self.general = GeneralSpeciesExpander(self.widgets)
        self.add_expander(self.general)
        self.vernacular = VernacularExpander(self.widgets)
        self.add_expander(self.vernacular)
        self.synonyms = SynonymsExpander(self.widgets)
        self.add_expander(self.synonyms)
        self.links = LinksExpander()
        self.add_expander(self.links)
        self.props = PropertiesExpander()
        self.add_expander(self.props)
        self.label = _("General")

        if "GardenPlugin" not in pluginmgr.plugins:
            self.widgets.remove_parent("sp_nacc_label")
            self.widgets.remove_parent("sp_nacc_data")
            self.widgets.remove_parent("sp_nplants_label")
            self.widgets.remove_parent("sp_nplants_data")
Esempio n. 21
0
    def __init__(self):
        '''
        the constructor
        '''
        super(SearchView, self).__init__()
        filename = os.path.join(paths.lib_dir(), 'bauble.glade')
        self.widgets = utils.load_widgets(filename)

        self.create_gui()

        import pictures_view
        pictures_view.floating_window = pictures_view.PicturesView(
            parent=self.widgets.search_h2pane)

        # we only need this for the timeout version of populate_results
        self.populate_callback_id = None

        # the context menu cache holds the context menus by type in the results
        # view so that we don't have to rebuild them every time
        self.context_menu_cache = {}
        self.infobox_cache = {}
        self.infobox = None

        # keep all the search results in the same session, this should
        # be cleared when we do a new search
        self.session = db.Session()
Esempio n. 22
0
    def __init__(self, view=None):
        self.filename = self.database = self.host = self.user = self.pictureroot = self.connection_name = ""
        self.use_defaults = True
        self.passwd = False
        ## following two look like overkill, since they will be initialized
        ## in the parent class constructor. but we need these attributes in
        ## place before we can invoke get_params
        self.model = self
        self.view = view

        ## initialize comboboxes, so we can fill them in
        view.combobox_init("name_combo")
        view.combobox_init("type_combo", dbtypes, type_combo_cell_data_func)
        self.connection_names = []
        self.connections = prefs.prefs[bauble.conn_list_pref] or {}
        for ith_connection_name in self.connections:
            view.combobox_append_text("name_combo", ith_connection_name)
            self.connection_names.append(ith_connection_name)
        if self.connection_names:
            self.connection_name = prefs.prefs[bauble.conn_default_pref]
            if self.connection_name not in self.connections:
                self.connection_name = self.connection_names[0]
            self.dbtype = None
            self.set_params()
        else:
            self.dbtype = ""
            self.connection_name = None
        GenericEditorPresenter.__init__(self, model=self, view=view, refresh_view=True)
        logo_path = os.path.join(paths.lib_dir(), "images", "bauble_logo.png")
        view.image_set_from_file("logo_image", logo_path)
        view.set_title("%s %s" % ("Bauble", bauble.version))
        try:
            view.set_icon(gtk.gdk.pixbuf_new_from_file(bauble.default_icon))
        except:
            pass
Esempio n. 23
0
    def __init__(self):
        '''
        '''

        button_defs = [
            {'name': 'IPNIButton', '_base_uri': "http://www.ipni.org/ipni/advPlantNameSearch.do?find_family=%(family)s&find_isAPNIRecord=on& find_isGCIRecord=on&find_isIKRecord=on&output_format=normal", '_space': ' ', 'title': _("Search IPNI"), 'tooltip': _("Search the International Plant Names Index"), },
            {'name': 'GoogleButton', '_base_uri': "http://www.google.com/search?q=%s", '_space': '+', 'title': "Search Google", 'tooltip': None, },
            {'name': 'GBIFButton', '_base_uri': "http://www.gbif.org/species/search?q=%s", '_space': '+', 'title': _("Search GBIF"), 'tooltip': _("Search the Global Biodiversity Information Facility"), },
            {'name': 'ITISButton', '_base_uri': "http://www.itis.gov/servlet/SingleRpt/SingleRpt?search_topic=Scientific_Name&search_value=%s&search_kingdom=Plant&search_span=containing&categories=All&source=html&search_credRating=All", '_space': '%20', 'title': _("Search ITIS"), 'tooltip': _("Search the Intergrated Taxonomic Information System"), },
            {'name': 'GRINButton', '_base_uri': "http://www.ars-grin.gov/cgi-bin/npgs/swish/accboth?query=%s&submit=Submit+Text+Query&si=0", '_space': '+', 'title': _("Search NPGS/GRIN"), 'tooltip': _('Search National Plant Germplasm System'), },
            {'name': 'ALAButton', '_base_uri': "http://bie.ala.org.au/search?q=%s", '_space': '+', 'title': _("Search ALA"), 'tooltip': _("Search the Atlas of Living Australia"), },

            ]
        InfoBox.__init__(self)
        filename = os.path.join(paths.lib_dir(), 'plugins', 'plants',
                                'infoboxes.glade')
        self.widgets = utils.load_widgets(filename)
        self.general = GeneralFamilyExpander(self.widgets)
        self.add_expander(self.general)
        self.synonyms = SynonymsExpander(self.widgets)
        self.add_expander(self.synonyms)
        self.links = view.LinksExpander('notes', links=button_defs)
        self.add_expander(self.links)
        self.props = PropertiesExpander()
        self.add_expander(self.props)

        if 'GardenPlugin' not in pluginmgr.plugins:
            self.widgets.remove_parent('fam_nacc_label')
            self.widgets.remove_parent('fam_nacc_data')
            self.widgets.remove_parent('fam_nplants_label')
            self.widgets.remove_parent('fam_nplants_data')
 def __init__(self, report_dialog=None, *args):
     super(MakoFormatterSettingsBox, self).__init__(*args)
     self.widgets = utils.load_widgets(os.path.join(paths.lib_dir(), "plugins", "report", "mako", "gui.glade"))
     # keep a refefence to settings box so it doesn't get destroyed in
     # remove_parent()
     self.settings_box = self.widgets.settings_box
     self.widgets.remove_parent(self.widgets.settings_box)
     self.pack_start(self.settings_box)
Esempio n. 25
0
 def __init__(self, parent=None):
     """
     """
     super(PropagationEditorView, self).\
         __init__(os.path.join(paths.lib_dir(), 'plugins', 'garden',
                               'prop_editor.glade'),
                  parent=parent)
     self.init_translatable_combo('prop_type_combo', prop_type_values)
 def __init__(self, parent=None):
     """
     """
     super(PropagationEditorView, self).\
         __init__(os.path.join(paths.lib_dir(), 'plugins', 'garden',
                               'prop_editor.glade'),
                  parent=parent)
     self.init_translatable_combo('prop_type_combo', prop_type_values)
    def install(cls, import_defaults=True):
	# copy default template files to user_dir
	templates = ['example.csv', 'example.csv']
        base_dir = os.path.join(paths.lib_dir(), "plugins", "report", 'mako')
	for template in templates:
	    f = os.path.join(paths.user_dir(), template)
	    if not os.path.exists(f):
		shutil.copy(os.path.join(base_dir, template), f)
Esempio n. 28
0
 def __init__(self, values):
     filename = os.path.join(paths.lib_dir(), 'plugins', 'tag', 'tag.glade')
     super(TagItemGUI, self).__init__(filename)
     self.item_data_label = self.widgets.items_data
     self.values = values
     self.item_data_label.set_text(', '.join([str(s) for s in self.values]))
     self.connect(self.widgets.new_button, 'clicked',
                  self.on_new_button_clicked)
 def install(cls, import_defaults=True):
     # copy default template files to user_dir
     templates = ['basic.xsl', 'labels.xsl', 'plant_list.xsl',
                  'plant_list_ex.xsl', 'small_labels.xsl']
     base_dir = os.path.join(paths.lib_dir(), "plugins", "report", 'xsl')
     for template in templates:
         f = os.path.join(paths.user_dir(), template)
         if not os.path.exists(f):
             shutil.copy(os.path.join(base_dir, template), f)
Esempio n. 30
0
 def install(cls, import_defaults=True):
     logger.debug("installing mako plugin")
     # copy default template files to user_dir
     templates = ['example.csv', 'example.csv']
     base_dir = os.path.join(paths.lib_dir(), "plugins", "report", 'mako')
     for template in templates:
         f = os.path.join(paths.user_dir(), template)
         if not os.path.exists(f):
             shutil.copy(os.path.join(base_dir, template), f)
Esempio n. 31
0
 def __init__(self, values):
     filename = os.path.join(paths.lib_dir(), 'plugins', 'tag',
                             'tag.glade')
     super(TagItemGUI, self).__init__(filename)
     self.item_data_label = self.widgets.items_data
     self.values = values
     self.item_data_label.set_text(', '.join([str(s) for s in self.values]))
     self.connect(self.widgets.new_button,
                  'clicked', self.on_new_button_clicked)
 def install(cls, import_defaults=True):
     logger.debug("installing mako plugin")
     # copy default template files to user_dir
     templates = ["example.csv", "example.csv"]
     base_dir = os.path.join(paths.lib_dir(), "plugins", "report", "mako")
     for template in templates:
         f = os.path.join(paths.user_dir(), template)
         if not os.path.exists(f):
             shutil.copy(os.path.join(base_dir, template), f)
 def test_set_visible_get_visible(self):
     filename = os.path.join(paths.lib_dir(), "connmgr.glade")
     view = GenericEditorView(filename, root_widget_name="main_dialog")
     view.widget_set_visible("noconnectionlabel", True)
     self.assertTrue(view.widget_get_visible("noconnectionlabel"))
     self.assertTrue(view.widgets.noconnectionlabel.get_visible())
     view.widget_set_visible("noconnectionlabel", False)
     self.assertFalse(view.widget_get_visible("noconnectionlabel"))
     self.assertFalse(view.widgets.noconnectionlabel.get_visible())
Esempio n. 34
0
 def test_set_visible_get_visible(self):
     filename = os.path.join(paths.lib_dir(), 'connmgr.glade')
     view = GenericEditorView(filename, root_widget_name='main_dialog')
     view.widget_set_visible('noconnectionlabel', True)
     self.assertTrue(view.widget_get_visible('noconnectionlabel'))
     self.assertTrue(view.widgets.noconnectionlabel.get_visible())
     view.widget_set_visible('noconnectionlabel', False)
     self.assertFalse(view.widget_get_visible('noconnectionlabel'))
     self.assertFalse(view.widgets.noconnectionlabel.get_visible())
Esempio n. 35
0
    def setUp(self):
        super(ABCDTestCase, self).setUp()
        plants_test.setUp_data()
        garden_test.setUp_data()

        schema_file = os.path.join(
            paths.lib_dir(), 'plugins', 'abcd', 'abcd_2.06.xsd')
        xmlschema_doc = etree.parse(schema_file)
        self.abcd_schema = etree.XMLSchema(xmlschema_doc)
Esempio n. 36
0
 def __init__(self):
     logger.debug('PrefsView::__init__')
     super(PrefsView, self).__init__(
         filename=os.path.join(paths.lib_dir(), 'bauble.glade'),
         root_widget_name='prefs_window')
     self.view.connect_signals(self)
     self.prefs_ls = self.view.widgets.prefs_prefs_ls
     self.plugins_ls = self.view.widgets.prefs_plugins_ls
     self.update()
Esempio n. 37
0
    def __init__(self, ):
        """
        """
        filename = os.path.join(paths.lib_dir(), 'plugins', 'users',
                                'ui.glade')
        super(UsersEditor, self).__init__(filename)

        if db.engine.name not in ('postgres', 'postgresql'):
            msg = _('The Users editor is only valid on a PostgreSQL database')
            utils.message_dialog(utils.utf8(msg))
            return

        # TODO: should allow anyone to view the priveleges but only
        # admins to change them
        #debug(current_user())
        if not has_privileges(current_user(), 'admin'):
            msg = _('You do not have privileges to change other '\
                        'user privileges')
            utils.message_dialog(utils.utf8(msg))
            return
        # setup the users tree
        tree = self.widgets.users_tree

        # remove any old columns
        for column in tree.get_columns():
            tree.remove_column(column)

        renderer = gtk.CellRendererText()

        def cell_data_func(col, cell, model, it):
            value = model[it][0]
            cell.set_property('text', value)

        tree.insert_column_with_data_func(0, _('Users'), renderer,
                                          cell_data_func)
        self.connect(tree, 'cursor-changed', self.on_cursor_changed)
        self.connect(renderer, 'edited', self.on_cell_edited)

        # connect the filter_check and also adds the users to the users_tree
        self.connect('filter_check', 'toggled', self.on_filter_check_toggled)
        self.widgets.filter_check.set_active(True)

        def on_toggled(button, priv=None):
            buttons = (self.widgets.read_button, self.widgets.write_button,
                       self.widgets.admin_button)
            role = self.get_selected_user()
            active = button.get_active()
            if active and not has_privileges(role, priv):
                #debug('grant %s to %s' % (priv, role))
                try:
                    set_privilege(role, priv)
                except Exception, e:
                    utils.message_dialog(utils.utf8(e),
                                         gtk.MESSAGE_ERROR,
                                         parent=self.get_window())
            return True
Esempio n. 38
0
 def __init__(self, report_dialog=None, *args):
     super(MakoFormatterSettingsBox, self).__init__(*args)
     self.widgets = utils.load_widgets(
         os.path.join(paths.lib_dir(), "plugins", "report", 'mako',
                      'gui.glade'))
     # keep a refefence to settings box so it doesn't get destroyed in
     # remove_parent()
     self.settings_box = self.widgets.settings_box
     self.widgets.remove_parent(self.widgets.settings_box)
     self.pack_start(self.settings_box)
Esempio n. 39
0
    def __init__(self, parent=None):

        filename = os.path.join(paths.lib_dir(), 'plugins', 'plants',
                                'genus_editor.glade')
        super(GenusEditorView, self).__init__(filename, parent=parent)
        self.attach_completion('gen_syn_entry', self.syn_cell_data_func)
        self.attach_completion('gen_family_entry')
        self.set_accept_buttons_sensitive(False)
        self.widgets.notebook.set_current_page(0)
        self.restore_state()
Esempio n. 40
0
 def __init__(self):
     logger.debug('PrefsView::__init__')
     super(PrefsView,
           self).__init__(filename=os.path.join(paths.lib_dir(),
                                                'bauble.glade'),
                          root_widget_name='prefs_window')
     self.view.connect_signals(self)
     self.prefs_ls = self.view.widgets.prefs_prefs_ls
     self.plugins_ls = self.view.widgets.prefs_plugins_ls
     self.update()
Esempio n. 41
0
    def __init__(self, parent=None):

        filename = os.path.join(paths.lib_dir(), 'plugins', 'plants',
                                'genus_editor.glade')
        super(GenusEditorView, self).__init__(filename, parent=parent)
        self.attach_completion('gen_syn_entry', self.syn_cell_data_func)
        self.attach_completion('gen_family_entry')
        self.set_accept_buttons_sensitive(False)
        self.widgets.notebook.set_current_page(0)
        self.restore_state()
Esempio n. 42
0
 def install(cls, import_defaults=True):
     # copy default template files to user_dir
     templates = [
         'basic.xsl', 'labels.xsl', 'plant_list.xsl', 'plant_list_ex.xsl',
         'small_labels.xsl'
     ]
     base_dir = os.path.join(paths.lib_dir(), "plugins", "report", 'xsl')
     for template in templates:
         f = os.path.join(paths.user_dir(), template)
         if not os.path.exists(f):
             shutil.copy(os.path.join(base_dir, template), f)
Esempio n. 43
0
 def __init__(self, session, parent=None):
     self.session = session
     filename = os.path.join(paths.lib_dir(), 'plugins', 'imex',
                             'select_export.glade')
     super(ExportToJson, self).__init__(filename, parent=parent)
     for wn in ['selection', 'taxa', 'accessions', 'plants']:
         self.connect('sbo_' + wn, 'toggled',
                      self.radio_button_pushed, "based_on")
     for wn in ['referred', 'referring']:
         self.connect('ei_' + wn, 'toggled',
                      self.radio_button_pushed, "includes")
Esempio n. 44
0
 def start(cls):
     # the presenter uses the view to interact with user then
     # performs the export, if this is the case.
     s = db.Session()
     filename = os.path.join(
         paths.lib_dir(), 'plugins', 'imex', 'select_export.glade')
     presenter = JSONExporter(view=editor.GenericEditorView(
         filename, root_widget_name='select_export_dialog'))
     presenter.start()  # interact && run
     presenter.cleanup()
     s.close()
Esempio n. 45
0
 def start(cls):
     """
     Start the JSON importer.  This tool will also reinitialize the
     plugins after importing.
     """
     s = db.Session()
     filename = os.path.join(paths.lib_dir(), 'plugins', 'imex',
                             'select_export.glade')
     presenter = JSONImporter(view=editor.GenericEditorView(
         filename, root_widget_name='select_import_dialog'))
     presenter.start()  # interact && run
     s.close()
Esempio n. 46
0
def validate_xml(root):
    """
    Validate root against ABCD 2.06 schema

    :param root: root of an XML tree to validate against
    :returns: True or False depending if root validates correctly
    """
    schema_file = os.path.join(paths.lib_dir(), 'plugins', 'abcd',
                               'abcd_2.06.xsd')
    xmlschema_doc = etree.parse(schema_file)
    abcd_schema = etree.XMLSchema(xmlschema_doc)
    return abcd_schema.validate(root)
def validate_xml(root):
    """
    Validate root against ABCD 2.06 schema

    :param root: root of an XML tree to validate against
    :returns: True or False depending if root validates correctly
    """
    schema_file = os.path.join(paths.lib_dir(), 'plugins',
            'abcd','abcd_2.06.xsd')
    xmlschema_doc = etree.parse(schema_file)
    abcd_schema = etree.XMLSchema(xmlschema_doc)
    return abcd_schema.validate(root)
Esempio n. 48
0
    def on_help_menu_about(self, widget, data=None):
	about = gtk.AboutDialog()
	about.set_name('Bauble')
	about.set_version(bauble.version)
        gtk.about_dialog_set_url_hook(lambda d, l: desktop.open(l, dialog_on_error=True))
        about.set_website(_('http://bauble.io'))
        f = os.path.join(paths.lib_dir(), 'images', 'icon.svg')
        pixbuf = gtk.gdk.pixbuf_new_from_file(f)
        about.set_logo(pixbuf)
	about.set_copyright(_(u'Copyright \u00A9 Belize Botanic Gardens'))
	about.run()
	about.destroy()
Esempio n. 49
0
 def __init__(self, parent=None):
     GenericEditorView.__init__(self,
                                os.path.join(paths.lib_dir(), 'plugins',
                                             'garden', 'loc_editor.glade'),
                                parent=parent)
     self.use_ok_and_add = True
     self.set_accept_buttons_sensitive(False)
     # if the parent isn't the main bauble window then we assume
     # that the LocationEditor was opened from the PlantEditor and
     # so we shouldn't enable adding more plants...this is a bit of
     # a hack but it serves our purposes
     if bauble.gui and parent != bauble.gui.window:
         self.use_ok_and_add = False
Esempio n. 50
0
 def __init__(self):
     '''
     '''
     InfoBox.__init__(self)
     filename = os.path.join(paths.lib_dir(), "plugins", "garden",
                             "loc_infobox.glade")
     self.widgets = utils.load_widgets(filename)
     self.general = GeneralLocationExpander(self.widgets)
     self.add_expander(self.general)
     self.description = DescriptionExpander(self.widgets)
     self.add_expander(self.description)
     self.props = PropertiesExpander()
     self.add_expander(self.props)
Esempio n. 51
0
def load(path=None):
    """
    Search the plugin path for modules that provide a plugin. If path
    is a directory then search the directory for plugins. If path is
    None then use the default plugins path, bauble.plugins.

    This method populates the pluginmgr.plugins dict and imports the
    plugins but doesn't do any plugin initialization.

    :param path: the path where to look for the plugins
    :type path: str
    """

    if path is None:
        if bauble.main_is_frozen():
            #path = os.path.join(paths.lib_dir(), 'library.zip')
            path = os.path.join(paths.main_dir(), 'library.zip')
        else:
            path = os.path.join(paths.lib_dir(), 'plugins')
    logger.debug('pluginmgr.load(%s)' % path)
    found, errors = _find_plugins(path)
    logger.debug('found=%s, errors=%s' % (found, errors))

    # show error dialog for plugins that couldn't be loaded...we only
    # give details for the first error and assume the others are the
    # same...and if not then it doesn't really help anyways
    if errors:
        name = ', '.join(sorted(errors.keys()))
        exc_info = errors.values()[0]
        exc_str = utils.xml_safe(exc_info[1])
        tb_str = ''.join(traceback.format_tb(exc_info[2]))
        utils.message_details_dialog('Could not load plugin: '
                                     '\n\n<i>%s</i>\n\n%s'
                                     % (name, exc_str),
                                     tb_str, type=gtk.MESSAGE_ERROR)

    if len(found) == 0:
        logger.debug('No plugins found at path: %s' % path)

    for plugin in found:
        # issue #27: should we include the module name of the plugin to
        # allow for plugin namespaces or just assume that the plugin class
        # name is unique?
        if isinstance(plugin, (type, types.ClassType)):
            plugins[plugin.__name__] = plugin
            logger.debug("registering plugin %s: %s"
                         % (plugin.__name__, plugin))
        else:
            plugins[plugin.__class__.__name__] = plugin
            logger.debug("registering plugin %s: %s"
                         % (plugin.__class__.__name__, plugin))
Esempio n. 52
0
    def __init__(self, button_callback):
        super(StatusBox, self).__init__()
        self.label = gtk.Label()
        self.pack_start(self.label, False, False)

        loading_image = os.path.join(paths.lib_dir(), 'images', 'loading.gif')
        animation = gtk.gdk.PixbufAnimation(loading_image)
        self.progress_image = gtk.Image()
        self.progress_image.set_from_animation(animation)
        self.pack_start(self.progress_image, False, False)

        self.button = gtk.Button(_('Settings'))
        self.button.connect('clicked', button_callback)
        self.pack_start(self.button, False, False, padding=10)
Esempio n. 53
0
def start_connection_manager(default_conn=None):
    '''activate connection manager and return connection name and uri
    '''
    glade_path = os.path.join(paths.lib_dir(), "connmgr.glade")
    view = GenericEditorView(glade_path,
                             parent=None,
                             root_widget_name='main_dialog')

    cm = ConnMgrPresenter(view)
    result = cm.start()
    if result == gtk.RESPONSE_OK:
        return cm.connection_name, cm.connection_uri
    else:
        return None, None
Esempio n. 54
0
 def install(cls, import_defaults=True):
     import bauble.paths as paths
     if not import_defaults:
         return
     path = os.path.join(paths.lib_dir(), "plugins", "plants",
                         "default")
     filenames = os.path.join(path, 'family.txt')
     from bauble.plugins.imex.csv_ import CSVImporter
     csv = CSVImporter()
     try:
         csv.start([filenames], metadata=db.metadata, force=True)
     except Exception, e:
         logger.error(e)
         raise
Esempio n. 55
0
    def __init__(self):
        self.widgets = utils.load_widgets(
            os.path.join(paths.lib_dir(), "plugins", "report", 'report.glade'))
        self.dialog = self.widgets.report_dialog
        self.dialog.set_transient_for(bauble.gui.window)
        self.builder = self.widgets.builder
        utils.setup_text_combobox(self.widgets.names_combo)
        utils.setup_text_combobox(self.widgets.formatter_combo)

        self._delete_sid = self.dialog.connect(
            'delete-event', self.on_dialog_close_or_delete)
        self._close_sid = self.dialog.connect(
            'close', self.on_dialog_close_or_delete)
        self._response_sid = self.dialog.connect(
            'response', self.on_dialog_response)
Esempio n. 56
0
def edit_callback(tags):
    tag = tags[0]
    if tag is None:
        tag = Tag()
    view = GenericEditorView(os.path.join(paths.lib_dir(), 'plugins', 'tag',
                                          'tag.glade'),
                             parent=None,
                             root_widget_name='tag_dialog')
    presenter = TagEditorPresenter(tag, view, refresh_view=True)
    error_state = presenter.start()
    if error_state:
        presenter.session.rollback()
    else:
        presenter.commit_changes()
    presenter.cleanup()
    return error_state