custom_filter.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2012, Willow Garage, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of Willow Garage, Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 
33 from .base_filter import BaseFilter
34 from .message_filter import MessageFilter
35 from .node_filter import NodeFilter
36 from .severity_filter import SeverityFilter
37 from .topic_filter import TopicFilter
38 
39 
40 class CustomFilter(BaseFilter):
41 
42  """
43  Contains filter logic for the custom filter which allows message, severity,
44  node and topic filtering simultaniously. All of these filters must match
45  together (if they are used) or the custom filter does not match.
46  """
47 
48  def __init__(self):
49  super(CustomFilter, self).__init__()
50 
51  self._message = MessageFilter()
52  self._severity = SeverityFilter()
53  self._node = NodeFilter()
54  self._topic = TopicFilter()
55 
56  self._all_filters = [self._message, self._severity, self._node, self._topic]
57  for f in self._all_filters:
58  f.filter_changed_signal.connect(self._relay_signal)
59 
60  def set_enabled(self, checked):
61  """
62  :signal: emits filter_changed_signal
63  :param checked: enables the filters if checked is True''bool''
64  """
65  for f in self._all_filters:
66  f.set_enabled(checked)
67  super(CustomFilter, self).set_enabled(checked)
68 
69  def _relay_signal(self):
70  """
71  Passes any signals emitted by the child filters along
72  """
73  self.start_emit_timer(1)
74 
75  def has_filter(self):
76  for f in self._all_filters:
77  if f.has_filter():
78  return True
79  return False
80 
81  def test_message(self, message):
82  """
83  Tests if the message matches the filter.
84  :param message: the message to be tested against the filters, ''Message''
85  :returns: True if the message matches all child filters, ''bool''
86  """
87  if not self.is_enabled():
88  return False
89  # if non of the subfilters contains any input the custom filter does not match
90  if not self.has_filter():
91  return False
92  # the custom filter matches when all subfilters which contain input match
93  all_filters = [not f.has_filter() or f.test_message(message) for f in self._all_filters]
94  return False not in all_filters


rqt_console
Author(s): Aaron Blasdel
autogenerated on Wed Jun 5 2019 21:05:12