/usr/share/pyshared/guiqwt/widgets/fliprotate.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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | # -*- coding: utf-8 -*-
#
# Copyright © 2012 CEA
# Pierre Raybaut
# Licensed under the terms of the CECILL License
# (see guiqwt/__init__.py for details)
"""
fliprotate
----------
The `FlipRotate` module provides a dialog box providing essential GUI elements
for rotating (arbitrary angle) and cropping an image:
* :py:class:`guiqwt.widgets.fliprotate.FlipRotateDialog`: dialog box
* :py:class:`guiqwt.widgets.fliprotate.FlipRotateWidget`: equivalent widget
Reference
~~~~~~~~~
.. autoclass:: FlipRotateDialog
:members:
:inherited-members:
.. autoclass:: FlipRotateWidget
:members:
:inherited-members:
"""
from PyQt4.QtGui import QLabel, QComboBox
from PyQt4.QtCore import SIGNAL
import numpy as np
from guidata.qthelpers import create_toolbutton
from guidata.configtools import get_icon
# Local imports
from guiqwt.config import _
from guiqwt.widgets import base
class FlipRotateMixin(base.BaseTransformMixin):
"""Rotate & Crop mixin class, to be mixed with a class providing the
get_plot method, like ImageDialog or FlipRotateWidget (see below)"""
ROTATION_ANGLES = [str((i-1)*90) for i in range(4)]
#------BaseTransformMixin API----------------------------------------------
def add_buttons_to_layout(self, layout):
"""Add tool buttons to layout"""
# Image orientation
angle_label = QLabel(_("Angle (°):"))
layout.addWidget(angle_label)
self.angle_combo = QComboBox(self)
self.angle_combo.addItems(self.ROTATION_ANGLES)
self.angle_combo.setCurrentIndex(1)
self.connect(self.angle_combo, SIGNAL("currentIndexChanged(int)"),
lambda index: self.apply_transformation())
layout.addWidget(self.angle_combo)
layout.addSpacing(10)
# Image flipping
flip_label = QLabel(_("Flip:"))
layout.addWidget(flip_label)
hflip = create_toolbutton(self, text="", icon=get_icon("hflip.png"),
toggled=lambda state: self.apply_transformation(),
autoraise=False)
self.hflip_btn = hflip
layout.addWidget(hflip)
vflip = create_toolbutton(self, text="", icon=get_icon("vflip.png"),
toggled=lambda state: self.apply_transformation(),
autoraise=False)
self.vflip_btn = vflip
layout.addWidget(vflip)
layout.addSpacing(15)
self.add_reset_button(layout)
def reset_transformation(self):
"""Reset transformation"""
self.angle_combo.setCurrentIndex(1)
self.hflip_btn.setChecked(False)
self.vflip_btn.setChecked(False)
def apply_transformation(self):
"""Apply transformation, e.g. crop or rotate"""
angle, hflip, vflip = self.get_parameters()
x, y, _a, px, py, _hf, _vf = self.item.get_transform()
self.item.set_transform(x, y, angle*np.pi/180, px, py, hflip, vflip)
self.get_plot().replot()
def compute_transformation(self):
"""Compute transformation, return compute output array"""
angle, hflip, vflip = self.get_parameters()
data = self.item.data.copy()
if hflip:
data = np.fliplr(data)
if vflip:
data = np.flipud(data)
if angle:
k = int( (-angle % 360)/90 )
data = np.rot90(data, k)
return data
#------Public API----------------------------------------------------------
def get_parameters(self):
"""Return transform parameters"""
angle = int(str(self.angle_combo.currentText()))
hflip = self.hflip_btn.isChecked()
vflip = self.vflip_btn.isChecked()
return angle, hflip, vflip
def set_parameters(self, angle, hflip, vflip):
"""Set transform parameters"""
angle_index = self.ROTATION_ANGLES.index(str(angle))
self.angle_combo.setCurrentIndex(angle_index)
self.hflip_btn.setChecked(hflip)
self.vflip_btn.setChecked(vflip)
class FlipRotateDialog(base.BaseTransformDialog, FlipRotateMixin):
"""Flip & Rotate Dialog
Flip and rotate a :py:class:`guiqwt.image.TrImageItem` plot item"""
def __init__(self, parent, wintitle=None, options=None, resize_to=None):
FlipRotateMixin.__init__(self)
base.BaseTransformDialog.__init__(self, parent, wintitle=wintitle,
options=options, resize_to=resize_to)
class FlipRotateWidget(base.BaseTransformWidget, FlipRotateMixin):
"""Flip & Rotate Widget
Flip and rotate a :py:class:`guiqwt.image.TrImageItem` plot item"""
def __init__(self, parent, options=None):
base.BaseTransformWidget.__init__(self, parent, options=options)
FlipRotateMixin.__init__(self)
class MultipleFlipRotateWidget(base.BaseMultipleTransformWidget):
"""Multiple Flip & Rotate Widget
Flip and rotate several :py:class:`guiqwt.image.TrImageItem` plot items"""
TRANSFORM_WIDGET_CLASS = FlipRotateWidget
|