When I select menu item Help > License and Attribution..., a new window pops up with what looks like a miniHTML Sheet, and it is sized appropriate to the content.
I would like to pop up a similar window with an HTML ASCII table in it, like a “tool palette” (i.e. you can leave it on the screen for reference while you’re coding in another window). I would also like to do something similar with current file information (path, size, modification timestamp, line endings on disk, whether it’s read-only or not).
The command for the License & Attribution window is "show_attribution" and I’ve searched all the code in the shipped packages for “ShowAttribution”, but have not found any clues about how to do this. The sublime.Window class is just a wrapper around the a real window, and instantiating one does not create a real window.
P.S.
I have learned from the EditSettingsCommand class in Packages/Default/settings.py:
sublime.run_command('new_window')
new_window = sublime.active_window()
and I’m almost there with:
sublime.run_command('new_window')
new_window = sublime.active_window()
print(f'{new_window = }')
new_window.set_tabs_visible(False)
new_window.set_menu_visible(False)
new_window.set_minimap_visible(False)
new_window.set_sidebar_visible(False, animate=False)
new_window.new_html_sheet('ASCII Table', content)
I’ve got the content showing, but now I need to size it so that it’s appropriate to the content, to a fixed size would be fine so that it is convenient to move to the side if necessary.
I’m on a Windows 10 x64 system and I didn’t see anything about width or height of windows in the Sublime API, so I have been trying to use ctypes.windll.user32.SetWindowPos using various approaches, e.g.
import ctypes
from ctypes.wintypes import HWND, UINT
from ctypes import WinDLL, c_int
user32 = WinDLL("user32", use_last_error=False)
SetWindowPos = user32.SetWindowPos
SetWindowPos.argtypes = [HWND, HWND, c_int, c_int, c_int, c_int, UINT]
SetWindowPos.restype = BOOL
hwnd = new_window.hwnd()
print(f'{hwnd=}')
result = SetWindowPos(hwnd, 0, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER)
but when I make the call, the sublime_text.exe process stops responding.
Does anyone know how to change the size of an ST window once it’s open?
Answer:
The ctypes.user32.SetWindowPos() was being dealt with incorrectly. I found a Python package that does it correctly and successfully (pygetwindow), so I am studying it to find out what I was doing wrong.
This code works:
import ctypes
from ctypes import c_int
from ctypes.wintypes import HWND, UINT, BOOL
SWP_NOMOVE = 0x0002
# Retains the current position (ignores X and Y parameters).
SWP_NOZORDER = 0x0004
# Retains the current Z order (ignores the hWndInsertAfter parameter).
SetWindowPos = ctypes.windll.user32.SetWindowPos
SetWindowPos.argtypes = [HWND, HWND, c_int, c_int, c_int, c_int, UINT]
SetWindowPos.restype = BOOL
flags = SWP_NOMOVE | SWP_NOZORDER # Ignore 2nd, 3rd and 4th args.
result = SetWindowPos(new_window.hwnd(), 0, 0, 0, width, height, flags)