text_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 # Author: Isaac Saito
34 
35 from python_qt_binding.QtCore import QRegExp, Qt
36 
37 from rqt_console.filters.message_filter import MessageFilter
38 
39 
41  """
42  Provides a filtering feature for text set by set_text.
43 
44  Inheriting rqt_console.filters.MessageFilter, this class provides timeout
45  effect to the input widget (eg. QLineEdit) that contains this class.
46  """
47 
48  def __init__(self, qregexp=None):
49  super(TextFilter, self).__init__()
50  self._regexp = qregexp
51 
52  def test_message(self, text):
53  """
54  Overridden.
55 
56  :param message: the message to be tested against the filters.
57  :type message: str.
58  :rtype: bool
59  """
60  _hit = False
61 
62  if (
63  self.is_enabled() and self._text != '' and
64  self._regexp is not None # If None, init process isn't done
65  # yet and we can ignore the call to
66  ): # this method.
67  pos_hit = self._regexp.indexIn(text)
68  if pos_hit >= 0:
69  _hit = True
70  else:
71  _hit = False
72  return _hit
73 
74  def get_regexp(self):
75  return self._regex
76 
77  def set_text(self, text):
78  """
79  Setter for _text
80  :param text: text to set ''str''
81  :emits filter_changed_signal: If _enabled is true
82  """
83  super(TextFilter, self).set_text(text)
84 
85  syntax_nr = QRegExp.RegExp
86  syntax = QRegExp.PatternSyntax(syntax_nr)
87  self.regex = QRegExp(text, Qt.CaseInsensitive, syntax)
88  self.set_regex(self.regex)
89 
90  def get_text(self):
91  return self._text
def __init__(self, qregexp=None)
Definition: text_filter.py:48


rqt_reconfigure
Author(s): Isaac Saito, Ze'ev Klapow
autogenerated on Wed Jul 10 2019 04:02:40