Package lib :: Module scripting :: Class Window
[hide private]
[frames] | no frames]

Class Window

source code

Basic window management using wmctrl

Note: in all cases where a window title is required (with the exception of wait_for_focus()), two special values of window title are permitted:

:ACTIVE: - select the currently active window :SELECT: - select the desired window by clicking on it

Instance Methods [hide private]
 
__init__(self, mediator) source code
boolean
wait_for_focus(self, title, timeOut=5)
Wait for window with the given title to have focus
source code
boolean
wait_for_exist(self, title, timeOut=5)
Wait for window with the given title to be created
source code
 
activate(self, title, switchDesktop=False, matchClass=False)
Activate the specified window, giving it input focus
source code
 
close(self, title, matchClass=False)
Close the specified window gracefully
source code
 
resize_move(self, title, xOrigin=-1, yOrigin=-1, width=-1, height=-1, matchClass=False)
Resize and/or move the specified window
source code
 
move_to_desktop(self, title, deskNum, matchClass=False)
Move the specified window to the given desktop
source code
 
switch_desktop(self, deskNum)
Switch to the specified desktop
source code
 
set_property(self, title, action, prop, matchClass=False)
Set a property on the given window using the specified action
source code
tuple(int, int, int, int)
get_active_geometry(self)
Get the geometry of the currently active window
source code
str
get_active_title(self)
Get the visible title of the currently active window
source code
str
get_active_class(self)
Get the class of the currently active window
source code
 
_run_wmctrl(self, args) source code
Method Details [hide private]

wait_for_focus(self, title, timeOut=5)

source code 

Wait for window with the given title to have focus

Usage: window.wait_for_focus(title, timeOut=5)

If the window becomes active, returns True. Otherwise, returns False if the window has not become active by the time the timeout has elapsed.

Parameters:
  • title - title to match against (as a regular expression)
  • timeOut - period (seconds) to wait before giving up
Returns: boolean

wait_for_exist(self, title, timeOut=5)

source code 

Wait for window with the given title to be created

Usage: window.wait_for_exist(title, timeOut=5)

If the window is in existence, returns True. Otherwise, returns False if the window has not been created by the time the timeout has elapsed.

Parameters:
  • title - title to match against (as a regular expression)
  • timeOut - period (seconds) to wait before giving up
Returns: boolean

activate(self, title, switchDesktop=False, matchClass=False)

source code 

Activate the specified window, giving it input focus

Usage: window.activate(title, switchDesktop=False, matchClass=False)

If switchDesktop is False (default), the window will be moved to the current desktop and activated. Otherwise, switch to the window's current desktop and activate it there.

Parameters:
  • title - window title to match against (as case-insensitive substring match)
  • switchDesktop - whether or not to switch to the window's current desktop
  • matchClass - if True, match on the window class instead of the title

close(self, title, matchClass=False)

source code 

Close the specified window gracefully

Usage: window.close(title, matchClass=False)

Parameters:
  • title - window title to match against (as case-insensitive substring match)
  • matchClass - if True, match on the window class instead of the title

resize_move(self, title, xOrigin=-1, yOrigin=-1, width=-1, height=-1, matchClass=False)

source code 

Resize and/or move the specified window

Usage: window.close(title, xOrigin=-1, yOrigin=-1, width=-1, height=-1, matchClass=False)

Leaving and of the position/dimension values as the default (-1) will cause that value to be left unmodified.

Parameters:
  • title - window title to match against (as case-insensitive substring match)
  • xOrigin - new x origin of the window (upper left corner)
  • yOrigin - new y origin of the window (upper left corner)
  • width - new width of the window
  • height - new height of the window
  • matchClass - if True, match on the window class instead of the title

move_to_desktop(self, title, deskNum, matchClass=False)

source code 

Move the specified window to the given desktop

Usage: window.move_to_desktop(title, deskNum, matchClass=False)

Parameters:
  • title - window title to match against (as case-insensitive substring match)
  • deskNum - desktop to move the window to (note: zero based)
  • matchClass - if True, match on the window class instead of the title

switch_desktop(self, deskNum)

source code 

Switch to the specified desktop

Usage: window.switch_desktop(deskNum)

Parameters:
  • deskNum - desktop to switch to (note: zero based)

set_property(self, title, action, prop, matchClass=False)

source code 

Set a property on the given window using the specified action

Usage: window.set_property(title, action, prop, matchClass=False)

Allowable actions: add, remove, toggle Allowable properties: modal, sticky, maximized_vert, maximized_horz, shaded, skip_taskbar, skip_pager, hidden, fullscreen, above

Parameters:
  • title - window title to match against (as case-insensitive substring match)
  • action - one of the actions listed above
  • prop - one of the properties listed above
  • matchClass - if True, match on the window class instead of the title

get_active_geometry(self)

source code 

Get the geometry of the currently active window

Usage: window.get_active_geometry()

Returns: tuple(int, int, int, int)
a 4-tuple containing the x-origin, y-origin, width and height of the window (in pixels)

get_active_title(self)

source code 

Get the visible title of the currently active window

Usage: window.get_active_title()

Returns: str
the visible title of the currentle active window

get_active_class(self)

source code 

Get the class of the currently active window

Usage: window.get_active_class()

Returns: str
the class of the currentle active window