First time here? Check out the FAQ!
0

Probably old wingapi

Hi, I have a script that I've used in the past with older versions of WingIDE. It evaluates in the debug probe the commented selection. I don't really remember where I got the script from but it doesn't work in WingIDE ver 10.

I wonder if someone who knows about scripts for wingIDE can tell me how to update it so it can work in wingide 10. This is the script:

from __future__ import with_statement

import os.path, sys
sys.path += [
    os.path.dirname(__file__), 
    os.path.join(os.path.dirname(__file__), 'third_party.zip'), 
]

import wingapi

def comment_evaluate_sel_in_debug_probe(editor=wingapi.kArgEditor):
    '''
    Evaluate a commented selection in debug probe, do `select-more` if no selection.
    Suggested key combination: `Ctrl-Alt-D`
    '''

    assert isinstance(editor, wingapi.CAPIEditor)
    wingapi.gApplication.ExecuteCommand('comment-toggle')    
    wingapi.gApplication.ExecuteCommand('evaluate-sel-in-debug-probe')
    editor.ExecuteCommand('undo')

When the script load an error message appears with:

Runtime failure details:
Exception: "<class 'AttributeError'>"
Value = "module 'wingapi' has no attribute 'kArgEditor'"
martinako's avatar
80
martinako
asked 2024-08-14 02:15:26 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

1

The following should be an equivalent script --

from __future__ import with_statement

import os.path, sys
sys.path += [
    os.path.dirname(__file__), 
    os.path.join(os.path.dirname(__file__), 'third_party.zip'), 
]

import wingapi

def comment_evaluate_sel_in_debug_probe(editor=None):
    '''
    Evaluate a commented selection in debug probe, do `select-more` if no selection.
    Suggested key combination: `Ctrl-Alt-D`
    '''

    if editor is None:
        editor = wingapi.gApplication.GetActiveEditor()

    assert isinstance(editor, wingapi.CAPIEditor)
    wingapi.gApplication.ExecuteCommand('comment-toggle')    
    wingapi.gApplication.ExecuteCommand('evaluate-sel-in-debug-console')
    editor.ExecuteCommand('undo')

There are two changes:

  • The editor=wingapi.kArgEditor is replaced by editor=None followed by if editor is None: editor = wingapi.gApplication.GetActiveEditor()

  • The 'evaluate-sel-in-debug-probe' command name is replaced by 'evaluate-sel-in-debug-console'

Wingware Support's avatar
4.1k
Wingware Support
answered 2024-08-15 11:50:05 -0500
edit flag offensive 0 remove flag delete link

Comments

That works! thank you very much!

martinako's avatar martinako (2024-08-15 12:04:00 -0500) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer