Window:
Filter:
Classes | GUI > Views

Window : Object

Top-level container of views
Source: QWindow.sc
Subclasses: QWindow

Description

The Window is the most fundamental element of the GUI. It occupies a rectangular space on the screen within which other GUI elements (Views) are displayed.

A child view is added into a window by passing the window to the view's constructor. See View: *new.

NOTE: There is no distinction between windows, views, and containers; a View can be displayed directly on screen, and can contain other views. Therefore, visual descriptions of Window and most of the methods that are specific to Window in other GUI kits, also apply to and make part of View in Qt, and are thus shared by all its subclasses.

The Window class is provided in Qt GUI for compatibility as well as convenience: e.g. unlike View, Window will be created by default in the center of the screen, and various aspects can be conveniently controlled using its constructor arguments.

The Window is usually drawn with a bar on its top edge that displays the window's title which you can set in the constructor, or using -name.

Class Methods

Window.new(name: "", bounds, resizable: true, border: true, server, scroll: false)

Creates a new Window instance. You will need to call -front on it to become visible.

Arguments:

name

A String for the text that will be displayed in the title bar. The default is 'panel'.

bounds

A Rect specifying position and size of the window. The size does not include the border and title bar. Position is measured from the bottom-left corner of the screen (this is different than View: -bounds). The default is size 400x400 at position 128x64, but in Qt the window is centered on the screen by default.

resizable

A Boolean indicating whether this window is resizable by the user. The default is true.

border

A Boolean indicating whether this window has a border. Borderless windows have no title bar and thus can only be closed in code. The default is true.

server

This is a dummy argument which is here to provide compatibility with SwingOSC and has no effect.

scroll

A Boolean indicating whether this window will add scrollbars if its contents exceed its bounds. If this is set to true, then View: -resize settings will be ignored for contained views. The default is false.

Window.allWindows

An array of all existing Window instances.

Window.closeAll

Calls -close an all existing Window instances.

Window.initAction

Window.initAction = value

The default action object to be evaluated whenever a new Window is instantiated.

Window.screenBounds

Returns a Rect with the size of the screen in pixels

Window.availableBounds

Returns a Rect describing the area of the screen that windows can actually occupy (i.e. excluding the Mac dock, the task bar, or similar).

Inherited class methods

Undocumented class methods

Window.addWindow(window)

Window.flipY(aRect)

Window.removeWindow(window)

Instance Methods

View hierarchy

.view

When a Window is created, it creates a container view, accessible using this method, that occupies the whole area of the window, and which will be used as the actual parent of the child widgets.

Returns:

A View.

.asView

Equivalent to -view

.currentSheet

NOTE: Only in Cocoa GUI

returns: The current modal sheet attached to this window, if it exists. See "SCModalSheet".help.

Visibility

.front

Displays the window on the screen (This has the same effect as setting -visible to true).

.minimize

Hides the window, only keeping its representation in the dock, taskbar, etc..

.unminimize

Restores the window's previous state after being minimized.

.fullScreen

Displays the window full-screen.

.endFullScreen

Restores the window's previous state after being displayed full-screen.

.alwaysOnTop

.alwaysOnTop = boolean

Whether the window should always stay on top of other windows, even when it is not the active one.

Arguments:

boolean

A Boolean.

.visible

.visible = boolean

Whether the window is visible.

Setting this to true has the same effect as -front, and setting it to false closes the window without destroying it.

Arguments:

boolean

A Boolean.

.close

Closes and destroys the window.

.isClosed

Returns:

A Boolean stating whether the view has been closed.

Geometry

.bounds

.bounds = aRect

The position and size of the window. The position is relative to the bottom-left corner of the screen.

Arguments:

aRect

A Rect or a Point interpreted as Rect.

Returns:

A Rect.

.setTopLeftBounds(rect, menuSpacer: 45)

A convenience method that, unlike -bounds, sets the bounds by measuring position from the top-left corner of the screen, and vertically offset by menuSpacer.

Arguments:

rect

A Rect.

menuSpacer

An Integer amount of pixels.

.setInnerExtent(w, h)

Resizes the window, keeping its position intact.

This is equivalent to View: -resizeTo called on the -view.

Arguments:

w

An Integer width in pixels.

h

An Integer height in pixels.

.sizeHint

Redirects to View: -sizeHint of the -view.

.minSizeHint

Redirects to View: -minSizeHint of the -view.

.addFlowLayout(margin, gap)

A convenience method which sets decorator of the -view to a new instance of FlowLayout. See FlowLayout for examples.

Arguments:

margin

A Point describing the margin of the FlowLayout.

gap

A Point describing the gap of the FlowLayout.

Returns:

The new FlowLayout instance.

.layout

.layout = layout

Redirects to View: -layout of the -view.

Appearance

.name

.name = string

The title of the window.

Arguments:

string

A String.

.background

.background = aColor

The background color of the window.

Arguments:

aColor

A Color.

.alpha = value

The transparency of the window.

Arguments:

value

A Float between 0.0 (invisible) and 1.0 (opaque).

.refresh

Redraws the window and all its children.

Interaction

.userCanClose

.userCanClose = boolean

Whether the user can close the window. The default is true.

Arguments:

boolean

A Boolean.

.acceptsClickThrough

.acceptsClickThrough = value

Whether the window receives clicks when it is not front-most. The default is true.

Arguments:

(arg1)

A Boolean.

.acceptsMouseOver

.acceptsMouseOver = flag

Whether the window and all its children receive mouse-over events. The default is false.

See also: View: -acceptsMouseOver and View: -mouseOverAction.

Arguments:

flag

A Boolean.

Actions and hooks

.drawFunc

.drawFunc = aFunction

Just like the UserView, the window can be given a Function to evaluate whenever it is asked to redraw itself, so you can use the Pen class to draw on the window. See UserView: -drawFunc for explanation.

Arguments:

aFunction

A Function.

.toFrontAction

.toFrontAction = action

The action object to be evaluated whenever the window becomes the active one.

.endFrontAction

.endFrontAction = action

The action object to be evaluated whenever the window ceases to be the active one.

.onClose

.onClose = func

The action object to be evaluated when the window is closed.

.addToOnClose(function)

Adds an object to -onClose, wrapping the current value into an Array, if it is not yet.

.removeFromOnClose(function)

Removes an object from -onClose, if the latter is an Array.

Inherited instance methods

Undocumented instance methods

.asFlowView(bounds)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/Base/viewExtensionsQt.sc

.asPageLayout(title, bounds)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/backwardsCompatibility/flowViewSupportQt.sc

.comp(func, bounds)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/Base/viewExtensionsQt.sc

.drawHook = func

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/backwardsCompatibility/classNameRedirects.sc

.flow(func, bounds)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/Base/viewExtensionsQt.sc

.initWindow(name, bounds, resize, border, scroll)

.resizeToHint

Examples

Adding Views

Using Decorator

Setting Bounds

Borderless Window

Window with Scrollers

onClose

Using Layouts

Layouts are used to organize view sizes automatically. See: Layout Management.

NOTE: Only in Cocoa GUI

Drawing on Window with Pen