[wingide-users] Re: Wing 2.0 plugin question

Wing IDE Support support at wingware.com
Sat Dec 4 23:26:00 EST 2004


Hi,

The scripting API is largely broken in 2.0 because it was unmaintained
across changes in our internal code -- we'll hopefully fix that in 2.0.2
(2.0.1 is coming out soon but doesn't yet address these problems).

Here's another example script that contains work-around implementations to
bypass the API, and it includes the ability to get current editor
selection position and related things.  You can use this with 2.0 and
later replace the _* calls with calls to the fixed API:

ftp://wingware.com/pub/wingide/support/tmp/2.0-tidbits/editor-extensions.py

Or via http:

http://wingware.com/pub/wingide/support/tmp/2.0-tidbits/editor-extensions.py

Let me know if you need any other functionality or if you have requests
for additional API calls.

Once we get scripting working decently we'll be happy to redistribute
scripts people want to share with other users.  We've set up a contributed
software section in our downloads area (currently just used for
contributed builds of the product):

http://wingware.com/downloads/wingide/2.0.0/contrib

Thanks,

Stephan Deibel

--
Wingware
Wing IDE for Python
Advancing Software Development

www.wingware.com

On Sat, 4 Dec 2004, Adam Feuer wrote:

> Wingware folks,
>   Hi, I'm developing a Wing plugin for bicycle repairman. My platform
> is Mac OSX.
>   
>   I built a small plugin using the example.py script, and can access
> it from the keyboard.
> 
>   I am trying to get the current editor cursor or selection position.
> When I access wingapi.gApplication.GetActiveEditor(), I get an
> exception NameError: global name singletons is not defined.
> 
>   This appears to occur because of an error in the wingapi.py code-
> the GetActiveEditor() function should be using self.fSingletons
> instead of the global singletons.
>   I couldn't test this fix, since I am not set up to build Wing.
>   
>   I have a couple of questions. How can I work around this problem? Is
> there another way to get the cursor position and selection in the
> current file...?
> 
> 
> 
> Here's my test plugin script:
> 
> ......
> 
> import os
> import sys
> from wingutils import datatype
> from guiutils import formbuilder
> from guiutils import dialogs
> from scripting import wingapi
> from guimgr import messages
> 
> import gettext
> _ = gettext.translation('scripts_example', fallback = 1).gettext
> _i18n_module = 'scripts_example'
> 
> _AI = wingapi.CArgInfo
> 
> 
> def brm_rename( newname ):
>    cursorPos = None
>    selectionEndPos = None
>    message = ""
>    try:
>       wingApplication = wingapi.gApplication
>       activeEditor = wingApplication.GetActiveEditor()
>       if activeEditor is not None:
>          scintilla = activeEditor._fScint
>          cursorPos, selectionEndPos = scintilla.get_selection()
>    except:      
>       type, value = sys.exc_info()[:2]
>       message = "%s %s" % ( type, value ) 
>    buttons = ( dialogs.CButtonSpec( _( 'OK' ), None ), )
>    dlg = messages.CMessageDialog( wingapi.gApplication.fSingletons, _(
> "brm-rename" ), 
>                                _( "New name: %s [%s, %s] (%s)" ) % (
> newname, cursorPos, selectionEndPos, message ), [], buttons )
> 
> brm_rename.arginfo = {}
> brm_rename.arginfo[ 'newname' ] = _AI( _( "New name" ),
> datatype.CType( '' ), formbuilder.CSmallTextGui() )
> brm_rename.label = _( "brm-rename" )
> brm_rename.contexts = [wingapi.kContextScriptsMenu,]
> 
> ......
> 
> 
>   Here's a diff of my attempted fix for wingapi.py:
> 
> 
> $ diff wingapi.py wingapi.py.orig 
> 181c181
> <     return CAPIEditor(self.fSingletons, editor)
> ---
> >     return CAPIEditor(singletons, editor)
> 189c189
> <     return CAPIDocument(self.fSingletons, editor.fCache)
> ---
> >     return CAPIDocument(singletons, editor.fCache)
> 
> 
> cheers
> adam
> --
> Adam Feuer <adamf at aviarc dot com>
> 


More information about the wingide-users mailing list