Exemple #1
0
 def format(objs, **kwargs):
     template_filename = kwargs['template']
     use_private = kwargs.get('private', True)
     if not template_filename:
         msg = _('Please select a template.')
         utils.message_dialog(msg, gtk.MESSAGE_WARNING)
         return False
     template = Template(filename=template_filename,
                         input_encoding='utf-8',
                         output_encoding='utf-8')
     session = db.Session()
     values = map(session.merge, objs)
     report = template.render(values=values)
     session.close()
     # assume the template is the same file type as the output file
     head, ext = os.path.splitext(template_filename)
     fd, filename = tempfile.mkstemp(suffix=ext)
     os.write(fd, report)
     os.close(fd)
     try:
         desktop.open(filename)
     except OSError:
         utils.message_dialog(
             _('Could not open the report with the '
               'default program. You can open the '
               'file manually at %s') % filename)
     return report
 def format(objs, **kwargs):
     template_filename = kwargs["template"]
     use_private = kwargs.get("private", True)
     if not template_filename:
         msg = _("Please select a template.")
         utils.message_dialog(msg, gtk.MESSAGE_WARNING)
         return False
     template = Template(filename=template_filename, input_encoding="utf-8", output_encoding="utf-8")
     session = db.Session()
     values = map(session.merge, objs)
     report = template.render(values=values)
     session.close()
     # assume the template is the same file type as the output file
     head, ext = os.path.splitext(template_filename)
     fd, filename = tempfile.mkstemp(suffix=ext)
     os.write(fd, report)
     os.close(fd)
     try:
         desktop.open(filename)
     except OSError:
         utils.message_dialog(
             _("Could not open the report with the " "default program. You can open the " "file manually at %s")
             % filename
         )
     return report
    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()
    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.wikidot.com"))
        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 © by its contributors."))

        import codecs

        with codecs.open(os.path.join(paths.installation_dir(), "share", "LICENSE.bauble")) as f:
            license = f.read()
        about.set_license(license)  # not translated
        about.run()
        about.destroy()
Exemple #5
0
    def on_help_menu_about(self, widget, data=None):
        about = gtk.AboutDialog()
        about.set_name('Ghini')
        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://ghini.github.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 © by its contributors.'))

        import codecs
        with codecs.open(os.path.join(paths.installation_dir(), 'share',
                                      'LICENSE.ghini')) as f:
            license = f.read()
        about.set_license(license)  # not translated
        about.run()
        about.destroy()
Exemple #6
0
 def on_help_menu_logfile(self, widget, data=None):
     filename = os.path.join(paths.user_dir(), 'bauble.log')
     desktop.open(filename, dialog_on_error=True)
Exemple #7
0
 def on_help_menu_web_wiki(self, widget, data=None):
     desktop.open('http://github.com/Bauble/bauble.classic/wiki',
                  dialog_on_error=True)
Exemple #8
0
 def on_help_menu_contents(self, widget, data=None):
     desktop.open('http://bauble.readthedocs.org/en/latest/',
                  dialog_on_error=True)
Exemple #9
0
 def on_help_menu_bug(self, widget, data=None):
     desktop.open('https://github.com/Bauble/bauble.classic/issues/new',
                  dialog_on_error=True)
Exemple #10
0
 def on_help_menu_web_forum(self, widget, data=None):
     desktop.open('https://groups.google.com/forum/#!forum/bauble',
                  dialog_on_error=True)
Exemple #11
0
def _open_link(func, data=None):
    desktop.open(data)
Exemple #12
0
 def on_help_menu_contents(self, widget, data=None):
     desktop.open('http://bauble.readthedocs.org/en/latest/',
                  dialog_on_error=True)
Exemple #13
0
 def on_help_menu_logfile(self, widget, data=None):
     filename = os.path.join(paths.user_dir(), 'bauble.log')
     desktop.open(filename, dialog_on_error=True)
Exemple #14
0
 def on_help_menu_web_forum(self, widget, data=None):
     desktop.open('https://groups.google.com/forum/#!forum/bauble',
                  dialog_on_error=True)
Exemple #15
0
 def on_tnrs_browse_button_clicked(self, *args):
     from bauble.utils import desktop
     desktop.open('http://tnrs.iplantcollaborative.org/TNRSapp.html')
    def on_help_menu_web(self, widget, data=None):
	desktop.open('http://bauble.belizebotanic.org',
                     dialog_on_error=True)
 def on_inst_register_clicked(self, *args, **kwargs):
     from bauble.utils import desktop
     desktop.open('mailto:[email protected]')
    def format(objs, **kwargs):
#        debug('format(%s)' % kwargs)
        stylesheet = kwargs['stylesheet']
        authors = kwargs['authors']
        renderer = kwargs['renderer']
        source_type = kwargs['source_type']
        use_private = kwargs['private']
        error_msg = None
        if not stylesheet:
            error_msg = _('Please select a stylesheet.')
        elif not renderer:
            error_msg = _('Please select a a renderer')
        if error_msg is not None:
            utils.message_dialog(error_msg, gtk.MESSAGE_WARNING)
            return False

        fo_cmd = renderers_map[renderer]
        exe = fo_cmd.split(' ')[0]
        if not on_path(exe):
            utils.message_dialog(_('Could not find the command "%(exe)s" to '
                                   'start the %(renderer_name)s '
                                   'renderer.') %
                                  ({'exe': exe, 'renderer_name': renderer}),
                                 gtk.MESSAGE_ERROR)
            return False

        session = db.Session()

        # convert objects to ABCDAdapters depending on source type for
        # passing to create_abcd
        adapted = []
        if source_type == plant_source_type:
            plants = sorted(get_plants_pertinent_to(objs, session=session),
                            key=utils.natsort_key)
            if len(plants) == 0:
                utils.message_dialog(_('There are no plants in the search '
                                       'results.  Please try another search.'))
                return False
            for p in plants:
                if use_private:
                    adapted.append(PlantABCDAdapter(p, for_labels=True))
                elif not p.accession.private:
                    adapted.append(PlantABCDAdapter(p, for_labels=True))
        elif source_type == species_source_type:
            species = sorted(get_species_pertinent_to(objs, session=session),
                             key=utils.natsort_key)
            if len(species) == 0:
                utils.message_dialog(_('There are no species in the search '
                                       'results.  Please try another search.'))
                return False
            for s in species:
                adapted.append(SpeciesABCDAdapter(s, for_labels=True))
        elif source_type == accession_source_type:
            accessions = sorted(get_accessions_pertinent_to(objs,
                                                            session=session),
                                key=utils.natsort_key)
            if len(accessions) == 0:
                utils.message_dialog(_('There are no accessions in the search '
                                       'results.  Please try another search.'))
                return False
            for a in accessions:
                if use_private:
                    adapted.append(AccessionABCDAdapter(a, for_labels=True))
                elif not a.private:
                    adapted.append(AccessionABCDAdapter(a, for_labels=True))
        else:
            raise NotImplementedError('unknown source type')

        if len(adapted) == 0:
            # nothing adapted....possibly everything was private
            # TODO: if everything was private and that is really why we got
            # here then it is probably better to show a dialog with a message
            # and raise and exception which appears as an error
            raise Exception('No objects could be adapted to ABCD units.')
        abcd_data = create_abcd(adapted, authors=authors, validate=False)

        session.close()

        # logger.debug(etree.dump(abcd_data.getroot()))

        # create xsl fo file
        dummy, fo_filename = tempfile.mkstemp()
        style_etree = etree.parse(stylesheet)
        transform = etree.XSLT(style_etree)
        result = transform(abcd_data)
        fo_outfile = open(fo_filename, 'w')
        fo_outfile.write(str(result))
        fo_outfile.close()
        dummy, filename = tempfile.mkstemp()
        filename = '%s.pdf' % filename

        # TODO: checkout pyexpect for spawning processes

        # run the report to produce the pdf file, the command has to be
        # on the path for this to work
        fo_cmd = fo_cmd % ({'fo_filename': fo_filename,
                            'out_filename': filename})
#        print fo_cmd
#        debug(fo_cmd)
        # TODO: use popen to get output
        os.system(fo_cmd)

#        print filename
        if not os.path.exists(filename):
            utils.message_dialog(_('Error creating the PDF file. Please '
                                   'ensure that your PDF formatter is '
                                   'properly installed.'), gtk.MESSAGE_ERROR)
            return False
        else:
            try:
                desktop.open(filename)
            except OSError:
                utils.message_dialog(_('Could not open the report with the '
                                       'default program. You can open the '
                                       'file manually at %s') % filename)

        return True
Exemple #19
0
    def format(objs, **kwargs):
        #        debug('format(%s)' % kwargs)
        stylesheet = kwargs['stylesheet']
        authors = kwargs['authors']
        renderer = kwargs['renderer']
        source_type = kwargs['source_type']
        use_private = kwargs['private']
        error_msg = None
        if not stylesheet:
            error_msg = _('Please select a stylesheet.')
        elif not renderer:
            error_msg = _('Please select a a renderer')
        if error_msg is not None:
            utils.message_dialog(error_msg, gtk.MESSAGE_WARNING)
            return False

        fo_cmd = renderers_map[renderer]
        exe = fo_cmd.split(' ')[0]
        if not on_path(exe):
            utils.message_dialog(
                _('Could not find the command "%(exe)s" to '
                  'start the %(renderer_name)s '
                  'renderer.') % ({
                      'exe': exe,
                      'renderer_name': renderer
                  }), gtk.MESSAGE_ERROR)
            return False

        session = db.Session()

        # convert objects to ABCDAdapters depending on source type for
        # passing to create_abcd
        adapted = []
        if source_type == plant_source_type:
            plants = sorted(get_plants_pertinent_to(objs, session=session),
                            key=utils.natsort_key)
            if len(plants) == 0:
                utils.message_dialog(
                    _('There are no plants in the search '
                      'results.  Please try another search.'))
                return False
            for p in plants:
                if use_private:
                    adapted.append(PlantABCDAdapter(p, for_labels=True))
                elif not p.accession.private:
                    adapted.append(PlantABCDAdapter(p, for_labels=True))
        elif source_type == species_source_type:
            species = sorted(get_species_pertinent_to(objs, session=session),
                             key=utils.natsort_key)
            if len(species) == 0:
                utils.message_dialog(
                    _('There are no species in the search '
                      'results.  Please try another search.'))
                return False
            for s in species:
                adapted.append(SpeciesABCDAdapter(s, for_labels=True))
        elif source_type == accession_source_type:
            accessions = sorted(get_accessions_pertinent_to(objs,
                                                            session=session),
                                key=utils.natsort_key)
            if len(accessions) == 0:
                utils.message_dialog(
                    _('There are no accessions in the search '
                      'results.  Please try another search.'))
                return False
            for a in accessions:
                if use_private:
                    adapted.append(AccessionABCDAdapter(a, for_labels=True))
                elif not a.private:
                    adapted.append(AccessionABCDAdapter(a, for_labels=True))
        else:
            raise NotImplementedError('unknown source type')

        if len(adapted) == 0:
            # nothing adapted....possibly everything was private
            # TODO: if everything was private and that is really why we got
            # here then it is probably better to show a dialog with a message
            # and raise and exception which appears as an error
            raise Exception('No objects could be adapted to ABCD units.')
        abcd_data = create_abcd(adapted, authors=authors, validate=False)

        session.close()

        logger.debug(etree.dump(abcd_data.getroot()))

        # create xsl fo file
        dummy, fo_filename = tempfile.mkstemp()
        style_etree = etree.parse(stylesheet)
        transform = etree.XSLT(style_etree)
        result = transform(abcd_data)
        fo_outfile = open(fo_filename, 'w')
        fo_outfile.write(str(result))
        fo_outfile.close()
        dummy, filename = tempfile.mkstemp()
        filename = '%s.pdf' % filename

        # TODO: checkout pyexpect for spawning processes

        # run the report to produce the pdf file, the command has to be
        # on the path for this to work
        fo_cmd = fo_cmd % ({
            'fo_filename': fo_filename,
            'out_filename': filename
        })
        logger.debug(fo_cmd)
        # TODO: use popen to get output
        os.system(fo_cmd)

        logger.debug(filename)
        if not os.path.exists(filename):
            utils.message_dialog(
                _('Error creating the PDF file. Please '
                  'ensure that your PDF formatter is '
                  'properly installed.'), gtk.MESSAGE_ERROR)
            return False
        else:
            try:
                desktop.open(filename)
            except OSError:
                utils.message_dialog(
                    _('Could not open the report with the '
                      'default program. You can open the '
                      'file manually at %s') % filename)

        return True
Exemple #20
0
 def on_help_menu_bug(self, widget, data=None):
     desktop.open('https://github.com/Ghini/ghini.desktop/issues/new',
                  dialog_on_error=True)
Exemple #21
0
 def on_help_menu_bug(self, widget, data=None):
     desktop.open('https://github.com/Bauble/bauble.classic/issues/new',
                  dialog_on_error=True)
Exemple #22
0
 def on_help_menu_web_wiki(self, widget, data=None):
     desktop.open('http://github.com/Ghini/ghini.desktop/wiki',
                  dialog_on_error=True)
Exemple #23
0
 def on_help_menu_web_wiki(self, widget, data=None):
     desktop.open('http://github.com/Bauble/bauble.classic/wiki',
                  dialog_on_error=True)
Exemple #24
0
def _open_link(func, data=None):
    desktop.open(data)
Exemple #25
0
    def on_tnrs_browse_button_clicked(self, *args):
        from bauble.utils import desktop

        desktop.open("http://tnrs.iplantcollaborative.org/TNRSapp.html")
 def on_help_menu_web_devel(self, widget, data=None):
     desktop.open("http://github.com/Bauble/bauble.classic/", dialog_on_error=True)