<commit_before>#
# Copyright (C) 2016  UAVCAN Development Team  <uavcan.org>
#
# This software is distributed under the terms of the MIT License.
#
# Author: <NAME> <<EMAIL>>
#

import logging
from PyQt5.QtWidgets import QDockWidget, QVBoxLayout, QHBoxLayout, QWidget
from .. import make_icon_button
from .value_extractor_views import NewValueExtractorWindow, ExtractorWidget


logger = logging.getLogger(__name__)


class PlotContainerWidget(QDockWidget):
    def __init__(self, parent, plot_area_class, active_data_types):
        super(PlotContainerWidget, self).__init__(parent)

        self.on_close = lambda: None

        self._plot_area = plot_area_class(self, display_measurements=self.setWindowTitle)

        self.update = self._plot_area.update
        self.reset = self._plot_area.reset

        self._active_data_types = active_data_types
        self._extractors = []

        self._new_extractor_button = make_icon_button('plus', 'Add new value extractor', self,
                                                      on_clicked=self._do_new_extractor)

        widget = QWidget(self)

        layout = QVBoxLayout(widget)
        layout.addWidget(self._plot_area, 1)

        footer_layout = QHBoxLayout(self)

        controls_layout = QVBoxLayout(widget)
        controls_layout.addWidget(self._new_extractor_button)
        controls_layout.addStretch(1)
        controls_layout.setContentsMargins(0, 0, 0, 0)
        footer_layout.addLayout(controls_layout)

        self._extractors_layout = QVBoxLayout(widget)
        self._extractors_layout.setContentsMargins(0, 0, 0, 0)
        footer_layout.addLayout(self._extractors_layout)

        footer_layout.setContentsMargins(0, 0, 0, 0)
        layout.addLayout(footer_layout)
        widget.setLayout(layout)

        self.setWidget(widget)
        self.setFeatures(QDockWidget.DockWidgetFloatable |
                         QDockWidget.DockWidgetClosable |
                         QDockWidget.DockWidgetMovable)

        self.setMinimumWidth(700)
        self.setMinimumHeight(400)

    def _do_new_extractor(self):
        def done(extractor):
            self._extractors.append(extractor)
            widget = ExtractorWidget(self, extractor)
            self._extractors_layout.addWidget(widget)

            def remove():
                self._plot_area.remove_curves_provided_by_extractor(extractor)
                self._extractors.remove(extractor)
                self._extractors_layout.removeWidget(widget)

            widget.on_remove = remove

        win = NewValueExtractorWindow(self, self._active_data_types)
        win.on_done = done
        win.show()

    def process_transfer(self, timestamp, tr):<commit_msg>Self-documenting feature for the plot widget<commit_after>#
# Copyright (C) 2016  UAVCAN Development Team  <uavcan.org>
#
# This software is distributed under the terms of the MIT License.
#
# Author: <NAME> <<EMAIL>>
#

import logging
from PyQt5.QtWidgets import QDockWidget, QVBoxLayout, QHBoxLayout, QWidget, QLabel
from .. import make_icon_button
from .value_extractor_views import NewValueExtractorWindow, ExtractorWidget


logger = logging.getLogger(__name__)


class PlotContainerWidget(QDockWidget):
    def __init__(self, parent, plot_area_class, active_data_types):
        super(PlotContainerWidget, self).__init__(parent)

        self.on_close = lambda: None

        self._plot_area = plot_area_class(self, display_measurements=self.setWindowTitle)

        self.update = self._plot_area.update
        self.reset = self._plot_area.reset

        self._active_data_types = active_data_types
        self._extractors = []

        self._new_extractor_button = make_icon_button('plus', 'Add new value extractor', self,
                                                      on_clicked=self._do_new_extractor)

        self._how_to_label = QLabel('\u27F5 Click to configure plotting', self)

        widget = QWidget(self)

        layout = QVBoxLayout(widget)
        layout.addWidget(self._plot_area, 1)

        footer_layout = QHBoxLayout(self)

        controls_layout = QVBoxLayout(widget)
        controls_layout.addWidget(self._new_extractor_button)
        controls_layout.addStretch(1)
        controls_layout.setContentsMargins(0, 0, 0, 0)
        footer_layout.addLayout(controls_layout)
        footer_layout.addWidget(self._how_to_label, 1)

        self._extractors_layout = QVBoxLayout(widget)
        self._extractors_layout.setContentsMargins(0, 0, 0, 0)
        footer_layout.addLayout(self._extractors_layout)

        footer_layout.setContentsMargins(0, 0, 0, 0)
        layout.addLayout(footer_layout)
        widget.setLayout(layout)

        self.setWidget(widget)
        self.setFeatures(QDockWidget.DockWidgetFloatable |
                         QDockWidget.DockWidgetClosable |
                         QDockWidget.DockWidgetMovable)

        self.setMinimumWidth(700)
        self.setMinimumHeight(400)

    def _do_new_extractor(self):
        if self._how_to_label is not None:
            self._how_to_label.hide()
            self._how_to_label.setParent(None)
            self._how_to_label.deleteLater()
            self._how_to_label = None

        def done(extractor):
            self._extractors.append(extractor)
            widget = ExtractorWidget(self, extractor)
            self._extractors_layout.addWidget(widget)

            def remove():
                self._plot_area.remove_curves_provided_by_extractor(extractor)
                self._extractors.remove(extractor)
                self._extractors_layout.removeWidget(widget)

            widget.on_remove = remove

        win = NewValueExtractorWindow(self, self._active_data_types)
        win.on_done = done
        win.show()

    def process_transfer(self, timestamp, tr):
{'fraction_non_alphanumeric': 0.07917888563049853, 'fraction_numerical': 0.009315163015352769, 'mean_word_length': 2.762491888384166, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6954138', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1664, 'n_words': 290}