Sublime Forum

Why do I call 'show_panel' with 'output.exec', but need to call window.find_output_panel("exec") instead of window.find_output_panel("output.exec")?

#1

When you want to show the output panel, you call:

        window.run_command('show_panel', args={'panel': 'output.exec'})

But when you want to find the output panel view, you need to drop the output. from the panel name:

       window.focus_view( window.find_output_panel( "exec" ) )

This does not make sense. Isn’t the panel name "output.exec"? Why I am searching for "exec" only?

Does the API internally drop everything before the first dot in "output.exec" leaving only "exec"? What is happening with the "output." here?

Related:

0 Likes

#2

There are internal panels and then panels created by the API, also known as “output” panels.

To prevent a user panel name from conflicting with an internal panel name, the API prefixed the user’s output panel name with output.. Since the show_panel commands works on both internal and API (output) panels, you have to use the fully-qualified name.

You’ll notice the API methods that don’t require output. have output_panel in the method name.

3 Likes

#3

Not all panels are output panels. When using an operation that only pertains to output panels, you don’t have to specify output.. Operations that pertain to all panels require the full panel name.

If this bothers you, I suggest sublime_lib.OutputPanel to abstract it away:

from sublime_lib import OutputPanel
panel = OutputPanel.create(window, 'myPanel')

panel.name # 'myPanel'
panel.panel_name  # 'output.myPanel'
panel.is_visible() # panel.window.active_panel() == panel.panel_name
panel.exists() # panel.view.is_valid()
panel.show()
panel.hide()
panel.toggle_visibility()

panel.write('Hello, World!') # It's a TextIOBase

panel.destroy()

Or, for non-output panels:

from sublime_lib import Panel
panel = Panel('console')

panel.panel_name  # 'console'
panel.is_visible()
panel.exists() # panel.panel_name in panel.window.panels()
panel.show()
panel.hide()
panel.toggle_visibility()
4 Likes