spacr.qt.dialogs

Standardize movement and resizing of spaCR modal dialogs.

Some desktop window managers attach a parented modal QDialog to its main window. detach_from_window_manager() preserves ownership and modality while presenting it as an independently movable top-level window.

The resizing helpers remove explicit minimum sizes when appropriate, wrap content in a scroll area only when its layout prevents useful shrinking, add a visible size grip, and preserve the dialog’s natural opening size. Qt’s own specialized dialogs, simple message dialogs, and content that already scrolls are left unchanged. install_the_dialog_filters() applies these rules to new dialogs at application level.

Functions

content_floor(dialog)

Return the layout's minimum size for rendering without clipping.

detach_all_dialogs(→ bool)

Install the application-wide detacher. Returns True if it installed.

detach_from_window_manager(→ Any)

Prevent a window manager from attaching dialog to its parent.

drop_the_explicit_floor(→ bool)

Clear an explicit minimum size and report whether one was present.

fields_in(→ int)

Return the number of independent data-entry fields in dialog.

give_it_a_size_grip(→ bool)

Enable a transparent corner size grip on dialog.

is_stuck_at_its_contents(→ bool)

Return whether content prevents useful shrinking in either dimension.

let_the_content_scroll(→ bool)

Move a dialog's layout into a resizable scroll area.

make_the_window_resizable(→ bool)

Apply standardized resizing behavior to one eligible dialog.

more_than_a_message(→ bool)

Return whether dialog contains resizable interactive content.

open_at_its_natural_size(→ bool)

Apply a stored natural opening size once and clear the stored value.

wants_resizing(→ bool)

Return whether spaCR should add standardized resizing to dialog.

window_floor(dialog)

Return the explicit minimum size enforced for dialog.

Module Contents

spacr.qt.dialogs.content_floor(dialog)[source]

Return the layout’s minimum size for rendering without clipping.

Parameters:

dialog – the widget whose minimumSizeHint() is returned.

spacr.qt.dialogs.detach_all_dialogs(app) → bool[source]

Install the application-wide detacher. Returns True if it installed.

Idempotent PER APPLICATION: calling it twice on the same app leaves one filter, and calling it on a NEW app installs again, because the old filter died with the old app.

Parameters:

app – the QApplication that receives the event filter. None, or the application already holding the filter, returns False without installing.

spacr.qt.dialogs.detach_from_window_manager(dialog: Any) → Any[source]

Prevent a window manager from attaching dialog to its parent.

Call this before exec() when a modal dialog must remain independently movable. Repeated calls and dialogs without parents are supported.

Parameters:

dialog – the QDialog (or any QWidget shown as a window).

Returns:

the same object, so it can be used inline.

spacr.qt.dialogs.drop_the_explicit_floor(dialog) → bool[source]

Clear an explicit minimum size and report whether one was present.

The original value can be retained separately and passed to open_at_its_natural_size() so the initial window size is preserved.

Parameters:

dialog – the dialog whose explicit minimum size is reset to zero when one is set.

spacr.qt.dialogs.fields_in(dialog) → int[source]

Return the number of independent data-entry fields in dialog.

Editors nested inside another field, such as a spin box’s line editor, are not counted separately. Push buttons are not considered fields.

Parameters:

dialog – the widget whose descendant widgets are searched for data-entry fields.

spacr.qt.dialogs.give_it_a_size_grip(dialog) → bool[source]

Enable a transparent corner size grip on dialog.

Parameters:

dialog – the QDialog whose size grip is enabled and made transparent.

Returns:

True if the dialog contains a size-grip widget.

spacr.qt.dialogs.is_stuck_at_its_contents(dialog) → bool[source]

Return whether content prevents useful shrinking in either dimension.

SLACK defines the minimum proportional reduction required for a dialog to be considered usefully resizable. Call this before changing its layout or minimum size.

Parameters:

dialog – the dialog to measure; its size hint (at least its explicit minimum) is compared with its layout’s minimum size hint.

spacr.qt.dialogs.let_the_content_scroll(dialog) → bool[source]

Move a dialog’s layout into a resizable scroll area.

The existing layout and widgets are transferred to a transparent holder, while the original outer margins remain on the dialog. The holder expands with the viewport, and content exceeding the current window size scrolls.

Parameters:

dialog – the dialog whose existing layout is moved into a scroll area; it must already have a layout. It is flagged as scrolling afterwards.

Returns:

True after the content has been moved.

spacr.qt.dialogs.make_the_window_resizable(dialog) → bool[source]

Apply standardized resizing behavior to one eligible dialog.

Explicit minimum sizes are cleared first. If the content still prevents useful shrinking and does not already scroll, it is moved into a scroll area. A size grip is then enabled. Repeated calls leave the dialog unchanged.

Parameters:

dialog – the widget to process; anything wants_resizing() rejects is left untouched and returns False.

Returns:

True if the dialog was eligible and processed.

spacr.qt.dialogs.more_than_a_message(dialog) → bool[source]

Return whether dialog contains resizable interactive content.

A dialog qualifies when it contains at least one data-entry field or an existing scroll area. Simple confirmation and message dialogs do not.

Parameters:

dialog – the widget searched for data-entry fields and scroll areas.

spacr.qt.dialogs.open_at_its_natural_size(dialog) → bool[source]

Apply a stored natural opening size once and clear the stored value.

This is called after Qt’s initial size adjustment so removing a minimum size does not cause a dialog to open smaller than its original layout. Later shows retain the size selected by the user.

Parameters:

dialog – the dialog whose stored opening size, if any, is applied (never shrinking its current size) and then cleared.

Returns:

True if a stored size was applied.

spacr.qt.dialogs.wants_resizing(dialog) → bool[source]

Return whether spaCR should add standardized resizing to dialog.

The dialog must contain interactive content and must not be a specialized Qt dialog, explicitly exempt, or already processed.

Parameters:

dialog – the widget to judge. Only a QDialog that is not one of Qt’s own specialised dialogs, is not flagged exempt or already resizable, and has a non-empty layout can qualify.

spacr.qt.dialogs.window_floor(dialog)[source]

Return the explicit minimum size enforced for dialog.

Unlike minimumSizeHint(), this value directly constrains manual and initial window resizing.

Parameters:

dialog – the widget whose minimumSize() is returned.

Nested helpers

_drag_class._DragTheWindowByTheForm.__init__(self, holder)

Move the window when its holder’s empty space is dragged.

Parameters:

holder – the widget that owns the empty space, and the QObject parent. NOT the window and not the scroll area: putting the contents in a scroll area moved the empty space to this holder, which is the whole point of the class.

spacr/qt/dialogs.py:389

_drag_class._DragTheWindowByTheForm.eventFilter(self, watched, event)

Move the window when its holder’s empty space is dragged.

spacr/qt/dialogs.py:402

_form_scroll_class._FormScroll.minimumSizeHint(self)

A floor small enough that the dialog can always be shrunk.

spacr/qt/dialogs.py:355

_form_scroll_class._FormScroll.sizeHint(self)

The inner form’s own width, so the dialog opens wide enough to read.

spacr/qt/dialogs.py:346

detach_all_dialogs._Filter.__init__(self)

Wrap the detacher this filter applies to every dialog.

spacr/qt/dialogs.py:765

detach_all_dialogs._Filter.eventFilter(self, obj, event)

Forward the two events the detacher acts on, and no others.

THE TEST IS HERE AS WELL AS INSIDE because this method is what Qt calls for every event in the application, and a Python call that returns False is not free at 94,431 of them per module open. The detacher makes the same test for anyone calling it directly.

spacr/qt/dialogs.py:771