[wingide-users] Wing 2.0 plugin question
Adam Feuer
adamf at aviarc.com
Sat Dec 4 22:36:03 EST 2004
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