ActiveState Community

Python macro access to command output window

Posted by man_who_was_thursday on 2009-08-07 11:38

This seems like it should be simple, but I've searched and can't find the answer. I am running a Python macro that interacts with another proprietary IDE. I can build and capture the error output. Is there a way to send this output to the "Command Output" tab and have it parsed the way you can with a simple "Run" item in the toolbox?

I am new to Python, but I'm using it because it allowed access to the ActiveX control used to script the proprietary IDE.

Regards,
Dave

toddw | Fri, 2009-08-07 15:14

It is not easy for Python macros to access to the actual UI elements, but here is some code that should get you there:

from xpcom import components
wm = components.classes["@mozilla.org/appshell/window-mediator;1"].getService(components.interfaces.nsIWindowMediator)
win = wm.getMostRecentWindow("Komodo")
# Get the run output element in the UI.
elem = win.document.getElementById('runoutput-scintilla')
elem.QueryInterface(components.interfaces.koIScintillaView)
scimoz = elem.scimoz
scimoz.readOnly = False
scimoz.text = "Hello\nthere\n"
from xpcom import components
wm = components.classes["@mozilla.org/appshell/window-mediator;1"].getService(components.interfaces.nsIWindowMediator)
win = wm.getMostRecentWindow("Komodo")
# Get the run output element in the UI.
elem = win.document.getElementById('runoutput-scintilla')
elem.QueryInterface(components.interfaces.koIScintillaView)
scimoz = elem.scimoz
scimoz.readOnly = False
scimoz.text = "Hello\nthere\n"

Cheers,
Todd

man_who_was_thursday | Mon, 2009-08-10 07:29

Todd,

Thanks for the code. I had to change it slightly to make it run without errors. I added an import line, and changed the case. Unfortunately, the text is not being displayed.

Here's the code:

from xpcom import components
wm = components.classes["@mozilla.org/appshell/window-mediator;1"].getService(components.interfaces.nsIWindowMediator)
win = wm.getMostRecentWindow("Komodo")
# Get the run output element in the UI.
elem = win.document.getElementById('runoutput-scintilla')
elem.QueryInterface(components.interfaces.koIScintillaView)
scimoz = elem.scimoz
scimoz.text="Hello\nthere\n"
from xpcom import components 
wm = components.classes["@mozilla.org/appshell/window-mediator;1"].getService(components.interfaces.nsIWindowMediator)
win = wm.getMostRecentWindow("Komodo")
# Get the run output element in the UI.
elem = win.document.getElementById('runoutput-scintilla')
elem.QueryInterface(components.interfaces.koIScintillaView)
scimoz = elem.scimoz
scimoz.text="Hello\nthere\n"

Komodo Version: 5.1.4, build 3797
WinXP Pro

man_who_was_thursday | Fri, 2009-09-11 05:55

I still can't get this to work. Any other ideas?

Regards

toddw | Fri, 2009-09-11 10:28

The above code should work - note you'll need the "from xpcom import components" line as noted by Dave.

If it's not working for you, you might want to install the Komodo Developer Extension:
http://community.activestate.com/xpi/komodo-developer-extension

then use the "Tools->Extension Developer->PyShell" to launch an interactive Python window, paste in line by line and see where it's failing...

Cheers,
Todd

sridharr | Tue, 2009-09-22 22:44

Actually Todd's code works. I made it append to existing text instead of overwriting it:

from xpcom import components

def log(line):
    wm = components.classes["@mozilla.org/appshell/window-mediator;1"].getService(components.interfaces.nsIWindowMediator)
    win = wm.getMostRecentWindow("Komodo")
    # Get the run output element in the UI.
    elem = win.document.getElementById('runoutput-scintilla')
    elem.QueryInterface(components.interfaces.koIScintillaView)
    scimoz = elem.scimoz
    scimoz.text += line + '\n'

log('hello there?')

from xpcom import components

def log(line):
    wm = components.classes["@mozilla.org/appshell/window-mediator;1"].getService(components.interfaces.nsIWindowMediator)
    win = wm.getMostRecentWindow("Komodo")
    # Get the run output element in the UI.
    elem = win.document.getElementById('runoutput-scintilla')
    elem.QueryInterface(components.interfaces.koIScintillaView)
    scimoz = elem.scimoz
    scimoz.text += line + '\n'

log('hello there?')

man_who_was_thursday | Wed, 2009-09-23 06:18

I loaded the developer extension and ran the macro line by line in pyshell. When I type the line:

elem.QueryInterface(components.interfaces.koIScintillaView)

I get the following error message:

XPCOM component '' (implementing koIScintillaView, nsIDOM3Node, nsIDOMElement, nsIDOMElementCSSInlineStyle, nsIDOMEventTarget, nsIDOMNSElement, nsIDOMXULElement)

I can continue and append text to the scimoz text property. If I do a "print(scimoz.text)" the text is echoed to the python console, but the text does not appear in the Command tab.

Any ideas?

toddw | Wed, 2009-09-23 10:30

SciMoz may be in a read-only state, so try adding this before the set text call:

scimoz.readOnly = False
scimoz.readOnly = False

man_who_was_thursday | Wed, 2009-09-23 10:32

That did the trick! Thanks. I had tried this awhile back, but I think there was another error and I took the line out.