~ubuntu-branches/ubuntu/trusty/guiqwt/trusty

« back to all changes in this revision

Viewing changes to guiqwt/styles.py

  • Committer: Bazaar Package Importer
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2011-04-07 22:41:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110407224150-kkhppnq7rp2c8b3c
Tags: 2.1.0-1
* Imported Upstream version 2.1.0
* debian/patches/
  - 0001-features-01_bts614083.patch (delete)
  - 0001-feature-fix-the-documentation-build.patch (new)
* add and install the sift desktop file
* recommends python-dicom (Closes: #621421)
  thanks Junqian Gordon Xu for the report

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
 
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
106
105
 
107
106
from guidata.dataset.datatypes import (DataSet, ObjectItem, BeginGroup,
108
107
                                       EndGroup, Obj, DataSetGroup,
116
115
from guidata.utils import update_dataset
117
116
 
118
117
# Local imports
 
118
from guiqwt.transitional import QwtPlot, QwtPlotCurve, QwtSymbol, QwtPlotMarker
119
119
from guiqwt.config import _
120
120
from guiqwt.colormap import get_colormap_list, build_icon_from_cmap_name
121
121
from guiqwt.signals import SIG_ITEMS_CHANGED
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)
338
338
    if valid:
339
339
        param.update_param( result )
340
340
    
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")
612
612
 
613
613
    def update_param(self, item):
614
 
        sw = item.plot()
 
614
        plot = item.plot()
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()
625
625
 
626
626
    def update_axes(self, item):
627
 
        sw = item.plot()
628
 
        sw.grid.setAxis(self.xaxis, self.yaxis)
 
627
        plot = item.plot()
 
628
        plot.grid.setAxis(self.xaxis, self.yaxis)
629
629
        # x
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)
634
634
        # y
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)
639
639
        
640
 
        sw.disable_unused_axes()
 
640
        plot.disable_unused_axes()
641
641
 
642
642
class ImageAxesParam(DataSet):
643
643
    xparams = BeginGroup(_("X Axis") )
654
654
    _zparams = EndGroup("end Z")
655
655
 
656
656
    def update_param(self, item):
657
 
        sw = item.plot()
658
 
        xaxis = sw.axisScaleDiv(item.xAxis())
 
657
        plot = item.plot()
 
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
665
665
 
666
666
    def update_axes(self, item):
667
 
        sw = item.plot()
668
 
        sw.setAxisScale(item.xAxis(), self.xmin, self.xmax)
669
 
        sw.setAxisScale(item.yAxis(), self.ymin, self.ymax)
 
667
        plot = item.plot()
 
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)
672
671
 
673
672
# ===================================================
674
673
# Marker parameters
975
974
        choices.append((cmap_name, cmap_name, build_icon_from_cmap_name))
976
975
    return choices
977
976
 
978
 
 
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"),
988
982
                          default=False)
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"))
992
989
    
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"))
 
997
 
 
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"))
1000
1003
                               
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]
1015
1017
 
1016
1018
    def update_image(self, image):
1017
1019
        image.setTitle(self.label)
1018
 
        image.set_background_color(self.background)
1019
1020
        image.set_color_map(self.colormap)
1020
1021
        size = self.interpolation
1021
1022
        from guiqwt.image import INTERP_NEAREST, INTERP_LINEAR, INTERP_AA
1027
1028
            mode = INTERP_AA
1028
1029
        image.set_interpolation(mode, size)
1029
1030
 
 
1031
 
 
1032
class RawImageParam(BaseImageParam):
 
1033
    _hide_background = False
 
1034
    background = ColorItem(_("Background color"), default="#000000"
 
1035
                           ).set_prop("display",
 
1036
                                      hide=GetAttrProp("_hide_background"))
 
1037
    
 
1038
    def update_param(self, image):
 
1039
        super(RawImageParam, self).update_param(image)
 
1040
        self.background = QColor(image.bg_qcolor).name()
 
1041
 
 
1042
    def update_image(self, image):
 
1043
        super(RawImageParam, self).update_image(image)
 
1044
        image.set_background_color(self.background)
 
1045
 
 
1046
class RawImageParam_MS(RawImageParam):
 
1047
    _multiselection = True
 
1048
    
 
1049
ItemParameters.register_multiselection(RawImageParam, RawImageParam_MS)
 
1050
 
 
1051
 
 
1052
class XYImageParam(RawImageParam):
 
1053
    pass
 
1054
 
 
1055
class XYImageParam_MS(XYImageParam):
 
1056
    _multiselection = True
 
1057
    
 
1058
ItemParameters.register_multiselection(XYImageParam, XYImageParam_MS)
 
1059
 
 
1060
 
 
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"))
 
1070
    
 
1071
    def update_param(self, image):
 
1072
        super(ImageParam, self).update_param(image)
 
1073
        self.xmin = image.xmin
 
1074
        if self.xmin is None:
 
1075
            self.xmin = 0.
 
1076
        self.ymin = image.ymin
 
1077
        if self.ymin is None:
 
1078
            self.ymin = 0.
 
1079
        if image.is_empty():
 
1080
            shape = (0, 0)
 
1081
        else:
 
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])
 
1089
 
 
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()
 
1098
 
1030
1099
class ImageParam_MS(ImageParam):
1031
1100
    _multiselection = True
1032
1101
    
1033
1102
ItemParameters.register_multiselection(ImageParam, ImageParam_MS)
1034
1103
 
1035
1104
 
1036
 
class ImageFilterParam(ImageParam):
 
1105
class RGBImageParam(ImageParam):
 
1106
    _hide_background = True
 
1107
    _hide_colormap = True
 
1108
 
 
1109
    def update_image(self, image):
 
1110
        super(RGBImageParam, self).update_image(image)
 
1111
        image.recompute_alpha_channel()
 
1112
 
 
1113
class RGBImageParam_MS(RGBImageParam):
 
1114
    _multiselection = True
 
1115
    
 
1116
ItemParameters.register_multiselection(RGBImageParam, RGBImageParam_MS)
 
1117
 
 
1118
 
 
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"))
 
1128
    
 
1129
    def update_image(self, image):
 
1130
        super(MaskedImageParam, self).update_image(image)
 
1131
        image.update_mask()
 
1132
                         
 
1133
class MaskedImageParam_MS(MaskedImageParam):
 
1134
    _multiselection = True
 
1135
    
 
1136
ItemParameters.register_multiselection(MaskedImageParam, MaskedImageParam_MS)
 
1137
 
 
1138
 
 
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)
1063
1166
 
1064
1167
 
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"))
1083
1194
 
1089
1200
        # directly in this DataSet
1090
1201
 
1091
1202
    def update_image(self, image):
1092
 
        ImageParam.update_image(self, image)
 
1203
        RawImageParam.update_image(self, image)
1093
1204
        image.set_transform(*self.get_transform())
1094
1205
 
1095
1206
    def get_transform(self):
1116
1227
        return (self.crop_left, self.crop_top,
1117
1228
                self.crop_right, self.crop_bottom)
1118
1229
    
1119
 
ItemParameters.register_multiselection(TrImageParam, ImageParam_MS)
 
1230
class TrImageParam_MS(TrImageParam):
 
1231
    _multiselection = True
 
1232
    
 
1233
ItemParameters.register_multiselection(TrImageParam, TrImageParam_MS)
1120
1234
 
1121
1235
 
1122
1236
# ===================================================
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"),
1129
 
                                default=False)
1130
1242
 
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()
1135
1246
 
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)
1140
1250
 
1141
1251
 
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)
1196
1311
    
1197
1312
    def update_param(self, obj):
1198
1313
        self.line.update_param(obj.pen)
1201
1316
        self.sel_line.update_param(obj.sel_pen)
1202
1317
        self.sel_symbol.update_param(obj.sel_symbol)
1203
1318
        self.sel_fill.update_param(obj.sel_brush)
 
1319
        self.readonly = obj.is_readonly()
 
1320
        self.private = obj.is_private()
1204
1321
        
1205
1322
    def update_shape(self, obj):
1206
1323
        obj.pen = self.line.build_pen()
1209
1326
        obj.sel_pen = self.sel_line.build_pen()
1210
1327
        obj.sel_symbol = self.sel_symbol.build_symbol()
1211
1328
        obj.sel_brush = self.sel_fill.build_brush()
 
1329
        obj.set_readonly(self.readonly)
 
1330
        obj.set_private(self.private)
1212
1331
 
1213
1332
class AxesShapeParam(DataSet):
1214
1333
    arrow_angle = FloatItem(_("Arrow angle (°)"), min=0, max=90, nonzero=True)
1246
1365
 
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")
1255
1375
    
1256
1376
    def update_param(self, obj):
1257
1377
        self.show_label = obj.is_label_visible()
1258
 
        self.show_position = obj.position_and_size_visible
 
1378
        self.show_computations = obj.area_computations_visible
1259
1379
        self.title = obj.title().text()
1260
1380
        
1261
1381
    def update_annotation(self, obj):
1262
1382
        obj.setTitle(self.title)
1263
1383
        obj.set_label_visible(self.show_label)
1264
 
        obj.position_and_size_visible = self.show_position
 
1384
        obj.area_computations_visible = self.show_computations
1265
1385
        obj.update_label()
1266
1386
 
1267
1387
 
1306
1426
        range.symbol = self.symbol.build_symbol()
1307
1427
        range.sel_symbol = self.sel_symbol.build_symbol()
1308
1428
 
 
1429
 
 
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")
 
1447
    
 
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)
 
1453
        
 
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()