def open(self, fnames=None): """Open files with the appropriate application""" if fnames is None: fnames = self.get_selected_filenames() for fname in fnames: if osp.isfile(fname) and encoding.is_text_file(fname): self.parent_widget.sig_open_file.emit(fname) else: self.open_outside_spyder([fname])
def is_python_interpreter(filename): """Evaluate wether a file is a python interpreter or not.""" real_filename = os.path.realpath(filename) # To follow symlink if existent if (not osp.isfile(real_filename) or encoding.is_text_file(real_filename) or not is_python_interpreter_valid_name(filename)): return False try: proc = run_program(filename, ["-h"]) output = to_text_string(proc.communicate()[0]) valid = ("Options and arguments (and corresponding environment " "variables)") if 'usage:' in output and valid in output: return True else: return False except: return False
def create_file_manage_actions(self, fnames): """Return file management actions""" only_files = all([osp.isfile(_fn) for _fn in fnames]) only_modules = all([ osp.splitext(_fn)[1] in ('.py', '.pyw', '.ipy') for _fn in fnames ]) only_notebooks = all( [osp.splitext(_fn)[1] == '.ipynb' for _fn in fnames]) only_exe = all([ os.path.isfile(_fn) and os.access(_fn, os.X_OK) for _fn in fnames ]) only_valid = all([encoding.is_text_file(_fn) for _fn in fnames]) run_action = create_action(self, _("Run"), icon=ima.icon('run'), triggered=self.run) exe_action = create_action(self, _("Execute"), icon=ima.icon('run'), triggered=self.exe) run_con_action = create_action(self, _("Run (console)"), icon=ima.icon('run'), triggered=self.run_con) edit_action = create_action(self, _("Edit"), icon=ima.icon('edit'), triggered=self.edit_file) move_action = create_action(self, _("Move..."), icon=QIcon(), triggered=self.move) delete_action = create_action(self, _("Delete..."), icon=ima.icon('editdelete'), triggered=self.delete) rename_action = create_action(self, _("Rename..."), icon=ima.icon('rename'), triggered=self.rename) open_action = create_action(self, _("Open"), triggered=self.open) ipynb_convert_action = create_action(self, _("Convert to Python script"), icon=ima.icon('python'), triggered=self.convert_notebooks) ipynb_open_action = create_action(self, _("Open notebook"), icon=ima.icon('python'), triggered=self.open_notebook) endpoint_action = create_action(self, _("Make endpoint"), triggered=self.make_endpoint) actions = [] if only_modules: actions.append(run_action) if only_valid and only_files: actions.append(edit_action) if only_modules: actions.extend([run_action, run_con_action]) if only_notebooks and nbexporter is not None: actions.extend([ipynb_open_action, ipynb_convert_action]) if only_notebooks and nbexporter is None: actions.extend([ipynb_open_action]) if only_modules or only_notebooks or only_exe: actions.extend([exe_action, endpoint_action]) sep = QAction(self) sep.setSeparator(True) actions.append(sep) actions += [delete_action, rename_action] basedir = fixpath(osp.dirname(fnames[0])) if all([fixpath(osp.dirname(_fn)) == basedir for _fn in fnames]): actions.append(move_action) sep = QAction(self) sep.setSeparator(True) actions.append(sep) return actions