103
103
from PyQt4.QtGui import QPen, QBrush, QColor, QFont, QFontDialog, QTransform
104
104
from PyQt4.QtCore import Qt, QSize, QPointF
105
from PyQt4.Qwt5 import QwtPlot, QwtPlotCurve, QwtSymbol, QwtPlotMarker
107
106
from guidata.dataset.datatypes import (DataSet, ObjectItem, BeginGroup,
108
107
EndGroup, Obj, DataSetGroup,
332
332
# ===================================================
333
333
# Common font parameters
334
334
# ===================================================
335
def _font_selection(param, item, value):
335
def _font_selection(param, item, value, parent):
336
336
font = param.build_font()
337
result, valid = QFontDialog.getFont( font )
337
result, valid = QFontDialog.getFont(font, parent)
339
339
param.update_param( result )
600
600
_xparams = EndGroup("end X")
601
601
yparams = BeginGroup(_("Y Axis") )
602
602
yaxis = ChoiceItem(_("Position"),
603
[(QwtPlot.yLeft, _("left")),
603
[(QwtPlot.yLeft, _("left")),
604
604
(QwtPlot.yRight, _("right"))],
605
605
default=QwtPlot.yLeft, help=_("Y-axis position"))
606
606
yscale = ChoiceItem(_("Scale"),
611
611
_yparams = EndGroup("end Y")
613
613
def update_param(self, item):
615
615
self.xaxis = item.xAxis()
616
self.xscale = sw.get_axis_scale(self.xaxis)
617
xaxis = sw.axisScaleDiv(self.xaxis)
616
self.xscale = plot.get_axis_scale(self.xaxis)
617
xaxis = plot.axisScaleDiv(self.xaxis)
618
618
self.xmin = xaxis.lowerBound()
619
619
self.xmax = xaxis.upperBound()
620
620
self.yaxis = item.yAxis()
621
self.yscale = sw.get_axis_scale(self.yaxis)
622
yaxis = sw.axisScaleDiv(self.yaxis)
621
self.yscale = plot.get_axis_scale(self.yaxis)
622
yaxis = plot.axisScaleDiv(self.yaxis)
623
623
self.ymin = yaxis.lowerBound()
624
624
self.ymax = yaxis.upperBound()
626
626
def update_axes(self, item):
628
sw.grid.setAxis(self.xaxis, self.yaxis)
628
plot.grid.setAxis(self.xaxis, self.yaxis)
630
630
item.setXAxis(self.xaxis)
631
sw.enableAxis(self.xaxis, True)
632
sw.set_axis_scale(self.xaxis, self.xscale)
633
sw.setAxisScale(self.xaxis, self.xmin, self.xmax)
631
plot.enableAxis(self.xaxis, True)
632
plot.set_axis_scale(self.xaxis, self.xscale)
633
plot.setAxisScale(self.xaxis, self.xmin, self.xmax)
635
635
item.setYAxis(self.yaxis)
636
sw.enableAxis(self.yaxis, True)
637
sw.set_axis_scale(self.yaxis, self.yscale)
638
sw.setAxisScale(self.yaxis, self.ymin, self.ymax)
636
plot.enableAxis(self.yaxis, True)
637
plot.set_axis_scale(self.yaxis, self.yscale)
638
plot.setAxisScale(self.yaxis, self.ymin, self.ymax)
640
sw.disable_unused_axes()
640
plot.disable_unused_axes()
642
642
class ImageAxesParam(DataSet):
643
643
xparams = BeginGroup(_("X Axis") )
654
654
_zparams = EndGroup("end Z")
656
656
def update_param(self, item):
658
xaxis = sw.axisScaleDiv(item.xAxis())
658
xaxis = plot.axisScaleDiv(item.xAxis())
659
659
self.xmin = xaxis.lowerBound()
660
660
self.xmax = xaxis.upperBound()
661
yaxis = sw.axisScaleDiv(item.yAxis())
661
yaxis = plot.axisScaleDiv(item.yAxis())
662
662
self.ymin = yaxis.lowerBound()
663
663
self.ymax = yaxis.upperBound()
664
664
self.zmin, self.zmax = item.min, item.max
666
666
def update_axes(self, item):
668
sw.setAxisScale(item.xAxis(), self.xmin, self.xmax)
669
sw.setAxisScale(item.yAxis(), self.ymin, self.ymax)
668
plot.set_plot_limits(self.xmin, self.xmax, self.ymin, self.ymax)
670
669
item.set_lut_range([self.zmin, self.zmax])
671
sw.update_colormap_axis(item)
670
plot.update_colormap_axis(item)
673
672
# ===================================================
674
673
# Marker parameters
975
974
choices.append((cmap_name, cmap_name, build_icon_from_cmap_name))
979
class ImageParam(DataSet):
977
class BaseImageParam(DataSet):
980
978
_multiselection = False
981
979
label = StringItem(_("Image title"), default=_("Image")) \
982
980
.set_prop("display", hide=GetAttrProp("_multiselection"))
983
_hide_background = False
984
background = ColorItem(_("Background color"), default="#000000"
985
).set_prop("display",
986
hide=GetAttrProp("_hide_background"))
987
981
alpha_mask = BoolItem(_("Use image level as alpha"), _("Alpha channel"),
989
alpha = FloatItem(_("Global alpha"), default=1.0,
983
alpha = FloatItem(_("Global alpha"), default=1.0, min=0, max=1,
990
984
help=_("Global alpha value"))
991
colormap = ImageChoiceItem(_("Colormap"), _create_choices(), default="jet")
985
_hide_colormap = False
986
colormap = ImageChoiceItem(_("Colormap"), _create_choices(), default="jet"
987
).set_prop("display",
988
hide=GetAttrProp("_hide_colormap"))
993
990
interpolation = ChoiceItem(_("Interpolation"),
994
991
[(0, _("None (nearest pixel)")),
997
994
(3, _("3x3 antialiasing filter")),
998
995
(5, _("5x5 antialiasing filter"))],
999
996
default=0, help=_("Image interpolation type"))
998
_formats = BeginGroup(_("Statistics string formatting"))
999
xformat = StringItem(_("X-Axis"), default=r'%.1f')
1000
yformat = StringItem(_("Y-Axis"), default=r'%.1f')
1001
zformat = StringItem(_("Z-Axis"), default=r'%.1f')
1002
_end_formats = EndGroup(_("Statistics string formatting"))
1001
1004
def update_param(self, image):
1002
1005
self.label = unicode(image.title().text())
1003
self.background = QColor(image.bg_qcolor).name()
1004
1006
self.colormap = image.get_color_map_name()
1005
1007
interpolation = image.get_interpolation()
1006
1008
mode = interpolation[0]
1027
1028
mode = INTERP_AA
1028
1029
image.set_interpolation(mode, size)
1032
class RawImageParam(BaseImageParam):
1033
_hide_background = False
1034
background = ColorItem(_("Background color"), default="#000000"
1035
).set_prop("display",
1036
hide=GetAttrProp("_hide_background"))
1038
def update_param(self, image):
1039
super(RawImageParam, self).update_param(image)
1040
self.background = QColor(image.bg_qcolor).name()
1042
def update_image(self, image):
1043
super(RawImageParam, self).update_image(image)
1044
image.set_background_color(self.background)
1046
class RawImageParam_MS(RawImageParam):
1047
_multiselection = True
1049
ItemParameters.register_multiselection(RawImageParam, RawImageParam_MS)
1052
class XYImageParam(RawImageParam):
1055
class XYImageParam_MS(XYImageParam):
1056
_multiselection = True
1058
ItemParameters.register_multiselection(XYImageParam, XYImageParam_MS)
1061
class ImageParam(RawImageParam):
1062
_xdata = BeginGroup(_("Image placement along X-axis"))
1063
xmin = FloatItem(_("x|min"), default=None)
1064
xmax = FloatItem(_("x|max"), default=None)
1065
_end_xdata = EndGroup(_("Image placement along X-axis"))
1066
_ydata = BeginGroup(_("Image placement along Y-axis"))
1067
ymin = FloatItem(_("y|min"), default=None)
1068
ymax = FloatItem(_("y|max"), default=None)
1069
_end_ydata = EndGroup(_("Image placement along Y-axis"))
1071
def update_param(self, image):
1072
super(ImageParam, self).update_param(image)
1073
self.xmin = image.xmin
1074
if self.xmin is None:
1076
self.ymin = image.ymin
1077
if self.ymin is None:
1079
if image.is_empty():
1082
shape = image.data.shape
1083
self.xmax = image.xmax
1084
if self.xmax is None:
1085
self.xmax = float(shape[1])
1086
self.ymax = image.ymax
1087
if self.ymax is None:
1088
self.ymax = float(shape[0])
1090
def update_image(self, image):
1091
super(ImageParam, self).update_image(image)
1092
image.xmin = self.xmin
1093
image.xmax = self.xmax
1094
image.ymin = self.ymin
1095
image.ymax = self.ymax
1096
image.update_bounds()
1097
image.update_border()
1030
1099
class ImageParam_MS(ImageParam):
1031
1100
_multiselection = True
1033
1102
ItemParameters.register_multiselection(ImageParam, ImageParam_MS)
1036
class ImageFilterParam(ImageParam):
1105
class RGBImageParam(ImageParam):
1106
_hide_background = True
1107
_hide_colormap = True
1109
def update_image(self, image):
1110
super(RGBImageParam, self).update_image(image)
1111
image.recompute_alpha_channel()
1113
class RGBImageParam_MS(RGBImageParam):
1114
_multiselection = True
1116
ItemParameters.register_multiselection(RGBImageParam, RGBImageParam_MS)
1119
class MaskedImageParam(ImageParam):
1120
g_mask = BeginGroup(_("Mask"))
1121
filling_value = FloatItem(_("Filling value"))
1122
show_mask = BoolItem(_("Show image mask"), default=False)
1123
alpha_masked = FloatItem(_("Masked area alpha"),
1124
default=.7, min=0, max=1)
1125
alpha_unmasked = FloatItem(_("Unmasked area alpha"),
1126
default=0., min=0, max=1)
1127
_g_mask = EndGroup(_("Mask"))
1129
def update_image(self, image):
1130
super(MaskedImageParam, self).update_image(image)
1133
class MaskedImageParam_MS(MaskedImageParam):
1134
_multiselection = True
1136
ItemParameters.register_multiselection(MaskedImageParam, MaskedImageParam_MS)
1139
class ImageFilterParam(BaseImageParam):
1037
1140
label = StringItem(_("Title"), default=_("Filter"))
1038
1141
g1 = BeginGroup(_("Bounds"))
1039
1142
xmin = FloatItem(_("x|min"))
1062
1165
self.xmax, self.ymax)
1065
class TrImageParam(ImageParam):
1066
_crop = BeginGroup(_("Crop"))
1168
class TrImageParam(RawImageParam):
1169
_crop = BeginGroup(_("Crop")
1170
).set_prop("display", hide=GetAttrProp("_multiselection"))
1067
1171
crop_left = IntItem(_("Left"), default=0)
1068
1172
crop_right = IntItem(_("Right"), default=0)
1069
1173
crop_top = IntItem(_("Top"), default=0)
1070
1174
crop_bottom = IntItem(_("Bottom"), default=0)
1071
_end_crop = EndGroup(_("Cropping"))
1072
_ps = BeginGroup(_("Pixel size"))
1073
dx = FloatItem(_("Width (δx)"), default=1.0)
1074
dy = FloatItem(_("Height (δy)"), default=1.0)
1075
_end_ps = EndGroup(_("Pixel size"))
1175
_end_crop = EndGroup(_("Cropping")
1176
).set_prop("display", hide=GetAttrProp("_multiselection"))
1177
_ps = BeginGroup(_("Pixel size")
1178
).set_prop("display", hide=GetAttrProp("_multiselection"))
1179
dx = FloatItem(_("Width (dx)"), default=1.0)
1180
dy = FloatItem(_("Height (dy)"), default=1.0)
1181
_end_ps = EndGroup(_("Pixel size")
1182
).set_prop("display", hide=GetAttrProp("_multiselection"))
1076
1183
_pos = BeginGroup(_("Translate, rotate and flip"))
1077
pos_x0 = FloatItem(_("x<sub>CENTER</sub>"), default=0.0)
1078
hflip = BoolItem(_("Flip horizontally"), default=False).set_prop("display", col=1)
1079
pos_y0 = FloatItem(_("y<sub>CENTER</sub>"), default=0.0)
1080
vflip = BoolItem(_("Flip vertically"), default=False).set_prop("display", col=1)
1184
pos_x0 = FloatItem(_("x<sub>CENTER</sub>"), default=0.0
1185
).set_prop("display", hide=GetAttrProp("_multiselection"))
1186
hflip = BoolItem(_("Flip horizontally"), default=False
1187
).set_prop("display", col=1)
1188
pos_y0 = FloatItem(_("y<sub>CENTER</sub>"), default=0.0
1189
).set_prop("display", hide=GetAttrProp("_multiselection"))
1190
vflip = BoolItem(_("Flip vertically"), default=False
1191
).set_prop("display", col=1)
1081
1192
pos_angle = FloatItem(_("θ (°)"), default=0.0).set_prop("display", col=0)
1082
1193
_end_pos = EndGroup(_("Translate, rotate and flip"))
1125
1239
class HistogramParam(DataSet):
1126
1240
n_bins = IntItem(_("Bins"), default=100, min=1, help=_("Number of bins"))
1127
1241
logscale = BoolItem(_("logarithmic"), _("Y-axis scale"), default=False)
1128
remove_first_bin = BoolItem(_("force first bin to zero"), _("Display"),
1131
1243
def update_param(self, obj):
1132
1244
self.n_bins = obj.get_bins()
1133
1245
self.logscale = obj.get_logscale()
1134
self.remove_first_bin = obj.get_remove_first_bin()
1136
1247
def update_hist(self, hist):
1137
1248
hist.set_bins(self.n_bins)
1138
1249
hist.set_logscale(self.logscale)
1139
hist.set_remove_first_bin(self.remove_first_bin)
1142
1252
# ===================================================
1143
1253
# Histogram 2D parameters
1144
1254
# ===================================================
1145
class Histogram2DParam(ImageParam):
1255
class Histogram2DParam(BaseImageParam):
1146
1256
"""Histogram"""
1147
1257
_multiselection = False
1148
_hide_background = True
1149
1258
label = StringItem(_("Title"), default=_("Histogram")) \
1150
1259
.set_prop("display", hide=GetAttrProp("_multiselection"))
1151
1260
nx_bins = IntItem(_("X-axis bins"), default=100, min=1,
1193
1302
___efill = EndGroup(_("Fill pattern"))
1194
1303
#----------------------------------------------------------------------- End
1195
1304
_endstyles = EndTabGroup("Styles")
1305
readonly = BoolItem(_("Read-only shape"), default=False,
1306
help=_("Read-only shapes can't be removed from "
1307
"the item list panel"))
1308
private = BoolItem(_("Private shape"), default=False,
1309
help=_("Private shapes are not shown in "
1310
"the item list panel")).set_pos(col=1)
1197
1312
def update_param(self, obj):
1198
1313
self.line.update_param(obj.pen)
1247
1366
class AnnotationParam(DataSet):
1248
1367
show_label = BoolItem(_("Show annotation"), default=True)
1249
show_position = BoolItem(_("Show position and size"), default=True)
1368
show_computations = BoolItem(_("Show informations on area "
1369
"covered by this shape"), default=True)
1250
1370
title = StringItem(_("Title"), default=u"")
1251
1371
subtitle = StringItem(_("Subtitle"), default=u"")
1252
1372
format = StringItem(_("String formatting"), default="%d pixels")
1306
1426
range.symbol = self.symbol.build_symbol()
1307
1427
range.sel_symbol = self.sel_symbol.build_symbol()
1430
# ===================================================
1431
# Range selection parameters
1432
# ===================================================
1433
class CursorShapeParam(DataSet):
1434
_styles = BeginTabGroup("Styles")
1435
#------------------------------------------------------------------ Line tab
1436
___line = BeginGroup(_("Line")).set_prop("display", icon="dashdot.png")
1437
line = LineStyleItem(_("Line (not selected)"))
1438
sel_line = LineStyleItem(_("Line (selected)"))
1439
___eline = EndGroup(_("Line"))
1440
#---------------------------------------------------------------- Symbol tab
1441
___symbol = BeginGroup(_("Symbol")).set_prop("display", icon="diamond.png")
1442
symbol = SymbolItem(_("Symbol (not selected)"))
1443
sel_symbol = SymbolItem(_("Symbol (selected)"))
1444
___esymbol = EndGroup(_("Symbol"))
1445
#----------------------------------------------------------------------- End
1446
_endstyles = EndTabGroup("Styles")
1448
def update_param(self, cursor):
1449
self.line.update_param(cursor.pen)
1450
self.sel_line.update_param(cursor.sel_pen)
1451
self.symbol.update_param(cursor.symbol)
1452
self.sel_symbol.update_param(cursor.sel_symbol)
1454
def update_range(self, cursor):
1455
cursor.pen = self.line.build_pen()
1456
cursor.sel_pen = self.sel_line.build_pen()
1457
cursor.symbol = self.symbol.build_symbol()
1458
cursor.sel_symbol = self.sel_symbol.build_symbol()