コード例 #1
0
    def _save_xls_data_table(self, root, ias, step_heat_title, fusion_title, spectrometer,
                             summary_sheet=False,
                             auto_view=False):

        ext = '.xls'
        app = 'Microsoft Office 2011/Microsoft Excel'
        shgroups, fgroups = self._assemble_groups(ias)

        if shgroups:
            w = StepHeatTableXLSWriter()
            name = '{}_{}_step_heat_data'.format(self.name, spectrometer)
            p, _ = unique_path(root, name, extension=ext)

            iagroups, shgroups = zip(*shgroups)
            w.build(p, iagroups, shgroups, use_summary_sheet=summary_sheet,
                    title=step_heat_title)
            if auto_view:
                view_file(p, application=app)

        if fgroups:
            w = FusionTableXLSWriter()
            name = '{}_{}_fusion_data'.format(self.name, spectrometer)
            p, _ = unique_path(root, name, extension=ext)
            iagroups, fgroups = zip(*fgroups)
            w.build(p, iagroups, fgroups, use_summary_sheet=summary_sheet,
                    title=fusion_title)
            if auto_view:
                view_file(p, application=app)
コード例 #2
0
 def run(self, state):
     from pychron.pipeline.editors.interpreted_age_table_editor import InterpretedAgeTableEditor
     for editor in state.editors:
         if isinstance(editor, InterpretedAgeTableEditor):
             opt = self.options.model
             if opt.extension == 'xls':
                 editor.make_xls_table(opt)
                 view_file(opt.path)
コード例 #3
0
 def run(self, state):
     from pychron.pipeline.editors.interpreted_age_table_editor import InterpretedAgeTableEditor
     for editor in state.editors:
         if isinstance(editor, InterpretedAgeTableEditor):
             opt = self.options.model
             if opt.extension == 'xls':
                 editor.make_xls_table(opt)
                 view_file(opt.path)
コード例 #4
0
    def run(self, state):
        from pychron.pipeline.editors.arar_table_editor import ArArTableEditor

        for editor in state.editors:
            if isinstance(editor, ArArTableEditor):
                opt = self.options.model
                if opt.extension == 'xls':
                    editor.make_xls_table(opt)
                    view_file(opt.path)
コード例 #5
0
    def run(self, state):
        from pychron.pipeline.editors.arar_table_editor import ArArTableEditor

        for editor in state.editors:
            if isinstance(editor, ArArTableEditor):
                opt = self.options.model
                if opt.extension == 'xls':
                    editor.make_xls_table(opt)
                    view_file(opt.path)
コード例 #6
0
ファイル: xlsx_table_writer.py プロジェクト: NMGRL/pychron
    def build(self, groups, path=None, options=None):
        if options is None:
            options = XLSXAnalysisTableWriterOptions()

        self._options = options
        if path is None:
            path = options.path

        self.debug('saving table to {}'.format(path))
        r_mkdir(os.path.dirname(path))

        self._new_workbook(path)

        self._bold = self._workbook.add_format({'bold': True})
        self._superscript = self._workbook.add_format({'font_script': 1})
        self._subscript = self._workbook.add_format({'font_script': 2})
        self._ital = self._workbook.add_format({'italic': True})

        unknowns = groups.get('unknowns')
        if unknowns:
            # make a human optimized table
            unknowns = self._make_human_unknowns(unknowns)

            # make a machine optimized table
        munknowns = groups.get('machine_unknowns')
        if munknowns:
            self._make_machine_unknowns(munknowns)

        airs = groups.get('airs')
        if airs:
            self._make_airs(airs)

        blanks = groups.get('blanks')
        if blanks:
            self._make_blanks(blanks)

        monitors = groups.get('monitors')
        if monitors:
            self._make_monitors(monitors)

        # if not self._options.include_production_ratios:
        #     self._make_irradiations(unknowns)

        if self._options.include_summary_sheet:
            if unknowns:
                self._make_summary_sheet(unknowns)

        self._workbook.close()

        view = self._options.auto_view
        if not view:
            view = confirm(None, 'Table saved to {}\n\nView Table?'.format(path)) == YES

        if view:
            view_file(path, application='Excel')
コード例 #7
0
def save_pdf(component,
             path=None,
             default_directory=None,
             view=False,
             options=None):
    if default_directory is None:
        default_directory = os.path.join(os.path.expanduser('~'), 'Documents')

    ok = True
    if options is None:
        ok = False
        options = FigurePDFOptions()
        options.load()
        dlg = SavePDFDialog(model=options)
        info = dlg.edit_traits(kind='livemodal')
        # path = '/Users/ross/Documents/pdftest.pdf'
        if info.result:
            options.dump()
            ok = True
    if ok:
        if path is None:
            dlg = FileDialog(action='save as',
                             default_directory=default_directory)

            if dlg.open() == OK:
                path = dlg.path

        if path:

            path = add_extension(path, '.pdf')
            gc = PdfPlotGraphicsContext(filename=path,
                                        dest_box=options.dest_box,
                                        pagesize=options.page_size)
            # component.inset_border = False
            # component.padding = 0
            # component.border_visible = True
            # component.border_width = 2
            # component.fill_padding = True
            # component.bgcolor = 'green'
            obounds = component.bounds
            size = None
            if not obounds[0] and not obounds[1]:
                size = options.bounds

            if options.fit_to_page:
                size = options.bounds

            component.do_layout(size=size, force=True)
            gc.render_component(component, valign='center')
            gc.save()
            if view:
                view_file(path)
            component.do_layout(size=obounds, force=True)
コード例 #8
0
    def save_summary_table(self, root, auto_view=False):
        name = '{}_summary'.format(self.name)
        w = SummaryPDFTableWriter()
        items = self.interpreted_ages
        title = self.get_title()

        opt = self.pdf_table_options
        p, _ = unique_path(root, name, extension='.pdf')
        w.options = opt
        w.build(p, items, title)
        if auto_view:
            view_file(p)
コード例 #9
0
    def save_pdf(self):
        self.debug('save pdf')

        # p = LoadingPDFWriter()
        ln = self.load_name
        if ln:
            root = self.save_directory
            if not root or not os.path.isdir(root):
                root = paths.loading_dir

            ps = ', '.join({p.project for p in self.grouped_positions})

            un = self.username

            dt = datetime.now()
            date_str = dt.strftime("%Y-%m-%d %H:%M:%S")
            meta = dict(load_name=ln,
                        username=un,
                        load_date=date_str,
                        projects=ps)

            path = os.path.join(root, '{}.pdf'.format(ln))

            options = self._pdf_writer.options

            osl = self.show_identifiers
            osw = self.show_weights
            oshn = self.show_hole_numbers
            oss = self.show_samples

            for attr in ('identifiers', 'weights', 'hole_numbers', 'samples'):
                attr = 'show_{}'.format(attr)
                setattr(self, attr, getattr(options, attr))

            # c = self.canvas.clone_traits()
            self._pdf_writer.build(path, self.positions,
                                   self.grouped_positions, self.canvas, meta)
            if options.view_pdf:
                view_file(path)
            on = self.load_name
            self.canvas = None
            self.load_name = ''
            self.load_name = on

            self.show_identifiers = osl
            self.show_weights = osw
            self.show_hole_numbers = oshn
            self.show_samples = oss

        else:
            self.information_dialog('Please select a load')
コード例 #10
0
ファイル: loading_manager.py プロジェクト: NMGRL/pychron
    def save_pdf(self):
        self.debug('save pdf')

        # p = LoadingPDFWriter()
        ln = self.load_name
        if ln:
            root = self.save_directory
            if not root or not os.path.isdir(root):
                root = paths.loading_dir

            ps = ', '.join({p.project for p in self.grouped_positions})

            un = self.username

            dt = datetime.now()
            date_str = dt.strftime("%Y-%m-%d %H:%M:%S")
            meta = dict(load_name=ln, username=un,
                        load_date=date_str,
                        projects=ps)

            path = os.path.join(root, '{}.pdf'.format(ln))

            options = self._pdf_writer.options

            osl = self.show_identifiers
            osw = self.show_weights
            oshn = self.show_hole_numbers
            oss = self.show_samples

            for attr in ('identifiers', 'weights', 'hole_numbers', 'samples'):
                attr = 'show_{}'.format(attr)
                setattr(self, attr, getattr(options, attr))

            # c = self.canvas.clone_traits()
            self._pdf_writer.build(path, self.positions, self.grouped_positions, self.canvas, meta)
            if options.view_pdf:
                view_file(path)
            on = self.load_name
            self.canvas = None
            self.load_name = ''
            self.load_name = on

            self.show_identifiers = osl
            self.show_weights = osw
            self.show_hole_numbers = oshn
            self.show_samples = oss

        else:
            self.information_dialog('Please select a load')
コード例 #11
0
ファイル: persist.py プロジェクト: NMGRL/pychron
    def run(self, state):
        p = os.path.join(paths.csv_data_dir, add_extension(self.pathname, '.csv'))

        with open(p, 'w') as wfile:
            writer = csv.writer(wfile)
            for ans in (state.unknowns, state.references):
                if ans:
                    header = self._get_header()
                    writer.writerow(header)
                    for ai in ans:
                        row = self._get_row(header, ai)
                        writer.writerow(row)

            if confirmation_dialog('File saved to {}\n\nWould you like to open?'.format(p)):
                view_file(p, application='Excel')
コード例 #12
0
    def build(self,
              path=None,
              unknowns=None,
              airs=None,
              blanks=None,
              monitors=None,
              options=None):
        if options is None:
            options = XLSXTableWriterOptions()

        self._options = options
        if path is None:
            path = options.path
        self.debug('saving table to {}'.format(path))
        self._workbook = xlsxwriter.Workbook(add_extension(path, '.xlsx'),
                                             {'nan_inf_to_errors': True})
        self._bold = self._workbook.add_format({'bold': True})
        self._superscript = self._workbook.add_format({'font_script': 1})
        self._subscript = self._workbook.add_format({'font_script': 2})

        if unknowns:
            self._make_unknowns(unknowns)

        if airs:
            self._make_airs(airs)

        if blanks:
            self._make_blanks(blanks)

        if monitors:
            self._make_monitors(monitors)

        if not self._options.include_production_ratios:
            self._make_irradiations(unknowns)

        if self._options.include_summary_sheet:
            self._make_summary_sheet(unknowns)

        self._workbook.close()

        view = self._options.auto_view
        if not view:
            view = confirm(
                None, 'Table saved to {}\n\nView Table?'.format(path)) == YES

        if view:
            view_file(path, application='Excel')
コード例 #13
0
ファイル: save_pdf_dialog.py プロジェクト: NMGRL/pychron
def save_pdf(component, path=None, default_directory=None, view=False, options=None):
    if default_directory is None:
        default_directory = os.path.join(os.path.expanduser("~"), "Documents")

    ok = True
    if options is None:
        ok = False
        options = FigurePDFOptions()
        options.load()
        dlg = SavePDFDialog(model=options)
        info = dlg.edit_traits(kind="livemodal")
        # path = '/Users/ross/Documents/pdftest.pdf'
        if info.result:
            options.dump()
            ok = True
    if ok:
        if path is None:
            dlg = FileDialog(action="save as", default_directory=default_directory)

            if dlg.open() == OK:
                path = dlg.path

        if path:

            path = add_extension(path, ".pdf")
            gc = PdfPlotGraphicsContext(filename=path, dest_box=options.dest_box, pagesize=options.page_size)
            # component.inset_border = False
            # component.padding = 0
            # component.border_visible = True
            # component.border_width = 2
            # component.fill_padding = True
            # component.bgcolor = 'green'
            obounds = component.bounds
            size = None
            if not obounds[0] and not obounds[1]:
                size = options.bounds

            if options.fit_to_page:
                size = options.bounds

            component.do_layout(size=size, force=True)
            gc.render_component(component, valign="center")
            gc.save()
            if view:
                view_file(path)
            component.do_layout(size=obounds, force=True)
コード例 #14
0
    def make(self):
        root = os.path.join(paths.dissertation, 'data', 'minnabluff', 'irradiations')
        p = os.path.join(root, 'irradiations.yaml')
        with open(p, 'r') as fp:
            yd = yaml.load(fp)

        db = self.db
        irrads = []
        with db.session_ctx():
            for yi in yd:
                dbirrad = db.get_irradiation(yi)
                irrads.append(Irradiation(dbirrad))

        outpath = os.path.join(root, 'irradiations.pdf')
        p = PDFWriter()
        opt = p.options
        opt.orientation = 'portrait'
        p.build(outpath, irrads)
        view_file(outpath)
コード例 #15
0
    def perform(self, event):
        from pyface.file_dialog import FileDialog
        dialog = FileDialog(action='save as', default_filename='IrradiationTemplate.xls')

        from pyface.constant import OK
        if dialog.open() == OK:
            path = dialog.path
            if path:
                from pychron.core.helpers.filetools import add_extension
                path = add_extension(path, '.xls')

                from pychron.entry.loaders.irradiation_template import IrradiationTemplate
                i = IrradiationTemplate()
                i.make_template(path)

                from pyface.confirmation_dialog import confirm
                if confirm(None, 'Template saved to {}.\n\nWould you like to open the template?'):
                    from pychron.core.helpers.filetools import view_file
                    application = 'Microsoft Office 2011/Microsoft Excel'
                    view_file(path, application=application)
コード例 #16
0
    def make(self):
        root = os.path.join(paths.dissertation, 'data', 'minnabluff',
                            'irradiations')
        p = os.path.join(root, 'irradiations.yaml')
        with open(p, 'r') as rfile:
            yd = yaml.load(rfile)

        db = self.db
        irrads = []
        with db.session_ctx():
            for yi in yd:
                dbirrad = db.get_irradiation(yi)
                irrads.append(Irradiation(dbirrad))

        outpath = os.path.join(root, 'irradiations.pdf')
        p = PDFWriter()
        opt = p.options
        opt.orientation = 'portrait'
        p.build(outpath, irrads)
        view_file(outpath)
コード例 #17
0
    def _save_pdf_data_table(self, root, ias, step_heat_title, fusion_title, spectrometer, auto_view=False):

        shgroups, fgroups = self._assemble_groups(ias)
        ext = '.pdf'
        if shgroups:
            w = StepHeatPDFTableWriter()
            # name = '{}_{}_step_heatdata'.format(self.name, spectrometer)
            name = '{}stepheatdata'.format(spectrometer)
            p, _ = unique_path(root, name, extension=ext)

            iagroups, shgroups = zip(*shgroups)
            w.build(p, shgroups, title=step_heat_title)
            if auto_view:
                view_file(p)

        if fgroups:
            w = FusionPDFTableWriter()
            # name = '{}_{}_fusion_data'.format(self.name, spectrometer)
            name = '{}fusiondata'.format(spectrometer)
            p, _ = unique_path(root, name, extension=ext)
            iagroups, fgroups = zip(*fgroups)
            w.build(p, fgroups, title=fusion_title)
            if auto_view:
                view_file(p)
コード例 #18
0
ファイル: actions.py プロジェクト: stephen-e-cox/pychron
    def perform(self, event):
        from pyface.file_dialog import FileDialog
        dialog = FileDialog(action='save as',
                            default_filename='IrradiationTemplate.xls')

        from pyface.constant import OK
        if dialog.open() == OK:
            path = dialog.path
            if path:
                from pychron.core.helpers.filetools import add_extension
                path = add_extension(path, '.xls')

                from pychron.entry.loaders.irradiation_template import IrradiationTemplate
                i = IrradiationTemplate()
                i.make_template(path)

                from pyface.confirmation_dialog import confirm
                if confirm(
                        None,
                        'Template saved to {}.\n\nWould you like to open the template?'
                ):
                    from pychron.core.helpers.filetools import view_file
                    application = 'Microsoft Office 2011/Microsoft Excel'
                    view_file(path, application=application)
コード例 #19
0
def save_pdf(component,
             path=None,
             default_directory=None,
             view=False,
             options=None):
    if default_directory is None:
        default_directory = os.path.join(os.path.expanduser('~'), 'Documents')

    ok = True
    if options is None:
        ok = False
        options = FigurePDFOptions()
        options.load()
        dlg = SavePDFDialog(model=options)
        info = dlg.edit_traits(kind='livemodal')
        # path = '/Users/ross/Documents/pdftest.pdf'
        if info.result:
            options.dump()
            ok = True
    if ok:
        if path is None:
            dlg = FileDialog(action='save as',
                             default_directory=default_directory)

            if dlg.open() == OK:
                path = dlg.path

        if path:
            use_ps = False
            use_svg = False
            if use_ps:
                path = add_extension(path, '.ps')
                gc = PSGC(component.bounds)
                component.draw(gc)
                gc.save(path)
            elif use_svg:
                path = add_extension(path, '.svg')
                gc = SVGGraphicsContext(component.bounds)
                obackbuffer = component.use_backbuffer
                component.use_backbuffer = False
                gc.render_component(component)
                gc.save(path)
                component.use_backbuffer = obackbuffer

            else:
                path = add_extension(path, '.pdf')
                gc = myPdfPlotGraphicsContext(filename=path,
                                              dest_box=options.dest_box,
                                              pagesize=options.page_size)

                obounds = component.bounds
                # size = None
                if not obounds[0] and not obounds[1]:
                    size = options.bounds
                    component.do_layout(size=size, force=True)

                if options.fit_to_page:
                    size = options.bounds
                    component.do_layout(size=size, force=True)

                gc.render_component(component, valign='center')
                gc.save()
                if view:
                    view_file(path)

                if options.fit_to_page:
                    component.do_layout(size=obounds, force=True)
コード例 #20
0
    def build(self, groups, path=None, options=None):
        if options is None:
            options = XLSXAnalysisTableWriterOptions()

        self._options = options
        if path is None:
            path = options.path

        self.debug('saving table to {}'.format(path))
        r_mkdir(os.path.dirname(path))

        self._new_workbook(path)

        self._bold = self._workbook.add_format({'bold': True})
        self._superscript = self._workbook.add_format({'font_script': 1})
        self._subscript = self._workbook.add_format({'font_script': 2})
        self._bsuperscript = self._workbook.add_format({
            'font_script': 1,
            'bold': True
        })
        self._bsubscript = self._workbook.add_format({
            'font_script': 2,
            'bold': True
        })
        self._ital = self._workbook.add_format({'italic': True})

        unknowns = groups.get('unknowns')
        if unknowns:
            # make a human optimized table
            unknowns = self._make_human_unknowns(unknowns)

            # make a machine optimized table
        munknowns = groups.get('machine_unknowns')
        if munknowns:
            self._make_machine_unknowns(munknowns)

        airs = groups.get('airs')
        if airs:
            self._make_airs(airs)

        blanks = groups.get('blanks')
        if blanks:
            self._make_blanks(blanks)

        monitors = groups.get('monitors')
        if monitors:
            self._make_monitors(monitors)

        # if not self._options.include_production_ratios:
        #     self._make_irradiations(unknowns)

        if self._options.include_summary_sheet:
            if unknowns:
                self._make_summary_sheet(unknowns)

        self._workbook.close()

        view = self._options.auto_view
        if not view:
            view = confirm(
                None, 'Table saved to {}\n\nView Table?'.format(path)) == YES

        if view:
            view_file(path, application='Excel')
コード例 #21
0
ファイル: base_task.py プロジェクト: UManPychron/pychron
 def view_file(self, p, application='Preview'):
     view_file(p, application=application, logger=self)
コード例 #22
0
ファイル: base_task.py プロジェクト: ael-noblegas/pychron
 def view_file(self, p, application='Preview'):
     view_file(p, application=application, logger=self)