Beispiel #1
0
    def _open_via_finder_button_fired(self):
        msg = '''CSV File Format
        # Create/select a file with a column header as the first line.
        # The following columns are required:
        #
        # runid, age, age_err
        #
        # Optional columns are:
        #
        # group, aliquot, sample
        #
        # e.x.
        # runid, age, age_error
        # Run1, 10, 0.24
        # Run2, 11, 0.32
        # Run3, 10, 0.40'''
        information(None, msg)

        dlg = FileDialog(default_directory=paths.csv_data_dir, action='open')
        path = ''
        if dlg.open() == OK:
            if dlg.path:
                path = dlg.path

        self.in_path = path
 def save_as(self):
     dlg = FileDialog(action='save as',
                      default_directory=paths.extraction_dir)
     if dlg.open() == OK:
         p = dlg.path
         if p:
             self._save(p)
Beispiel #3
0
    def make_gosub(self):
        selection = self.control.code.textCursor().selectedText()
        dlg = FileDialog(action='save as',
                         default_directory=os.path.dirname(self.path))

        p = None
        # root = os.path.dirname(self.path)
        # p = os.path.join(root, 'common', 'test_gosub.py')
        if dlg.open():
            p = dlg.path

        if p:
            p = add_extension(p, '.py')
            # p='/Users/ross/Desktop/foosub.py'
            with open(p, 'w') as wfile:
                wfile.write('# Extracted Gosub\n')
                wfile.write('# Source: from {}\n'.format(self.path))
                wfile.write('# Date: {}\n'.format(datetime.now().strftime('%m-%d-%Y %H:%M')))
                wfile.write('def main():\n')
                for li in selection.split(u'\u2029'):
                    wfile.write(u'    {}\n'.format(li.lstrip()))

            p = remove_extension(p)
            rp = os.path.relpath(p, self.path)
            rp = rp.replace('/', ':')
            self.control.code.replace_selection("gosub('{}')".format(rp[3:]))
Beispiel #4
0
    def _upload_image_button_fired(self):
        step, msm = self._pre_image()

        # host = self.application.preferences.get('pychron.entry.sample_prep.host')
        # username = self.application.preferences.get('pychron.entry.sample_prep.username')
        # password = self.application.preferences.get('pychron.entry.sample_prep.password')

        # ssh = paramiko.SSHClient()
        # ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # try:
        #     ssh.connect(host, username=username, password=password, timeout=2)
        # except (socket.timeout, paramiko.AuthenticationException):
        #     self.warning_dialog('Could not connect to Image Server')
        #     return
        #
        # client = ssh.open_sftp()

        sessionname = self.session.replace(' ', '_')
        dlg = FileDialog(action='open files')
        if dlg.open() == OK:
            if not dlg.paths:
                return

            # root = self.application.preferences.get('pychron.entry.sample_prep.root')
            dvc = self.dvc
            for p in dlg.paths:
                pp = '{}/{}'.format(sessionname, os.path.basename(p))
                self.debug('putting {} {}'.format(p, pp))
                url = msm.put(p, pp)
                # client.put(p, pp)
                dvc.add_sample_prep_image(step.id, msm.get_host(), url)
Beispiel #5
0
    def _open_button_fired(self):
        self.data_selectors = []
        #        p = '/Users/ross/Sandbox/csvdata.txt'
        #        self._path = p
        #        self._path=os.path.join(paths.data_dir,'spectrometer_scans','scan007.txt')
        dlg = FileDialog(action='open', default_directory=paths.data_dir)
        if dlg.open() == OK:
            self._path = dlg.path

        with open(self._path, 'U') as rfile:


            reader = csv.reader(rfile, delimiter=self.delimiter)
            self.column_names = names = reader.next()
            try:
                cs = DataSelector(column_names=names,
                                  index=names[0],
                                  value=names[1],
                                  removable=False,
                                  parent=self,
                )
                self.data_selectors.append(cs)
            except IndexError:

                self.warning_dialog('Invalid delimiter {} for {}'.format(DELIMITERS[self.delimiter],
                                                                         os.path.basename(self._path)
                ))
Beispiel #6
0
    def _open_fired(self):
        dlg = FileDialog(action='open')
        if dlg.open() == OK:
            with open(dlg.path, 'rb') as fp:
                self.viewer.set_image(fp)
                self.hierarchy.files.append(os.path.basename(dlg.path))

            self.client.cache(dlg.path)
Beispiel #7
0
    def _get_save_path(self, path, ext='.pdf'):
        if path is None:
            dlg = FileDialog(action='save as', default_directory=paths.processed_dir)
            if dlg.open():
                if dlg.path:
                    path = add_extension(dlg.path, ext)

        return path
Beispiel #8
0
 def get_path():
     return '/Users/ross/Sandbox/exporttest2.db'
     dlg = FileDialog(action='open',
                      default_directory=paths.data_dir,
                      wildcard='*.db')
     if dlg.open():
         if dlg.path:
             return dlg.path
Beispiel #9
0
def get_file_path(root, action='open'):
    dlg = FileDialog(action=action,
                     wildcard=FileDialog.create_wildcard(
                         'YAML', '*.yaml *.yml'),
                     default_directory=root)
    if dlg.open():
        if dlg.path:
            return add_extension(dlg.path, ext=('.yaml', '.yml'))
 def open_file(self, p=''):
     if not os.path.isfile(p):
         dlg = FileDialog(action='open', default_directory=paths.extraction_dir)
         if dlg.open() == OK and dlg.path:
             p = dlg.path
     if p:
         self._open_file(p)
         return True
Beispiel #11
0
 def open_csv(self, info):
     if config.DEBUG:
         self.model.load_file(config.DEBUG_PATH)
     else:
         dlg = FileDialog(action='open',
                          default_directory=config.default_data_dir)
         if dlg.open() == 'OK':
             if os.path.isfile(dlg.path):
                 self.model.load_file(dlg.path)
Beispiel #12
0
 def save_as(self):
     if self._validate_sequence():
         dialog = FileDialog(action='save as',
                             default_directory=paths.hops_dir)
         if dialog.open() == OK:
             p = dialog.path
             p = add_extension(p, '.txt')
             self._save_file(p)
             self.path = p
Beispiel #13
0
 def _add_tray_button_fired(self):
     dlg = FileDialog(action='open', default_directory=paths.irradiation_tray_maps_dir)
     if dlg.open() == OK:
         if dlg.path:
             # verify this is a valid irradiation map file
             if parse_irradiation_tray_map(dlg.path) is not None:
                 db = self.db
                 load_irradiation_map(db, dlg.path,
                                      os.path.basename(dlg.path), overwrite_geometry=True)
Beispiel #14
0
 def _add_favorite_path_fired(self):
     dlg = FileDialog(action='open')
     if dlg.open() == OK:
         if dlg.path:
             self._fav_items.append(
                 self._fav_factory(kind='sqlite',
                                   path=dlg.path,
                                   enabled=True))
             self._set_favorites()
Beispiel #15
0
 def perform(self, event):
     dvc = event.task.application.get_service(DVC_PROTOCOL)
     if dvc is not None:
         dialog = FileDialog(action='open',
                             default_directory=os.path.join(
                                 os.path.expanduser('~'), 'Desktop'))
         if dialog.open() == OK:
             if dialog.path:
                 dvc.meta_repo.add_irradiation_geometry_file(dialog.path)
Beispiel #16
0
 def _save_fired(self):
     dlg = FileDialog(default_directory=paths.root_dir, action='save as')
     if dlg.open() == OK:
         self.info('saving results to {}'.format(dlg.path))
         with open(dlg.path, 'w') as f:
             f.write('name = {} id = {}\n'.format(self.axis.name,
                                                  self.axis.id))
             for r in self.results:
                 f.write(r.tostring())
Beispiel #17
0
 def load_experiment(self, info):
     """Loads the experiment."""
     self.logger.info("Load a experiment [SMRCHandler]")
     fdlg = FileDialog(wildcard="*{0}".format(experiment_ext),
                       title="Choose experiment")
     if fdlg.open() == OK:
         suc = info.object.model.load_experiment(fdlg.path)
         if not suc:
             self.application_dialogs.open_state(suc)
Beispiel #18
0
    def configure(self, pre_run=False, **kw):
        if not pre_run:
            self._manual_configured = True

        if not self.path or not os.path.isfile(self.path):
            dlg = FileDialog()
            if dlg.open() == OK:
                self.path = dlg.path

        return self.path is not None
Beispiel #19
0
 def save_file_dialog(self, ext=None, **kw):
     if 'default_directory' not in kw:
         kw['default_directory'] = self.default_directory
     dialog = FileDialog(parent=self.window.control, action='save as', **kw)
     if dialog.open() == OK:
         path = dialog.path
         if path:
             if ext is None:
                 ext = self._default_extension
             return add_extension(path, ext=ext)
Beispiel #20
0
    def _save_as_button_fired(self):
        dlg = FileDialog(action='save as',
                         default_directory=paths.incremental_heat_template_dir)
        if dlg.open() == OK:
            path = dlg.path
            if not path.endswith('.txt'):
                path = '{}.txt'.format(path)

            self.dump(path)
            self.path = path
            self.close_ui()
Beispiel #21
0
    def _save_button_fired(self):
        from pyface.file_dialog import FileDialog
        dialog = FileDialog(action='save as',
                            default_directory=os.path.join(
                                os.path.expanduser('~')))

        from pyface.constant import OK
        if dialog.open() == OK:
            path = dialog.path
            if path:
                self.selected_image.save(add_extension(path, '.jpg'))
    def _save_button_fired(self):
        dlg = FileDialog(action='save as')
        if dlg.open() == OK:
            path = dlg.path
            if self.save_mode == 'orig':
                p = self.oplot
            elif self.save_mode == 'thresh':
                p = self.plot
            else:
                p = self.container

            self.render_pdf(p, path)
Beispiel #23
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)
Beispiel #24
0
    def _get_path(self):
        p = self.model.path
        if not p:
            p = '/Users/ross/Sandbox/actions.yafml'

        if not os.path.isfile(p):
            p = None
            dlg = FileDialog(action='save as', default_directory=paths.conditionals_dir)
            if dlg.open():
                p = dlg.path.strip()
                if p:
                    p = add_extension(p, '.yaml')

        return p
Beispiel #25
0
    def do_save(self):
        dlg = FileDialog(action='save as')
        if dlg.open() == OK:
            path = dlg.path

        if not path.endswith('.pdf'):
            path += '.pdf'

        gc = PdfPlotGraphicsContext(filename=path)
        pc = self.highlighter.container

        gc.render_component(pc, valign='center')
        gc.save()

        return gc
Beispiel #26
0
    def perform(self, event):
        path = self.path
        if path is None:
            dlg = FileDialog(action='open',
                             wildcard='*.log;*.json|log|*.json',
                             default_directory=paths.log_dir)
            if dlg.open() == OK:
                path = dlg.path

        if path:
            klass = TwistedLogModel if path.endswith('.json') else LogModel
            lm = klass()
            lm.open_file(path)
            lv = LogViewer(model=lm)
            open_view(lv)
Beispiel #27
0
    def _save_zip_button_fired(self):
        from pyface.file_dialog import FileDialog
        dialog = FileDialog(action='save as',
                            default_directory=os.path.join(
                                os.path.expanduser('~')))

        from pyface.constant import OK
        if dialog.open() == OK:
            path = dialog.path
            if path:
                with ZipFile(add_extension(path, '.zip'), 'w') as zipf:
                    for p in self.image_names:
                        buf = self._get_image_buf(p)
                        if buf:
                            zipf.writestr(p, buf.getvalue())
Beispiel #28
0
 def copy_files(self, fnames, dst_path, fname):
     fdlg = FileDialog(wildcard="*.csv*", title="Select {0}".format(fnames),
                       action='open files')
     if fdlg.open() == OK:
         files = sorted(fdlg.paths)
         progress = ProcessDialog(title="Copy file", max_n=len(files))
         for i in range(1, len(files)):
             f = files[i]
             progress.update(i, msg="Copy file: {0}".format(basename(f)))
             dst_file = fname.format(convert_number(i))
             dst = join(dst_path, dst_file)
             copy(f, dst)
         progress.close()
         return True
     return False
Beispiel #29
0
    def open(self, p=None):
        if p is None:
            p = '/Users/ross/Pychrondata_dev/scripts/measurement/hops/hop.txt'

        if not os.path.isfile(p):
            p = ''
            dialog = FileDialog(action='open',
                                default_directory=paths.hops_dir)
            if dialog.open() == OK:
                p = dialog.path

        if os.path.isfile(p):
            self.path = p
            # self.saveable = True
            # self.saveasable = True
            self._load(p)
Beispiel #30
0
    def open_file_dialog(self, action=None, **kw):
        if 'default_directory' not in kw:
            kw['default_directory'] = self.default_directory

        if 'wildcard' not in kw:
            if self.wildcard:
                kw['wildcard'] = self.wildcard

        if action is None:
            action = self.default_open_action

        dialog = FileDialog(action=action, **kw)
        if dialog.open() == OK:
            r = dialog.path
            if action == 'open files':
                r = dialog.paths
            return r