Thread: [Pydev-code] Re: Jython scripting
Brought to you by:
fabioz
From: Fabio Z. <fa...@gm...> - 2006-04-04 01:36:45
|
Hi Don, I'm forwarding it to the pydev-code list, as I think it might be useful to others... A general question about Jython scripting. > > Before 1.0.4 was released I had imagined that I might be able to write a > script that could receive a selection from the editor, reformat it and > return it to the editor to be pasted over the original selection. I was > thinking of doing some comment reformatting on demand. > > As far as I can tell the current scripting API does not support this > sort of thing. Is that right? Actually, you can do it, but you have to know a bit from the Eclipse API too... A 'simple' way of doing it would be requesting the editor document (something like editor.getDocument()) and play with it. It is an IDocument, and you can get whatever you want from it and change it as much as you like= . Also, maybe taking a look at PySelection ( http://cvs.sourceforge.net/viewcvs.py/pydev/org.python.pydev.core/src/org/p= ython/pydev/core/docutils/PySelection.java?rev=3D1.7&view=3Dmarkup ) might be worth it... It provides a nicer interface for getting info from a document/selection. You can instantiate it in jython with: from org.python.pydev.core.docutils import PySelection sel =3D PySelection(editor) Cheers, Fabio |
From: Don T. <nos...@gm...> - 2006-04-25 22:39:29
|
Fabio Zadrozny wrote: > Hi Don, > > I'm forwarding it to the pydev-code list, as I think it might be useful > to others... > > A general question about Jython scripting. > > Before 1.0.4 was released I had imagined that I might be able to write a > script that could receive a selection from the editor, reformat it and > return it to the editor to be pasted over the original selection. I > was > thinking of doing some comment reformatting on demand. > > As far as I can tell the current scripting API does not support this > sort of thing. Is that right? > > > Actually, you can do it, but you have to know a bit from the Eclipse API > too... A 'simple' way of doing it would be requesting the editor > document (something like editor.getDocument()) and play with it. It is > an IDocument, and you can get whatever you want from it and change it as > much as you like. > > Also, maybe taking a look at PySelection ( > http://cvs.sourceforge.net/viewcvs.py/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/PySelection.java?rev=1.7&view=markup > <http://cvs.sourceforge.net/viewcvs.py/pydev/org.python.pydev.core/src/org/python/pydev/core/docutils/PySelection.java?rev=1.7&view=markup>) > might be worth it... It provides a nicer interface for getting info from > a document/selection. > > You can instantiate it in jython with: > > from org.python.pydev.core.docutils import PySelection > sel = PySelection(editor) > Hi Fabio: As far as I can see there are no methods in PySelection that allow you to put text back into the editor, is this correct? I know that I can do what I want with an IDocument using the replace method, I just wondered if I am missing something in the PySelection. Thanks, Don. |
From: Fabio Z. <fa...@gm...> - 2006-04-25 23:19:41
|
Actually there is 1 method that does it (but it's the single one, so, you may want to use one of IDocument if it's not what you want): public void addLine(String contents, int afterLine) Cheers, Fabio On 4/25/06, Don Taylor <nos...@gm...> wrote: > > Fabio Zadrozny wrote: > > Hi Don, > > > > I'm forwarding it to the pydev-code list, as I think it might be useful > > to others... > > > > A general question about Jython scripting. > > > > Before 1.0.4 was released I had imagined that I might be able to > write a > > script that could receive a selection from the editor, reformat it > and > > return it to the editor to be pasted over the original selection. = I > > was > > thinking of doing some comment reformatting on demand. > > > > As far as I can tell the current scripting API does not support thi= s > > sort of thing. Is that right? > > > > > > Actually, you can do it, but you have to know a bit from the Eclipse AP= I > > too... A 'simple' way of doing it would be requesting the editor > > document (something like editor.getDocument()) and play with it. It is > > an IDocument, and you can get whatever you want from it and change it a= s > > much as you like. > > > > Also, maybe taking a look at PySelection ( > > > http://cvs.sourceforge.net/viewcvs.py/pydev/org.python.pydev.core/src/org= /python/pydev/core/docutils/PySelection.java?rev=3D1.7&view=3Dmarkup > > < > http://cvs.sourceforge.net/viewcvs.py/pydev/org.python.pydev.core/src/org= /python/pydev/core/docutils/PySelection.java?rev=3D1.7&view=3Dmarkup > >) > > might be worth it... It provides a nicer interface for getting info fro= m > > a document/selection. > > > > You can instantiate it in jython with: > > > > from org.python.pydev.core.docutils import PySelection > > sel =3D PySelection(editor) > > > Hi Fabio: > > As far as I can see there are no methods in PySelection that allow you > to put text back into the editor, is this correct? > > I know that I can do what I want with an IDocument using the replace > method, I just wondered if I am missing something in the PySelection. > > Thanks, > > Don. > > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim= o > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642 > _______________________________________________ > pydev-code mailing list > pyd...@li... > https://lists.sourceforge.net/lists/listinfo/pydev-code > |
From: Don T. <nos...@gm...> - 2006-04-26 01:22:57
|
Fabio Zadrozny wrote: > Actually there is 1 method that does it (but it's the single one, so, > you may want to use one of IDocument if it's not what you want): > > public void addLine(String contents, int afterLine) Ah, ok. This does not do quite what I want. I want to replace the current selection with some new text. Right now I am using something like: selection = PySelection(editor) selected_text = selection.getSelectedText() offset = selection.getAbsoluteCursorOffset() length = selection.getSelLength() document = editor.getDocument() new_text = "Did this make it in?" + "\nNew line" document.replace(offset, length, new_text) Don. |
From: Fabio Z. <fa...@gm...> - 2006-04-26 11:00:47
|
Yeap, that's what I'd do too... Maybe I can do a 'replace selected text' method in pyselection... Also, I think that the scripting engine could start having some 'utilities' module that you can use, where this kind of stuff would go so that you coul= d share it among scripts (and maybe provide a more pythonic interface for man= y of the things Eclipse provides). What do you think? On 4/25/06, Don Taylor <nos...@gm...> wrote: > > Fabio Zadrozny wrote: > > Actually there is 1 method that does it (but it's the single one, so, > > you may want to use one of IDocument if it's not what you want): > > > > public void addLine(String contents, int afterLine) > > > Ah, ok. This does not do quite what I want. I want to replace the > current selection with some new text. Right now I am using something > like: > > selection =3D PySelection(editor) > selected_text =3D selection.getSelectedText() > offset =3D selection.getAbsoluteCursorOffset() > length =3D selection.getSelLength() > > document =3D editor.getDocument() > new_text =3D "Did this make it in?" + "\nNew line" > document.replace(offset, length, new_text) > > Don. > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim= o > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642 > _______________________________________________ > pydev-code mailing list > pyd...@li... > https://lists.sourceforge.net/lists/listinfo/pydev-code > |
From: Don T. <nos...@gm...> - 2006-04-26 13:04:53
|
Fabio Zadrozny wrote: > Yeap, that's what I'd do too... Maybe I can do a 'replace selected text' > method in pyselection... > > Also, I think that the scripting engine could start having some > 'utilities' module that you can use, where this kind of stuff would go > so that you could share it among scripts (and maybe provide a more > pythonic interface for many of the things Eclipse provides). What do you > think? > Yes, I think that would be good. I am wondering what to do about my own utility modules. I use a couple right now that I was thinking of incorporating into the source of my pyedit_ file or simply including as peer files with the pyedit_ file. Any thoughts on the right way to do this? Don. PS. I really wish that Jython had kept up with CPython. My coding style is 'Google and steal' and I keep tripping up on things that are in later versions of CPython but not in Jython. |
From: Fabio Z. <fa...@gm...> - 2006-04-26 13:09:18
|
> > > I am wondering what to do about my own utility modules. I use a couple > right now that I was thinking of incorporating into the source of my > pyedit_ file or simply including as peer files with the pyedit_ file. > Any thoughts on the right way to do this? I think that you could do a module (say: docutils.py -- or something descriptive on what it has if that's not all it contains), put your functions there and import that module from your scripts (the jysrc and the additional scripts path should be on your pythonpath). Don. > > PS. I really wish that Jython had kept up with CPython. My coding > style is 'Google and steal' and I keep tripping up on things that are in > later versions of CPython but not in Jython. Yeap, I wish that too... hopefully they'll turn a 2.2 version soon enough (= I keep track of the jython list, and it appears there is development going on= ) . Fabio |
From: Joel H. <yo...@if...> - 2006-04-27 12:55:11
Attachments:
pyedit_assign_params_to_attributes.py
|
Hi! Now I feel my script pyedit_assign_params_to_attributes.py is mature enou= gh to=20 come out of the alpha closet, so here ya go: The official v1.0.0. In this version I've incorporated a few of the guards and tricks recently= =20 discussed on this list, and I now no longer wait for Enter to activate af= ter=20 Ctrl-2+a. Otherwise there are no changes in functionality from the alpha1. Cheers guys! /Joel Hedlund Ph.D. Student, IFM Bioinformatics Link=F6ping University, Sweden |