First time here? Check out the FAQ!
1

capturing stdout from external command to Wing panel

I'm calling an external Python script (or any other Windows EXE) from my plugin extension using the ExecuteCommandLine API. It works but it only captures the stdout string to a variable. Is it possible to redirect stdout to a panel like for example Debug I/O instead of a variable ?

steve1964's avatar
114
steve1964
asked 2022-06-15 05:00:41 -0600
Wingware Support's avatar
4k
Wingware Support
updated 2022-06-15 08:59:57 -0600
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

0

I'm not able to use print to write stuff to the Messages > Plugins panel Still some questions: 1) how can I clear the Messages > Plugins panel before writing ? 2) how can I automatically select the "Plugins" option inside the Show Messages combobox ?

I'm already using app.ShowTool('messages', flash=True, grab_focus=True but it can not control the specific channel...

steve1964's avatar
114
steve1964
answered 2022-06-16 04:05:47 -0600
edit flag offensive 0 remove flag delete link

Comments

From context I'm assuming you meant "I'm now able to" and not "I'm not able to". Unfortunately there's no way to clear the Messages tool nor show a specific channel through the API. However, you could reach through the API like this: panel = app.fSingletons.fGuiMgr.ShowPanel('messages', flash=True, grab_focus=True) -- this gets the actual internal panel instance. Then you can switch channels with panel.ShowDomain('scripts') and clear with panel.fMessageText.Clear(). Clearing is a bit screwy, though, since the cleared text is restored if you switch channels again. However, that will only happen if panel.GetDomain() is not 'scripts' before you call panel.ShowDomain('scripts') so you can probably work around it. We'll try to improve this by adding API support for adding a panel w/ output or something like that.

Wingware Support's avatar Wingware Support (2022-06-16 07:57:09 -0600) edit

thanks, using your suggested direct access to the internal panel works fine in my scenario

steve1964's avatar steve1964 (2022-06-16 10:08:56 -0600) edit
add a comment see more comments
0

The simple way to see printed output from extension scripts in Wing is to look at the Scripts channel of the Messages tool, which is in the Tools menu. Or if it fits what you're doing then you can call CAPIApplication.ShowMessageDialog().

You can also add a tool to Wing with a script, but it's not trivial and not 100% supported by the API so you end up writing code that calls PyQt directly. There's a disabled example in scripts/pylintpanel.py in your Wing installation. If you copy that into the scripts directory below your Settings Directory (listed in Wing's About box) and remove or comment out _ignore_scripts = 1 and do Edit > Reload All Scripts you'll have PyLint appear in Wing's Tools menu and that's implemented by scripts/pylintpanel.py. From there you can edit and save and Wing will auto-reload and recreate any already-displayed panel. You'll want to replace the tool's contents with something that just lists the output and not the tabbed area it contains. There are details on scripting/extending Wing at https://wingware.com/doc/scripting/index

Please let me know if this does not help.

Wingware Support's avatar
4k
Wingware Support
answered 2022-06-15 08:59:49 -0600
edit flag offensive 0 remove flag delete link

Comments

I'm already using ShowMessageDialog() for simple messages, but it's not enough. How can I write text to the Scripts channel of the Messages tool from my extension scripts ? Using 'print' does not seem to write anything on that panel or anywhere else.

steve1964's avatar steve1964 (2022-06-15 10:35:33 -0600) edit

It works for me to have a script that just contains print("test from script") -- when I invoke that with Edit > Command by Name I see the output in the Messages tool. But note that you need to change the popup next to Show Messages at the top of the Messages tool to Scripts. The output from scripts is not shown under any of the other channels, not even All or General. Does this also not work for you?

Wingware Support's avatar Wingware Support (2022-06-15 10:44:10 -0600) 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