straditize.widgets.selection_toolbar module¶
Module for the selection toolbar
This module defines the selection toolbar that is added to the
psyplot_gui.main.MainWindow
for selecting features in the
stratigraphic diagram and the data reader image.
Disclaimer
Copyright (C) 2018-2019 Philipp S. Sommer
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Classes
|
RectangleSelector that allows to select points |
|
A toolbar for selecting features in the straditizer and data image |
-
class
straditize.widgets.selection_toolbar.
PointOrRectangleSelector
(ax, onselect, drawtype='box', minspanx=None, minspany=None, useblit=False, lineprops=None, rectprops=None, spancoords='data', button=None, maxdist=10, marker_props=None, interactive=False, state_modifier_keys=None)[source]¶ Bases:
matplotlib.widgets.RectangleSelector
RectangleSelector that allows to select points
This class reimplements the
matplotlib.widgets.RectangleSelector
to select pointsCreate a selector in ax. When a selection is made, clear the span and call onselect with:
onselect(pos_1, pos_2)
Methods
press
(*args, **kwargs)Button press handler and validator
and clear the drawn box/line. The
pos_1
andpos_2
are arrays of length 2 containing the x- and y-coordinate.If minspanx is not None then events smaller than minspanx in x direction are ignored (it’s the same for y).
The rectangle is drawn with rectprops; default:
rectprops = dict(facecolor='red', edgecolor = 'black', alpha=0.2, fill=True)
The line is drawn with lineprops; default:
lineprops = dict(color='black', linestyle='-', linewidth = 2, alpha=0.5)
Use drawtype if you want the mouse to draw a line, a box or nothing between click and actual position by setting
drawtype = 'line'
,drawtype='box'
ordrawtype = 'none'
. Drawing a line would result in a line from vertex A to vertex C in a rectangle ABCD.spancoords is one of ‘data’ or ‘pixels’. If ‘data’, minspanx and minspanx will be interpreted in the same coordinates as the x and y axis. If ‘pixels’, they are in pixels.
button is a list of integers indicating which mouse buttons should be used for rectangle selection. You can also specify a single integer if only a single button is desired. Default is None, which does not limit which button can be used.
- Note, typically:
1 = left mouse button 2 = center mouse button (scroll wheel) 3 = right mouse button
interactive will draw a set of handles and allow you interact with the widget after it is drawn.
state_modifier_keys are keyboard modifiers that affect the behavior of the widget.
The defaults are: dict(move=’ ‘, clear=’escape’, square=’shift’, center=’ctrl’)
Keyboard modifiers, which: ‘move’: Move the existing shape. ‘clear’: Clear the current shape. ‘square’: Makes the shape square. ‘center’: Make the initial point the center of the shape. ‘square’ and ‘center’ can be combined.
-
class
straditize.widgets.selection_toolbar.
SelectionToolbar
(straditizer_widgets, *args, **kwargs)[source]¶ Bases:
PyQt5.QtWidgets.QToolBar
,straditize.widgets.StraditizerControlBase
A toolbar for selecting features in the straditizer and data image
The current data object is set in the
combo
and can be accessed through thedata_obj
attribute. It’s either the straditizer or the data_reader that is accessedMethods
Enable the removing or adding of the pattern selection
Clear the current selection
Define the actions for the toolbar and set everything up
disconnect
(self)Enable or disable the widgets in this control
Finish the selection and disconnect everything
Expand the selected areas to select the full labels
get_xy_slice
(lastx, lasty, x, y)Transform x- and y-coordinates to
slice
objectsInvert the current selection
on_poly_select
(points)Call the
poly_callbacks
after a polygon selectionon_rect_select
(e0, e1)Call the
rect_callbacks
after a rectangle selectionrefresh
()Refresh from the straditizer
Select all features in the image
Selects everything to the right of the current selection
select_poly
(points)Select the data defined by a polygon
select_rect
(slx, sly)Select the data defined by a rectangle
Set the current pattern mode to the binary pattern
Set the current wand tool to the color wand
Set the current wand tool to the color wand
Set the current pattern mode to the binary pattern
Set the current wand tool to the color wand
Set the current wand tool to the color wand
Set the current wand tool to the color wand
Set the current wand tool to the color wand
Check if a widget should be enabled
Open the pattern selection dialog
start_selection
([arr, rgba, rect_callbacks, …])Start the selection in the current
data_obj
Activate selection mode
Disable the pattern selection
update_alpha
(i)Set the transparency of the selection image
Attributes
The action to add to the current selection with the selection tools
The
matplotlib.axes.Axes
of thedata_obj
The canvas of the
data_obj
An action to clear the current selection
The QCombobox that defines the data object to be used
The np.ndarray of the
data_obj
imageThe data object as set in the
combo
.An action to expand the current selection to the full feature
The
Figure
of thedata_obj
An action to invert the current selection
The labeled data that is displayed
The action to make new selection with one of the selection tools
The functions to call after the polygon selection
The functions to call after the rectangle selection.
An action to remove from the current selection with the selection tools
The rectangle selection tool
An action to select all features in the
data
An action to start a pattern selection
An action to select everything in the data column to the right
selected
(*args, **kwargs)A signal that is emitted when something is selected
A
PointOrRectangleSelector
to select features in the imageThe toolbar of the
canvas
The wand selection tool
Built-in mutable sequence.
-
property
add_select_action
¶ The action to add to the current selection with the selection tools
-
property
ax
¶ The
matplotlib.axes.Axes
of thedata_obj
-
property
clear_select_action
¶ An action to clear the current selection
-
combo
= None¶ The QCombobox that defines the data object to be used
-
property
data_obj
¶ The data object as set in the
combo
.Either a
Straditizer
or astraditize.binary.DataReader
instance.
-
enable_or_disable_widgets
(b)[source]¶ Enable or disable the widgets in this control
This method enables or disables the
widgets2disable
if theshould_be_enabled()
method evaluates to True- Parameters
b (bool) – If True, enable the widgets, if False, disable them
-
property
expand_select_action
¶ An action to expand the current selection to the full feature
-
property
invert_select_action
¶ An action to invert the current selection
-
property
labels
¶ The labeled data that is displayed
-
property
new_select_action
¶ The action to make new selection with one of the selection tools
-
on_poly_select
(points)[source]¶ Call the
poly_callbacks
after a polygon selection- Parameters
e0 (matplotlib.backend_bases.Event) – The initial event
e1 (matplotlib.backend_bases.Event) – The final event
-
on_rect_select
(e0, e1)[source]¶ Call the
rect_callbacks
after a rectangle selection- Parameters
e0 (matplotlib.backend_bases.Event) – The initial event
e1 (matplotlib.backend_bases.Event) – The final event
-
property
poly_callbacks
¶ The functions to call after the polygon selection
If not set manually, it is the
select_poly()
method. Note that this is cleared at every call of theend_selection()
.Callables in this list must accept one argument, a
np.ndarray
of shape(N, 2)
. This array defines theN
x- and y-coordinates of the points of the polygon
-
property
rect_callbacks
¶ The functions to call after the rectangle selection.
If not set manually, it is the
select_rect()
method. Note that this is cleared at every call of theend_selection()
.Callables in this list must accept two arguments
(slx, sly)
: the first one is the x-slice, and the second one the y-slice. They both correspond to thedata
attribute.
-
property
remove_select_action
¶ An action to remove from the current selection with the selection tools
-
reset_cursor_id
= None¶
-
property
select_action
¶ The rectangle selection tool
-
property
select_pattern_action
¶ An action to start a pattern selection
-
select_poly
(points)[source]¶ Select the data defined by a polygon
- Parameters
points (np.ndarray of shape (N, 2)) – The x- and y-coordinates of the vertices of the polygon
See also
-
property
select_right_action
¶ An action to select everything in the data column to the right
-
selected
(*args, **kwargs)¶ A signal that is emitted when something is selected
-
selector
= None¶ A
PointOrRectangleSelector
to select features in the image
-
set_cursor_id
= None¶
-
should_be_enabled
(w)[source]¶ Check if a widget should be enabled
This function checks if a given widget w from the
widgets2disable
attribute should be enabled or not- Parameters
w (QWidget) – The widget to check
- Returns
True, if the widget should be enabled
- Return type
-
start_pattern_selection
()[source]¶ Open the pattern selection dialog
This method will enable the pattern selection by starting a
straditize.widgets.pattern_selection.PatternSelectionWidget
-
start_selection
(arr=None, rgba=None, rect_callbacks=None, poly_callbacks=None, apply_funcs=(), cancel_funcs=(), remove_on_apply=True)[source]¶ Start the selection in the current
data_obj
- Parameters
arr (np.ndarray) – The labeled selection array that is used. If specified, the
enable_label_selection()
method is called of thedata_obj
with the given arr. If this parameter isNone
, then we expect that this method has already been calledrgba (np.ndarray) – The RGBA image that shall be used for the color selection (see the
set_color_wand_mode()
)rect_callbacks (list) – A list of callbacks that shall be called after a rectangle selection has been made by the user (see
rect_callbacks
)poly_callbacks (list) – A list of callbacks that shall be called after a polygon selection has been made by the user (see
poly_callbacks
)apply_funcs (list) – A list of callables that shall be connected to the
apply_button
cancel_funcs (list) – A list of callables that shall be connected to the
cancel_button
remove_on_apply (bool) – If True and the
apply_button
is clicked, the selected labels will be removed.
-
update_alpha
(i)[source]¶ Set the transparency of the selection image
- Parameters
i (int) – The transparency between 0 and 100
-
property
wand_action
¶ The wand selection tool
-
property
widgets2disable
¶ Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.
-
property