Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: Unavailable Standard PGPLOT Methods Up: Glish/PGPLOT Previous: Hints

Subsections


Non-Standard Methods

The non-standard commands available from the pgplot agent are documented here to avoid ``contaminating'' your knowledge of standard PGPLOT. Note also that these commands are only available when the device is the Tk device, not when it is the PostScript device.

bind
- notice cursor, mouse button, and keyboard events
cursor
- set the cursor in the pgplot window
height
- height of the pgplot display widget in pixels
width
- width of the pgplot display widget in pixels


bind - notice cursor, mouse button, and keyboard events

    pg->bind (EVENT, NAME)
    String EVENT, NAME

This method turns on a ``reception'' of X-events. That is, whenever X-event EVENT is seen, glish event NAME is emitted. For example, the following code puts up a grid and prints the world value of the current cursor position in a label below the plot widget:

    f := frame (side='top');
    pg := pgplot (f, width=400, height=400);
    pg->env (-100, 100, -100, 100, 0, 2);
    xylabel := label (f, width=20);
    pg->bind ('<Motion>', 'motion');
    whenever pg->motion do
        xylabel->text (paste (as_string ($value.world)));

While there are a lot of possible X events, the ones that are most apt to be of interest are the following. Note that in the bind method you enclose the X event name in angle brackets (<>).

Button
This event occurs whenever a mouse button is pressed. If bound, the returned event has the form:

[world=[wx, wy], device=[dx, dy], button=bn, type='ButtonPress']

where ``world'' is the floating point position in PGPLOT world coordinates, ``device'' is an integral pixel position, and ``button'' is the button number (i.e., 1, 2, or 3 for a three-button mouse). If you are interested in only a particular mouse button, you can specify it by appending it with a dash, e.g., pg->bind('<Button-1>', 'b1'). If you are interested in a double click, you can specify it as: pg->bind('<Double-1>', 'double'). Binding any button other than the first to double-clicking is perverse.

ButtonRelease
This event is exactly like Button, except that it occurs when the button is released. It also can be specified as, e.g., ButtonRelease-1. The returned event has exactly the same format as for Button, except that type='ButtonRelease'.
Motion
This event is generated whenever the cursor is moved inside the PGPLOT widget. If bound, the form of the returned event is:

[world=[wx, wy], device=[dx, dy], type='MotionNotify']

Key
This event occurs whenever a key is pressed on the keyboard. This includes ``special'' keys. The returned event is:

[world=[wx, wy], device=[dx, dy], key=ch, type='KeyPress']

where ``world'' is the floating point position in PGPLOT world coordinates, ``device'' is an integral pixel position, and ``ch'' is a string that contains the pressed key, or the string '<UNKNOWN>' if the key does not have an ASCII representation. If you are interested in only a particular key, you can specify it by appending it with a dash, e.g., pg->bind ('<Key-a>, 'a') causes events to be emitted only when the lower case a is pressed.

KeyRelease
This event has the same relation to Key that ButtonRelease has to Button.

Note that there's no ``drag'' event, but you can have the same effect by keeping track of mouse-button presses and releases. For example, the following example draws on the pgplot widget when the mouse is moved while a button is pressed (``scribble''):

    f := frame ();
    pg := pgplot (f, width=400, height=400);
    pg->env (-100, 100, -100, 100, 0, -1);
    pg->bind ('<Motion>', 'motion');
    pg->bind ('<Button>', 'button');
    pg->bind ('<ButtonRelease>', 'button');

    last := [0, 0];
    pressed := F;

    whenever pg->button do {
        global pressed, last;
        pressed := ($value.type == 'ButtonPress'); # T or F
        last := $value.world;
    }
    whenever pg->motion do {
        global last, pressed;
        if (pressed)
            pg->line ([last[1], $value.world[1]],  # x
                      [last[2], $value.world[2]]); # y
        last := $value.world;
    }

A very poor typewriter is implemented in the following example. The example is poor because it doesn't handle special ``characters'' other than space, and it doesn't wrap in ``y'' when it reaches the end of the screen.

    f := frame ();
    pg := pgplot (f, width=400, height=400);
    pg->env (0, 1, 1, 0, 0, -2);
    pg->sch (3);           # set character height
    ych := pg->qcs (4)[2]; # y character height
    xch := 3 / 40;         # good enough for spaces
    pg->bind ('<Key>', 'key');

    pos := [0, 0 - ych];   # position to write next char

    whenever pg->key do {
        global pos;
        if ($value.key == ' ') {
            pos[1] +:= xch;
        } else if ($value.key == '<UNKNOWN>' ) {
            # Ignore
        } else {
            bounds := pg->qtxt (pos[1], pos[2], 0, 0, $value.key);
            if (bounds[4] > 1) { # wrap?
                pos[1] := 0;
                pos[2] -:= ych;
            }
            bounds := pg->qtxt (pos[1], pos[2], 0, 0, $value.key);
            pg->ptxt (pos[1], pos[2], 0, 0, spaste ($value.key));
            pos[1] := bounds[4];
        }
    }

Note that at present, there is no way to unbind an event once bound. You can, of course, deactivate the whenever's that process the events, but the events are still being generated.

Arguments:
 EVENT : the X-event you want to notice.
 NAME  : the name of the glish event generated.



cursor - set the cursor in the pgplot window

    String mode := pg->cursor (mode='', x=0, y=0, color=1)
    String mode
    Integer color, x, y

This function lets you set the reference position, cursor position, and color. The reference position is, for example, the ``starting'' position for a rectangle (rubber band) cursor. This is probably best illustrated with an example. In the following, whenver a button down is detected, a rectangle cursor is started with the reference position at the location where the button was pressed. When the button is released, the cursor is returned to normal, and a permanent rectangle is drawn from the reference position to the cursors last position.

    f := frame ();
    pg := pgplot (f, width=400, height=400);
    pg->env (0, 100, 0, 100, 0, 0);
    pg->bind ('<Button-1>', 'down');
    pg->bind ('<ButtonRelease-1>', 'up');

    start := [0, 0];

    whenever pg->down do {
        global start;
        start := $value.world;
        pg->cursor ('rect', x=$value.world[1], y=$value.world[2]);
    }
    whenever pg->up do {
        global start;
        pg->cursor ('norm');
        pg->rect (start[1], $value.world[1], start[2], $value.world[2]);
    }

The available modes for the cursor are:

norm
Un-augmented X cursor.
line
Line cursor between ref and pointer.
rect
Rectangle between ref and pointer.
yrng
Horizontal lines at ref.x and pointer.x.
xrng
Vertical lines at ref.y and pointer.y.
hline
Horizontal line cursor at y = ref.y.
vline
Vertical line cursor at x = ref.x.
cross
Pointer centered cross-hair.



height - notice cursor, mouse button, and keyboard events

    HEIGHT := pg->height ();
    Integer HEIGHT;
Height of the PGPLOT widget.


width - notice cursor, mouse button, and keyboard events

    WIDTH := pg->width ();
    Integer WIDTH;
Width of the PGPLOT widget.


next up previous contents index
Next: Unavailable Standard PGPLOT Methods Up: Glish/PGPLOT Previous: Hints   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15