Class GWindow

The GWindow class implements the background canvas for the Portable Graphics Library. Graphical applications begin by creating a new GWindow object and then assemble a collage-like display by adding instances of type GObject to the window. By convention, the first statement in an application that uses the Portable Graphics Library is

    gw = GWindow(GWINDOW_WIDTH, GWINDOW_HEIGHT)

in which GWINDOW_WIDTH and GWINDOW_HEIGHT are constants specifying the dimensions of the window in pixels.

As an example, the following program displays a blue rectangle on the screen:

    from pgl import GWindow, GRect

    GWINDOW_WIDTH = 500
    GWINDOW_HEIGHT = 200

    def BlueRectangle():
        gw = GWindow(GWINDOW_WIDTH, GWINDOW_HEIGHT)
        rect = GRect(150, 50, 200, 100)
        rect.setColor("Blue")
        rect.setFilled(True)
        gw.add(rect)


Constructor Summary
GWindow()
Creates a new GWindow with a default preferred size.
GWindow(width, height)
Creates a new GWindow and sets the size of its canvas to the specified width and height.
 
Method Summary
add(gobj)
Adds the graphical object to this canvas.
add(gobj, x, y)
Adds the graphical object to this canvas and sets its location to the point (xy).
addEventListener(type, fn)
Registers a new listener for events of the specified type occuring in the window.
createTimer(fn, delay)
Creates a new timer object that calls fn after the specified delay, which is measured in milliseconds.
getElement(k)
Returns the graphical object at index k, numbering from back to front in the z dimension.
getElementAt(x, y)
Returns the topmost graphical object that contains the point (x, y), or None if no such object exists.
getWindowHeight()
Returns the height of the window in pixels.
getWindowWidth()
Returns the width of the window in pixels.
remove(gobj)
Returns the number of graphical objects stored in this GWindow.
remove(gobj)
Removes a graphical object from the window.
 

Constructor Detail

GWindow()

Creates a new GWindow with a default size.
Usage: gw = GWindow() 
 


GWindow(width, height)

Creates a new GWindow with the specified dimensions.
Usage: gw = GWindow(width, height) 
Parameters: 
width  The width of the window in pixels
height  The height of the window in pixels.
 

Method Detail

add(gobj)

Adds the graphical object to this canvas.
Usage: gw.add(gobj) 
Parameter: 
gobj  The graphical object to add
 


add(gobj, x, y)

Adds the graphical object to this canvas and sets its location to the point (xy).
Usage: gw.add(gobj, x, y) 
Parameters: 
gobj  The graphical object to add
 The new x-coordinate for the object
 The new y-coordinate for the object
 


addEventListener(type, fn)

Registers a new listener for events of the specified type occuring in the window. The type parameter should be one of the strings "mousedown", "mouseup", "click", "mousemove", "mousemove", or "drag".
Usage: timer = gw.addEventListener(type, fn) 
Parameter: 
type  The event type
fn  The callback function
 


createTimer(fn, delay)

Creates a new timer object that calls fn after the specified delay, which is measured in milliseconds. The timer must be started by calling its start method.
Usage: timer = gw.createTimer(fn, delay) 
Parameter: 
fn  The callback function
delay  The delay, measured in milliseconds
Returns: The GTimer object that implements the timer
 


getElement(k)

Returns the graphical object at index k, numbering from back to front in the the z dimension.
Usage: gobj = gw.getElement(index) 
Parameter: 
index  The index of the component to return
Returns: The graphical object at the specified index
 


getElementAt(x, y)

Returns the topmost graphical object that contains the point (x, y), or None if no such object exists.
Usage: gobj = gw.getElementAt(x, y) 
Parameters: 
 The x-coordinate of the point being tested
 The y-coordinate of the point being tested
Returns: The graphical object at the specified location, or None if no such object exists
 


getElementCount()

Returns the number of graphical objects stored in this GWindow.
Usage: n = gw.getElementCount() 
Returns: The number of graphical objects in this GWindow
 


getWindowHeight()

Returns the height of this window in pixels.
Usage: height = gw.getWindowHeight() 
Returns: The height of this window in pixels
 


getWindowWidth()

Returns the width of this window in pixels.
Usage: width = gw.getWindowWidth() 
Returns: The width of this window in pixels
 


remove(gobj)

Removes a graphical object from the window.
 
Usage: gw.remove(gobj) 
Parameter: 
gobj  The graphical object to remove