Package pywm :: Class WM
[show private | hide private]
[frames | no frames]

Class WM


pywm.WM is the main PYWM class that you should subclass when building your own custom window manager.

Encapsulates the Pythonised 'FLWM' window manager for X, into a python class.

Subclass this and override methods according to your tastes

Python components written by David McNab <david@freenet.org.au>
Method Summary
  __init__(self, **kwds)
Constructor.
  addHandlers(self, **kwds)
Add a set of handlers for various events.
  bindKey(self, func, arg, key, shift, control, alt, meta)
Allows you to bind a Ctrl-Alt key combo to a function
  cascadeWindows(self, spacing)
Arranges all the windows cascaded from top left.
  closeCurrent(self, arg)
Closes current window
  getMousePos(self, arg)
Returns the current x, y coordinates of the mouse as a tuple
  getScreenSize(self, arg)
Returns x, y size of the screen as a tuple
  goNextDesk(self, arg)
Switches to next desk
  goNextWindow(self, arg)
Switches to next window
  goPrevDesk(self, arg)
Switches to previous desk
  goPrevWindow(self, arg)
Switches to previous window
  indexFromWindow(self, win)
Returns the index of win in the window creation order, or -1 if there (oops) is no such window.
  launch(self, cmd)
Launch a new window in a separate process
  moveCurrent(self, direction)
Moves the current window in the specified direction.
  on_activate(self, win)
Called when an existing window is activated
  on_buttonPress(self, button)
Called when a button click is received.
  on_create(self, win)
Called when a new window is created (or an existing one un-hidden)
  on_deactivate(self, win)
Called when an existing window is deactivated
  on_destroy(self, win)
Called when an existing window is being destroyed (or hidden)
  on_enter(self, win)
Called when the mouse pointer enters a window
  on_keyEvent(self, key)
Called when a Ctrl-Alt key sequence is received.
  on_resize(self, win, x, y, w, h)
Called when the size of the window changes.
  on_startup(self)
Callback which is invoked when WM starts up.
  pan(self, dx, dy)
Pans all the windows on the screen
  panDown(self, amount)
Pans all the windows on the screen downwards
  panLeft(self, amount)
Pans all the windows on the screen to the left
  panRight(self, amount)
Pans all the windows on the screen to the right
  panUp(self, amount)
Pans all the windows on the screen upwards
  resizeCurrent(self, how)
Moves the current window in the specified direction.
  run(self)
Launch the window manager, and receive events via callbacks.
  showMenu(self, arg)
Pops up the main window manager menu
  toggleMaxCurrent(self, arg)
Toggles maximise on the current window
  toggleMaxHeightCurrent(self, arg)
Toggles maximise on the current window
  toggleMaxWidthCurrent(self, arg)
Toggles maximise on the current window
  window(self, hWin)
Maps a window handle to a window object.
  windowFromIndex(self, idx)
Returns a ref to the window with index idx in the creation order
  zoom(self, factor, xView, yView)
Zooms in or out by a given factor.
  zoomIn(self, factor, fromMouse)
Zooms in to the current view.
  zoomInMouse(self, factor)
Zooms in to the current view, relative to mouse position
  zoomOut(self, factor, fromMouse)
Zooms out from the current view.
  zoomOutMouse(self, factor)
Zooms out from the current view, relative to mouse position
  _addWin(self, hWin)
Makes a window known to this wm object
  _delWin(self, hWin)
Deletes a window's mapping from our dict.

Class Variable Summary
dict windows = {}
dict _keyBindings = {}
dict _keyBindingsArg = {}
dict _optionKeywords = {'bg2': '-bg2', 'bg': '-bg', 'cbg': '-...
dict _options = {}

Method Details

__init__(self, **kwds)
(Constructor)

Constructor.

Creates an FLWM object.

Available keywords are:
  • display (host:#.#) X display & screen to use
  • visual (#) visual to use
  • geometry (WxH+X+Y) limits windows to this area
  • maximum (WxH) size of maximized windows
  • exit - menu says Exit instead of logout
  • bg - (color) Frame color
  • abg - (color) Frame color for active windows
  • fg - (color) Label color
  • bg2 - (color) Text field color
  • cursor - (#) Cursor number for root
  • cfg - (color) Cursor color
  • cbg - (color) Cursor outline color
  • windowclass - class to use when windows get created. should be a subclass of pywm.window

addHandlers(self, **kwds)

Add a set of handlers for various events.

These are given as 'eventname=func' keywords.

Available eventname keywords are:
  • startup - when WM is started:
    • handler receives no arguments
  • create - when a window is created (or unhidden):
    • handler is called with a single window arg
  • destroy - when a window is destroyed (or hidden)
    • handler is called with a single window arg
  • activate - when a window gets activated
    • handler is called with a single window arg
  • deactivate - when a window is deactivated
    • handler is called with a single window arg
  • keyevent - when a keystroke is received:
    • handler is called with keystroke
  • buttonpress - when a mouse button gets clicked:
    • handler is called with button number
  • resize - when a window gets resized:
    • handler is called with window as arg

bindKey(self, func, arg, key, shift, control, alt, meta)

Allows you to bind a Ctrl-Alt key combo to a function

Arguments:
  • func - function to call when key gets pressed
  • arg - an argument to pass to the function. Can be a number, string, list, tuple, dict or anything you like.
  • key - key to bind - either:
    • a single character
    • one of 'f1'..'f12'
    • one of 'kp0'..'kp9', or 'kpenter'
    • one of 'enter', 'tab', 'backspace', 'intert', 'delete', 'home', 'end', 'pageup', 'pagedown', 'up', 'down', 'left', 'right'
  • shift - whether shift key is added - 0 or 1
  • control - whether control key is added - 0 or 1
  • alt - whether alt key is added - 0 or 1
  • meta - whether meta key is added - 0 or 1

When the key combination gets pressed, the function you give will get called with the argument you give.

If you find it hard to remember the 'shift'/'control'/'alt'/'meta' order, just think 'history' - the Shift key was the first to be added (in typewriters), then Ctrl (with ASCII), then Alt (with the IBM PC), then Meta (contributed by Microsoft with Windows).

cascadeWindows(self, spacing=30)

Arranges all the windows cascaded from top left.

closeCurrent(self, arg=None)

Closes current window

getMousePos(self, arg=None)

Returns the current x, y coordinates of the mouse as a tuple

getScreenSize(self, arg=None)

Returns x, y size of the screen as a tuple

goNextDesk(self, arg=None)

Switches to next desk

goNextWindow(self, arg=None)

Switches to next window

goPrevDesk(self, arg=None)

Switches to previous desk

goPrevWindow(self, arg=None)

Switches to previous window

indexFromWindow(self, win)

Returns the index of win in the window creation order, or -1 if there (oops) is no such window.

launch(self, cmd)

Launch a new window in a separate process

Arguments:
  • cmd - a command to run in the shell to create the window. Syntax of this is anything acceptable to os.system().
If you want that command to run inside a terminal window, then modify your command to invoke your favourite X terminal prog

moveCurrent(self, direction)

Moves the current window in the specified direction.

Arguments:
  • direction - the direction to move. One of:
    • n or north - move to top centre of screen
    • ne or northeast - move to top right of screen
    • e or east - move to centre right of screen
    • se or southeast - move to bottom right of screen
    • s or south - move to bottom centre of screen
    • sw or southwest - move to bottom left of screen
    • w or west - move to centre left of screen
    • nw or northwest - move to top oeft of screen
    • c or centre/center - move to centre of screen
    • up - move up a bit
    • down - move down a bit
    • left - move left a bit
    • right - move right a bit

on_activate(self, win)

Called when an existing window is activated

on_buttonPress(self, button)

Called when a button click is received. Buttons 1, 2, 3, 4, 5 are left-click, right-click, middle-click, wheelscroll up and wheelscroll down, respectively.

If you override this, you should accept a single argument, 'button_num', and return 1 if you've handled it locally, or 0 if you want the WM to handle it instead.

NOT YET WORKING

on_create(self, win)

Called when a new window is created (or an existing one un-hidden)

on_deactivate(self, win)

Called when an existing window is deactivated

on_destroy(self, win)

Called when an existing window is being destroyed (or hidden)

If overriding in a subclass, call this parent method just before you exit

on_enter(self, win)

Called when the mouse pointer enters a window

If overriding, just accept a single argument, hWin

NOT YET WORKING

on_keyEvent(self, key)

Called when a Ctrl-Alt key sequence is received.

on_resize(self, win, x, y, w, h)

Called when the size of the window changes.

If overriding, you need to accept the arguments:
  • hWin, x, y, w, h
where hWin is the python handle for the window and x, y, w, h are the new position and size for the window

on_startup(self)

Callback which is invoked when WM starts up.

Note that this callback fires *after* all the existing windows have been re-framed (and the on_create callbacks fired), and *before* the main WM event loop starts up.

Override this if you want to do your own processing during startup.

pan(self, dx=None, dy=None)

Pans all the windows on the screen

Arguments:
  • dx, dy - x,y offset for panning. default is to pan the windows such that the mouse position is used as the screen's new central point

panDown(self, amount=30)

Pans all the windows on the screen downwards

Arguments:
  • amount - number of pixels to pan, default 30

panLeft(self, amount=30)

Pans all the windows on the screen to the left

Arguments:
  • amount - number of pixels to pan, default 30

panRight(self, amount=30)

Pans all the windows on the screen to the right

Arguments:
  • amount - number of pixels to pan, default 30

panUp(self, amount=30)

Pans all the windows on the screen upwards

Arguments:
  • amount - number of pixels to pan, default 30

resizeCurrent(self, how)

Moves the current window in the specified direction.

Arguments:
  • how - the resize mode:
    • 'taller' - grow vertically
    • 'shorter' - shrink vertically
    • 'wider - grow horizontally
    • 'narrower' - shrink horizontally
    • 'larger' - grow vertically and horizontally
    • 'smaller' - shrink vertically and horizontally

run(self)

Launch the window manager, and receive events via callbacks.

If overriding this in a subclass, don't forget to call this parent method.

showMenu(self, arg=None)

Pops up the main window manager menu

toggleMaxCurrent(self, arg=None)

Toggles maximise on the current window

toggleMaxHeightCurrent(self, arg=None)

Toggles maximise on the current window

toggleMaxWidthCurrent(self, arg=None)

Toggles maximise on the current window

window(self, hWin)

Maps a window handle to a window object.

You should never need to call this yourself

windowFromIndex(self, idx)

Returns a ref to the window with index idx in the creation order

zoom(self, factor=1, xView=None, yView=None)

Zooms in or out by a given factor.

Arguments:
  • factor = float - >1 to zoom in, <1 to zoom out
  • xView, yView - x,y origin to use for the zooming, defaults to centre of screen

zoomIn(self, factor=1.1000000000000001, fromMouse=False)

Zooms in to the current view.

Arguments:
  • factor - amount to zoom by, default 1.1
  • fromMouse - whether to use themouse position as the viewpoint - if False (default), uses centre of screen as view point

zoomInMouse(self, factor=1.1000000000000001)

Zooms in to the current view, relative to mouse position

Arguments:
  • factor - amount to zoom by, default 1.1

zoomOut(self, factor=0.88, fromMouse=False)

Zooms out from the current view.

Arguments:
  • factor - amount to zoom by, default 0.88
  • fromMouse - whether to use themouse position as the viewpoint - if False (default), uses centre of screen as view point

zoomOutMouse(self, factor=0.88)

Zooms out from the current view, relative to mouse position

Arguments:
  • factor - amount to zoom by, default 0.88

_addWin(self, hWin)

Makes a window known to this wm object

Used by the lower level window create event handler. Don't call this yourself.

_delWin(self, hWin)

Deletes a window's mapping from our dict.

Called by underlying handler of window delete events.

Don't call this yourself

Class Variable Details

windows

Type:
dict
Value:
{}                                                                     

_keyBindings

Type:
dict
Value:
{}                                                                     

_keyBindingsArg

Type:
dict
Value:
{}                                                                     

_optionKeywords

Type:
dict
Value:
{'bg': '-bg',
 'bg2': '-bg2',
 'cbg': '-cbg',
 'cfg': '-cfg',
 'cursor': '-c',
 'display': '-d',
 'exit': '-x',
 'fg': '-fg',
...                                                                    

_options

Type:
dict
Value:
{}                                                                     

Generated by Epydoc 2.1 on Mon Feb 27 15:47:08 2006 http://epydoc.sf.net