Sublime Forum

How to Create and Size a Floating Window

#1

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)
0 Likes

#2

Windows, Linux or Mac?

0 Likes

#3

Windows 10 x64

It looks like Packages/Default/settings.py contains MOST of what I was looking for…

0 Likes

#4

I interpreted requirements as tiling and point to this handy tool to “tile” windows, where one window can contain the reference data perhaps in a local server … https://github.com/giuspen/x-tile … Multiple others here … https://www.reddit.com/r/software/comments/1jar8qa/can_anyone_please_recommend_a_floating_always_on/

0 Likes

#5

I need/want it to be WITHIN the Sublime Text application. It looks like Packages/Default/settings.py contains MOST of what I was looking for.

0 Likes

#6

Then use Origami plugin to split windows as my next suggestion

0 Likes

#7

I don’t think you’re understanding my need. I want to write a Package/Plugin that simply pops up an ASCII table in a floating window (like a tool palette). Origami just divides up window space. Not the same thing. FYI, there does appear to be a way to do this using a miniHTML sheet in a new window, turning off tabs and side bar and menu, all doable from within the Sublime API.

Unless I am missing something about Origami… I’ve just about got it done now.

0 Likes

#8

Markdown Popups - Sublime Markdown Popups Documentation

0 Likes

#9

Nice, @klo.

0 Likes

#10

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

0 Likes