예제 #1
0
    def __init__(self, parent, **params):
        get_or_put(params, 'layout', QHBoxLayout())
        self.params = Params(**params)
        self.data_accessor = self.params.data_accessor  # alias
        i18n_def = "Square filter " + self.data_accessor.signal_unit.display_label # @IgnorePep8
        super(SquareFilterWidget, self).__init__(parent, i18n_def=i18n_def,
                                                     **params)

        self.__filter__ = SquareFilter()

        LabelWidget(self, i18n_def="Min value")
        self.__min_value__ = NumberEditWidget(self,
                                    text_changed_handler=self.__min_handler__)
        LabelWidget(self, i18n_def="Max value")
        self.__max_value__ = NumberEditWidget(self,
                                    text_changed_handler=self.__max_handler__)

        if self.params.use_apply_button:
            self.__action_button__ = PushButtonWidget(self, i18n_def='Apply',
                                clicked_handler=self.__filter_handler__)
        else:
            self.__action_button__ = CheckBoxWidget(self,
                            i18n_def='Use filter',
                            clicked_handler=self.__use_handler__)
            self.data_accessor.addListener(self,
                                    __SquareFilterDataVectorListener__(self))
            self.__action_button__.setChecked(False)

        self.reset()
예제 #2
0
    def __init__(self, parent, **params):
        get_or_put(params, 'layout', QHBoxLayout())
        self.params = Params(**params)
        self.data_accessor = self.params.data_accessor  # alias
        i18n_def = "Square filter " + self.data_accessor.signal_unit.display_label  # @IgnorePep8
        super(SquareFilterWidget, self).__init__(parent,
                                                 i18n_def=i18n_def,
                                                 **params)

        self.__filter__ = SquareFilter()

        LabelWidget(self, i18n_def="Min value")
        self.__min_value__ = NumberEditWidget(
            self, text_changed_handler=self.__min_handler__)
        LabelWidget(self, i18n_def="Max value")
        self.__max_value__ = NumberEditWidget(
            self, text_changed_handler=self.__max_handler__)

        if self.params.use_apply_button:
            self.__action_button__ = PushButtonWidget(
                self,
                i18n_def='Apply',
                clicked_handler=self.__filter_handler__)
        else:
            self.__action_button__ = CheckBoxWidget(
                self,
                i18n_def='Use filter',
                clicked_handler=self.__use_handler__)
            self.data_accessor.addListener(
                self, __SquareFilterDataVectorListener__(self))
            self.__action_button__.setChecked(False)

        self.reset()
    def __init__(self, parent, **params):
        self.params = Params(**params)

        self.data_vectors_accessor_group = \
            self.params.data_vectors_accessor_group  # alias
        if not self.data_vectors_accessor_group == None:
            self.main_data_accessor = \
                self.data_vectors_accessor_group.group_data_vector_accessor
        else:
            self.main_data_accessor = self.params.data_accessor  # alias

        super(PoincarePlotMovieDockWidget, self).__init__(parent,
                title=params.get('title', 'Poincare plot movie maker'),
                **params)

        self.__composite__ = CompositeWidget(self.dockComposite,
                                             layout=QHBoxLayout())

        self.__active_color__ = ChooseColorWidget(self.__composite__,
                                                 title='Active plot color',
                                                 default_color=Qt.red)

        self.__inactive_color__ = ChooseColorWidget(self.__composite__,
                                                 title='Inactive plot color',
                                                 default_color=Qt.black)

        self.__centroid_color__ = ChooseColorWidget(self.__composite__,
                                                 title='Centroid color',
                                                 default_color=Qt.green)

        self.__fps__ = NumberEditWidget(self.__composite__,
                                    #text_changed_handler=self.__min_handler__
                                    )

        PushButtonWidget(self.__composite__,
                            i18n="poincare.plot.movie.generate.button",
                            i18n_def="Generate movie",
                            clicked_handler=self.__generate_handler__)

        parent.addDockWidget(Qt.LeftDockWidgetArea, self)
예제 #4
0
class SquareFilterWidget(GroupBoxWidget):
    """
    graphical representation of a square filter
    """
    def __init__(self, parent, **params):
        get_or_put(params, 'layout', QHBoxLayout())
        self.params = Params(**params)
        self.data_accessor = self.params.data_accessor  # alias
        i18n_def = "Square filter " + self.data_accessor.signal_unit.display_label # @IgnorePep8
        super(SquareFilterWidget, self).__init__(parent, i18n_def=i18n_def,
                                                     **params)

        self.__filter__ = SquareFilter()

        LabelWidget(self, i18n_def="Min value")
        self.__min_value__ = NumberEditWidget(self,
                                    text_changed_handler=self.__min_handler__)
        LabelWidget(self, i18n_def="Max value")
        self.__max_value__ = NumberEditWidget(self,
                                    text_changed_handler=self.__max_handler__)

        if self.params.use_apply_button:
            self.__action_button__ = PushButtonWidget(self, i18n_def='Apply',
                                clicked_handler=self.__filter_handler__)
        else:
            self.__action_button__ = CheckBoxWidget(self,
                            i18n_def='Use filter',
                            clicked_handler=self.__use_handler__)
            self.data_accessor.addListener(self,
                                    __SquareFilterDataVectorListener__(self))
            self.__action_button__.setChecked(False)

        self.reset()

    def __use_handler__(self):
        if not self.params.use_apply_button:
            if not self.isCorrectSignalRange(self.data_accessor.signal):
                self.__action_button__.setChecked(False)

    def __filter_handler__(self):
        if self.isCorrectSignalRange(self.data_accessor.signal):
            run_filter(self.parent(), self.__filter__, self.data_accessor,
                       filter_name='square')

    def isCorrectSignalRange(self, _signal):
        _min = pl.amin(_signal)
        if _min >= self.__filter__.min_value and \
            _min <= self.__filter__.max_value:
            return True
        _max = pl.amax(_signal)
        if _max >= self.__filter__.min_value and \
            _max <= self.__filter__.max_value:
            return True
        if _min <= self.__filter__.min_value and \
            _max >= self.__filter__.max_value:
            return True
        InformationWindow(message="Signal data out of range !")
        return False

    def __min_handler__(self, text):
        self.__filter__.min_value = text
        self.__check_range__(self.__min_value__)

    def __max_handler__(self, text):
        self.__filter__.max_value = text
        self.__check_range__(self.__max_value__)

    def __check_range__(self, _widget):
        message = self.__filter__.check()
        if message == None:
            self.__action_button__.setEnabled(True)
            _widget.setToolTip('')
            self.__action_button__.setToolTip('')
            return True
        else:
            _widget.setToolTip(message)
            self.__action_button__.setToolTip(message)
            self.__action_button__.setEnabled(False)
            if not self.params.use_apply_button:
                self.__action_button__.setChecked(False)
            return False

    def useFilter(self):
        return self.__action_button__.isChecked() \
            if not self.params.use_apply_button else False

    def getFilter(self):
        return self.__filter__

    def reset(self):
        self.setSquareFilterParams(SquareFilterParams(
                                    int(pl.amin(self.data_accessor.signal)),
                                    int(pl.amax(self.data_accessor.signal)),
                                    True))

    def setEnabled(self, _enabled):
        self.__min_value__.setEnabled(_enabled)
        self.__max_value__.setEnabled(_enabled)

    def setSquareFilterParams(self, square_filter_params):
        """
        set up square filter widget parameters
        """
        self.__filter__.min_value = square_filter_params.min_value
        self.__min_value__.setText(self.__filter__.min_value)

        self.__filter__.max_value = square_filter_params.max_value
        self.__max_value__.setText(self.__filter__.max_value)

        if not self.params.use_apply_button:
            self.__action_button__.setChecked(square_filter_params.use_filter)

    def getSquareFilterParams(self):
        return SquareFilterParams(self.__filter__.min_value,
                                  self.__filter__.max_value,
                                  self.useFilter())
class PoincarePlotMovieDockWidget(DockWidgetWidget):
    """
    a dock widget give ability to generate poincare plot movie
    Warning ! there are codecs required: ffmpeg, ffplay, ffprobe
              to generate a movie
    """
    def __init__(self, parent, **params):
        self.params = Params(**params)

        self.data_vectors_accessor_group = \
            self.params.data_vectors_accessor_group  # alias
        if not self.data_vectors_accessor_group == None:
            self.main_data_accessor = \
                self.data_vectors_accessor_group.group_data_vector_accessor
        else:
            self.main_data_accessor = self.params.data_accessor  # alias

        super(PoincarePlotMovieDockWidget, self).__init__(parent,
                title=params.get('title', 'Poincare plot movie maker'),
                **params)

        self.__composite__ = CompositeWidget(self.dockComposite,
                                             layout=QHBoxLayout())

        self.__active_color__ = ChooseColorWidget(self.__composite__,
                                                 title='Active plot color',
                                                 default_color=Qt.red)

        self.__inactive_color__ = ChooseColorWidget(self.__composite__,
                                                 title='Inactive plot color',
                                                 default_color=Qt.black)

        self.__centroid_color__ = ChooseColorWidget(self.__composite__,
                                                 title='Centroid color',
                                                 default_color=Qt.green)

        self.__fps__ = NumberEditWidget(self.__composite__,
                                    #text_changed_handler=self.__min_handler__
                                    )

        PushButtonWidget(self.__composite__,
                            i18n="poincare.plot.movie.generate.button",
                            i18n_def="Generate movie",
                            clicked_handler=self.__generate_handler__)

        parent.addDockWidget(Qt.LeftDockWidgetArea, self)

    def __generate_handler__(self):

        self.main_data_accessor.prepareParametersContainer()
        data_accessors = [self.main_data_accessor]
        #movie_parameters = MovieParameters()
        movie_parameters = PoincarePlotParameters()
        movie_parameters.fps = self.__fps__.getNumber()
        pp_movie_generator_progress_bar = \
            PoincarePlotMovieGeneratorProgressBar(self,
                data_accessors,
                movie_parameters,
                check_level=CoreParameters.LOW_CHECK_LEVEL
                #output_file_listener=self.params.output_file_listener
                # label_text='Statistics calculation',
                #check_level=check_level, save_csv=save_csv,
                #formatted_summary_statistics=formatted_summary_statistics,
                #output_file_listener=self.params.output_file_listener
                )
        pp_movie_generator_progress_bar.start()
예제 #6
0
class SquareFilterWidget(GroupBoxWidget):
    """
    graphical representation of a square filter
    """
    def __init__(self, parent, **params):
        get_or_put(params, 'layout', QHBoxLayout())
        self.params = Params(**params)
        self.data_accessor = self.params.data_accessor  # alias
        i18n_def = "Square filter " + self.data_accessor.signal_unit.display_label  # @IgnorePep8
        super(SquareFilterWidget, self).__init__(parent,
                                                 i18n_def=i18n_def,
                                                 **params)

        self.__filter__ = SquareFilter()

        LabelWidget(self, i18n_def="Min value")
        self.__min_value__ = NumberEditWidget(
            self, text_changed_handler=self.__min_handler__)
        LabelWidget(self, i18n_def="Max value")
        self.__max_value__ = NumberEditWidget(
            self, text_changed_handler=self.__max_handler__)

        if self.params.use_apply_button:
            self.__action_button__ = PushButtonWidget(
                self,
                i18n_def='Apply',
                clicked_handler=self.__filter_handler__)
        else:
            self.__action_button__ = CheckBoxWidget(
                self,
                i18n_def='Use filter',
                clicked_handler=self.__use_handler__)
            self.data_accessor.addListener(
                self, __SquareFilterDataVectorListener__(self))
            self.__action_button__.setChecked(False)

        self.reset()

    def __use_handler__(self):
        if not self.params.use_apply_button:
            if not self.isCorrectSignalRange(self.data_accessor.signal):
                self.__action_button__.setChecked(False)

    def __filter_handler__(self):
        if self.isCorrectSignalRange(self.data_accessor.signal):
            run_filter(self.parent(),
                       self.__filter__,
                       self.data_accessor,
                       filter_name='square')

    def isCorrectSignalRange(self, _signal):
        _min = pl.amin(_signal)
        if _min >= self.__filter__.min_value and \
            _min <= self.__filter__.max_value:
            return True
        _max = pl.amax(_signal)
        if _max >= self.__filter__.min_value and \
            _max <= self.__filter__.max_value:
            return True
        if _min <= self.__filter__.min_value and \
            _max >= self.__filter__.max_value:
            return True
        InformationWindow(message="Signal data out of range !")
        return False

    def __min_handler__(self, text):
        self.__filter__.min_value = text
        self.__check_range__(self.__min_value__)

    def __max_handler__(self, text):
        self.__filter__.max_value = text
        self.__check_range__(self.__max_value__)

    def __check_range__(self, _widget):
        message = self.__filter__.check()
        if message == None:
            self.__action_button__.setEnabled(True)
            _widget.setToolTip('')
            self.__action_button__.setToolTip('')
            return True
        else:
            _widget.setToolTip(message)
            self.__action_button__.setToolTip(message)
            self.__action_button__.setEnabled(False)
            if not self.params.use_apply_button:
                self.__action_button__.setChecked(False)
            return False

    def useFilter(self):
        return self.__action_button__.isChecked() \
            if not self.params.use_apply_button else False

    def getFilter(self):
        return self.__filter__

    def reset(self):
        self.setSquareFilterParams(
            SquareFilterParams(int(pl.amin(self.data_accessor.signal)),
                               int(pl.amax(self.data_accessor.signal)), True))

    def setEnabled(self, _enabled):
        self.__min_value__.setEnabled(_enabled)
        self.__max_value__.setEnabled(_enabled)

    def setSquareFilterParams(self, square_filter_params):
        """
        set up square filter widget parameters
        """
        self.__filter__.min_value = square_filter_params.min_value
        self.__min_value__.setText(self.__filter__.min_value)

        self.__filter__.max_value = square_filter_params.max_value
        self.__max_value__.setText(self.__filter__.max_value)

        if not self.params.use_apply_button:
            self.__action_button__.setChecked(square_filter_params.use_filter)

    def getSquareFilterParams(self):
        return SquareFilterParams(self.__filter__.min_value,
                                  self.__filter__.max_value, self.useFilter())