Sublime Forum

`window.set_layout` does not send window command event 'set_layout'

#1

I am developer of tiny plugin https://github.com/alkuzad/CloseMinimapOnMultiView,

one of users complains about incompatibility with Origami plugin, which seems to use window.set_layout (documented only on unofficial doc http://docs.sublimetext.info/en/latest/reference/api.html?highlight=event#sublime.Window.set_layout) method. This method indeed does what it needs to - it sets layout.

But why it’s different from standard Window command call ?

window.run_command("set_layout", {"cols": [0, 0.5, 1],"rows": [0, 1],"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]}) will set layout and send event to plugins, debug:

>>> window.run_command("set_layout", {"cols": [0, 0.5, 1],"rows": [0, 1],"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]})
Window Command send <sublime.Window object at 0x0000028E4BD0A9B0> = set_layout - {'cells': [[0, 0, 1, 1], [1, 0, 2, 1]], 'cols': [0, 0.5, 1], 'rows': [0, 1]}

window.set_layout({"cols": [0, 0.5, 1],"rows": [0, 1],"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]}) will set layout but do not send event, as nothing happens:

>>> window.set_layout({'cells': [[0, 0, 1, 1]], 'cols': [0.0, 1.0], 'rows': [0.0, 1.0]})

Is this incosistency bug or some hidden feature ?

0 Likes

#2

What kind of ‘event’ do you mean? The EventListener class does not define something like a on_layout method.

Let me guess:

You use on_window_command() method to catch the “set_layout” command?

So you don’t catch a layout change event, but only the WindowCommand “set_layout” to be executed.

By calling window.run_command("set_layout", ...) a WindowCommand object is executed, which itself forwards the arguments to window.set_layout(). Guess the main intend of this command is to provide macro compatibility for the API itself.

No chance to detect the layout change events directly. You’d need to poll the active layout, which I found stupid.

0 Likes

#3

@deathaxe yep i use window listener for set_layout and set_group. St3 GUI buttons, panel actions and shortcuts sends events so I could rely on this.

Thanks for hint but polling is bad workaround as plugin is intended to catch event very rarely.

Its funny that api action do not trigger other events like window modified.

I will wait a bit if devs respond to this and eventually add bug to issue tracker.

0 Likes

#4

as its an undocumented API, it may be better to file an issue for the Origami plugin to ask them to use the set_layout command instead of the method

3 Likes

#5

Even though it might be undocumented, set_layout() is an ordinary part of the sublime.Window class and can therefore be considered for public use.

1 Like

#6

I’ve created bug report on github.com for this: https://github.com/SublimeTextIssues/Core/issues/2144

0 Likes