/usr/share/pyshared/guiqwt/widgets/rotatecrop.py is in python-guiqwt 2.3.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | # -*- coding: utf-8 -*-
#
# Copyright © 2012 CEA
# Pierre Raybaut
# Licensed under the terms of the CECILL License
# (see guiqwt/__init__.py for details)
"""
rotatecrop
----------
The `rotatecrop` module provides a dialog box providing essential GUI elements
for rotating (arbitrary angle) and cropping an image:
* :py:class:`guiqwt.widgets.rotatecrop.RotateCropDialog`: dialog box
* :py:class:`guiqwt.widgets.rotatecrop.RotateCropWidget`: equivalent widget
Reference
~~~~~~~~~
.. autoclass:: RotateCropDialog
:members:
:inherited-members:
.. autoclass:: RotateCropWidget
:members:
:inherited-members:
"""
from PyQt4.QtGui import QCheckBox
from PyQt4.QtCore import SIGNAL
# Local imports
from guiqwt.config import _
from guiqwt.builder import make
from guiqwt.image import get_image_in_shape
from guiqwt.widgets import base
class RotateCropMixin(base.BaseTransformMixin):
"""Rotate & Crop mixin class, to be mixed with a class providing the
get_plot method, like ImageDialog or RotateCropWidget (see below)"""
def __init__(self):
base.BaseTransformMixin.__init__(self)
self.crop_rect = None
#------BaseTransformMixin API----------------------------------------------
def add_buttons_to_layout(self, layout):
"""Add tool buttons to layout"""
# Show crop rectangle checkbox
show_crop = QCheckBox(_("Show cropping rectangle"), self)
show_crop.setChecked(True)
self.connect(show_crop, SIGNAL("toggled(bool)"), self.show_crop_rect)
layout.addWidget(show_crop)
layout.addSpacing(15)
base.BaseTransformMixin.add_buttons_to_layout(self, layout)
def set_item(self, item):
"""Set associated item -- must be a TrImageItem object"""
base.BaseTransformMixin.set_item(self, item)
crect = make.annotated_rectangle(0, 0, 1, 1, _("Cropping rectangle"))
self.crop_rect = crect
crect.annotationparam.format = "%.1f cm"
plot = self.get_plot()
plot.add_item(crect)
plot.set_active_item(crect)
x0, y0, x1, y1 = self.item.get_crop_coordinates()
crect.set_rect(x0, y0, x1, y1)
plot.replot()
def reset_transformation(self):
"""Reset transformation"""
x0, y0, x1, y1 = self.item.border_rect.get_rect()
self.crop_rect.set_rect(x0, y0, x1, y1)
def apply_transformation(self):
"""Apply transformation, e.g. crop or rotate"""
# Let's crop!
i_points = self.item.border_rect.get_points()
xmin, ymin = i_points.min(axis=0)
xmax, ymax = i_points.max(axis=0)
xc0, yc0, xc1, yc1 = self.crop_rect.shape.get_rect()
left = max([0, xc0-xmin])
right = max([0, xmax-xc1])
top = max([0, yc0-ymin])
bottom = max([0, ymax-yc1])
self.item.set_crop(left, top, right, bottom)
# print "set_crop:", left, top, right, bottom
self.item.compute_bounds()
self.get_plot().replot()
def compute_transformation(self):
"""Compute transformation, return compute output array"""
return get_image_in_shape(self.crop_rect, apply_interpolation=False)
#------Private API---------------------------------------------------------
def show_crop_rect(self, state):
"""Show/hide cropping rectangle shape"""
self.crop_rect.setVisible(state)
self.crop_rect.label.setVisible(state)
self.get_plot().replot()
class RotateCropDialog(base.BaseTransformDialog, RotateCropMixin):
"""Rotate & Crop Dialog
Rotate and crop a :py:class:`guiqwt.image.TrImageItem` plot item"""
def __init__(self, parent, wintitle=None, options=None, resize_to=None):
RotateCropMixin.__init__(self)
base.BaseTransformDialog.__init__(self, parent, wintitle=wintitle,
options=options, resize_to=resize_to)
class RotateCropWidget(base.BaseTransformWidget, RotateCropMixin):
"""Rotate & Crop Widget
Rotate and crop a :py:class:`guiqwt.image.TrImageItem` plot item"""
def __init__(self, parent, options=None):
base.BaseTransformWidget.__init__(self, parent, options=options)
RotateCropMixin.__init__(self)
class MultipleRotateCropWidget(base.BaseMultipleTransformWidget):
"""Multiple Rotate & Crop Widget
Rotate and crop several :py:class:`guiqwt.image.TrImageItem` plot items"""
TRANSFORM_WIDGET_CLASS = RotateCropWidget
|