Example #1
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:]))
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 dlg.path
Example #3
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 fp:


            reader = csv.reader(fp, 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)
                ))
 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)
Example #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)
                ))
Example #6
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):
            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

e.x.
runid, age, age_error
SampleA, 10, 0.24
SampleB, 11, 0.32
SampleC, 10, 0.40'''
            information(None, msg)

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

        return bool(self.path)
Example #7
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)
Example #8
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
Example #9
0
 def _open_logfiles_fired(self):
   dlg = FileDialog()
   dlg.action = 'open files'
   if dlg.open() == OK:
       paths = dlg.paths
       for filePath in paths:
         self.log_files.append(filePath)
Example #10
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
Example #11
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'))
Example #12
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
Example #13
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)
Example #14
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
Example #15
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
Example #16
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)
 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
Example #18
0
 def _getFilePath(self, defFileName):
     dlg = FileDialog()
     dlg.action = 'save as'
     dlg.default_filename = defFileName
     if dlg.open() == OK:
         return dlg.path
     else:
         return None
Example #19
0
 def _open_esffiles_fired(self):
   dlg = FileDialog()
   dlg.wildcard = "*.esf"
   dlg.action = 'open files'
   if dlg.open() == OK:
       paths = dlg.paths
       for filePath in paths:
         self.esf_files.append(filePath)
Example #20
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)
Example #21
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()
Example #22
0
  def _exportCSV_changed(self):
    dlg = FileDialog()
    dlg.action = 'save as'
    dlg.default_filename = self.groupAddress.replace("/", "-") + '_' + self.name + '.csv'
    if dlg.open() != OK:
      return

    if self._exportCSV_hock != None:
      self._exportCSV_hock(self, dlg.path)
Example #23
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)
Example #24
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)
Example #25
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())
Example #26
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)
Example #27
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
Example #28
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)
Example #29
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)
Example #30
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
Example #31
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'))
Example #32
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)
Example #33
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())
Example #34
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
Example #35
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()
Example #36
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_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()
Example #38
0
    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)
Example #39
0
    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)
Example #40
0
    def _get_export_path(self):
        dlg = FileDialog(action='save as',
                         default_directory=paths.data_dir,
                         wildcard='CSV (*.csv, *.txt)|*.csv;*.txt'
                         )

        if dlg.open() == OK:
            p = dlg.path
            if not p.endswith('.csv'):
                if not p.endswith('.txt'):
                    p += '.csv'

            return p
Example #41
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())
Example #42
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
Example #43
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)
Example #44
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
Example #45
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)
Example #46
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
Example #47
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())
Example #48
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
Example #49
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)
Example #50
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
    def _save_as_button_fired(self):
        sims = self._check_similarity()
        if sims:
            if not self.confirmation_dialog('Similar templates already exist. {}\n '
                                            'Are you sure you want to save this template?'.format(','.join(sims))):
                return

        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()
    def _save_as_button_fired(self):
        sims = self._check_similarity()
        if sims:
            if not self.confirmation_dialog('Similar templates already exist. {}\n '
                                            'Are you sure you want to save this template?'.format(','.join(sims))):
                return

        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()
Example #53
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
Example #54
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