wx.TopLevelWindow¶
wx.TopLevelWindow is a common base class for wx.Dialog and wx.Frame.
It is an abstract base class meaning that you never work with objects of this class directly, but all of its methods are also applicable for the two classes above.
Note that the instances of wx.TopLevelWindow are managed by wxWidgets in the internal top level window list.
Events Emitted by this Class¶
Event macros for events emitted by this class:
EVT_MAXIMIZE: Process a
wxEVT_MAXIMIZEevent. See wx.MaximizeEvent.EVT_MOVE: Process a
wxEVT_MOVEevent, which is generated when a window is moved. See wx.MoveEvent.EVT_MOVE_START: Process a
wxEVT_MOVE_STARTevent, which is generated when the user starts to move or size a window. wxMSW only. See wx.MoveEvent.EVT_MOVE_END: Process a
wxEVT_MOVE_ENDevent, which is generated when the user stops moving or sizing a window. wxMSW only. See wx.MoveEvent.EVT_SHOW: Process a
wxEVT_SHOWevent. See wx.ShowEvent.EVT_FULLSCREEN: Process a
wxEVT_FULLSCREENevent. See wx.FullScreenEvent.
Class Hierarchy¶
Known Subclasses¶
Methods Summary¶
Default constructor. |
|
Returns |
|
A synonym for |
|
Centres the window on screen. |
|
Creates the top level window. |
|
Enables or disables the Close button (most often in the right upper corner of a dialog) and the Close entry of the system menu (most often in the left upper corner of the dialog). |
|
Enables the zoom button to toggle full screen mode. |
|
Enables or disables the Maximize button (in the right or left upper corner of a frame or dialog). |
|
Enables or disables the Minimize button (in the right or left upper corner of a frame or dialog). |
|
Get the current content protection of the window. |
|
Returns a pointer to the button which is the default for this window, or |
|
Get the default size for a new top level window. |
|
Returns the standard icon of the window. |
|
Returns all icons associated with the window, there will be none of them if neither |
|
Gets a string containing the window title. |
|
Iconizes or restores the window. |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Lays out the children using the window sizer or resizes the only child of the window to cover its entire area. |
|
Maximizes or restores the window. |
|
Returns the current modified state of the wx.TopLevelWindow on macOS. |
|
This function sets the wx.TopLevelWindow’s modified state on macOS, which currently draws a black dot in the wx.TopLevelWindow’s close button. |
|
Use a system-dependent way to attract users attention to the window when it is in background. |
|
Restore a previously iconized or maximized window to its normal state. |
|
Restores the window to the previously saved geometry. |
|
Save the current window geometry to allow restoring it later. |
|
Set content protection for the window. |
|
Changes the default item for the panel, usually win is a button. |
|
Sets the icon for this window. |
|
Sets several icons of different sizes for this window: this allows using different icons for different situations (e.g. |
|
A simpler interface for setting the size hints than |
|
A simpler interface for setting the size hints than |
|
Sets the file name represented by this wx.TopLevelWindow. |
|
Allows specification of minimum and maximum window sizes, and window size increments. |
|
Sets the window title. |
|
If the platform supports it will set the window to be translucent. |
|
This virtual function is not meant to be called directly but can be overridden to return |
|
Depending on the value of show parameter the window is either shown full screen or restored to its normal state. |
|
Show the wx.TopLevelWindow, but do not give it keyboard focus. |
Properties Summary¶
See |
|
See |
|
See |
Class API¶
- class wx.TopLevelWindow(NonOwnedWindow)¶
Possible constructors:
TopLevelWindow() -> None TopLevelWindow(parent, id=ID_ANY, title='', pos=DefaultPosition, size=DefaultSize, style=DEFAULT_FRAME_STYLE, name=FrameNameStr) -> None
TopLevelWindow is a common base class for Dialog and Frame.
Methods¶
- __init__(self, *args, **kw)¶
-
__init__ (self)
Default constructor.
- Return type:
None
__init__ (self, parent, id=ID_ANY, title=’’, pos=DefaultPosition, size=DefaultSize, style=DEFAULT_FRAME_STYLE, name=FrameNameStr)
Constructor creating the top level window.
- Parameters:
- Return type:
None
- CanSetTransparent(self)¶
Returns
Trueif the platform supports making the window translucent.- Return type:
bool
See also
- CenterOnScreen(self, direction=BOTH)¶
A synonym for
CentreOnScreen.- Parameters:
direction (int)
- Return type:
None
- CentreOnScreen(self, direction=BOTH)¶
Centres the window on screen.
- Parameters:
direction (int) – Specifies the direction for the centering. May be
HORIZONTAL,VERTICALorBOTH.- Return type:
None
See also
- Create(self, parent, id=ID_ANY, title='', pos=DefaultPosition, size=DefaultSize, style=DEFAULT_FRAME_STYLE, name=FrameNameStr)¶
Creates the top level window.
- EnableCloseButton(self, enable=True)¶
Enables or disables the Close button (most often in the right upper corner of a dialog) and the Close entry of the system menu (most often in the left upper corner of the dialog).
Returns
Trueif operation was successful. This may be wrong on X11 (including GTK+) where the window manager may not support this operation and there is no way to find out.- Parameters:
enable (bool)
- Return type:
bool
- EnableFullScreenView(self, enable=True, style=FULLSCREEN_ALL)¶
Enables the zoom button to toggle full screen mode.
A wx.FullScreenEvent is generated when the users enters or exits full screen via the enter/exit full screen button.
- Parameters:
enable (bool) – If
True(default) make the zoom button toggle full screen; ifFalsethe button does only toggle zoom.style (long) – This parameter sets which elements will be hidden when the user presses the full screen button. See
ShowFullScreenfor possible values. It is available since wxWidgets 3.1.6.
- Return type:
bool
- Returns:
Trueif the button behaviour has been changed,Falseif running under another OS.
Added in version 4.1/wxWidgets-3.1.0.
Availability
Only available for OSX.
Note
Having the button is also required to let
ShowFullScreenmake use of the full screen API: a full screen window gets its own space and entering and exiting the mode is animated. If the button is not present the old way of switching to full screen is used. OnlyFULLSCREEN_NOTOOLBARandFULLSCREEN_NOMENUBARwill be used when using the fullscreen API (other values are ignored).See also
- EnableMaximizeButton(self, enable=True)¶
Enables or disables the Maximize button (in the right or left upper corner of a frame or dialog).
Currently only implemented for wxMSW and wxOSX.
The window style must contain
wx.MAXIMIZE_BOX.Returns
Trueif operation was successful. Note that a successful operation does not change the window style flags.- Parameters:
enable (bool)
- Return type:
bool
Added in version 4.1/wxWidgets-3.1.0.
- EnableMinimizeButton(self, enable=True)¶
Enables or disables the Minimize button (in the right or left upper corner of a frame or dialog).
Currently only implemented for wxMSW and wxOSX.
The window style must contain
wx.MINIMIZE_BOX.Note that in wxMSW a successful operation will change the window style flags.
Returns
Trueif operation was successful. Note that a successful operation does not change the window style flags.- Parameters:
enable (bool)
- Return type:
bool
Added in version 4.1/wxWidgets-3.1.0.
- static GetClassDefaultAttributes(variant=WINDOW_VARIANT_NORMAL)¶
- Parameters:
variant (WindowVariant)
- Return type:
- GetContentProtection(self)¶
Get the current content protection of the window.
- Return type:
Added in version 4.1/wxWidgets-3.1.6.
See also
- GetDefaultItem(self)¶
Returns a pointer to the button which is the default for this window, or
None.The default button is the one activated by pressing the Enter key.
- Return type:
- static GetDefaultSize()¶
Get the default size for a new top level window.
This is used internally by wxWidgets on some platforms to determine the default size for a window created using
wx.DefaultSizeso it is not necessary to use it when creating a wx.TopLevelWindow, however it may be useful if a rough estimation of the window size is needed for some other reason.- Return type:
Added in version 2.9.2.
- GetIcon(self)¶
Returns the standard icon of the window.
The icon will be invalid if it hadn’t been previously set by
SetIcon.- Return type:
See also
- GetIcons(self)¶
Returns all icons associated with the window, there will be none of them if neither
SetIconnorSetIconshad been called before.Use
GetIconto get the main icon of the window.- Return type:
See also
- Iconize(self, iconize=True)¶
Iconizes or restores the window.
Note that in wxGTK the change to the window state is not immediate, i.e.
IsIconizedwill typically returnFalseright after a call toIconizeand its return value will only change after the control flow returns to the event loop and the notification about the window being really iconized is received.- Parameters:
iconize (bool) – If
True, iconizes the window; ifFalse, shows and restores it.- Return type:
None
See also
- IsActive(self)¶
Returns
Trueif this window is currently active, i.e. if the user is currently working with it.- Return type:
bool
- IsAlwaysMaximized(self)¶
Returns
Trueif this window is expected to be always maximized, either due to platform policy or due to local policy regarding particular class.- Return type:
bool
- IsFullScreen(self)¶
Returns
Trueif the window is in fullscreen mode.- Return type:
bool
See also
- IsIconized(self)¶
Returns
Trueif the window is iconized.- Return type:
bool
- IsMaximized(self)¶
Returns
Trueif the window is maximized.- Return type:
bool
- Layout(self)¶
Lays out the children using the window sizer or resizes the only child of the window to cover its entire area.
This class overrides the base class
Layoutmethod to check if this window contains exactly one child – which is commonly the case, with wx.Panel being often created as the only child of wx.TopLevelWindow – and, if this is the case, resizes this child window to cover the entire client area.Note that if you associate a sizer with this window, the sizer takes precedence and the only-child-resizing is only used as fallback.
- Return type:
bool
- Returns:
Falseif nothing was done because the window has neither a sizer nor a single child,Trueotherwise.
- MacGetMetalAppearance(self)¶
- Return type:
bool
- MacGetTopLevelWindowRef(self)¶
- Return type:
Any
- MacGetUnifiedAppearance(self)¶
- Return type:
bool
- MacSetMetalAppearance(self, on)¶
- Return type:
None
- Maximize(self, maximize=True)¶
Maximizes or restores the window.
Note that, just as with
Iconize, the change to the window state is not immediate in at least wxGTK port.- Parameters:
maximize (bool) – If
True, maximizes the window, otherwise it restores it.- Return type:
None
- OSXIsModified(self)¶
Returns the current modified state of the wx.TopLevelWindow on macOS.
On other platforms, this method does nothing.
- Return type:
bool
See also
- OSXSetModified(self, modified)¶
This function sets the wx.TopLevelWindow’s modified state on macOS, which currently draws a black dot in the wx.TopLevelWindow’s close button.
On other platforms, this method does nothing.
- Parameters:
modified (bool)
- Return type:
None
See also
- RequestUserAttention(self, flags=USER_ATTENTION_INFO)¶
Use a system-dependent way to attract users attention to the window when it is in background.
flags may have the value of either
USER_ATTENTION_INFO(default) orUSER_ATTENTION_ERRORwhich results in a more drastic action. When in doubt, use the default value.This function is currently implemented for Win32 where it flashes the window icon in the taskbar, and for wxGTK with task bars supporting it.
- Parameters:
flags (int)
- Return type:
None
Note
This function should normally be only used when the application is not already in foreground.
- Restore(self)¶
Restore a previously iconized or maximized window to its normal state.
In wxGTK this method currently doesn’t return the maximized window to its normal state and you must use
MaximizewithFalseargument explicitly for this. In the other ports, it both unmaximizes the maximized windows and uniconizes the iconized ones.- Return type:
None
- RestoreToGeometry(self, ser)¶
Restores the window to the previously saved geometry.
This is a companion function to
SaveGeometryand can be called later to restore the window to the geometry it had when it was saved.- Parameters:
ser (wx.TopLevelWindow.GeometrySerializer) – An object implementing wx.TopLevelWindow.GeometrySerializer virtual methods.
- Return type:
bool
- Returns:
Trueif any (and, usually, but not necessarily, all) of the window geometry attributes were restored orFalseif there was no saved geometry information at all or restoring it failed.
Added in version 4.1/wxWidgets-3.1.2.
- SaveGeometry(self, ser)¶
Save the current window geometry to allow restoring it later.
After calling this function, window geometry is saved in the provided serializer and calling
RestoreToGeometrywith the same serializer later (i.e. usually during a subsequent program execution) would restore the window to the same position, size, maximized/minimized state etc.This function is used by PersistentTLW , so it is not necessary to use it if the goal is to just save and restore window geometry in the simplest possible way. However is more flexibility is required, it can be also used directly with a custom serializer object.
- Parameters:
ser (wx.TopLevelWindow.GeometrySerializer) – An object implementing wx.TopLevelWindow.GeometrySerializer virtual methods.
- Return type:
bool
- Returns:
Trueif the geometry was saved,Falseif doing it failed
Added in version 4.1/wxWidgets-3.1.2.
- SetContentProtection(self, contentProtection)¶
Set content protection for the window.
When content protection is enabled contents of this window will not be included in screen captures.
Obviously this can’t provide absolute security as there might be workarounds and tools that bypass this protection. Additionally a screen could always be photographed.
- Parameters:
contentProtection (ContentProtection)
- Return type:
bool
- Returns:
Trueif the content protection was changed,Falseif running under an unsupported OS.
Added in version 4.1/wxWidgets-3.1.6.
Availability
Only available for MSW, OSX.
Note
Windows 7 or newer is required but any macOS version is supported.
See also
- SetDefaultItem(self, win)¶
Changes the default item for the panel, usually win is a button.
See also
- SetIcon(self, icon)¶
Sets the icon for this window.
Note
The window takes a ‘copy’ of icon, but since it uses reference counting, the copy is very quick. It is safe to delete icon after calling this function.
Note
In wxMSW, icon must be either 16x16 or 32x32 icon.
- SetIcons(self, icons)¶
Sets several icons of different sizes for this window: this allows using different icons for different situations (e.g.
task switching bar, taskbar, window title bar) instead of scaling, with possibly bad looking results, the only icon set by
SetIcon.- Parameters:
icons (wx.IconBundle) – The icons to associate with this window.
- Return type:
None
Note
In wxMSW, icons must contain a 16x16 or 32x32 icon, preferably both.
See also
- SetMaxSize(self, size)¶
A simpler interface for setting the size hints than
SetSizeHints.- Parameters:
size (wx.Size)
- Return type:
None
- SetMinSize(self, size)¶
A simpler interface for setting the size hints than
SetSizeHints.- Parameters:
size (wx.Size)
- Return type:
None
- SetRepresentedFilename(self, filename)¶
Sets the file name represented by this wx.TopLevelWindow.
Under macOS, this file name is used to set the “proxy icon”, which appears in the window title bar near its title, corresponding to this file name. Under other platforms it currently doesn’t do anything but it is harmless to call it now and it might be implemented to do something useful in the future so you’re encouraged to use it for any window representing a file-based document.
- Parameters:
filename (string)
- Return type:
None
Added in version 2.9.4.
- SetSizeHints(self, *args, **kw)¶
-
SetSizeHints (self, minW, minH, maxW=-1, maxH=-1, incW=-1, incH=-1)
Allows specification of minimum and maximum window sizes, and window size increments.
If a pair of values is not set (or set to -1), no constraints will be used.
- Parameters:
minW (int) – The minimum width.
minH (int) – The minimum height.
maxW (int) – The maximum width.
maxH (int) – The maximum height.
incW (int) – Specifies the increment for sizing the width (GTK/Motif/Xt only).
incH (int) – Specifies the increment for sizing the height (GTK/Motif/Xt only).
- Return type:
None
Note
Notice that this function not only prevents the user from resizing the window outside the given bounds but it also prevents the program itself from doing it using
wx.Window.SetSize.SetSizeHints (self, minSize, maxSize=DefaultSize, incSize=DefaultSize)
Allows specification of minimum and maximum window sizes, and window size increments.
If a pair of values is not set (or set to -1), no constraints will be used.
- Parameters:
- Return type:
None
Note
Notice that this function not only prevents the user from resizing the window outside the given bounds but it also prevents the program itself from doing it using
wx.Window.SetSize.
- SetTitle(self, title)¶
Sets the window title.
- Parameters:
title (string) – The window title.
- Return type:
None
See also
- SetTransparent(self, alpha)¶
If the platform supports it will set the window to be translucent.
Note that in wxGTK this function must be called before the window is shown the first time it’s called (but it can be called again after showing the window too).
See the shaped sample for an example of using this function.
- Parameters:
alpha (wx.Byte) – Determines how opaque or transparent the window will be, if the platform supports the operation. A value of 0 sets the window to be fully transparent, and a value of 255 sets the window to be fully opaque.
- Return type:
bool
- ShouldPreventAppExit(self)¶
This virtual function is not meant to be called directly but can be overridden to return
False(it returnsTrueby default) to allow the application to close even if this, presumably not very important, window is still opened.By default, the application stays alive as long as there are any open top level windows.
- Return type:
bool
- ShowFullScreen(self, show, style=FULLSCREEN_ALL)¶
Depending on the value of show parameter the window is either shown full screen or restored to its normal state.
style is a bit list containing some or all of the following values, which indicate what elements of the window to hide in full-screen mode:
FULLSCREEN_NOMENUBARFULLSCREEN_NOTOOLBARFULLSCREEN_NOSTATUSBARFULLSCREEN_NOBORDERFULLSCREEN_NOCAPTIONFULLSCREEN_ALL(all of the above)
This function has not been tested with MDI frames.
- Parameters:
show (bool)
style (long)
- Return type:
bool
Note
Showing a window full screen also actually
Shows the window if it isn’t shown.See also
- ShowWithoutActivating(self)¶
Show the wx.TopLevelWindow, but do not give it keyboard focus.
This can be used for pop up or notification windows that should not steal the current focus.
- Return type:
None
Properties¶
- DefaultItem¶
See
GetDefaultItemandSetDefaultItem
- MacMetalAppearance¶
- OSXModified¶
See
OSXIsModifiedandOSXSetModified
- TmpDefaultItem¶
See
GetTmpDefaultItemandSetTmpDefaultItem
