示例#1
0
    def setData(self, index, value, role=Qt.EditRole):

        if role == Qt.EditRole  and index.column() == self.ColumnID.Color:
            row = index.row()
            color = QColor(value["color"][0])
            colorglobal=value["color"][1]

            fontsize,fontsizeglobal = value["fontsize"]
            linewidth,linewidthglobal = value["linewidth"]

            fontcolor = QColor(value["fontcolor"][0])
            fontcolorglobal = value["fontcolor"][1]



            if color.isValid():
                if not colorglobal:
                    self._elements[row].color=color
                    self.dataChanged.emit(index, index)
                else:
                    for row,el in enumerate(self._elements):
                        el.color=color
                        ind=self.createIndex(row, self.ColumnID.Color, object=0)
                        self.dataChanged.emit(ind, ind)


            if fontcolor.isValid():
                if not fontcolorglobal:
                    self._elements[row].fontcolor=fontcolor
                else:
                    for row,el in enumerate(self._elements):
                        el.fontcolor=fontcolor

            if not linewidthglobal:
                self._elements[row].linewidth=linewidth
            else:
                for row,el in enumerate(self._elements):
                    el.linewidth=linewidth



            if not fontsizeglobal:
                self._elements[row].fontsize=fontsize
            else:
                for row,el in enumerate(self._elements):
                    el.fontsize=fontsize

            return True


        if index.column()==self.ColumnID.Fix:
            try:
                value=float(value.toString())
                self._elements[index.row()].isFixed=True
                row=index.row()
                self._elements[row].fixvalue=QString("%.1f"%value)
                self.dataChanged.emit(index,index)
                return True
            except:
                return False
示例#2
0
    def setData(self, index, value, role=Qt.EditRole):
        if role == Qt.EditRole  and index.column() == ColumnID.Color:
            row = index.row()
            brushColor = QColor(value[0])
            pmapColor = QColor(value[1])
            if brushColor.isValid() and pmapColor.isValid():
                print "setData: brushColor = {}, pmapColor = {}".format(
                    brushColor.name(), pmapColor.name())
                print "  self._labels[row] has type {}".format(
                    type(self._labels[row]))
                self._labels[row].setBrushColor(brushColor)
                self._labels[row].setPmapColor(pmapColor)
                print "  self._labels[row].brushColor = {}".format(
                    self._labels[row].brushColor().name())
                print "  self._labels[row].pmapColor  = {}".format(
                    self._labels[row].pmapColor().name())
                self.dataChanged.emit(index, index)
                return True

        if role == Qt.EditRole  and index.column() == ColumnID.Name:
            row = index.row()
            name = value
            self._labels[row].name = str(name.toString())
            self.dataChanged.emit(index, index)
            return True

        return False
示例#3
0
    def setData(self, index, value, role=Qt.EditRole):

        if role == Qt.EditRole and index.column() == self.ColumnID.Color:
            row = index.row()
            color = QColor(value["color"][0])
            colorglobal = value["color"][1]

            fontsize, fontsizeglobal = value["fontsize"]
            linewidth, linewidthglobal = value["linewidth"]

            fontcolor = QColor(value["fontcolor"][0])
            fontcolorglobal = value["fontcolor"][1]

            if color.isValid():
                if not colorglobal:
                    self._elements[row].color = color
                    self.dataChanged.emit(index, index)
                else:
                    for row, el in enumerate(self._elements):
                        el.color = color
                        ind = self.createIndex(row,
                                               self.ColumnID.Color,
                                               object=0)
                        self.dataChanged.emit(ind, ind)

            if fontcolor.isValid():
                if not fontcolorglobal:
                    self._elements[row].fontcolor = fontcolor
                else:
                    for row, el in enumerate(self._elements):
                        el.fontcolor = fontcolor

            if not linewidthglobal:
                self._elements[row].linewidth = linewidth
            else:
                for row, el in enumerate(self._elements):
                    el.linewidth = linewidth

            if not fontsizeglobal:
                self._elements[row].fontsize = fontsize
            else:
                for row, el in enumerate(self._elements):
                    el.fontsize = fontsize

            return True

        if index.column() == self.ColumnID.Fix:
            try:
                value = float(value.toString())
                self._elements[index.row()].isFixed = True
                row = index.row()
                self._elements[row].fixvalue = QString("%.1f" % value)
                self.dataChanged.emit(index, index)
                return True
            except:
                return False
示例#4
0
class ColorButton(QPushButton):
    """A PushButton displaying a color.
    
    When clicked, opens a color dialog to change the color.
    
    """
    colorChanged = pyqtSignal(QColor)
    
    def __init__(self, parent=None):
        super(ColorButton, self).__init__(parent)
        
        self.setFixedSize(self.sizeHint())
        self._color = QColor()
        self.clicked.connect(self.openDialog)
    
    def color(self):
        """Returns the currently set color."""
        return self._color
    
    def setColor(self, color):
        """Sets the current color. Maybe QColor() to indicate 'unset'."""
        if self._color != color:
            self._color = color
            self.update()
            self.colorChanged.emit(color)

    def clear(self):
        """Unsets the current color (setting it to QColor())."""
        self.setColor(QColor())
        
    def openDialog(self):
        """Called when clicked, opens a dialog to change the color."""
        color = self._color if self._color.isValid() else QColor(Qt.white)
        color = QColorDialog.getColor(color, self)
        if color.isValid():
            self.setColor(color)

    def paintEvent(self, ev):
        """Reimplemented to display a colored rectangle."""
        QPushButton.paintEvent(self, ev)
        if not self._color.isValid():
            return
        style = self.style()
        opt = QStyleOptionButton()
        self.initStyleOption(opt)
        r = style.subElementRect(QStyle.SE_PushButtonContents, opt, self)
        shift = style.pixelMetric(QStyle.PM_ButtonMargin, opt, self) // 2
        r.adjust(shift, shift, -shift, -shift)
        if self.isChecked() or self.isDown():
            dx = style.pixelMetric(QStyle.PM_ButtonShiftHorizontal, opt, self)
            dy = style.pixelMetric(QStyle.PM_ButtonShiftVertical, opt, self)
            r.translate(dx, dy)
        p = QPainter(self)
        qDrawShadeRect(p, r, self.palette(), True, 1, 0, self._color)
示例#5
0
class ColorButton(QPushButton):
    """A PushButton displaying a color.
    
    When clicked, opens a color dialog to change the color.
    
    """
    colorChanged = pyqtSignal(QColor)

    def __init__(self, parent=None):
        super(ColorButton, self).__init__(parent)

        self.setFixedSize(self.sizeHint())
        self._color = QColor()
        self.clicked.connect(self.openDialog)

    def color(self):
        """Returns the currently set color."""
        return self._color

    def setColor(self, color):
        """Sets the current color. Maybe QColor() to indicate 'unset'."""
        if self._color != color:
            self._color = color
            self.update()
            self.colorChanged.emit(color)

    def clear(self):
        """Unsets the current color (setting it to QColor())."""
        self.setColor(QColor())

    def openDialog(self):
        """Called when clicked, opens a dialog to change the color."""
        color = self._color if self._color.isValid() else QColor(Qt.white)
        color = QColorDialog.getColor(color, self)
        if color.isValid():
            self.setColor(color)

    def paintEvent(self, ev):
        """Reimplemented to display a colored rectangle."""
        QPushButton.paintEvent(self, ev)
        if not self._color.isValid():
            return
        style = self.style()
        opt = QStyleOptionButton()
        self.initStyleOption(opt)
        r = style.subElementRect(QStyle.SE_PushButtonContents, opt, self)
        shift = style.pixelMetric(QStyle.PM_ButtonMargin, opt, self) // 2
        r.adjust(shift, shift, -shift, -shift)
        if self.isChecked() or self.isDown():
            dx = style.pixelMetric(QStyle.PM_ButtonShiftHorizontal, opt, self)
            dy = style.pixelMetric(QStyle.PM_ButtonShiftVertical, opt, self)
            r.translate(dx, dy)
        p = QPainter(self)
        qDrawShadeRect(p, r, self.palette(), True, 1, 0, self._color)
示例#6
0
 def load_preferences(self):
     settings = QSettings()
     settings.beginGroup("Plotting")
     try:
         os = int(settings.value("OverSampling"))
     except (ValueError, TypeError):
         os = 1
     self._over_sampling = os
     self.ui.overSampling.setValue(os)
     try:
         wt = float(settings.value("WallThickness"))
     except (ValueError, TypeError):
         wt = 0
     self._wall_thickness = wt
     self.ui.wallThickness.setValue(wt)
     try:
         ps = float(settings.value("PointSize"))
     except (ValueError, TypeError):
         ps = 0
     self._point_size = ps
     self.ui.pointSize.setValue(ps)
     try:
         plt = float(settings.value("PointLineThickness"))
     except (ValueError, TypeError):
         plt = 0
     self._point_line_thickness = plt
     plc = QColor(settings.value("PointLineColor"))
     if not plc.isValid():
         plc = QColor(0,0,0)
     self._point_line_color = plc
     bg = QColor(settings.value("BackgroundColor"))
     if not bg.isValid():
         bg = QColor(0,0,0)
     self._bg_color = bg
     #setColor(self.ui.bgColor, bg)
     ff = str(settings.value("FileFormat"))
     uiff = self.ui.fileFormat
     img_formats = self.img_formats
     if ff in img_formats:
         uiff.setCurrentIndex(self.img_formats.index(ff))
     else:
         prefered_exts = ["png", "tif", "jpg"]
         for ff in prefered_exts:
             if ff in img_formats:
                 uiff.setCurrentIndex(self.img_formats.index(ff))
                 break
         else:
             uiff.setCurrentIndex(0)
             ff = self.img_formats[0]
     self._file_format = ff
     settings.endGroup()
示例#7
0
 def load_preferences(self):
     settings = QSettings()
     settings.beginGroup("Plotting")
     try:
         os = int(settings.value("OverSampling"))
     except (ValueError, TypeError):
         os = 1
     self._over_sampling = os
     self.ui.overSampling.setValue(os)
     try:
         wt = float(settings.value("WallThickness"))
     except (ValueError, TypeError):
         wt = 0
     self._wall_thickness = wt
     self.ui.wallThickness.setValue(wt)
     try:
         ps = float(settings.value("PointSize"))
     except (ValueError, TypeError):
         ps = 0
     self._point_size = ps
     self.ui.pointSize.setValue(ps)
     try:
         plt = float(settings.value("PointLineThickness"))
     except (ValueError, TypeError):
         plt = 0
     self._point_line_thickness = plt
     plc = QColor(settings.value("PointLineColor"))
     if not plc.isValid():
         plc = QColor(0, 0, 0)
     self._point_line_color = plc
     bg = QColor(settings.value("BackgroundColor"))
     if not bg.isValid():
         bg = QColor(0, 0, 0)
     self._bg_color = bg
     #setColor(self.ui.bgColor, bg)
     ff = str(settings.value("FileFormat"))
     uiff = self.ui.fileFormat
     img_formats = self.img_formats
     if ff in img_formats:
         uiff.setCurrentIndex(self.img_formats.index(ff))
     else:
         prefered_exts = ["png", "tif", "jpg"]
         for ff in prefered_exts:
             if ff in img_formats:
                 uiff.setCurrentIndex(self.img_formats.index(ff))
                 break
         else:
             uiff.setCurrentIndex(0)
             ff = self.img_formats[0]
     self._file_format = ff
     settings.endGroup()
示例#8
0
def _collect_colors(document):
    '''Scan a given document and collect unique colors

        Returns a list of QColor objects.
    '''
    result = []
    # Iterate over document's lines trying to find #colors
    for l in range(0, document.lines()):
        line = document.line(l)                             # Get the current line
        start = 0                                           # Set initial position to 0 (line start)
        while start < len(line):                            # Repeat 'till the line end
            start = line.find('#', start)                   # Try to find a '#' character (start of #color)
            if start == -1:                                 # Did we found smth?
                break                                       # No! Nothing to do...
            # Try to get a word right after the '#' char
            end = start + 1
            for c in line[end:]:
                if not (c in string.hexdigits or c in string.ascii_letters):
                    break
                end += 1
            color_range = KTextEditor.Range(l, start, l, end)
            color_str = document.text(color_range)
            color = QColor(color_str)
            if color.isValid() and color not in result:
                result.append(color)
                kate.kDebug('ColorUtils: scan for #colors found {}'.format(color_str))
            start = end
    return result
示例#9
0
 def updateColors(self, view=None):
     """Scan a document for #colors"""
     self.colors = list()  # Clear previous colors
     if view:
         document = view.document()
     else:
         try:
             document = kate.activeDocument()
         except kate.NoActiveView:
             return  # Do nothing if we can't get a current document
     # Iterate over document's lines trying to find #colors
     for l in range(0, document.lines()):
         line = document.line(l)  # Get the current line
         start = 0  # Set initial position to 0 (line start)
         while start < len(line):  # Repeat 'till the line end
             start = line.find(
                 '#',
                 start)  # Try to find a '#' character (start of #color)
             if start == -1:  # Did we found smth?
                 break  # No! Nothing to do...
             # Try to get a word right after the '#' char
             end = start + 1
             for c in line[end:]:
                 if not (c in string.hexdigits
                         or c in string.ascii_letters):
                     break
                 end += 1
             color_range = KTextEditor.Range(l, start, l, end)
             color_str = document.text(color_range)
             color = QColor(color_str)
             if color.isValid():
                 self.colors.append(ColorRangePair(color, color_range))
                 print('PALETTE VIEW: Found %s' % color_str)
             start = end
示例#10
0
 def show_swatch(self, view):
     '''Shows the swatch if a valid color is selected'''
     if view.selection():
         color = QColor(view.selectionText())
         if color.isValid():
             cursor_pos = view.cursorPositionCoordinates()
             QToolTip.showText(cursor_pos, self.swatch_template)
             self.change_palette(color)
示例#11
0
 def show_swatch(self, view):
     """Shows the swatch if a valid color is selected"""
     if view.selection():
         color = QColor(view.selectionText())
         if color.isValid():
             cursor_pos = view.cursorPositionCoordinates()
             QToolTip.showText(cursor_pos, self.swatch_template)
             self.change_palette(color)
示例#12
0
 def cell_color(self, color):
     col = QColor(color)
     if col.isValid() and col != self._cell_color:
         self._cell_color = col
         self.cell_hover_color = col.lighter(150)
         if self.cell_hover_color == col:
             self.cell_hover_color = col.lighter(50)
         self.cellParameterChange.emit()
示例#13
0
 def cell_color(self, color):
     col = QColor(color)
     if col.isValid() and col != self._cell_color:
         self._cell_color = col
         self.cell_hover_color = col.lighter(150)
         if self.cell_hover_color == col:
             self.cell_hover_color = col.lighter(50)
         self.cellParameterChange.emit()
示例#14
0
 def new_point_color(self, color):
     col = QColor(color)
     if col.isValid() and col != self._new_point_color:
         self._new_point_color = col
         self.new_point_hover_color = col.lighter(150)
         if self.new_point_hover_color == col:
             self.new_point_hover_color = col.lighter(50)
         self.pointParameterChange.emit()
示例#15
0
 def new_point_color(self, color):
     col = QColor(color)
     if col.isValid() and col != self._new_point_color:
         self._new_point_color = col
         self.new_point_hover_color = col.lighter(150)
         if self.new_point_hover_color == col:
             self.new_point_hover_color = col.lighter(50)
         self.pointParameterChange.emit()
示例#16
0
    def setData(self, index, value, role=Qt.EditRole):
        if role == Qt.EditRole and index.column() == self.ColumnID.Color:
            row = index.row()
            brushColor = QColor(value[0])
            pmapColor = QColor(value[1])
            if brushColor.isValid() and pmapColor.isValid():
                logger.debug("setData: brushColor = {}, pmapColor = {}" "".format(brushColor.name(), pmapColor.name()))
                logger.debug("  self._elements[row] has type {}" "".format(type(self._elements[row])))
                self._elements[row].setBrushColor(brushColor)
                self._elements[row].setPmapColor(pmapColor)
                logger.debug("  self._elements[row].brushColor = {}" "".format(self._elements[row].brushColor().name()))
                logger.debug("  self._elements[row].pmapColor  = {}" "".format(self._elements[row].pmapColor().name()))
                self.dataChanged.emit(index, index)
                return True

        else:
            return ListModel.setData(self, index, value, role)
示例#17
0
def getcolor(color_def):
    """Make a QColor"""
    try:
        color = pg.mkColor(color_def)
    except:
        color = QColor(color_def)
        if not color.isValid():
            raise ValueError('Invalid color def {}'.format(color_def))
    return color
示例#18
0
def getcolor(color_def):
    """Make a QColor"""
    try:
        color = pg.mkColor(color_def)
    except:
        color = QColor(color_def)
        if not color.isValid():
            raise ValueError('Invalid color def {}'.format(color_def))
    return color
示例#19
0
 def load(params, settings):
     col = QColor(settings.value("ScaleText"))
     if not col.isValid():
         col = QColor(0, 0, 0)
     params.scale_text = col
     col = QColor(settings.value("ScaleLine"))
     if not col.isValid():
         col = QColor(0, 0, 0)
     params.scale_line = col
     try:
         params.scale_line_thickness = int(settings.value("ScaleLineThickness"))
     except (ValueError, TypeError):
         params.scale_line_thickness = 0
     params.scale_position = settings.value("ScalePosition", "Top")
     fnt = QFont(settings.value("ScaleFont", QFont()))
     params.scale_font = fnt
     params.scale_show = toBool(settings.value("ScaleShow", "True"))
     params.scale_bar_outside_image = toBool(settings.value("ScaleBarOutsideImage", "False"))
示例#20
0
 def setWidgetCategory(self, desc):
     """
     Set the widget category.
     """
     self.category_description = desc
     if desc and desc.background:
         background = NAMED_COLORS.get(desc.background, desc.background)
         color = QColor(background)
         if color.isValid():
             self.setColor(color)
示例#21
0
 def show_swatch(self, view):
     '''Shows the swatch if a valid color is selected'''
     if view.selection():
         color = QColor(view.selectionText())
         if color.isValid():
             cursor_pos = view.mapToGlobal(view.cursorPositionCoordinates())
             QToolTip.showText(cursor_pos, ColorSwatcher._SWATCH_TEMPLATE)
             self.change_palette(color)
     else:
         QToolTip.hideText()
 def setWidgetCategory(self, desc):
     """
     Set the widget category.
     """
     self.category_description = desc
     if desc and desc.background:
         background = NAMED_COLORS.get(desc.background, desc.background)
         color = QColor(background)
         if color.isValid():
             self.setColor(color)
示例#23
0
 def load(params, settings):
     col = QColor(settings.value("ScaleText"))
     if not col.isValid():
         col = QColor(0, 0, 0)
     params.scale_text = col
     col = QColor(settings.value("ScaleLine"))
     if not col.isValid():
         col = QColor(0, 0, 0)
     params.scale_line = col
     try:
         params.scale_line_thickness = int(
             settings.value("ScaleLineThickness"))
     except (ValueError, TypeError):
         params.scale_line_thickness = 0
     params.scale_position = settings.value("ScalePosition", "Top")
     fnt = QFont(settings.value("ScaleFont", QFont()))
     params.scale_font = fnt
     params.scale_show = toBool(settings.value("ScaleShow", "True"))
     params.scale_bar_outside_image = toBool(
         settings.value("ScaleBarOutsideImage", "False"))
示例#24
0
    def setData(self, index, value, role=Qt.EditRole):

        if role == Qt.EditRole:
            row = index.row()
            color = QColor(value)

            if color.isValid():
                self._colors[row] = color
                self.dataChanged.emit(index, index)
                return True
            return False
示例#25
0
    def setData(self, index, value, role=Qt.EditRole):
        if role == Qt.EditRole and index.column() == self.ColumnID.Color:
            row = index.row()
            brushColor = QColor(value[0])
            pmapColor = QColor(value[1])
            if brushColor.isValid() and pmapColor.isValid():
                print "setData: brushColor = {}, pmapColor = {}".format(
                    brushColor.name(), pmapColor.name())
                print "  self._elements[row] has type {}".format(
                    type(self._elements[row]))
                self._elements[row].setBrushColor(brushColor)
                self._elements[row].setPmapColor(pmapColor)
                print "  self._elements[row].brushColor = {}".format(
                    self._elements[row].brushColor().name())
                print "  self._elements[row].pmapColor  = {}".format(
                    self._elements[row].pmapColor().name())
                self.dataChanged.emit(index, index)
                return True

        else:
            return ListModel.setData(self, index, value, role)
示例#26
0
 def load(params, settings):
     ScaleBar.load(params, settings)
     df = settings.value("DataFile", "")
     if df:
         params.data_file = path(df)
     else:
         params.data_file = None
     try:
         p0 = int(settings.value("DataPoint0"))
     except (ValueError, TypeError):
         p0 = 0
     try:
         p1 = int(settings.value("DataPoint1"))
     except (ValueError, TypeError):
         p1 = 1
     params.data_points = (p0, p1)
     tr = settings.value("TransferFunction", "")
     if tr:
         params.transfer_function = TransferFunction.loads(str(tr))
     else:
         params.transfer_function = TransferFunction.hue_scale()
     params.orthogonal = toBool(settings.value("Orthogonal"))
     params.symetric_coloring = toBool(
         settings.value("SymetricColoring", False))
     params.draw_line = toBool(settings.value("DrawLine", False))
     col = QColor(settings.value("LineColor"))
     if not col.isValid():
         col = QColor(0, 0, 0)
     params.line_color = col
     try:
         lw = int(settings.value("LineWidth", 0))
     except (ValueError, TypeError):
         lw = 0
     params.line_width = lw
     isc = toBool(settings.value("IsCapping"))
     if isc:
         vc = [0, 0]
         try:
             vc[0] = float(settings.value("ValueCappingMin"))
         except (ValueError, TypeError):
             vc[0] = 0
         try:
             vc[1] = float(settings.value("ValueCappingMax"))
         except (ValueError, TypeError):
             vc[1] = 1
         params.value_capping = vc
     else:
         params.value_capping = None
示例#27
0
 def setData(self, index, value, role = Qt.EditRole):
     if role == Qt.EditRole  and index.column() == 0:
         row = index.row()
         color = QColor(value)
         if color.isValid():
             self._labels[row].color = color
             self.dataChanged.emit(index, index)
             return True
         
     if role == Qt.EditRole  and index.column() == 1:
         row = index.row()
         name = value
         self._labels[row].name = str(name.toString())
         self.dataChanged.emit(index, index)
         return True
     return False
示例#28
0
def _get_color_range_under_cursor(view):
    assert(view is not None)
    if view.selection():                                    # Some text selected, just use it as input...
        color_range = view.selectionRange()
    else:                                                   # If no selection, try to get a #color under cursor
        color_range = common.getBoundTextRangeSL(
            common.IDENTIFIER_BOUNDARIES - {'#'}
          , common.IDENTIFIER_BOUNDARIES
          , view.cursorPosition()
          , view.document()
          )
        # Check if a word under cursor is a valid #color
        color = QColor(view.document().text(color_range))
        if not color.isValid():
            color_range = KTextEditor.Range(view.cursorPosition(), view.cursorPosition())
    return color_range
示例#29
0
 def load(params, settings):
     ScaleBar.load(params, settings)
     df = settings.value("DataFile", "")
     if df:
         params.data_file = path(df)
     else:
         params.data_file = None
     try:
         p0 = int(settings.value("DataPoint0"))
     except (ValueError, TypeError):
         p0 = 0
     try:
         p1 = int(settings.value("DataPoint1"))
     except (ValueError, TypeError):
         p1 = 1
     params.data_points = (p0, p1)
     tr = settings.value("TransferFunction", "")
     if tr:
         params.transfer_function = TransferFunction.loads(str(tr))
     else:
         params.transfer_function = TransferFunction.hue_scale()
     params.orthogonal = toBool(settings.value("Orthogonal"))
     params.symetric_coloring = toBool(settings.value("SymetricColoring", False))
     params.draw_line = toBool(settings.value("DrawLine", False))
     col = QColor(settings.value("LineColor"))
     if not col.isValid():
         col = QColor(0, 0, 0)
     params.line_color = col
     try:
         lw = int(settings.value("LineWidth", 0))
     except (ValueError, TypeError):
         lw = 0
     params.line_width = lw
     isc = toBool(settings.value("IsCapping"))
     if isc:
         vc = [0, 0]
         try:
             vc[0] = float(settings.value("ValueCappingMin"))
         except (ValueError, TypeError):
             vc[0] = 0
         try:
             vc[1] = float(settings.value("ValueCappingMax"))
         except (ValueError, TypeError):
             vc[1] = 1
         params.value_capping = vc
     else:
         params.value_capping = None
    def setData(self, index, value, role=Qt.EditRole):
        if role == Qt.EditRole and index.column() == 0:
            row = index.row()
            color = QColor(value)
            if color.isValid():
                self._labels[row].color = color
                self.dataChanged.emit(index, index)
                return True

        if role == Qt.EditRole and index.column() == 1:
            row = index.row()
            name = value
            self._labels[row].name = str(name.toString())
            self.dataChanged.emit(index, index)
            return True

        return False
示例#31
0
def insertColor():
    """Insert/edit color string using color chooser dialog

    If cursor positioned in a color string, this action will edit it, otherwise
    a new color string will be inserted into a document.
    """
    document = kate.activeDocument()
    view = kate.activeView()
    cursor = view.cursorPosition()

    if view.selection():  # Some text selected, just use it as input...
        color_range = view.selectionRange()
    else:  # If no selection, try to get a #color under cursor
        color_range = common.getBoundTextRangeSL(
            common.IDENTIFIER_BOUNDARIES - {'#'}, common.IDENTIFIER_BOUNDARIES,
            cursor, document)

    if color_range.isValid():
        current_color = document.text(color_range)
    else:
        current_color = kate.configuration[_INSERT_COLOR_LCC]

    color = QColor(current_color)
    # If no text selected (i.e. user doesn’t want to override selection)
    # and (guessed) color string is not valid, entered color will
    # be inserted at the current cursor position.
    if not color.isValid():
        color = QColor(kate.configuration[_INSERT_COLOR_LCC])
        if not view.selection():
            color_range = KTextEditor.Range(
                cursor, 0)  # Will not override the text under cursor…
    # Choose a color via dialog
    result = KColorDialog.getColor(color)
    if result == KColorDialog.Accepted:  # Did user press OK?
        color_str = color.name()  # Get it as color string
        # Remember for future use
        kate.configuration[_INSERT_COLOR_LCC] = color_str
        document.startEditing()
        document.replaceText(
            color_range,
            color_str)  # Replace selected/found range w/ a new text
        document.endEditing()
        # Select just entered #color, if something was selected before
        if view.selection():
            start_pos = color_range.start()
            view.setSelection(KTextEditor.Range(start_pos, len(color_str)))
示例#32
0
 def updateColor(self, item):
    pixmap = QPixmap(16, 16)
    color = QColor()
    if item:
       color = item.backgroundColor()
    if not color.isValid():
       color = self.palette().base().color()
    painter = QPainter(pixmap)
    painter.fillRect(0, 0, 16, 16, color)
    lighter = color.lighter()
    painter.setPen(lighter)
    # light frame
    painter.drawPolyline(QPoint(0, 15), QPoint(0, 0), QPoint(15, 0))
    painter.setPen(color.darker())
    # dark frame
    painter.drawPolyline(QPoint(1, 15), QPoint(15, 15), QPoint(15, 1))
    painter.end()
    self.colorAction.setIcon(QIcon(pixmap))
示例#33
0
文件: __init__.py 项目: nerdocs/MedUX
    def setBaseColor(cls, newcolor: QColor):
        """
        Sets the base color and makes sure all top level widgets are updated.
        It tries to ensure that the actual used colors are within
        reasonable bounds while generating the actual baseColor
        from the users request.
        :param newcolor: New color to be set
        """
        cls._requestedBaseColor = newcolor

        color = QColor()
        color.setHsv(newcolor.hue(),
                     newcolor.saturation() * 0.7,
                     64 + newcolor.value() / 3)

        if color.isValid() and color != cls._baseColor:
            cls._baseColor = color
            for widget in QApplication.topLevelWidgets():
                widget.update()
示例#34
0
    def setCurrentColor(self, color):
        if color is None: return
        color = QColor(color)
        if self.col == color or not color.isValid():
            return

        item = self.popup.find(color)
        if not item:
            self.insertColor(color, self.tr('Custom'))
            item = self.popup.find(color)

        self.col = color
        self.setText(item.text())

        self.dirty = True

        self.popup.hide()
        self.repaint()

        item.setSelected(True)
        self.emit(SIGNAL('colorChanged(QColor'), color)
示例#35
0
    def getColorFromCmnd(self, colorinfo):
        '''
        Returns a QColor based on the information in the dictionary
        colorinfo.  Raises a KeyError if the "color" key is not given.

        Recognized keys are:
            "color": color name or 24-bit RGB integer value
                         (eg, 0xFF0088)
            "alpha": alpha value from 0 (transparent) to 255 (opaque)
                     if viewer.ignoreAlpha True, this value is ignored
        '''
        colordata = colorinfo["color"]
        mycolor = QColor(colordata)
        if not mycolor.isValid():
            raise ValueError("Invalid color '%s'" % str(colordata))
        if not self.__viewer.ignoreAlpha():
            try:
                mycolor.setAlpha(int(colorinfo["alpha"]))
            except KeyError:
                pass
        return mycolor
示例#36
0
def convert_to_color ( object, name, value ):
    """ Converts a number into a QColor object.
    """
    if isinstance( value, QColor ):
        return value

    if isinstance( value, ColorTypes ):
        return QColor( *normalized_color( value, has_alpha = True ) )

    color = None
    if isinstance( value, basestring ):
        # Allow for spaces in the string value:
        value = value.replace( ' ', '' )
    else:
        # Try the toolkit agnostic format:
        try:
            tup = eval( value )
            if isinstance( tup, tuple ):
                if 3 <= len( tup ) <= 4:
                    try:
                        color = QColor( *tup )
                    except TypeError:
                        raise FacetError
                else:
                    raise FacetError
        except:
            pass

    if color is None:
        # Let the constructor handle the value:
        try:
            color = QColor( value )
        except TypeError:
            raise FacetError

    if color.isValid():
        return color

    raise FacetError
示例#37
0
    def chooseColor(self):
        """Show a color picker to let the user choose a color.

        Args:
            None
        Returns:
            None
        Raises:
            None

        """
        mySettings = QSettings()
        try:
            myInitialColor = QColor(mySettings
                .value("vectorbucketfill/current_color"))
        except:
            myInitialColor = QColor(255, 255, 255)
        #myColor = QColor()
        myColor = QColorDialog.getColor(initial=myInitialColor)
        #myColorSelect = BucketFillDialog()
        if QColor.isValid(myColor):
            # do something useful
            mySettings.setValue("vectorbucketfill/current_color", myColor)
示例#38
0
    def chooseColor(self):
        """Show a color picker to let the user choose a color.

        Args:
            None
        Returns:
            None
        Raises:
            None

        """
        mySettings = QSettings()
        try:
            myInitialColor = QColor(
                mySettings.value("vectorbucketfill/current_color"))
        except:
            myInitialColor = QColor(255, 255, 255)
        #myColor = QColor()
        myColor = QColorDialog.getColor(initial=myInitialColor)
        #myColorSelect = BucketFillDialog()
        if QColor.isValid(myColor):
            # do something useful
            mySettings.setValue("vectorbucketfill/current_color", myColor)
示例#39
0
    def updateColors(self, view=None):
        '''Scan a document for #colors

            Returns a list of tuples: QColor and range in a document
            TODO Some refactoring needed to reduce code duplication
            (@sa _get_color_range_under_cursor())
        '''
        self.colors = []                                    # Clear previous colors
        if view:
            document = view.document()
        else:
            try:
                document = kate.activeDocument()
            except kate.NoActiveView:
                return                                      # Do nothing if we can't get a current document
        # Iterate over document's lines trying to find #colors
        for l in range(0, document.lines()):
            line = document.line(l)                         # Get the current line
            start = 0                                       # Set initial position to 0 (line start)
            while start < len(line):                        # Repeat 'till the line end
                start = line.find('#', start)               # Try to find a '#' character (start of #color)
                if start == -1:                             # Did we found smth?
                    break                                   # No! Nothing to do...
                # Try to get a word right after the '#' char
                end = start + 1
                for c in line[end:]:
                    if not (c in string.hexdigits):
                        break
                    end += 1
                color_range = KTextEditor.Range(l, start, l, end)
                color_str = document.text(color_range)
                color = QColor(color_str)
                if color.isValid():
                    self.colors.append(ColorRangePair(color, color_range))
                    kate.kDebug('ColorUtilsToolView: scan for #colors found {}'.format(color_str))
                start = end
示例#40
0
    def load(self):
        settings = QSettings()

        settings.beginGroup("GraphicParameters")
# First, parameters for normal points
        self._point_size = None
        try:
            _point_size = float(settings.value("PointSize"))
        except (ValueError, TypeError):
            _point_size = 5.0
        self.point_size = _point_size
        self._point_thickness = None
        try:
            _point_thickness = int(settings.value("PointThickness"))
        except (ValueError, TypeError):
            _point_thickness = 0
        self.point_thickness = _point_thickness
        self._point_color = None
        _point_color = QColor(settings.value("PointColor"))
        if not _point_color.isValid():
            _point_color = QColor(Qt.red)
        self.point_color = _point_color
        _selected_point_color = QColor(settings.value("SelectedPointColor"))
        if not _selected_point_color.isValid():
            _selected_point_color = QColor(255, 128, 128, 255)
        self._selected_point_color = _selected_point_color
        _new_point_color = QColor(settings.value("NewPointColor"))
        if not _new_point_color.isValid():
            _new_point_color = QColor(Qt.blue)
        self._new_point_color = None
        self.new_point_color = _new_point_color

# Parameter for cells
        self._cell_size = None
        try:
            _cell_size = float(settings.value("CellSize"))
        except (ValueError, TypeError):
            _cell_size = 5.0
        self.cell_size = _cell_size
        self._cell_thickness = None
        try:
            _cell_thickness = int(settings.value("CellThickness"))
        except (ValueError, TypeError):
            _cell_thickness = 1
        self.cell_thickness = _cell_thickness
        self._cell_color = None
        _cell_color = QColor(settings.value("CellColor"))
        if not _cell_color.isValid():
            _cell_color = QColor(Qt.darkCyan)
            _cell_color.setAlphaF(0.5)
        self.cell_color = _cell_color

        self._selected_cell_color = None
        _selected_cell_color = QColor(settings.value("SelectedCellColor"))
        if not _selected_cell_color.isValid():
            _selected_cell_color = QColor(Qt.yellow)
            _selected_cell_color.setAlphaF(0.5)
        self.selected_cell_color = _selected_cell_color

        self._division_wall_color = None
        _division_wall_color = QColor(settings.value("DivisionWallColor"))
        if not _division_wall_color.isValid():
            _division_wall_color = QColor(255, 85, 0)
            _division_wall_color.setAlphaF(0.8)
        self.division_wall_color = _division_wall_color

# Then, parameters for old points
        try:
            self._old_point_size = float(settings.value("OldPointSize"))
        except (ValueError, TypeError):
            self._old_point_size = 5.0
        try:
            self._old_point_thickness = int(settings.value("OldPointThickness"))
        except (ValueError, TypeError):
            self._old_point_thickness = 0
        self._old_point_color = None
        self._old_point_color = QColor(settings.value("OldPointColor"))
        if not self._old_point_color.isValid():
            self._old_point_color = QColor(Qt.yellow)
        self._old_point_matching_color = QColor(settings.value("OldPointMatchingColor"))
        if not self._old_point_matching_color.isValid():
            self._old_point_matching_color = QColor(Qt.darkYellow)
        self._show_id = toBool(settings.value("ShowId", 'false'))
# Parameters for arrow
        try:
            self._arrow_line_size = float(settings.value("ArrowLineSize"))
        except (ValueError, TypeError):
            self._arrow_line_size = 2
        try:
            self._arrow_head_size = float(settings.value("ArrowHeadSize"))
        except (ValueError, TypeError):
            self._arrow_head_size = .1
        self._arrow_color = QColor(settings.value("ArrowColor"))
        if not self._arrow_color.isValid():
            self._arrow_color = QColor(Qt.lightGray)
        self._draw_arrow = toBool(settings.value("DrawArrow", 'true'))
        self._show_template = toBool(settings.value("ShowTemplate", 'false'))
        self._template_color = QColor(settings.value("TemplateColor"))
        if not self._template_color.isValid():
            self._template_color = QColor(255, 0, 0, 100)
        self._search_color = QColor(settings.value("SearchColor"))
        if not self._search_color.isValid():
            self._search_color = QColor(255, 0, 255, 100)
        settings.endGroup()

# The search parameters
        settings.beginGroup("SearchParameters")
        try:
            self._template_size = int(settings.value("TemplateSize"))
        except (ValueError, TypeError):
            self._template_size = 10
        s = self._template_size
        self.template_rect = QRectF(-s, -s, 2*s, 2*s)
        try:
            self._search_size = int(settings.value("SearchSize"))
        except (ValueError, TypeError):
            self._search_size = 50
        s = self._search_size
        self.search_rect = QRectF(-s, -s, 2*s, 2*s)
        self._estimate = toBool(settings.value("Estimate", 'false'))
        try:
            self._filter_size_ratio = float(settings.value("FilterSizeRatio"))
        except (ValueError, TypeError):
            self._filter_size_ratio = .5
        settings.endGroup()

        settings.beginGroup("GUI")
        self._show_vectors = toBool(settings.value("ShowVectors", 'true'))
        self._link_views = toBool(settings.value("LinkViews", 'true'))
        try:
            cache_size = int(settings.value("CacheSize"))
        except (ValueError, TypeError):
            cache_size = 200
        self.cache_size = cache_size
        self._last_dir = path(settings.value("LastsDir", "."))
        self._use_OpenGL = toBool(settings.value("UseOpenGL", 'false'))
        settings.beginGroup("RecentProjects")
        try:
            numproj = int(settings.value("NumberOfProjects"))
        except (ValueError, TypeError):
            numproj = 0
        self._recent_projects = []
        if numproj > 0:
            for i in range(numproj):
                name = "Project%d" % i
                value = path(settings.value(name))
                self._recent_projects.append(value)
        try:
            self._max_number_of_projects = int(settings.value("MaxNumberOfProjects"))
        except (ValueError, TypeError):
            self._max_number_of_projects = 5
        settings.endGroup()
        settings.endGroup()

# The plotting parameters
        settings.beginGroup("PlottingParameters")
        settings.beginGroup("Ellipsis")
        try:
            self._ellipsis_scaling = float(settings.value("Scaling", 1.0))
        except (ValueError, TypeError):
            self._ellipsis_scaling = 1.0
        self._ellipsis_color = QColor(settings.value("Color"))
        if not self._ellipsis_color.isValid():
            self._ellipsis_color = QColor(0, 0, 0)
        try:
            self._ellipsis_thickness = int(settings.value("Thickness", 0))
        except (ValueError, TypeError):
            self._ellipsis_thickness = 0
        try:
            self._ellipsis_min_anisotropy = float(settings.value("MinAnisotropy", 1e-3))
        except (ValueError, TypeError):
            self._ellipsis_min_anisotropy = 1e-3
        self._ellipsis_positive_color = QColor(settings.value("PositiveColor"))
        if not self._ellipsis_positive_color.isValid():
            self._ellipsis_positive_color = QColor(0, 0, 255)
        self._ellipsis_negative_color = QColor(settings.value("NegativeColor"))
        if not self._ellipsis_negative_color.isValid():
            self._ellipsis_negative_color = QColor(255, 0, 0)
        self._ellipsis_plot = toBool(settings.value("Plot", 'false'))
        self._ellipsis_scale_axis = toBool(settings.value("ScaleAxis", 'false'))
        settings.endGroup()
        settings.endGroup()
        self._point_editable = True
        self._point_selectable = True
        self._cell_editable = False
示例#41
0
 def old_point_matching_color(self, color):
     col = QColor(color)
     if col.isValid() and col != self._old_point_matching_color:
         self._old_point_matching_color = col
         self.oldPointParameterChange.emit()
示例#42
0
 def arrow_color(self, color):
     col = QColor(color)
     if col.isValid() and col != self._arrow_color:
         self._arrow_color = col
         self.arrowParameterChange.emit()
示例#43
0
 def template_color(self, color):
     col = QColor(color)
     if col.isValid() and col != self._template_color:
         self._template_color = col
         self.searchParameterChange.emit()
示例#44
0
 def selected_cell_color(self, color):
     col = QColor(color)
     if col.isValid() and col != self._selected_cell_color:
         self._selected_cell_color = col
         self.cellParameterChange.emit()
示例#45
0
 def old_point_matching_color(self, color):
     col = QColor(color)
     if col.isValid() and col != self._old_point_matching_color:
         self._old_point_matching_color = col
         self.oldPointParameterChange.emit()
示例#46
0
    def load(self):
        settings = QSettings()

        settings.beginGroup("GraphicParameters")
        # First, parameters for normal points
        self._point_size = None
        try:
            _point_size = float(settings.value("PointSize"))
        except (ValueError, TypeError):
            _point_size = 5.0
        self.point_size = _point_size
        self._point_thickness = None
        try:
            _point_thickness = int(settings.value("PointThickness"))
        except (ValueError, TypeError):
            _point_thickness = 0
        self.point_thickness = _point_thickness
        self._point_color = None
        _point_color = QColor(settings.value("PointColor"))
        if not _point_color.isValid():
            _point_color = QColor(Qt.red)
        self.point_color = _point_color
        _selected_point_color = QColor(settings.value("SelectedPointColor"))
        if not _selected_point_color.isValid():
            _selected_point_color = QColor(255, 128, 128, 255)
        self._selected_point_color = _selected_point_color
        _new_point_color = QColor(settings.value("NewPointColor"))
        if not _new_point_color.isValid():
            _new_point_color = QColor(Qt.blue)
        self._new_point_color = None
        self.new_point_color = _new_point_color

        # Parameter for cells
        self._cell_size = None
        try:
            _cell_size = float(settings.value("CellSize"))
        except (ValueError, TypeError):
            _cell_size = 5.0
        self.cell_size = _cell_size
        self._cell_thickness = None
        try:
            _cell_thickness = int(settings.value("CellThickness"))
        except (ValueError, TypeError):
            _cell_thickness = 1
        self.cell_thickness = _cell_thickness
        self._cell_color = None
        _cell_color = QColor(settings.value("CellColor"))
        if not _cell_color.isValid():
            _cell_color = QColor(Qt.darkCyan)
            _cell_color.setAlphaF(0.5)
        self.cell_color = _cell_color

        self._selected_cell_color = None
        _selected_cell_color = QColor(settings.value("SelectedCellColor"))
        if not _selected_cell_color.isValid():
            _selected_cell_color = QColor(Qt.yellow)
            _selected_cell_color.setAlphaF(0.5)
        self.selected_cell_color = _selected_cell_color

        self._division_wall_color = None
        _division_wall_color = QColor(settings.value("DivisionWallColor"))
        if not _division_wall_color.isValid():
            _division_wall_color = QColor(255, 85, 0)
            _division_wall_color.setAlphaF(0.8)
        self.division_wall_color = _division_wall_color

        # Then, parameters for old points
        try:
            self._old_point_size = float(settings.value("OldPointSize"))
        except (ValueError, TypeError):
            self._old_point_size = 5.0
        try:
            self._old_point_thickness = int(
                settings.value("OldPointThickness"))
        except (ValueError, TypeError):
            self._old_point_thickness = 0
        self._old_point_color = None
        self._old_point_color = QColor(settings.value("OldPointColor"))
        if not self._old_point_color.isValid():
            self._old_point_color = QColor(Qt.yellow)
        self._old_point_matching_color = QColor(
            settings.value("OldPointMatchingColor"))
        if not self._old_point_matching_color.isValid():
            self._old_point_matching_color = QColor(Qt.darkYellow)
        self._show_id = toBool(settings.value("ShowId", 'false'))
        # Parameters for arrow
        try:
            self._arrow_line_size = float(settings.value("ArrowLineSize"))
        except (ValueError, TypeError):
            self._arrow_line_size = 2
        try:
            self._arrow_head_size = float(settings.value("ArrowHeadSize"))
        except (ValueError, TypeError):
            self._arrow_head_size = .1
        self._arrow_color = QColor(settings.value("ArrowColor"))
        if not self._arrow_color.isValid():
            self._arrow_color = QColor(Qt.lightGray)
        self._draw_arrow = toBool(settings.value("DrawArrow", 'true'))
        self._show_template = toBool(settings.value("ShowTemplate", 'false'))
        self._template_color = QColor(settings.value("TemplateColor"))
        if not self._template_color.isValid():
            self._template_color = QColor(255, 0, 0, 100)
        self._search_color = QColor(settings.value("SearchColor"))
        if not self._search_color.isValid():
            self._search_color = QColor(255, 0, 255, 100)
        settings.endGroup()

        # The search parameters
        settings.beginGroup("SearchParameters")
        try:
            self._template_size = int(settings.value("TemplateSize"))
        except (ValueError, TypeError):
            self._template_size = 10
        s = self._template_size
        self.template_rect = QRectF(-s, -s, 2 * s, 2 * s)
        try:
            self._search_size = int(settings.value("SearchSize"))
        except (ValueError, TypeError):
            self._search_size = 50
        s = self._search_size
        self.search_rect = QRectF(-s, -s, 2 * s, 2 * s)
        self._estimate = toBool(settings.value("Estimate", 'false'))
        try:
            self._filter_size_ratio = float(settings.value("FilterSizeRatio"))
        except (ValueError, TypeError):
            self._filter_size_ratio = .5
        settings.endGroup()

        settings.beginGroup("GUI")
        self._show_vectors = toBool(settings.value("ShowVectors", 'true'))
        self._link_views = toBool(settings.value("LinkViews", 'true'))
        try:
            cache_size = int(settings.value("CacheSize"))
        except (ValueError, TypeError):
            cache_size = 200
        self.cache_size = cache_size
        self._last_dir = path(settings.value("LastsDir", "."))
        self._use_OpenGL = toBool(settings.value("UseOpenGL", 'false'))
        settings.beginGroup("RecentProjects")
        try:
            numproj = int(settings.value("NumberOfProjects"))
        except (ValueError, TypeError):
            numproj = 0
        self._recent_projects = []
        if numproj > 0:
            for i in range(numproj):
                name = "Project%d" % i
                value = path(settings.value(name))
                self._recent_projects.append(value)
        try:
            self._max_number_of_projects = int(
                settings.value("MaxNumberOfProjects"))
        except (ValueError, TypeError):
            self._max_number_of_projects = 5
        settings.endGroup()
        settings.endGroup()

        # The plotting parameters
        settings.beginGroup("PlottingParameters")
        settings.beginGroup("Ellipsis")
        try:
            self._ellipsis_scaling = float(settings.value("Scaling", 1.0))
        except (ValueError, TypeError):
            self._ellipsis_scaling = 1.0
        self._ellipsis_color = QColor(settings.value("Color"))
        if not self._ellipsis_color.isValid():
            self._ellipsis_color = QColor(0, 0, 0)
        try:
            self._ellipsis_thickness = int(settings.value("Thickness", 0))
        except (ValueError, TypeError):
            self._ellipsis_thickness = 0
        try:
            self._ellipsis_min_anisotropy = float(
                settings.value("MinAnisotropy", 1e-3))
        except (ValueError, TypeError):
            self._ellipsis_min_anisotropy = 1e-3
        self._ellipsis_positive_color = QColor(settings.value("PositiveColor"))
        if not self._ellipsis_positive_color.isValid():
            self._ellipsis_positive_color = QColor(0, 0, 255)
        self._ellipsis_negative_color = QColor(settings.value("NegativeColor"))
        if not self._ellipsis_negative_color.isValid():
            self._ellipsis_negative_color = QColor(255, 0, 0)
        self._ellipsis_plot = toBool(settings.value("Plot", 'false'))
        self._ellipsis_scale_axis = toBool(settings.value(
            "ScaleAxis", 'false'))
        settings.endGroup()
        settings.endGroup()
        self._point_editable = True
        self._point_selectable = True
        self._cell_editable = False
示例#47
0
 def setColor(self):
     action = self.sender()
     if action is not None and isinstance(action, QAction):
         color = QColor(action.data())
         if color.isValid():
             self.setTextColor(color)
示例#48
0
 def setColor(self):
     action = self.sender()
     if action is not None and isinstance(action, QAction):
         color = QColor(action.data())
         if color.isValid():
             self.setTextColor(color)
示例#49
0
 def load(params, settings):
     log_debug("Loading with parameter object: %s" % id(params))
     color = QColor(settings.value("Color"))
     if not color.isValid():
         color = QColor(0, 0, 0)
     params.color = color
示例#50
0
 def template_color(self, color):
     col = QColor(color)
     if col.isValid() and col != self._template_color:
         self._template_color = col
         self.searchParameterChange.emit()
示例#51
0
 def arrow_color(self, color):
     col = QColor(color)
     if col.isValid() and col != self._arrow_color:
         self._arrow_color = col
         self.arrowParameterChange.emit()
示例#52
0
 def division_wall_color(self, color):
     col = QColor(color)
     if col.isValid() and col != self._division_wall_color:
         self._division_wall_color = col
         self.cellParameterChange.emit()
示例#53
0
 def load(params, settings):
     log_debug("Loading with parameter object: %s" % id(params))
     color = QColor(settings.value("Color"))
     if not color.isValid():
         color = QColor(0, 0, 0)
     params.color = color
示例#54
0
 def selected_cell_color(self, color):
     col = QColor(color)
     if col.isValid() and col != self._selected_cell_color:
         self._selected_cell_color = col
         self.cellParameterChange.emit()
示例#55
0
 def division_wall_color(self, color):
     col = QColor(color)
     if col.isValid() and col != self._division_wall_color:
         self._division_wall_color = col
         self.cellParameterChange.emit()
示例#56
0
class Parameters(QObject):

    pointParameterChange = Signal()
    oldPointParameterChange = Signal()
    arrowParameterChange = Signal()
    searchParameterChange = Signal()
    renderingChanged = Signal()
    recentProjectsChange = Signal()
    plottingParameterChange = Signal()
    cellParameterChange = Signal()

    """
    Signal launched when parameters change:
        - pointParameterChange
        - oldPointParameterChange
        - arrowParameterChange
        - searchParameterChange
        - renderingChanged
        - recentProjectsChange
        - cellParameterChange
        - plottingParameterChange
    """
    def __init__(self):
        QObject.__init__(self)
        self.load()

    #def __del__(self):
        #cleanQObject(self)

    # Use thread or not to compute on the background
    use_thread = False

    def load(self):
        settings = QSettings()

        settings.beginGroup("GraphicParameters")
# First, parameters for normal points
        self._point_size = None
        try:
            _point_size = float(settings.value("PointSize"))
        except (ValueError, TypeError):
            _point_size = 5.0
        self.point_size = _point_size
        self._point_thickness = None
        try:
            _point_thickness = int(settings.value("PointThickness"))
        except (ValueError, TypeError):
            _point_thickness = 0
        self.point_thickness = _point_thickness
        self._point_color = None
        _point_color = QColor(settings.value("PointColor"))
        if not _point_color.isValid():
            _point_color = QColor(Qt.red)
        self.point_color = _point_color
        _selected_point_color = QColor(settings.value("SelectedPointColor"))
        if not _selected_point_color.isValid():
            _selected_point_color = QColor(255, 128, 128, 255)
        self._selected_point_color = _selected_point_color
        _new_point_color = QColor(settings.value("NewPointColor"))
        if not _new_point_color.isValid():
            _new_point_color = QColor(Qt.blue)
        self._new_point_color = None
        self.new_point_color = _new_point_color

# Parameter for cells
        self._cell_size = None
        try:
            _cell_size = float(settings.value("CellSize"))
        except (ValueError, TypeError):
            _cell_size = 5.0
        self.cell_size = _cell_size
        self._cell_thickness = None
        try:
            _cell_thickness = int(settings.value("CellThickness"))
        except (ValueError, TypeError):
            _cell_thickness = 1
        self.cell_thickness = _cell_thickness
        self._cell_color = None
        _cell_color = QColor(settings.value("CellColor"))
        if not _cell_color.isValid():
            _cell_color = QColor(Qt.darkCyan)
            _cell_color.setAlphaF(0.5)
        self.cell_color = _cell_color

        self._selected_cell_color = None
        _selected_cell_color = QColor(settings.value("SelectedCellColor"))
        if not _selected_cell_color.isValid():
            _selected_cell_color = QColor(Qt.yellow)
            _selected_cell_color.setAlphaF(0.5)
        self.selected_cell_color = _selected_cell_color

        self._division_wall_color = None
        _division_wall_color = QColor(settings.value("DivisionWallColor"))
        if not _division_wall_color.isValid():
            _division_wall_color = QColor(255, 85, 0)
            _division_wall_color.setAlphaF(0.8)
        self.division_wall_color = _division_wall_color

# Then, parameters for old points
        try:
            self._old_point_size = float(settings.value("OldPointSize"))
        except (ValueError, TypeError):
            self._old_point_size = 5.0
        try:
            self._old_point_thickness = int(settings.value("OldPointThickness"))
        except (ValueError, TypeError):
            self._old_point_thickness = 0
        self._old_point_color = None
        self._old_point_color = QColor(settings.value("OldPointColor"))
        if not self._old_point_color.isValid():
            self._old_point_color = QColor(Qt.yellow)
        self._old_point_matching_color = QColor(settings.value("OldPointMatchingColor"))
        if not self._old_point_matching_color.isValid():
            self._old_point_matching_color = QColor(Qt.darkYellow)
        self._show_id = toBool(settings.value("ShowId", 'false'))
# Parameters for arrow
        try:
            self._arrow_line_size = float(settings.value("ArrowLineSize"))
        except (ValueError, TypeError):
            self._arrow_line_size = 2
        try:
            self._arrow_head_size = float(settings.value("ArrowHeadSize"))
        except (ValueError, TypeError):
            self._arrow_head_size = .1
        self._arrow_color = QColor(settings.value("ArrowColor"))
        if not self._arrow_color.isValid():
            self._arrow_color = QColor(Qt.lightGray)
        self._draw_arrow = toBool(settings.value("DrawArrow", 'true'))
        self._show_template = toBool(settings.value("ShowTemplate", 'false'))
        self._template_color = QColor(settings.value("TemplateColor"))
        if not self._template_color.isValid():
            self._template_color = QColor(255, 0, 0, 100)
        self._search_color = QColor(settings.value("SearchColor"))
        if not self._search_color.isValid():
            self._search_color = QColor(255, 0, 255, 100)
        settings.endGroup()

# The search parameters
        settings.beginGroup("SearchParameters")
        try:
            self._template_size = int(settings.value("TemplateSize"))
        except (ValueError, TypeError):
            self._template_size = 10
        s = self._template_size
        self.template_rect = QRectF(-s, -s, 2*s, 2*s)
        try:
            self._search_size = int(settings.value("SearchSize"))
        except (ValueError, TypeError):
            self._search_size = 50
        s = self._search_size
        self.search_rect = QRectF(-s, -s, 2*s, 2*s)
        self._estimate = toBool(settings.value("Estimate", 'false'))
        try:
            self._filter_size_ratio = float(settings.value("FilterSizeRatio"))
        except (ValueError, TypeError):
            self._filter_size_ratio = .5
        settings.endGroup()

        settings.beginGroup("GUI")
        self._show_vectors = toBool(settings.value("ShowVectors", 'true'))
        self._link_views = toBool(settings.value("LinkViews", 'true'))
        try:
            cache_size = int(settings.value("CacheSize"))
        except (ValueError, TypeError):
            cache_size = 200
        self.cache_size = cache_size
        self._last_dir = path(settings.value("LastsDir", "."))
        self._use_OpenGL = toBool(settings.value("UseOpenGL", 'false'))
        settings.beginGroup("RecentProjects")
        try:
            numproj = int(settings.value("NumberOfProjects"))
        except (ValueError, TypeError):
            numproj = 0
        self._recent_projects = []
        if numproj > 0:
            for i in range(numproj):
                name = "Project%d" % i
                value = path(settings.value(name))
                self._recent_projects.append(value)
        try:
            self._max_number_of_projects = int(settings.value("MaxNumberOfProjects"))
        except (ValueError, TypeError):
            self._max_number_of_projects = 5
        settings.endGroup()
        settings.endGroup()

# The plotting parameters
        settings.beginGroup("PlottingParameters")
        settings.beginGroup("Ellipsis")
        try:
            self._ellipsis_scaling = float(settings.value("Scaling", 1.0))
        except (ValueError, TypeError):
            self._ellipsis_scaling = 1.0
        self._ellipsis_color = QColor(settings.value("Color"))
        if not self._ellipsis_color.isValid():
            self._ellipsis_color = QColor(0, 0, 0)
        try:
            self._ellipsis_thickness = int(settings.value("Thickness", 0))
        except (ValueError, TypeError):
            self._ellipsis_thickness = 0
        try:
            self._ellipsis_min_anisotropy = float(settings.value("MinAnisotropy", 1e-3))
        except (ValueError, TypeError):
            self._ellipsis_min_anisotropy = 1e-3
        self._ellipsis_positive_color = QColor(settings.value("PositiveColor"))
        if not self._ellipsis_positive_color.isValid():
            self._ellipsis_positive_color = QColor(0, 0, 255)
        self._ellipsis_negative_color = QColor(settings.value("NegativeColor"))
        if not self._ellipsis_negative_color.isValid():
            self._ellipsis_negative_color = QColor(255, 0, 0)
        self._ellipsis_plot = toBool(settings.value("Plot", 'false'))
        self._ellipsis_scale_axis = toBool(settings.value("ScaleAxis", 'false'))
        settings.endGroup()
        settings.endGroup()
        self._point_editable = True
        self._point_selectable = True
        self._cell_editable = False

    def save(self):
        settings = QSettings()
        settings.beginGroup("GraphicParameters")
        settings.setValue("PointSize", self._point_size)
        settings.setValue("PointColor", self._point_color)
        settings.setValue("PointThickness", self._point_thickness)
        settings.setValue("SelectedPointColor", self._selected_point_color)
        settings.setValue("NewPointColor", self._new_point_color)
        settings.setValue("CellSize", self._cell_size)
        settings.setValue("CellColor", self._cell_color)
        settings.setValue("CellThickness", self._cell_thickness)
        settings.setValue("SelectedCellColor", self._selected_cell_color)
        settings.setValue("DivisionWallColor", self._division_wall_color)
        settings.setValue("OldPointSize", self._old_point_size)
        settings.setValue("OldPointColor", self._old_point_color)
        settings.setValue("OldPointMatchingColor", self._old_point_matching_color)
        settings.setValue("ShowId", self._show_id)
        settings.setValue("ArrowLineSize", self._arrow_line_size)
        settings.setValue("ArrowHeadSize", self._arrow_head_size)
        settings.setValue("ArrowColor", self._arrow_color)
        settings.setValue("DrawArrow", self._draw_arrow)
        settings.setValue("ShowTemplate", self._show_template)
        settings.setValue("TemplateColor", self._template_color)
        settings.setValue("SearchColor", self._search_color)
        settings.endGroup()

        settings.beginGroup("SearchParameters")
        settings.setValue("TemplateSize", self._template_size)
        settings.setValue("SearchSize", self._search_size)
        settings.setValue("Estimate", self._estimate)
        settings.setValue("FilterSizeRatio", self._filter_size_ratio)
        settings.endGroup()

        settings.beginGroup("GUI")
        settings.setValue("UseOpenGL", self._use_OpenGL)
        settings.setValue("ShowVectors", self._show_vectors)
        settings.setValue("LinkViews", self._link_views)
        settings.setValue("CacheSize", self._cache_size)
        settings.setValue("LastsDir", unicode(self._last_dir))

        settings.beginGroup("RecentProjects")
        settings.setValue("MaxNumberOfProjects", self._max_number_of_projects)
        settings.setValue("NumberOfProjects", len(self._recent_projects))
        for i, p in enumerate(self._recent_projects):
            name = "Project%d" % i
            settings.setValue(name, unicode(p))
        settings.endGroup()
        settings.endGroup()
# The plotting parameters
        settings.beginGroup("PlottingParameters")
        settings.beginGroup("Ellipsis")
        settings.setValue("Scaling", self._ellipsis_scaling)
        settings.setValue("Color", self._ellipsis_color)
        settings.setValue("Thickness", self._ellipsis_thickness)
        settings.setValue("MinAnisotropy", self._ellipsis_min_anisotropy)
        settings.setValue("PositiveColor", self._ellipsis_positive_color)
        settings.setValue("NegativeColor", self._ellipsis_negative_color)
        settings.setValue("Plot", self._ellipsis_plot)
        settings.setValue("ScaleAxis", self._ellipsis_scale_axis)
        settings.endGroup()
        settings.endGroup()

#{ On Screen Drawing

    @property
    def point_size(self):
        """
        Size of a points on the scene
        """
        return self._point_size

    @point_size.setter
    def point_size(self, size):
        if size > 0 and size != self._point_size:
            self._point_size = size
            self._find_font()
            self.pointParameterChange.emit()

    @property
    def point_color(self):
        """
        Color used to draw points
        """
        return self._point_color

    @point_color.setter
    def point_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._point_color:
            self._point_color = col
            self.point_hover_color = col.lighter(150)
            if self.point_hover_color == col:
                self.point_hover_color = col.lighter(50)
            self.pointParameterChange.emit()

    @property
    def selected_point_color(self):
        """
        Set the color of a selected point
        """
        return self._selected_point_color

    @selected_point_color.setter
    def selected_point_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._selected_point_color:
            self._selected_point_color = col
            self.pointParameterChange.emit()

    @property
    def new_point_color(self):
        """
        Set the color of a new point
        """
        return self._new_point_color

    @new_point_color.setter
    def new_point_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._new_point_color:
            self._new_point_color = col
            self.new_point_hover_color = col.lighter(150)
            if self.new_point_hover_color == col:
                self.new_point_hover_color = col.lighter(50)
            self.pointParameterChange.emit()

    @property
    def cell_size(self):
        """
        Set the size of a cell graphic item
        """
        return self._cell_size

    @cell_size.setter
    def cell_size(self, new_size):
        if new_size > 0 and new_size != self._cell_size:
            self._cell_size = new_size
            self.cellParameterChange.emit()

    @property
    def cell_thickness(self):
        """
        Set the thickness of the line used to draw the cell graphic item
        """
        return self._cell_thickness

    @cell_thickness.setter
    def cell_thickness(self, th):
        thick = int(th)
        if thick >= 0 and thick != self._cell_thickness:
            self._cell_thickness = thick
            self.cellParameterChange.emit()

    @property
    def cell_color(self):
        """
        Set the color used to draw the cell
        """
        return self._cell_color

    @cell_color.setter
    def cell_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._cell_color:
            self._cell_color = col
            self.cell_hover_color = col.lighter(150)
            if self.cell_hover_color == col:
                self.cell_hover_color = col.lighter(50)
            self.cellParameterChange.emit()

    @property
    def selected_cell_color(self):
        """
        Set the color used to draw the selected cell
        """
        return self._selected_cell_color

    @selected_cell_color.setter
    def selected_cell_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._selected_cell_color:
            self._selected_cell_color = col
            self.cellParameterChange.emit()

    @property
    def division_wall_color(self):
        """
        Set the color used to draw the selected cell
        """
        return self._division_wall_color

    @division_wall_color.setter
    def division_wall_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._division_wall_color:
            self._division_wall_color = col
            self.cellParameterChange.emit()

    @property
    def old_point_size(self):
        """
        Size of a old points on the scene
        """
        return self._old_point_size

    @old_point_size.setter
    def old_point_size(self, size):
        if size > 0 and size != self._old_point_size:
            self._old_point_size = size
            self.oldPointParameterChange.emit()

    @property
    def old_point_color(self):
        """
        Color used to draw old points
        """
        return self._old_point_color

    @old_point_color.setter
    def old_point_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._old_point_color:
            self._old_point_color = col
            self.oldPointParameterChange.emit()

    @property
    def old_point_matching_color(self):
        """
        Color used to draw old point matching the current hovered point
        """
        return self._old_point_matching_color

    @old_point_matching_color.setter
    def old_point_matching_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._old_point_matching_color:
            self._old_point_matching_color = col
            self.oldPointParameterChange.emit()

    @property
    def arrow_line_size(self):
        """
        Width of the pen used to draw arrows.
        """
        return self._arrow_line_size

    @arrow_line_size.setter
    def arrow_line_size(self, size):
        if size > 0 and size != self._arrow_line_size:
            self._arrow_line_size = size
            self.arrowParameterChange.emit()

    @property
    def arrow_head_size(self):
        """
        Size of the arrow head in proportion to the length of the arrow
        """
        return self._arrow_head_size

    @arrow_head_size.setter
    def arrow_head_size(self, size):
        if 0 < size <= 1 and size != self._arrow_head_size:
            self._arrow_head_size = size
            self.arrowParameterChange.emit()

    @property
    def arrow_color(self):
        """
        Color used to draw arrows
        """
        return self._arrow_color

    @arrow_color.setter
    def arrow_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._arrow_color:
            self._arrow_color = col
            self.arrowParameterChange.emit()

    @property
    def draw_arrow(self):
        """
        Decide to make the arrows visible or not
        """
        return self._draw_arrow

    @draw_arrow.setter
    def draw_arrow(self, value):
        value = bool(value)
        if value != self._draw_arrow:
            self._draw_arrow = value
            self.arrowParameterChange.emit()

    @property
    def use_OpenGL(self):
        """
        Force the use of OpenGL for rendering images
        """
        return self._use_OpenGL

    @use_OpenGL.setter
    def user_OpenGL(self, value):
        if value != self._use_OpenGL:
            self._use_OpenGL = value
            self.renderingChanged.emit()

    @property
    def point_thickness(self):
        """Thickness of the line used to draw points"""
        return self._point_thickness

    @point_thickness.setter
    def point_thickness(self, value):
        value = int(value)
        if value >= 0 and self._point_thickness != value:
            self._point_thickness = value
            self.pointParameterChange.emit()

    @point_thickness.deleter
    def point_thickness(self):
        del self._point_thickness

    @property
    def old_point_thickness(self):
        """Thickness of the line used to draw old points"""
        return self._old_point_thickness

    @old_point_thickness.setter
    def old_point_thickness(self, value):
        value = int(value)
        if self._old_point_thickness != value:
            self._old_point_thickness = value
            self.oldPointParameterChange.emit()

    @property
    def show_vectors(self):
        """Are the vectors from old to now points shown?"""
        return self._show_vectors

    @show_vectors.setter
    def show_vectors(self, value):
        self._show_vectors = value

    @property
    def link_views(self):
        """Link the viewports of the two panes in the main GUI"""
        return self._link_views

    @link_views.setter
    def link_views(self, value):
        self._link_views = value

    @property
    def show_template(self):
        """
        Whether the template should be shown or not

        :returntype: bool
        """
        return self._show_template

    @show_template.setter
    def show_template(self, value):
        if value != self._show_template:
            self._show_template = value
            self.searchParameterChange.emit()

    @property
    def show_id(self):
        """
        If true, the id of the points should be shown as well.

        :returntype: bool
        """
        return self._show_id

    @show_id.setter
    def show_id(self, value):
        value = bool(value)
        if value != self._show_id:
            self._show_id = value
            self.pointParameterChange.emit()

    def _find_font(self):
        font = QFont()
        wanted_size = self._point_size
        font.setStyleStrategy(QFont.StyleStrategy(QFont.OpenGLCompatible | QFont.PreferAntialias))
        fm = QFontMetricsF(font)
        width = fm.width("888")
        ratio = 1.8*wanted_size/max(width, fm.ascent())
        self._font = font
        self._font_zoom = ratio

    @property
    def font(self):
        """
        Font used to display the points id in the points.

        :returntype: `QFont`
        """
        return self._font

    @property
    def font_zoom(self):
        """
        Zoom used to display the points id in the points.

        :returntype: float
        """
        return self._font_zoom

#}
#{ Search parameters

    @property
    def estimate(self):
        """
        True if the copy functions estimate the position using normalized cross-correlation
        """
        return self._estimate

    @estimate.setter
    def estimate(self, value):
        self._estimate = bool(value)

    @property
    def template_size(self):
        """
        Size of the template to search for (i.e. number of pixel around the position to extract)
        """
        return self._template_size

    @template_size.setter
    def template_size(self, size):
        size = int(size)
        if size > 0 and size != self._template_size:
            self._template_size = size
            self.template_rect = QRectF(-size, -size, 2*size, 2*size)
            if 1.5*size > self._search_size:
                self.search_size = int(ceil(1.5*size+0.1))
            self.searchParameterChange.emit()

    @property
    def search_size(self):
        """
        Area around the point to look for the template
        """
        return self._search_size

    @search_size.setter
    def search_size(self, size):
        size = int(size)
        if size > self._template_size and size != self._search_size:
            self._search_size = size
            self.search_rect = QRectF(-size, -size, 2*size, 2*size)
            if size < 1.5*self._template_size:
                self.template_size = int(floor(2./3.*size-0.1))
            self.searchParameterChange.emit()

    @property
    def search_color(self):
        """
        Color used to draw the searched area
        """
        return self._search_color

    @search_color.setter
    def search_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._search_color:
            self._search_color = col
            self.searchParameterChange.emit()

    @property
    def template_color(self):
        """
        Color used to draw the template around a point
        """
        return self._template_color

    @template_color.setter
    def template_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._template_color:
            self._template_color = col
            self.searchParameterChange.emit()

    @property
    def filter_size_ratio(self):
        """Ratio of the template size used to create the filter"""
        return self._filter_size_ratio

    @filter_size_ratio.setter
    def filter_size_ratio(self, value):
        if value != self._filter_size_ratio:
            self._filter_size_ratio = value
            self.searchParameterChange.emit()

    @property
    def filter_size_ratio_percent(self):
        """Ratio of the template size used to create the filter in percent

        This property is garantied to return an integer"""
        return int(self._filter_size_ratio*100)

    @filter_size_ratio_percent.setter
    def filter_size_ratio_percent(self, value):
        self.filter_size_ratio = int(value)/100.0

    @property
    def filter_size(self):
        """
        Size of the filter to use for the images
        """
        return int(self._template_size * self._filter_size_ratio)

    @property
    def estimate_position(self):
        """
        Boolean telling if the position of the points have to be estimated or just copied.

        :returntype: bool
        """
        return self._estimate_position

    @estimate_position.setter
    def estimate_position(self, value):
        self._estimate_position = value

#}
#{ Main configuration

    @property
    def last_dir(self):
        """Last directory used in file dialog box"""
        return self._last_dir

    @last_dir.setter
    def last_dir(self, value):
        self._last_dir = value

    @property
    def cache_size(self):
        """Size of the image cache in MB"""
        return self._cache_size

    @cache_size.setter
    def cache_size(self, value):
        self._cache_size = value
        from . import image_cache
        image_cache.cache.max_size = value

    @property
    def recent_projects(self):
        """List of the most recent projects loaded"""
        return self._recent_projects

    @recent_projects.setter
    def _set_recent_projects(self, value):
        if self._recent_projects != value:
            self._recent_projects = value
            self.recentProjectsChange.emit()

    def add_recent_project(self, project):
        recent_projects = self._recent_projects
        if project in recent_projects:
            recent_projects.remove(project)
        recent_projects.insert(0,  project)
        while len(recent_projects) > self._max_number_of_projects:
            recent_projects.pop()
        self.recentProjectsChange.emit()

#}
#{ User interaction parameters

    @property
    def is_point_editable(self):
        """
        True if the points can be edited.

        :returntype: bool
        """
        return self._point_editable

    @is_point_editable.setter
    def is_point_editable(self, value):
        value = bool(value)
        if value != self._point_editable:
            self._point_editable = value
            self.pointParameterChange.emit()

    @property
    def is_point_selectable(self):
        """
        True if the cells can be selected.

        :returntype: bool
        """
        return self._point_selectable

    @is_point_selectable.setter
    def is_point_selectable(self, value):
        value = bool(value)
        if value != self._point_selectable:
            self._point_selectable = value
            self.pointParameterChange.emit()

    @property
    def is_cell_editable(self):
        """
        True if the cells can be edited.

        :returntype: bool
        """
        return self._cell_editable

    @is_cell_editable.setter
    def is_cell_editable(self, value):
        value = bool(value)
        if value != self._cell_editable:
            self._cell_editable = value
            self.cellParameterChange.emit()

#}

#{ Growth representation parameters

    @property
    def walls_coloring(self):
        """
        Mode used to color walls.

        :returntype: `str`
        """
        return self._walls_coloring

    @walls_coloring.setter
    def walls_coloring(self, value):
        value = unicode(value)
        if value != self._walls_coloring:
            self._walls_coloring = value
            self.plottingParameterChange.emit()

    @property
    def walls_symetric_coloring(self):
        """
        True if the coloring scheme must be symetric around 0.

        :returntype: bool
        """
        return self._walls_symetric_coloring

    @walls_symetric_coloring.setter
    def walls_symetric_coloring(self, value):
        value = bool(value)
        if value != self._walls_symetric_coloring:
            self._walls_symetric_coloring = value
            self.plottingParameterChange.emit()

    @property
    def walls_cap_values(self):
        '''
        True if the values used to color the walls must be caped.

        :returntype: bool
        '''
        return self._walls_cap_values

    @walls_cap_values.setter
    def walls_cap_values(self, value):
        if self._walls_cap_values != value:
            self._walls_cap_values = value
            self.plottingParameterChange.emit()

    @property
    def walls_values_min(self):
        '''
        Minimum cap.

        :returntype: float
        '''
        return self._walls_values_min

    @walls_values_min.setter
    def walls_values_min(self, value):
        value = float(value)
        if self._walls_values_min != value:
            self._walls_values_min = value
            self.plottingParameterChange.emit()

    @property
    def walls_values_max(self):
        '''
        Maximum cap.

        :returntype: float
        '''
        return self._walls_values_max

    @walls_values_max.setter
    def walls_values_max(self, value):
        value = float(value)
        if self._walls_values_max != value:
            self._walls_values_max = value
            self.plottingParameterChange.emit()

    @property
    def cells_coloring(self):
        """
        Mode used to color cells

        :returntype: `str`
        """
        return self._cells_coloring

    @cells_coloring.setter
    def cells_coloring(self, value):
        value = unicode(value)
        if value != self._cells_coloring:
            self._cells_coloring = value
            self.plottingParameterChange.emit()

    @property
    def cells_symetric_coloring(self):
        """
        True if the coloring scheme must be symetric around 0.

        :returntype: bool
        """
        return self._cells_symetric_coloring

    @cells_symetric_coloring.setter
    def cells_symetric_coloring(self, value):
        value = bool(value)
        if value != self._cells_symetric_coloring:
            self._cells_symetric_coloring = value
            self.plottingParameterChange.emit()

    @property
    def cells_cap_values(self):
        '''
        True if the values used to color the cells must be caped.

        :returntype: bool
        '''
        return self._cells_cap_values

    @cells_cap_values.setter
    def cells_cap_values(self, value):
        value = bool(value)
        if self._cells_cap_values != value:
            self._cells_cap_values = value
            self.plottingParameterChange.emit()

    @property
    def cells_values_min(self):
        '''
        Minimum cap.

        :returntype: float
        '''
        return self._cells_values_min

    @cells_values_min.setter
    def cells_values_min(self, value):
        value = float(value)
        if self._cells_values_min != value:
            self._cells_values_min = value
            self.plottingParameterChange.emit()

    @property
    def cells_values_max(self):
        '''
        Maximum cap.

        :returntype: float
        '''
        return self._cells_values_max

    @cells_values_max.setter
    def cells_values_max(self, value):
        value = float(value)
        if self._cells_values_max != value:
            self._cells_values_max = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_scaling(self):
        '''
        Scaling applied to the kmin and kmaj to plot the ellipsis

        :returntype: float
        '''
        return self._ellipsis_scaling

    @ellipsis_scaling.setter
    def ellipsis_scaling(self, value):
        value = float(value)
        if self._ellipsis_scaling != value:
            self._ellipsis_scaling = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_color(self):
        '''
        Color used to draw the ellipsis.

        :returntype: `QColor`
        '''
        return self._ellipsis_color

    @ellipsis_color.setter
    def ellipsis_color(self, value):
        value = QColor(value)
        if self._ellipsis_color != value:
            self._ellipsis_color = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_thickness(self):
        '''
        Thickness used to draw the growth tensor ellipsis

        :returntype: int
        '''
        return self._ellipsis_thickness

    @ellipsis_thickness.setter
    def ellipsis_thickness(self, value):
        value = int(value)
        if self._ellipsis_thickness != value:
            self._ellipsis_thickness = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_min_anisotropy(self):
        '''
        Minimum anisotropy required to draw axes of an ellipsis.

        :returntype: float
        '''
        return self._ellipsis_min_anisotropy

    @ellipsis_min_anisotropy.setter
    def ellipsis_min_anisotropy(self, value):
        value = float(value)
        if self._ellipsis_min_anisotropy != value:
            self._ellipsis_min_anisotropy = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_positive_color(self):
        '''
        Color used to draw growth tensor ellipsis axis if the value is positive.

        :returntype: `QColor`
        '''
        return self._ellipsis_positive_color

    @ellipsis_positive_color.setter
    def ellipsis_positive_color(self, value):
        value = QColor(value)
        if self._ellipsis_positive_color != value:
            self._ellipsis_positive_color = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_negative_color(self):
        '''
        Color used to draw growth tensor ellipsis axis if the value is negative.

        :returntype: `QColor`
        '''
        return self._ellipsis_negative_color

    @ellipsis_negative_color.setter
    def ellipsis_negative_color(self, value):
        value = QColor(value)
        if self._ellipsis_negative_color != value:
            self._ellipsis_negative_color = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_plot(self):
        '''True if the ellipsis is to be plotted.

        :returntype: bool'''
        return self._ellipsis_plot

    @ellipsis_plot.setter
    def ellipsis_plot(self, value):
        value = bool(value)
        if self._ellipsis_plot != value:
            self._ellipsis_plot = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_scale_axis(self):
        '''True if the ellipsis is to be plotted.

        :returntype: bool'''
        return self._ellipsis_scale_axis

    @ellipsis_scale_axis.setter
    def ellipsis_scale_axis(self, value):
        value = bool(value)
        if self._ellipsis_scale_axis != value:
            self._ellipsis_scale_axis = value
            self.plottingParameterChange.emit()

    @property
    def growth_cell_color(self):
        '''
        Color used to draw cells without function.

        :returntype: `QColor`
        '''
        return self._growth_cell_color

    @growth_cell_color.setter
    def growth_cell_color(self, value):
        value = QColor(value)
        if self._growth_cell_color != value:
            self._growth_cell_color = value
            self.plottingParameterChange.emit()

    @property
    def growth_wall_color(self):
        '''
        Color used to draw walls without function.

        :returntype: `QColor`
        '''
        return self._growth_wall_color

    @growth_wall_color.setter
    def growth_wall_color(self, value):
        value = QColor(value)
        if self._growth_wall_color != value:
            self._growth_wall_color = value
            self.plottingParameterChange.emit()

    @property
    def growth_cell_function(self):
        '''
        Transfer function used to draw cells. This is actually the pickled form of the transfer function.

        :returntype: `str`
        '''
        return self._growth_cell_function

    @growth_cell_function.setter
    def growth_cell_function(self, value):
        if self._growth_cell_function != value:
            self._growth_cell_function = value
            self.plottingParameterChange.emit()

    @property
    def growth_wall_function(self):
        '''
        Transfer function used to draw walls. This is actually the pickled form of the transfer function.

        :returntype: `str`
        '''
        return self._growth_wall_function

    @growth_wall_function.setter
    def growth_wall_function(self, value):
        if self._growth_wall_function != value:
            self._growth_wall_function = value
            self.plottingParameterChange.emit()
示例#57
0
class Parameters(QObject):

    pointParameterChange = Signal()
    oldPointParameterChange = Signal()
    arrowParameterChange = Signal()
    searchParameterChange = Signal()
    renderingChanged = Signal()
    recentProjectsChange = Signal()
    plottingParameterChange = Signal()
    cellParameterChange = Signal()
    """
    Signal launched when parameters change:
        - pointParameterChange
        - oldPointParameterChange
        - arrowParameterChange
        - searchParameterChange
        - renderingChanged
        - recentProjectsChange
        - cellParameterChange
        - plottingParameterChange
    """
    def __init__(self):
        QObject.__init__(self)
        self.load()

    #def __del__(self):
    #cleanQObject(self)

    # Use thread or not to compute on the background
    use_thread = False

    def load(self):
        settings = QSettings()

        settings.beginGroup("GraphicParameters")
        # First, parameters for normal points
        self._point_size = None
        try:
            _point_size = float(settings.value("PointSize"))
        except (ValueError, TypeError):
            _point_size = 5.0
        self.point_size = _point_size
        self._point_thickness = None
        try:
            _point_thickness = int(settings.value("PointThickness"))
        except (ValueError, TypeError):
            _point_thickness = 0
        self.point_thickness = _point_thickness
        self._point_color = None
        _point_color = QColor(settings.value("PointColor"))
        if not _point_color.isValid():
            _point_color = QColor(Qt.red)
        self.point_color = _point_color
        _selected_point_color = QColor(settings.value("SelectedPointColor"))
        if not _selected_point_color.isValid():
            _selected_point_color = QColor(255, 128, 128, 255)
        self._selected_point_color = _selected_point_color
        _new_point_color = QColor(settings.value("NewPointColor"))
        if not _new_point_color.isValid():
            _new_point_color = QColor(Qt.blue)
        self._new_point_color = None
        self.new_point_color = _new_point_color

        # Parameter for cells
        self._cell_size = None
        try:
            _cell_size = float(settings.value("CellSize"))
        except (ValueError, TypeError):
            _cell_size = 5.0
        self.cell_size = _cell_size
        self._cell_thickness = None
        try:
            _cell_thickness = int(settings.value("CellThickness"))
        except (ValueError, TypeError):
            _cell_thickness = 1
        self.cell_thickness = _cell_thickness
        self._cell_color = None
        _cell_color = QColor(settings.value("CellColor"))
        if not _cell_color.isValid():
            _cell_color = QColor(Qt.darkCyan)
            _cell_color.setAlphaF(0.5)
        self.cell_color = _cell_color

        self._selected_cell_color = None
        _selected_cell_color = QColor(settings.value("SelectedCellColor"))
        if not _selected_cell_color.isValid():
            _selected_cell_color = QColor(Qt.yellow)
            _selected_cell_color.setAlphaF(0.5)
        self.selected_cell_color = _selected_cell_color

        self._division_wall_color = None
        _division_wall_color = QColor(settings.value("DivisionWallColor"))
        if not _division_wall_color.isValid():
            _division_wall_color = QColor(255, 85, 0)
            _division_wall_color.setAlphaF(0.8)
        self.division_wall_color = _division_wall_color

        # Then, parameters for old points
        try:
            self._old_point_size = float(settings.value("OldPointSize"))
        except (ValueError, TypeError):
            self._old_point_size = 5.0
        try:
            self._old_point_thickness = int(
                settings.value("OldPointThickness"))
        except (ValueError, TypeError):
            self._old_point_thickness = 0
        self._old_point_color = None
        self._old_point_color = QColor(settings.value("OldPointColor"))
        if not self._old_point_color.isValid():
            self._old_point_color = QColor(Qt.yellow)
        self._old_point_matching_color = QColor(
            settings.value("OldPointMatchingColor"))
        if not self._old_point_matching_color.isValid():
            self._old_point_matching_color = QColor(Qt.darkYellow)
        self._show_id = toBool(settings.value("ShowId", 'false'))
        # Parameters for arrow
        try:
            self._arrow_line_size = float(settings.value("ArrowLineSize"))
        except (ValueError, TypeError):
            self._arrow_line_size = 2
        try:
            self._arrow_head_size = float(settings.value("ArrowHeadSize"))
        except (ValueError, TypeError):
            self._arrow_head_size = .1
        self._arrow_color = QColor(settings.value("ArrowColor"))
        if not self._arrow_color.isValid():
            self._arrow_color = QColor(Qt.lightGray)
        self._draw_arrow = toBool(settings.value("DrawArrow", 'true'))
        self._show_template = toBool(settings.value("ShowTemplate", 'false'))
        self._template_color = QColor(settings.value("TemplateColor"))
        if not self._template_color.isValid():
            self._template_color = QColor(255, 0, 0, 100)
        self._search_color = QColor(settings.value("SearchColor"))
        if not self._search_color.isValid():
            self._search_color = QColor(255, 0, 255, 100)
        settings.endGroup()

        # The search parameters
        settings.beginGroup("SearchParameters")
        try:
            self._template_size = int(settings.value("TemplateSize"))
        except (ValueError, TypeError):
            self._template_size = 10
        s = self._template_size
        self.template_rect = QRectF(-s, -s, 2 * s, 2 * s)
        try:
            self._search_size = int(settings.value("SearchSize"))
        except (ValueError, TypeError):
            self._search_size = 50
        s = self._search_size
        self.search_rect = QRectF(-s, -s, 2 * s, 2 * s)
        self._estimate = toBool(settings.value("Estimate", 'false'))
        try:
            self._filter_size_ratio = float(settings.value("FilterSizeRatio"))
        except (ValueError, TypeError):
            self._filter_size_ratio = .5
        settings.endGroup()

        settings.beginGroup("GUI")
        self._show_vectors = toBool(settings.value("ShowVectors", 'true'))
        self._link_views = toBool(settings.value("LinkViews", 'true'))
        try:
            cache_size = int(settings.value("CacheSize"))
        except (ValueError, TypeError):
            cache_size = 200
        self.cache_size = cache_size
        self._last_dir = path(settings.value("LastsDir", "."))
        self._use_OpenGL = toBool(settings.value("UseOpenGL", 'false'))
        settings.beginGroup("RecentProjects")
        try:
            numproj = int(settings.value("NumberOfProjects"))
        except (ValueError, TypeError):
            numproj = 0
        self._recent_projects = []
        if numproj > 0:
            for i in range(numproj):
                name = "Project%d" % i
                value = path(settings.value(name))
                self._recent_projects.append(value)
        try:
            self._max_number_of_projects = int(
                settings.value("MaxNumberOfProjects"))
        except (ValueError, TypeError):
            self._max_number_of_projects = 5
        settings.endGroup()
        settings.endGroup()

        # The plotting parameters
        settings.beginGroup("PlottingParameters")
        settings.beginGroup("Ellipsis")
        try:
            self._ellipsis_scaling = float(settings.value("Scaling", 1.0))
        except (ValueError, TypeError):
            self._ellipsis_scaling = 1.0
        self._ellipsis_color = QColor(settings.value("Color"))
        if not self._ellipsis_color.isValid():
            self._ellipsis_color = QColor(0, 0, 0)
        try:
            self._ellipsis_thickness = int(settings.value("Thickness", 0))
        except (ValueError, TypeError):
            self._ellipsis_thickness = 0
        try:
            self._ellipsis_min_anisotropy = float(
                settings.value("MinAnisotropy", 1e-3))
        except (ValueError, TypeError):
            self._ellipsis_min_anisotropy = 1e-3
        self._ellipsis_positive_color = QColor(settings.value("PositiveColor"))
        if not self._ellipsis_positive_color.isValid():
            self._ellipsis_positive_color = QColor(0, 0, 255)
        self._ellipsis_negative_color = QColor(settings.value("NegativeColor"))
        if not self._ellipsis_negative_color.isValid():
            self._ellipsis_negative_color = QColor(255, 0, 0)
        self._ellipsis_plot = toBool(settings.value("Plot", 'false'))
        self._ellipsis_scale_axis = toBool(settings.value(
            "ScaleAxis", 'false'))
        settings.endGroup()
        settings.endGroup()
        self._point_editable = True
        self._point_selectable = True
        self._cell_editable = False

    def save(self):
        settings = QSettings()
        settings.beginGroup("GraphicParameters")
        settings.setValue("PointSize", self._point_size)
        settings.setValue("PointColor", self._point_color)
        settings.setValue("PointThickness", self._point_thickness)
        settings.setValue("SelectedPointColor", self._selected_point_color)
        settings.setValue("NewPointColor", self._new_point_color)
        settings.setValue("CellSize", self._cell_size)
        settings.setValue("CellColor", self._cell_color)
        settings.setValue("CellThickness", self._cell_thickness)
        settings.setValue("SelectedCellColor", self._selected_cell_color)
        settings.setValue("DivisionWallColor", self._division_wall_color)
        settings.setValue("OldPointSize", self._old_point_size)
        settings.setValue("OldPointColor", self._old_point_color)
        settings.setValue("OldPointMatchingColor",
                          self._old_point_matching_color)
        settings.setValue("ShowId", self._show_id)
        settings.setValue("ArrowLineSize", self._arrow_line_size)
        settings.setValue("ArrowHeadSize", self._arrow_head_size)
        settings.setValue("ArrowColor", self._arrow_color)
        settings.setValue("DrawArrow", self._draw_arrow)
        settings.setValue("ShowTemplate", self._show_template)
        settings.setValue("TemplateColor", self._template_color)
        settings.setValue("SearchColor", self._search_color)
        settings.endGroup()

        settings.beginGroup("SearchParameters")
        settings.setValue("TemplateSize", self._template_size)
        settings.setValue("SearchSize", self._search_size)
        settings.setValue("Estimate", self._estimate)
        settings.setValue("FilterSizeRatio", self._filter_size_ratio)
        settings.endGroup()

        settings.beginGroup("GUI")
        settings.setValue("UseOpenGL", self._use_OpenGL)
        settings.setValue("ShowVectors", self._show_vectors)
        settings.setValue("LinkViews", self._link_views)
        settings.setValue("CacheSize", self._cache_size)
        settings.setValue("LastsDir", unicode(self._last_dir))

        settings.beginGroup("RecentProjects")
        settings.setValue("MaxNumberOfProjects", self._max_number_of_projects)
        settings.setValue("NumberOfProjects", len(self._recent_projects))
        for i, p in enumerate(self._recent_projects):
            name = "Project%d" % i
            settings.setValue(name, unicode(p))
        settings.endGroup()
        settings.endGroup()
        # The plotting parameters
        settings.beginGroup("PlottingParameters")
        settings.beginGroup("Ellipsis")
        settings.setValue("Scaling", self._ellipsis_scaling)
        settings.setValue("Color", self._ellipsis_color)
        settings.setValue("Thickness", self._ellipsis_thickness)
        settings.setValue("MinAnisotropy", self._ellipsis_min_anisotropy)
        settings.setValue("PositiveColor", self._ellipsis_positive_color)
        settings.setValue("NegativeColor", self._ellipsis_negative_color)
        settings.setValue("Plot", self._ellipsis_plot)
        settings.setValue("ScaleAxis", self._ellipsis_scale_axis)
        settings.endGroup()
        settings.endGroup()

#{ On Screen Drawing

    @property
    def point_size(self):
        """
        Size of a points on the scene
        """
        return self._point_size

    @point_size.setter
    def point_size(self, size):
        if size > 0 and size != self._point_size:
            self._point_size = size
            self._find_font()
            self.pointParameterChange.emit()

    @property
    def point_color(self):
        """
        Color used to draw points
        """
        return self._point_color

    @point_color.setter
    def point_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._point_color:
            self._point_color = col
            self.point_hover_color = col.lighter(150)
            if self.point_hover_color == col:
                self.point_hover_color = col.lighter(50)
            self.pointParameterChange.emit()

    @property
    def selected_point_color(self):
        """
        Set the color of a selected point
        """
        return self._selected_point_color

    @selected_point_color.setter
    def selected_point_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._selected_point_color:
            self._selected_point_color = col
            self.pointParameterChange.emit()

    @property
    def new_point_color(self):
        """
        Set the color of a new point
        """
        return self._new_point_color

    @new_point_color.setter
    def new_point_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._new_point_color:
            self._new_point_color = col
            self.new_point_hover_color = col.lighter(150)
            if self.new_point_hover_color == col:
                self.new_point_hover_color = col.lighter(50)
            self.pointParameterChange.emit()

    @property
    def cell_size(self):
        """
        Set the size of a cell graphic item
        """
        return self._cell_size

    @cell_size.setter
    def cell_size(self, new_size):
        if new_size > 0 and new_size != self._cell_size:
            self._cell_size = new_size
            self.cellParameterChange.emit()

    @property
    def cell_thickness(self):
        """
        Set the thickness of the line used to draw the cell graphic item
        """
        return self._cell_thickness

    @cell_thickness.setter
    def cell_thickness(self, th):
        thick = int(th)
        if thick >= 0 and thick != self._cell_thickness:
            self._cell_thickness = thick
            self.cellParameterChange.emit()

    @property
    def cell_color(self):
        """
        Set the color used to draw the cell
        """
        return self._cell_color

    @cell_color.setter
    def cell_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._cell_color:
            self._cell_color = col
            self.cell_hover_color = col.lighter(150)
            if self.cell_hover_color == col:
                self.cell_hover_color = col.lighter(50)
            self.cellParameterChange.emit()

    @property
    def selected_cell_color(self):
        """
        Set the color used to draw the selected cell
        """
        return self._selected_cell_color

    @selected_cell_color.setter
    def selected_cell_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._selected_cell_color:
            self._selected_cell_color = col
            self.cellParameterChange.emit()

    @property
    def division_wall_color(self):
        """
        Set the color used to draw the selected cell
        """
        return self._division_wall_color

    @division_wall_color.setter
    def division_wall_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._division_wall_color:
            self._division_wall_color = col
            self.cellParameterChange.emit()

    @property
    def old_point_size(self):
        """
        Size of a old points on the scene
        """
        return self._old_point_size

    @old_point_size.setter
    def old_point_size(self, size):
        if size > 0 and size != self._old_point_size:
            self._old_point_size = size
            self.oldPointParameterChange.emit()

    @property
    def old_point_color(self):
        """
        Color used to draw old points
        """
        return self._old_point_color

    @old_point_color.setter
    def old_point_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._old_point_color:
            self._old_point_color = col
            self.oldPointParameterChange.emit()

    @property
    def old_point_matching_color(self):
        """
        Color used to draw old point matching the current hovered point
        """
        return self._old_point_matching_color

    @old_point_matching_color.setter
    def old_point_matching_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._old_point_matching_color:
            self._old_point_matching_color = col
            self.oldPointParameterChange.emit()

    @property
    def arrow_line_size(self):
        """
        Width of the pen used to draw arrows.
        """
        return self._arrow_line_size

    @arrow_line_size.setter
    def arrow_line_size(self, size):
        if size > 0 and size != self._arrow_line_size:
            self._arrow_line_size = size
            self.arrowParameterChange.emit()

    @property
    def arrow_head_size(self):
        """
        Size of the arrow head in proportion to the length of the arrow
        """
        return self._arrow_head_size

    @arrow_head_size.setter
    def arrow_head_size(self, size):
        if 0 < size <= 1 and size != self._arrow_head_size:
            self._arrow_head_size = size
            self.arrowParameterChange.emit()

    @property
    def arrow_color(self):
        """
        Color used to draw arrows
        """
        return self._arrow_color

    @arrow_color.setter
    def arrow_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._arrow_color:
            self._arrow_color = col
            self.arrowParameterChange.emit()

    @property
    def draw_arrow(self):
        """
        Decide to make the arrows visible or not
        """
        return self._draw_arrow

    @draw_arrow.setter
    def draw_arrow(self, value):
        value = bool(value)
        if value != self._draw_arrow:
            self._draw_arrow = value
            self.arrowParameterChange.emit()

    @property
    def use_OpenGL(self):
        """
        Force the use of OpenGL for rendering images
        """
        return self._use_OpenGL

    @use_OpenGL.setter
    def user_OpenGL(self, value):
        if value != self._use_OpenGL:
            self._use_OpenGL = value
            self.renderingChanged.emit()

    @property
    def point_thickness(self):
        """Thickness of the line used to draw points"""
        return self._point_thickness

    @point_thickness.setter
    def point_thickness(self, value):
        value = int(value)
        if value >= 0 and self._point_thickness != value:
            self._point_thickness = value
            self.pointParameterChange.emit()

    @point_thickness.deleter
    def point_thickness(self):
        del self._point_thickness

    @property
    def old_point_thickness(self):
        """Thickness of the line used to draw old points"""
        return self._old_point_thickness

    @old_point_thickness.setter
    def old_point_thickness(self, value):
        value = int(value)
        if self._old_point_thickness != value:
            self._old_point_thickness = value
            self.oldPointParameterChange.emit()

    @property
    def show_vectors(self):
        """Are the vectors from old to now points shown?"""
        return self._show_vectors

    @show_vectors.setter
    def show_vectors(self, value):
        self._show_vectors = value

    @property
    def link_views(self):
        """Link the viewports of the two panes in the main GUI"""
        return self._link_views

    @link_views.setter
    def link_views(self, value):
        self._link_views = value

    @property
    def show_template(self):
        """
        Whether the template should be shown or not

        :returntype: bool
        """
        return self._show_template

    @show_template.setter
    def show_template(self, value):
        if value != self._show_template:
            self._show_template = value
            self.searchParameterChange.emit()

    @property
    def show_id(self):
        """
        If true, the id of the points should be shown as well.

        :returntype: bool
        """
        return self._show_id

    @show_id.setter
    def show_id(self, value):
        value = bool(value)
        if value != self._show_id:
            self._show_id = value
            self.pointParameterChange.emit()

    def _find_font(self):
        font = QFont()
        wanted_size = self._point_size
        font.setStyleStrategy(
            QFont.StyleStrategy(QFont.OpenGLCompatible
                                | QFont.PreferAntialias))
        fm = QFontMetricsF(font)
        width = fm.width("888")
        ratio = 1.8 * wanted_size / max(width, fm.ascent())
        self._font = font
        self._font_zoom = ratio

    @property
    def font(self):
        """
        Font used to display the points id in the points.

        :returntype: `QFont`
        """
        return self._font

    @property
    def font_zoom(self):
        """
        Zoom used to display the points id in the points.

        :returntype: float
        """
        return self._font_zoom

#}
#{ Search parameters

    @property
    def estimate(self):
        """
        True if the copy functions estimate the position using normalized cross-correlation
        """
        return self._estimate

    @estimate.setter
    def estimate(self, value):
        self._estimate = bool(value)

    @property
    def template_size(self):
        """
        Size of the template to search for (i.e. number of pixel around the position to extract)
        """
        return self._template_size

    @template_size.setter
    def template_size(self, size):
        size = int(size)
        if size > 0 and size != self._template_size:
            self._template_size = size
            self.template_rect = QRectF(-size, -size, 2 * size, 2 * size)
            if 1.5 * size > self._search_size:
                self.search_size = int(ceil(1.5 * size + 0.1))
            self.searchParameterChange.emit()

    @property
    def search_size(self):
        """
        Area around the point to look for the template
        """
        return self._search_size

    @search_size.setter
    def search_size(self, size):
        size = int(size)
        if size > self._template_size and size != self._search_size:
            self._search_size = size
            self.search_rect = QRectF(-size, -size, 2 * size, 2 * size)
            if size < 1.5 * self._template_size:
                self.template_size = int(floor(2. / 3. * size - 0.1))
            self.searchParameterChange.emit()

    @property
    def search_color(self):
        """
        Color used to draw the searched area
        """
        return self._search_color

    @search_color.setter
    def search_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._search_color:
            self._search_color = col
            self.searchParameterChange.emit()

    @property
    def template_color(self):
        """
        Color used to draw the template around a point
        """
        return self._template_color

    @template_color.setter
    def template_color(self, color):
        col = QColor(color)
        if col.isValid() and col != self._template_color:
            self._template_color = col
            self.searchParameterChange.emit()

    @property
    def filter_size_ratio(self):
        """Ratio of the template size used to create the filter"""
        return self._filter_size_ratio

    @filter_size_ratio.setter
    def filter_size_ratio(self, value):
        if value != self._filter_size_ratio:
            self._filter_size_ratio = value
            self.searchParameterChange.emit()

    @property
    def filter_size_ratio_percent(self):
        """Ratio of the template size used to create the filter in percent

        This property is garantied to return an integer"""
        return int(self._filter_size_ratio * 100)

    @filter_size_ratio_percent.setter
    def filter_size_ratio_percent(self, value):
        self.filter_size_ratio = int(value) / 100.0

    @property
    def filter_size(self):
        """
        Size of the filter to use for the images
        """
        return int(self._template_size * self._filter_size_ratio)

    @property
    def estimate_position(self):
        """
        Boolean telling if the position of the points have to be estimated or just copied.

        :returntype: bool
        """
        return self._estimate_position

    @estimate_position.setter
    def estimate_position(self, value):
        self._estimate_position = value

#}
#{ Main configuration

    @property
    def last_dir(self):
        """Last directory used in file dialog box"""
        return self._last_dir

    @last_dir.setter
    def last_dir(self, value):
        self._last_dir = value

    @property
    def cache_size(self):
        """Size of the image cache in MB"""
        return self._cache_size

    @cache_size.setter
    def cache_size(self, value):
        self._cache_size = value
        from . import image_cache
        image_cache.cache.max_size = value

    @property
    def recent_projects(self):
        """List of the most recent projects loaded"""
        return self._recent_projects

    @recent_projects.setter
    def _set_recent_projects(self, value):
        if self._recent_projects != value:
            self._recent_projects = value
            self.recentProjectsChange.emit()

    def add_recent_project(self, project):
        recent_projects = self._recent_projects
        if project in recent_projects:
            recent_projects.remove(project)
        recent_projects.insert(0, project)
        while len(recent_projects) > self._max_number_of_projects:
            recent_projects.pop()
        self.recentProjectsChange.emit()

#}
#{ User interaction parameters

    @property
    def is_point_editable(self):
        """
        True if the points can be edited.

        :returntype: bool
        """
        return self._point_editable

    @is_point_editable.setter
    def is_point_editable(self, value):
        value = bool(value)
        if value != self._point_editable:
            self._point_editable = value
            self.pointParameterChange.emit()

    @property
    def is_point_selectable(self):
        """
        True if the cells can be selected.

        :returntype: bool
        """
        return self._point_selectable

    @is_point_selectable.setter
    def is_point_selectable(self, value):
        value = bool(value)
        if value != self._point_selectable:
            self._point_selectable = value
            self.pointParameterChange.emit()

    @property
    def is_cell_editable(self):
        """
        True if the cells can be edited.

        :returntype: bool
        """
        return self._cell_editable

    @is_cell_editable.setter
    def is_cell_editable(self, value):
        value = bool(value)
        if value != self._cell_editable:
            self._cell_editable = value
            self.cellParameterChange.emit()

#}

#{ Growth representation parameters

    @property
    def walls_coloring(self):
        """
        Mode used to color walls.

        :returntype: `str`
        """
        return self._walls_coloring

    @walls_coloring.setter
    def walls_coloring(self, value):
        value = unicode(value)
        if value != self._walls_coloring:
            self._walls_coloring = value
            self.plottingParameterChange.emit()

    @property
    def walls_symetric_coloring(self):
        """
        True if the coloring scheme must be symetric around 0.

        :returntype: bool
        """
        return self._walls_symetric_coloring

    @walls_symetric_coloring.setter
    def walls_symetric_coloring(self, value):
        value = bool(value)
        if value != self._walls_symetric_coloring:
            self._walls_symetric_coloring = value
            self.plottingParameterChange.emit()

    @property
    def walls_cap_values(self):
        '''
        True if the values used to color the walls must be caped.

        :returntype: bool
        '''
        return self._walls_cap_values

    @walls_cap_values.setter
    def walls_cap_values(self, value):
        if self._walls_cap_values != value:
            self._walls_cap_values = value
            self.plottingParameterChange.emit()

    @property
    def walls_values_min(self):
        '''
        Minimum cap.

        :returntype: float
        '''
        return self._walls_values_min

    @walls_values_min.setter
    def walls_values_min(self, value):
        value = float(value)
        if self._walls_values_min != value:
            self._walls_values_min = value
            self.plottingParameterChange.emit()

    @property
    def walls_values_max(self):
        '''
        Maximum cap.

        :returntype: float
        '''
        return self._walls_values_max

    @walls_values_max.setter
    def walls_values_max(self, value):
        value = float(value)
        if self._walls_values_max != value:
            self._walls_values_max = value
            self.plottingParameterChange.emit()

    @property
    def cells_coloring(self):
        """
        Mode used to color cells

        :returntype: `str`
        """
        return self._cells_coloring

    @cells_coloring.setter
    def cells_coloring(self, value):
        value = unicode(value)
        if value != self._cells_coloring:
            self._cells_coloring = value
            self.plottingParameterChange.emit()

    @property
    def cells_symetric_coloring(self):
        """
        True if the coloring scheme must be symetric around 0.

        :returntype: bool
        """
        return self._cells_symetric_coloring

    @cells_symetric_coloring.setter
    def cells_symetric_coloring(self, value):
        value = bool(value)
        if value != self._cells_symetric_coloring:
            self._cells_symetric_coloring = value
            self.plottingParameterChange.emit()

    @property
    def cells_cap_values(self):
        '''
        True if the values used to color the cells must be caped.

        :returntype: bool
        '''
        return self._cells_cap_values

    @cells_cap_values.setter
    def cells_cap_values(self, value):
        value = bool(value)
        if self._cells_cap_values != value:
            self._cells_cap_values = value
            self.plottingParameterChange.emit()

    @property
    def cells_values_min(self):
        '''
        Minimum cap.

        :returntype: float
        '''
        return self._cells_values_min

    @cells_values_min.setter
    def cells_values_min(self, value):
        value = float(value)
        if self._cells_values_min != value:
            self._cells_values_min = value
            self.plottingParameterChange.emit()

    @property
    def cells_values_max(self):
        '''
        Maximum cap.

        :returntype: float
        '''
        return self._cells_values_max

    @cells_values_max.setter
    def cells_values_max(self, value):
        value = float(value)
        if self._cells_values_max != value:
            self._cells_values_max = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_scaling(self):
        '''
        Scaling applied to the kmin and kmaj to plot the ellipsis

        :returntype: float
        '''
        return self._ellipsis_scaling

    @ellipsis_scaling.setter
    def ellipsis_scaling(self, value):
        value = float(value)
        if self._ellipsis_scaling != value:
            self._ellipsis_scaling = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_color(self):
        '''
        Color used to draw the ellipsis.

        :returntype: `QColor`
        '''
        return self._ellipsis_color

    @ellipsis_color.setter
    def ellipsis_color(self, value):
        value = QColor(value)
        if self._ellipsis_color != value:
            self._ellipsis_color = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_thickness(self):
        '''
        Thickness used to draw the growth tensor ellipsis

        :returntype: int
        '''
        return self._ellipsis_thickness

    @ellipsis_thickness.setter
    def ellipsis_thickness(self, value):
        value = int(value)
        if self._ellipsis_thickness != value:
            self._ellipsis_thickness = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_min_anisotropy(self):
        '''
        Minimum anisotropy required to draw axes of an ellipsis.

        :returntype: float
        '''
        return self._ellipsis_min_anisotropy

    @ellipsis_min_anisotropy.setter
    def ellipsis_min_anisotropy(self, value):
        value = float(value)
        if self._ellipsis_min_anisotropy != value:
            self._ellipsis_min_anisotropy = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_positive_color(self):
        '''
        Color used to draw growth tensor ellipsis axis if the value is positive.

        :returntype: `QColor`
        '''
        return self._ellipsis_positive_color

    @ellipsis_positive_color.setter
    def ellipsis_positive_color(self, value):
        value = QColor(value)
        if self._ellipsis_positive_color != value:
            self._ellipsis_positive_color = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_negative_color(self):
        '''
        Color used to draw growth tensor ellipsis axis if the value is negative.

        :returntype: `QColor`
        '''
        return self._ellipsis_negative_color

    @ellipsis_negative_color.setter
    def ellipsis_negative_color(self, value):
        value = QColor(value)
        if self._ellipsis_negative_color != value:
            self._ellipsis_negative_color = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_plot(self):
        '''True if the ellipsis is to be plotted.

        :returntype: bool'''
        return self._ellipsis_plot

    @ellipsis_plot.setter
    def ellipsis_plot(self, value):
        value = bool(value)
        if self._ellipsis_plot != value:
            self._ellipsis_plot = value
            self.plottingParameterChange.emit()

    @property
    def ellipsis_scale_axis(self):
        '''True if the ellipsis is to be plotted.

        :returntype: bool'''
        return self._ellipsis_scale_axis

    @ellipsis_scale_axis.setter
    def ellipsis_scale_axis(self, value):
        value = bool(value)
        if self._ellipsis_scale_axis != value:
            self._ellipsis_scale_axis = value
            self.plottingParameterChange.emit()

    @property
    def growth_cell_color(self):
        '''
        Color used to draw cells without function.

        :returntype: `QColor`
        '''
        return self._growth_cell_color

    @growth_cell_color.setter
    def growth_cell_color(self, value):
        value = QColor(value)
        if self._growth_cell_color != value:
            self._growth_cell_color = value
            self.plottingParameterChange.emit()

    @property
    def growth_wall_color(self):
        '''
        Color used to draw walls without function.

        :returntype: `QColor`
        '''
        return self._growth_wall_color

    @growth_wall_color.setter
    def growth_wall_color(self, value):
        value = QColor(value)
        if self._growth_wall_color != value:
            self._growth_wall_color = value
            self.plottingParameterChange.emit()

    @property
    def growth_cell_function(self):
        '''
        Transfer function used to draw cells. This is actually the pickled form of the transfer function.

        :returntype: `str`
        '''
        return self._growth_cell_function

    @growth_cell_function.setter
    def growth_cell_function(self, value):
        if self._growth_cell_function != value:
            self._growth_cell_function = value
            self.plottingParameterChange.emit()

    @property
    def growth_wall_function(self):
        '''
        Transfer function used to draw walls. This is actually the pickled form of the transfer function.

        :returntype: `str`
        '''
        return self._growth_wall_function

    @growth_wall_function.setter
    def growth_wall_function(self, value):
        if self._growth_wall_function != value:
            self._growth_wall_function = value
            self.plottingParameterChange.emit()