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

PointOrRectangleSelector(ax, onselect[, …])

RectangleSelector that allows to select points

SelectionToolbar(straditizer_widgets, *args, …)

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 points

Create 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 and pos_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' or drawtype = '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.

press(*args, **kwargs)[source]

Button press handler and validator

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 the data_obj attribute. It’s either the straditizer or the data_reader that is accessed

Methods

add_or_remove_pattern()

Enable the removing or adding of the pattern selection

clear_selection()

Clear the current selection

create_actions()

Define the actions for the toolbar and set everything up

disable_actions()

disconnect(self)

enable_or_disable_widgets(b)

Enable or disable the widgets in this control

end_selection()

Finish the selection and disconnect everything

expand_selection()

Expand the selected areas to select the full labels

get_xy_slice(lastx, lasty, x, y)

Transform x- and y-coordinates to slice objects

invert_selection()

Invert the current selection

on_poly_select(points)

Call the poly_callbacks after a polygon selection

on_rect_select(e0, e1)

Call the rect_callbacks after a rectangle selection

refresh()

Refresh from the straditizer

select_all()

Select all features in the image

select_everything_to_the_right()

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_binary_pattern_mode()

Set the current pattern mode to the binary pattern

set_col_wand_mode()

Set the current wand tool to the color wand

set_color_wand_mode()

Set the current wand tool to the color wand

set_grey_pattern_mode()

Set the current pattern mode to the binary pattern

set_label_wand_mode()

Set the current wand tool to the color wand

set_poly_select_mode()

Set the current wand tool to the color wand

set_rect_select_mode()

Set the current wand tool to the color wand

set_row_wand_mode()

Set the current wand tool to the color wand

should_be_enabled(w)

Check if a widget should be enabled

start_pattern_selection()

Open the pattern selection dialog

start_selection([arr, rgba, rect_callbacks, …])

Start the selection in the current data_obj

toggle_selection()

Activate selection mode

uncheck_pattern_selection()

Disable the pattern selection

update_alpha(i)

Set the transparency of the selection image

Attributes

add_select_action

The action to add to the current selection with the selection tools

ax

The matplotlib.axes.Axes of the data_obj

canvas

The canvas of the data_obj

clear_select_action

An action to clear the current selection

combo

The QCombobox that defines the data object to be used

data

The np.ndarray of the data_obj image

data_obj

The data object as set in the combo.

expand_select_action

An action to expand the current selection to the full feature

fig

The Figure of the data_obj

invert_select_action

An action to invert the current selection

labels

The labeled data that is displayed

new_select_action

The action to make new selection with one of the selection tools

poly_callbacks

The functions to call after the polygon selection

rect_callbacks

The functions to call after the rectangle selection.

remove_select_action

An action to remove from the current selection with the selection tools

select_action

The rectangle selection tool

select_all_action

An action to select all features in the data

select_pattern_action

An action to start a pattern selection

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

A PointOrRectangleSelector to select features in the image

toolbar

The toolbar of the canvas

wand_action

The wand selection tool

widgets2disable

Built-in mutable sequence.

add_or_remove_pattern()[source]

Enable the removing or adding of the pattern selection

property add_select_action

The action to add to the current selection with the selection tools

property ax

The matplotlib.axes.Axes of the data_obj

property canvas

The canvas of the data_obj

property clear_select_action

An action to clear the current selection

clear_selection()[source]

Clear the current selection

combo = None

The QCombobox that defines the data object to be used

create_actions()[source]

Define the actions for the toolbar and set everything up

property data

The np.ndarray of the data_obj image

property data_obj

The data object as set in the combo.

Either a Straditizer or a straditize.binary.DataReader instance.

disable_actions()[source]
disconnect(self)[source]
enable_or_disable_widgets(b)[source]

Enable or disable the widgets in this control

This method enables or disables the widgets2disable if the should_be_enabled() method evaluates to True

Parameters

b (bool) – If True, enable the widgets, if False, disable them

end_selection()[source]

Finish the selection and disconnect everything

property expand_select_action

An action to expand the current selection to the full feature

expand_selection()[source]

Expand the selected areas to select the full labels

property fig

The Figure of the data_obj

get_xy_slice(lastx, lasty, x, y)[source]

Transform x- and y-coordinates to slice objects

Parameters
  • lastx (int) – The initial x-coordinate

  • lasty (int) – The initial y-coordinate

  • x (int) – The final x-coordinate

  • y (int) – The final y-coordinate

Returns

  • slice – The slice(lastx, x)

  • slice – The slice(lasty, y)

property invert_select_action

An action to invert the current selection

invert_selection()[source]

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
on_rect_select(e0, e1)[source]

Call the rect_callbacks after a rectangle selection

Parameters
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 the end_selection().

Callables in this list must accept one argument, a np.ndarray of shape (N, 2). This array defines the N 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 the end_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 the data attribute.

refresh()[source]

Refresh from the straditizer

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

select_all()[source]

Select all features in the image

property select_all_action

An action to select all features in the data

select_everything_to_the_right()[source]

Selects everything to the right of the current selection

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

poly_callbacks()

select_rect(slx, sly)[source]

Select the data defined by a rectangle

Parameters
  • slx (slice) – The x-slice of the rectangle

  • sly (slice) – The y-slice of the rectangle

See also

rect_callbacks()

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_binary_pattern_mode()[source]

Set the current pattern mode to the binary pattern

set_col_wand_mode()[source]

Set the current wand tool to the color wand

set_color_wand_mode()[source]

Set the current wand tool to the color wand

set_cursor_id = None
set_grey_pattern_mode()[source]

Set the current pattern mode to the binary pattern

set_label_wand_mode()[source]

Set the current wand tool to the color wand

set_poly_select_mode()[source]

Set the current wand tool to the color wand

set_rect_select_mode()[source]

Set the current wand tool to the color wand

set_row_wand_mode()[source]

Set the current wand tool to the color wand

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

bool

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 the data_obj with the given arr. If this parameter is None, then we expect that this method has already been called

  • rgba (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.

toggle_selection()[source]

Activate selection mode

property toolbar

The toolbar of the canvas

uncheck_pattern_selection()[source]

Disable the pattern selection

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.