pymel.core.windows.windowPref

windowPref(*args, **kwargs)

Create or modify preferred window attributes. The size and position of a window is retained during and between application sessions. A default window preference is created when a window is closed. Window preferences must be named and, consequently, only affect the window with a matching name. Note that window preferences are not applied to the main Maya window nor the Command window. In query mode, return type is based on queried flag.

Flags:
Long name (short name) Argument Types Properties
enableAll (ea) bool ../../../_images/create.gif ../../../_images/query.gif
 
Enable/disable all window preferences. Preferences are enabled by default. Set this flag to false and window’s will ignore all preference values.
exists (ex) bool ../../../_images/create.gif
 
Returns true|false depending upon whether the specified object exists. Other flags are ignored.
height (h) int ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 
Height of the window.
leftEdge (le) int ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 
Left edge position of the window.
loadAll (la) bool ../../../_images/create.gif
 
Reads in file with window attributes from disk.
parentMain (pm) bool ../../../_images/create.gif ../../../_images/query.gif
 
Set whether window is parented to main application window. Windows only.
remove (r) bool ../../../_images/create.gif
 
Remove a window preference.
removeAll (ra) bool ../../../_images/create.gif
 
Remove all window preferences.
| .. |
rms)** | unicode | .. image:: /images/create.gif |
 

Reads in file with main window state (positions of toolbars and dock controls).Flag can appear in Create mode of commandFlag can have multiple arguments, passed either as a tuple or a list.

saveAll (sa) bool ../../../_images/create.gif
 
Writes out file with window attributes.
saveMainWindowState (sms) unicode ../../../_images/create.gif
 
Writes out file with main window state (positions of toolbars and dock controls).
topEdge (te) int ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 
Top edge position of the window.
topLeftCorner (tlc) int, int ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 
Top and left edge position of the window.
width (w) int ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 
Width of the window.
widthHeight (wh) int, int ../../../_images/create.gif ../../../_images/query.gif ../../../_images/edit.gif
 
Width and height of the window.

Derived from mel command maya.cmds.windowPref

Example:

import pymel.core as pm

import maya.cmds as cmds

#    Check if the window exists.
#
if pm.window('ExampleWindow', exists=True):
        pm.deleteUI('ExampleWindow', window=True)

#    Create a window.
#
pm.window( 'ExampleWindow' )
# Result: ui.Window('ExampleWindow') #
pm.columnLayout()
# Result: ui.ColumnLayout('ExampleWindow|columnLayout98') #
pm.text( label='Size and position the window before closing it.' )
# Result: ui.Text('ExampleWindow|columnLayout98|text25') #
pm.button( label='Close', command='pm.deleteUI("ExampleWindow", window=True)' )
# Result: ui.Button('ExampleWindow|columnLayout98|button111') #
pm.showWindow( 'ExampleWindow' )

#    When the window is closed a window preference object is
#    created for the window. It has the same name as the window
#    object.
#
pm.windowPref( 'ExampleWindow', exists=True )
# Result: True #

#    Query the window preference size and position.
#
pm.windowPref( 'ExampleWindow', query=True, topLeftCorner=True )
# Result: [494, 886] #
pm.windowPref( 'ExampleWindow', query=True, widthHeight=True )
# Result: [300, 300] #

#    Create a window with the same name. When it is shown
#    it will be sized and positioned according to the
#    window preference.
#
if pm.window('ExampleWindow', exists=True):
        pm.deleteUI('ExampleWindow', window=True)

pm.window( 'ExampleWindow' )
# Result: ui.Window('ExampleWindow') #
pm.columnLayout()
# Result: ui.ColumnLayout('ExampleWindow|columnLayout99') #
pm.text( label='Size and position the window before closing it.' )
# Result: ui.Text('ExampleWindow|columnLayout99|text26') #
pm.button( label='Close', command='pm.deleteUI("ExampleWindow", window=True)' )
# Result: ui.Button('ExampleWindow|columnLayout99|button112') #
pm.showWindow( 'ExampleWindow' )

#    Delete the window preference and the window will have a
#    default size and position.
#
pm.windowPref( 'ExampleWindow', remove=True )

#    Create the window one last time.
#
if pm.window('ExampleWindow', exists=True):
        pm.deleteUI('ExampleWindow', window=True)

pm.window( 'ExampleWindow' )
# Result: ui.Window('ExampleWindow') #
pm.columnLayout()
# Result: ui.ColumnLayout('ExampleWindow|columnLayout100') #
pm.text( label='Size and position the window before closing it.' )
# Result: ui.Text('ExampleWindow|columnLayout100|text27') #
pm.button( label='Close', command='pm.deleteUI("ExampleWindow", window=True)' )
# Result: ui.Button('ExampleWindow|columnLayout100|button113') #
pm.showWindow( 'ExampleWindow' )

Previous topic

pymel.core.windows.window

Next topic

pymel.core.windows.BaseCallback

Core

Core Modules

Other Modules

This Page