Tool class

Properties of the Tool class:

Property

Explanation

cursor

Allows you to update your cursor when the tool is clicked. By default, the cursor is set to 0. The choices of cursor ID values are shown here:

Types of cursors with icons and codes
enabled

Returns the availability of the tool, where by default it is set to True. When this property is set to False, the tool is disabled and unavailable. This property allows you to write logic to test the state of the desktop application in order to disable or enable the tool. For example, you might have a tool that requires a data layer to be loaded in ArcMap before execution is possible.

shape

Allows you to specify the type of shape that is drawn on the map. The shape can be used to select features, define an extent, or used as input to geoprocessing tools. After the shape is added to the map, the shape will dissappear from the display and its corresponding function is called. The functions are explained below.

There are three types of shapes that can be defined:

  • Line
  • Rectangle
  • Circle

Function

Explanation

__init__(self)

This is a Python built-in function referred to as the constructor where some initial variables can be defined. By default, the cursor and enabled properties of the tool is initially set for you.

onDblClick(self)

Occurs when a mouse button is double-clicked when this tool is active.

onCircle(self, circle_geometry)

Occurs when the mouse button is released after the circle is drawn on the map. circle_geometry represents a polygon object.

onLine(self, line_geometry)

Occurs when the mouse button is double-clicked to finish drawing the line on the map. line_geometry represents a Polyline object.

onRectangle(self, rectangle_geometry)

Occurs when the mouse button is released after the rectangle is drawn on the map. rectangle_geometry represents an Extent object.

onMouseDown(self, x, y, button, shift)

Occurs when a mouse button is released when this tool is active.

  • The x and y values for onMouseDown and onMouseUp represent the window coordinates where the mouse button was pressed or released. The x and y values for onMouseDownMap and onMouseUpMap represent the map coordinates where the button was pressed or released.
  • button specifies which mouse button is pressed. The values returned for the button are listed below.
  • shift indicates whether the SHIFT key, CTRL key, or ALT key is pressed when the mouse button is released. The values returned for shift are listed below.

onMouseDownMap(self, x, y, button, shift)

onMouseUp(self, x, y, button, shift)

onMouseUpMap(self, x, y, button, shift)

onKeyDown(self, keycode, shift)

Occurs when a key on the keyboard is pressed (onKeyDown) or released (onKeyUp) when this tool is active.

  • keycode specifies which key on the keyboard was pressed.
  • shift indicates whether the SHIFT key, CTRL key, or ALT key is pressed when the key button is also pressed. The values returned for shift are listed below.

onKeyUp(self, keycode, shift)

deactivate(self)

Causes the tool to no longer be the active tool.

Functions of the Tool class

Key code

Keys that are pressed

0

No key

1

SHIFT key

2

CTRL key

3

SHIFT + CTRL keys

4

ALT key

5

SHIFT + ALT keys

6

CTRL + ALT keys

7

SHIFT + CTRL + ALT keys

Key codes

Button code

Mouse buttons that are pressed

1

Left button

2

Right button

3

Left and Right buttons

4

Middle button

5

Left and Middle buttons

6

Right and Middle buttons

7

All buttons

Mouse button codes

Related Topics

10/29/2012