Class ImageToolSelector
IImageTool --+
|
ImageToolSelector
ImageToolSelector is a tool for selecting areas of an image. It is
useful for cropping an image, for example. The tool is an
implementor of the IImageTool inteface which means that it can
be plugged into an ImageView object by using the
ImageView.set_tool() method.
ImageToolSelector changes the default display of the ImageView. It
darkens down the unselected region of the image which provides a
nice effect and makes it clearer what part of the image that is
currently selected. Unfortunately, this effect is somewhat
incompatible with how ImageNav behaves and that widget will show
the image without darkening it.
The tool also changes the default behaviour of the mouse. When an
ImageToolSelector is set on an ImageView, mouse presses do not
"grab" the image and you cannot scroll by dragging. Instead mouse
presses and dragging is used to resize and move the selection
rectangle. When the mouse drags the selection rectangle to the
border of the widget, the view autoscrolls which is a convenient
way for a user to position the selection.
Please note that ImageToolSelector draws the image in two layers.
One darkened and the selection rectangle in normal luminosity.
Because it uses two draw operations instead one one like
ImageToolDragger does, it is significantly slower than that
tool. Therefore, it makes sense for a user of this library to set
the interpolation to gtk.gdk.INTERP_NEAREST when using this
tool to ensure that performance is acceptable to the users of the
program.
Zoom bug
There is a small bug in ImageToolSelector that becomes apparent
when the zoom factor is greater than about 30. The edge of the
selection rectangle may in that case intersect a pixel:
The bug is caused by bug 389832 in
gdk-pixbuf. There is
no way to solve this bug on ImageView's level (but if someone
knows how, I'd really like to know).
__init__(self,
view)
(Constructor)
|
|
Creates a new selector tool for the specified view with default
values. The default values are:
- selection : (0, 0) - [0, 0]
- Parameters:
|
sig_selection_changed(cls)
|
|
The selection-changed signal is emitted when the selection
rectangle on the selector is moved or resized. It is inteded
to be used by applications that wants to print status
information. For example:
def sel_changed_cb(selector):
rect = selector.get_selection()
if not rect.width or not rect.height):
print 'No selection'
else:
fmt = 'The selection is %d, %d - %d, %d'
print fmt % (rect.x, rect.y, rect.width, rect.height)
...
selector.connect('selection-changed', sel_changed_cb)
|
Returns the current selection rectangle in image space
coordinates. If either the width or the height of the
rectangle is zero, then noting is selected and the selection
should be considered inactive.
- Returns:
- the selection rectangle
|
set_selection(self,
rect)
|
|
Sets the selection rectangle for the tool. Setting this
attribute will cause the widget to immediately repaint itself
if its view is realized.
This method does nothing under the following circumstances:
- If the views pixbuf is None.
- If
rect is wider or taller than the size of the pixbuf.
- If
rect equals the current selection rectangle.
If the selection falls outside the pixbufs area, its position
is moved so that it is within the pixbuf.
Calling this method causes the sig_selection_changed signal
to be emitted.
The default selection is (0,0) - [0,0].
- Parameters:
rect - selection rectangle in image space coordinates
|