src
rqt_console
filters
message_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 stoporse 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
python_qt_binding.QtCore
import
QRegExp
34
from
.base_filter
import
BaseFilter
35
36
37
class
MessageFilter
(
BaseFilter
):
38
39
"""
40
Contains filter logic for a message filter. If the regex flag is False
41
simple 'is this in that' text matching is used on _text. If the regex flag is True
42
_text is treated as a regular expression with one exception. If it does not
43
start with a ^ a .* is appended, and if it does not end with a $ then a .*
44
is added to the end.
45
The filter_changed signal should be connected to a slot which notifies the
46
overall filtering system that it needs to reevaluate all entries.
47
"""
48
49
def
__init__
(self):
50
super(MessageFilter, self).
__init__
()
51
self.
_text
=
''
52
self.
_regex
=
False
53
54
def
set_text
(self, text):
55
"""
56
Setter for _text
57
:param text: text to set ''str''
58
:emits filter_changed_signal: If _enabled is true
59
"""
60
self.
_text
= text
61
if
self.
is_enabled
():
62
self.
start_emit_timer
(500)
63
64
def
set_regex
(self, checked):
65
"""
66
Setter for _regex
67
:param checked: boolean flag to set ''bool''
68
:emits filter_changed_signal: If _enabled is true
69
"""
70
self.
_regex
= checked
71
if
self.
is_enabled
():
72
self.
start_emit_timer
(500)
73
74
def
has_filter
(self):
75
return
self.
_text
!=
''
76
77
def
test_message
(self, message):
78
"""
79
Tests if the message matches the filter.
80
If the regex flag is False simple 'is this in that' text matching is used
81
on _text. If the regex flag is True _text is treated as a regular expression
82
with one exception. If it does not start with a ^ a .* is appended, and if
83
it does not end with a $ then a .* is added to the end.
84
85
:param message: the message to be tested against the filters, ''Message''
86
:returns: True if the message matches, ''bool''
87
"""
88
return
self.
_test_message
(message.message)
89
90
def
_test_message
(self, value):
91
if
not
self.
is_enabled
():
92
return
False
93
if
self.
_text
!=
''
:
94
if
self.
_regex
:
95
temp = self.
_text
96
if
temp[0] !=
'^'
:
97
temp =
'.*'
+ temp
98
if
temp[-1] !=
'$'
:
99
temp +=
'.*'
100
if
QRegExp(temp).exactMatch(value):
101
return
True
102
else
:
103
if
value.find(self.
_text
) != -1:
104
return
True
105
return
False
rqt_console.filters.message_filter.MessageFilter._regex
_regex
Definition:
message_filter.py:52
rqt_console.filters.message_filter.MessageFilter.set_regex
def set_regex(self, checked)
Definition:
message_filter.py:64
rqt_console.filters.message_filter.MessageFilter.__init__
def __init__(self)
Definition:
message_filter.py:49
rqt_console.filters.base_filter.BaseFilter
Definition:
base_filter.py:36
rqt_console.filters.message_filter.MessageFilter.test_message
def test_message(self, message)
Definition:
message_filter.py:77
rqt_console.filters.message_filter.MessageFilter
Definition:
message_filter.py:37
rqt_console.filters.base_filter.BaseFilter.is_enabled
def is_enabled(self)
Definition:
base_filter.py:62
rqt_console.filters.base_filter.BaseFilter.start_emit_timer
def start_emit_timer(self, msec=None)
Definition:
base_filter.py:52
rqt_console.filters.message_filter.MessageFilter.set_text
def set_text(self, text)
Definition:
message_filter.py:54
rqt_console.filters.message_filter.MessageFilter._text
_text
Definition:
message_filter.py:51
rqt_console.filters.message_filter.MessageFilter.has_filter
def has_filter(self)
Definition:
message_filter.py:74
rqt_console.filters.message_filter.MessageFilter._test_message
def _test_message(self, value)
Definition:
message_filter.py:90
rqt_console
Author(s): Aaron Blasdel
autogenerated on Sun Oct 15 2023 02:24:45