Examples of PyEdit


Examples of org.python.pydev.editor.PyEdit

* Selects the matching bracket for the current bracket.
*/
public class PyGoToMatchingBracket extends PyAction {

    public void run(IAction action) {
        PyEdit pyEdit = getPyEdit();
        PySelection ps = new PySelection(pyEdit);
        if (ps.getSelLength() != 0) {
            return;
        }
        try {
            IDocument doc = ps.getDoc();
            char c = doc.getChar(ps.getAbsoluteCursorOffset() - 1);
            boolean opening = StringUtils.isOpeningPeer(c);
            boolean closing = StringUtils.isClosingPeer(c);

            if (opening || closing) {
                PythonPairMatcher matcher = new PythonPairMatcher();
                IRegion match = matcher.match(doc, ps.getAbsoluteCursorOffset());
                if (match != null) {
                    if (closing) {
                        pyEdit.setSelection(match.getOffset() + 1, 0);
                    } else {//opening
                        pyEdit.setSelection(match.getOffset() + match.getLength(), 0);
                    }
                }
            }
        } catch (BadLocationException e) {
            return;
View Full Code Here

Examples of org.python.pydev.editor.PyEdit

    PythonNature nature = PythonNature.getPythonNature(project);
    PySelection selection = new PySelection(
        doc, new TextSelection(doc, offset, length));

    // needed for findAllOccurrences
    PyEdit pyEdit = new PyEdit(){
      public File getEditorFile() {
        return file;
      }
    };
    RefactoringRequest request = new RefactoringRequest(
View Full Code Here

Examples of org.python.pydev.editor.PyEdit

      @Override
      public void partActivated(IWorkbenchPart part) {
        LiveCodingAnalyst newAnalyst = null;
        if (part instanceof PyEdit)
        {
          PyEdit editor = (PyEdit)part;
          newAnalyst = PyEditDecorator.getAnalyst(editor);
        }
        setAnalyst(newAnalyst);
        if (newAnalyst != null) {
          newAnalyst.refresh();
View Full Code Here

Examples of org.python.pydev.editor.PyEdit

  private Process launchProcess(Rectangle bounds) throws IOException {
    checkScriptPath();
    if(mainViewer == null){
      return null;
    }
    PyEdit pyEdit = ((PySourceViewer)mainViewer).getEdit();
    IPythonNature nature;
    try {
      nature = pyEdit.getPythonNature();
      if (nature == null)
      {
        return null;
      }
    } catch (MisconfigurationException e) {
      Log.log(e);
      return null;
    }
    AbstractRunner runner = UniversalRunner.getRunner(nature);
    ArrayList<String> argumentList = new ArrayList<String>();
    if (bounds != null) {
      argumentList.add("-c");
      argumentList.add("-x");
      argumentList.add(Integer.toString(bounds.width));
      argumentList.add("-y");
      argumentList.add(Integer.toString(bounds.height));
    }
    String[] arguments =
        (String[])argumentList.toArray(new String[argumentList.size()]);
    File editorFile = pyEdit.getEditorFile();
    Tuple<Process, String> tuple = runner.createProcess(
        FileUtils.getFileAbsolutePath(scriptPath),
        arguments,
        editorFile.getParentFile(),
        null);
View Full Code Here

Examples of org.python.pydev.editor.PyEdit

  public void onEditorCreated(BaseEditor edit) {
    final LiveCodingAnalyst analyst = new LiveCodingAnalyst();
    analyst.setVisibility(isVisible);
    analystMap.put(edit, analyst);
   
    PyEdit pyEdit = (PyEdit) edit;
   
    pyEdit.onCreatePartControl.registerListener(
        new ICallbackListener<Composite>() {
      public Object call(Composite parent) {
        return analyst.createPartControl(parent);
View Full Code Here

Examples of org.python.pydev.editor.PyEdit

        ITextEditor textEditor = (ITextEditor) getAdapter(ITextEditor.class);
        if (region == null || !(textEditor instanceof PyEdit)) {
            return null;
        }

        PyEdit editor = (PyEdit) textEditor;

        int offset = region.getOffset();

        try {
            IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());

            //see if we can find a word there
            IRegion wordRegion = PythonWordFinder.findWord(document, offset);
            if (wordRegion == null) {
                return null;
            }

            //don't highlight keywords
            try {
                IDocument doc = editor.getDocument();
                String selectedWord = doc.get(wordRegion.getOffset(), wordRegion.getLength());
                if (PythonLanguageUtils.isKeyword(selectedWord)) {
                    return null;
                }
            } catch (BadLocationException e) {
View Full Code Here

Examples of org.python.pydev.editor.PyEdit

        String mod1Contents;
        TddCodeGenerationQuickFixParticipant quickFix;
        PySelection ps;
        IFile mod2 = initFile.getParent().getFile(new Path("other_module2.py"));
        mod2.create(new ByteArrayInputStream("".getBytes()), true, null);
        PyEdit editor2 = (PyEdit) PyOpenEditor.doOpenEditor(mod2);
        try {
            goToManual(AnalysisRequestsTestWorkbench.TIME_FOR_ANALYSIS); //give it a bit more time...
            mod1Contents = "" +
                    "import other_module2\n" +
                    "other_module2.Foo(a, b)";
            setContentsAndWaitReparseAndError(mod1Contents);

            quickFix = new TddCodeGenerationQuickFixParticipant();
            int offset = mod1Contents.length() - "o(a, b)".length();
            ps = new PySelection(editor.getDocument(), offset);
            assertTrue(quickFix.isValid(ps, "", editor, offset));
            waitForQuickFixProps(quickFix, ps, offset, "Create Foo method at other_module2.py").apply(
                    editor.getISourceViewer(), '\n', 0, offset);
            assertContentsEqual("" +
                    "def Foo(a, b):\n" +
                    "    pass\n" +
                    "\n" +
                    "\n" +
                    "", editor2.getDocument().get());

        } finally {
            editor2.close(false);
            mod2.delete(true, null);
        }
    }
View Full Code Here

Examples of org.python.pydev.editor.PyEdit

        String str = "" +
                "class Bar(object):\n" +
                "    pass\n" +
                "";
        mod2.create(new ByteArrayInputStream(str.getBytes()), true, null);
        PyEdit editor2 = (PyEdit) PyOpenEditor.doOpenEditor(mod2);
        try {
            goToManual(AnalysisRequestsTestWorkbench.TIME_FOR_ANALYSIS); //give it a bit more time...
            mod1Contents = "" +
                    "import other_module3\n" +
                    "other_module3.Bar.Foo(10, 20)";
            setContentsAndWaitReparseAndError(mod1Contents);

            quickFix = new TddCodeGenerationQuickFixParticipant();
            int offset = mod1Contents.length() - "o(a, b)".length();
            ps = new PySelection(editor.getDocument(), offset);
            assertTrue(quickFix.isValid(ps, "", editor, offset));
            waitForQuickFixProps(quickFix, ps, offset, "Create Foo classmethod at Bar in other_module3.py").apply(
                    editor.getISourceViewer(), '\n', 0, offset);
            assertContentsEqual("" +
                    "class Bar(object):\n" +
                    "    \n" +
                    "    \n" +
                    "    @classmethod\n"
                    +
                    "    def Foo(cls, param1, param2):\n" +
                    "        pass\n" +
                    "    \n" +
                    "    \n" +
                    "\n" +
                    "",
                    editor2.getDocument().get());

        } finally {
            editor2.close(false);
            mod2.delete(true, null);
        }
    }
View Full Code Here

Examples of org.python.pydev.editor.PyEdit

        TddCodeGenerationQuickFixParticipant quickFix;
        PySelection ps;
        IFile mod2 = initFile.getParent().getFile(new Path("other_module4.py"));
        String str = "";
        mod2.create(new ByteArrayInputStream(str.getBytes()), true, null);
        PyEdit editor2 = (PyEdit) PyOpenEditor.doOpenEditor(mod2);
        try {
            goToManual(AnalysisRequestsTestWorkbench.TIME_FOR_ANALYSIS); //give it a bit more time...
            mod1Contents = "" +
                    "from pack1.pack2.other_module4 import Foo";
            setContentsAndWaitReparseAndError(mod1Contents);

            quickFix = new TddCodeGenerationQuickFixParticipant();
            int offset = mod1Contents.length();
            ps = new PySelection(editor.getDocument(), offset);
            assertTrue(quickFix.isValid(ps, "", editor, offset));
            waitForQuickFixProps(quickFix, ps, offset, "Create Foo class at other_module4.py").apply(
                    editor.getISourceViewer(), '\n', 0, offset);
            assertContentsEqual("" +
                    "class Foo(object):\n" +
                    "    pass\n" +
                    "\n" +
                    "\n" +
                    "", editor2.getDocument()
                    .get());

        } finally {
            editor2.close(false);
            mod2.delete(true, null);
        }
    }
View Full Code Here

Examples of org.python.pydev.editor.PyEdit

            findCompletion(props, "Create newpack.module_new module").apply(editor.getISourceViewer(), '\n', 0, offset);
            assertTrue(mod2.exists());

            assertEquals(1, pyEditCreated.size());

            PyEdit editCreated = pyEditCreated.get(0);

            //Create class at module
            mod1Contents = "" +
                    "from newpack import module_new\n" +
                    "module_new.NewClass";
            setContentsAndWaitReparseAndError(mod1Contents);

            quickFix = new TddCodeGenerationQuickFixParticipant();
            offset = mod1Contents.length();
            ps = new PySelection(editor.getDocument(), offset);
            assertTrue(quickFix.isValid(ps, "", editor, offset));
            props = waitForQuickFixProps(quickFix, ps, offset);
            findCompletion(props, "Create NewClass class at module_new.py").apply(editor.getISourceViewer(), '\n', 0,
                    offset);

            String contents = editCreated.getDocument().get();
            assertContentsEqual("" +
                    "class NewClass(object):\n" +
                    "    pass\n" +
                    "\n" +
                    "\n" +
                    "", contents);
            editCreated.getSite().getPage().saveEditor(editCreated, false);

            //Create __init__ at class.
            mod1Contents = "" +
                    "'''\n" +
                    "'''\n" +
                    "" +
                    "def bar():\n" +
                    "    from newpack import module_new\n"
                    +
                    "    module_new.NewClass(param)"; //the 'undefined param' will be the error
            setContentsAndWaitReparseAndError(mod1Contents);

            quickFix = new TddCodeGenerationQuickFixParticipant();
            offset = mod1Contents.length();
            ps = new PySelection(editor.getDocument(), offset);
            assertTrue(quickFix.isValid(ps, "", editor, offset));
            props = waitForQuickFixProps(quickFix, ps, offset);
            findCompletion(props, "Create NewClass __init__ (newpack.module_new)").apply(editor.getISourceViewer(),
                    '\n', 0, offset);

            contents = editCreated.getDocument().get();
            assertContentsEqual("" +
                    "class NewClass(object):\n" +
                    "    \n" +
                    "    \n"
                    +
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.