custom_filter_widget.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2012, Willow Garage, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Willow Garage, Inc. nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
00032 
00033 import os
00034 
00035 from python_qt_binding import loadUi
00036 from python_qt_binding.QtCore import Qt
00037 from python_qt_binding.QtGui import QWidget
00038 
00039 from .filter_utils import pack, unpack
00040 
00041 
00042 class CustomFilterWidget(QWidget):
00043     def __init__(self, parentfilter, display_list_args):
00044         super(CustomFilterWidget, self).__init__()
00045         ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'custom_filter_widget.ui')
00046         loadUi(ui_file, self)
00047         self.setObjectName('CustomFilterWidget')
00048         self._parentfilter = parentfilter  # When data is changed it is stored in the parent filter
00049 
00050         # Text Filter Initialization
00051         self.text_edit.textChanged.connect(self.handle_text_changed)
00052         self.regex_check_box.clicked[bool].connect(self.handle_regex_clicked)
00053         self.handle_text_changed()
00054 
00055         # Severity Filter Initialization
00056         self.severity_list.itemSelectionChanged.connect(self.handle_severity_item_changed)
00057         newlist = display_list_args[0]()
00058         for item in newlist:
00059             self.severity_list.addItem(item)
00060 
00061         # Node Filter Initialization
00062         self._node_list_populate_function = display_list_args[1]
00063         self._node_function_argument = False
00064         self._node_function_argument = display_list_args[2]
00065         self.node_list.itemSelectionChanged.connect(self.handle_node_item_changed)
00066         self._node_display_list = []
00067 
00068         # Topic Filter Initialization
00069         self._topic_list_populate_function = display_list_args[3]
00070         self._topic_function_argument = False
00071         self._topic_function_argument = display_list_args[4]
00072         self.topic_list.itemSelectionChanged.connect(self.handle_topic_item_changed)
00073         self._topic_display_list = []
00074 
00075         self.repopulate()
00076 
00077     def handle_node_item_changed(self):
00078         self._parentfilter._node.set_list(self.node_list.selectedItems())
00079 
00080     def handle_topic_item_changed(self):
00081         self._parentfilter._topic.set_list(self.topic_list.selectedItems())
00082 
00083     def handle_severity_item_changed(self):
00084         self._parentfilter._severity.set_list(self.severity_list.selectedItems())
00085 
00086     def handle_text_changed(self):
00087         self._parentfilter._message.set_text(self.text_edit.text())
00088 
00089     def handle_regex_clicked(self, clicked):
00090         self._parentfilter._message.set_regex(clicked)
00091 
00092     def repopulate(self):
00093         """
00094         Repopulates the display widgets based on the function arguments passed
00095         in during initialization
00096         """
00097         newlist = self._topic_list_populate_function(self._topic_function_argument)
00098         if len(newlist) != len(self._topic_display_list):
00099             for item in newlist:
00100                 if item not in self._topic_display_list:
00101                     self.topic_list.addItem(item)
00102         self._topic_display_list = list(set(newlist + self._topic_display_list))
00103 
00104         newlist = self._node_list_populate_function(self._node_function_argument)
00105         if len(newlist) != len(self._node_display_list):
00106             for item in newlist:
00107                 if item not in self._node_display_list:
00108                     self.node_list.addItem(item)
00109         self._node_display_list = list(set(newlist + self._node_display_list))
00110 
00111     def save_settings(self, settings):
00112         """
00113         Saves the settings for this filter to an ini file.
00114         :param settings: used to write the settings to an ini file ''qt_gui.settings.Settings''
00115         """
00116         settings.set_value('text', self._parentfilter._message._text)
00117         settings.set_value('regex', self._parentfilter._message._regex)
00118 
00119         settings.set_value('severityitemlist', pack(self._parentfilter._severity._list))
00120 
00121         settings.set_value('topicdisplaylist', pack(self._topic_display_list))
00122         settings.set_value('topicitemlist', pack(self._parentfilter._topic._list))
00123 
00124         settings.set_value('nodedisplaylist', pack(self._node_display_list))
00125         settings.set_value('nodeitemlist', pack(self._parentfilter._node._list))
00126 
00127         return
00128 
00129     def restore_settings(self, settings):
00130         """
00131         Restores the settings for this filter from an ini file.
00132         :param settings: used to extract the settings from an ini file ''qt_gui.settings.Settings''
00133         """
00134         text = settings.value('text', '')
00135         self.text_edit.setText(text)
00136         self.handle_text_changed()
00137 
00138         regex = settings.value('regex') in [True, 'true']
00139         self.regex_check_box.setChecked(regex)
00140         self.handle_regex_clicked(regex)
00141 
00142         #Restore Severities
00143         for index in range(self.severity_list.count()):
00144             self.severity_list.item(index).setSelected(False)
00145         severity_item_list = unpack(settings.value('severityitemlist'))
00146         for item in severity_item_list:
00147             items = self.severity_list.findItems(item, Qt.MatchExactly)
00148             for item in items:
00149                 item.setSelected(True)
00150         self.handle_severity_item_changed()
00151 
00152         #Restore Topics
00153         self._topic_display_list = unpack(settings.value('topicdisplaylist'))
00154         for item in self._topic_display_list:
00155             if len(self.topic_list.findItems(item, Qt.MatchExactly)) == 0:
00156                 self.topic_list.addItem(item)
00157         for index in range(self.topic_list.count()):
00158             self.topic_list.item(index).setSelected(False)
00159         topic_item_list = unpack(settings.value('topicitemlist'))
00160         for item in topic_item_list:
00161             items = self.topic_list.findItems(item, Qt.MatchExactly)
00162             for item in items:
00163                 item.setSelected(True)
00164         self.handle_topic_item_changed()
00165 
00166         #Restore Nodes
00167         self._node_display_list = unpack(settings.value('nodedisplaylist'))
00168         for item in self._node_display_list:
00169             if len(self.node_list.findItems(item, Qt.MatchExactly)) == 0:
00170                 self.node_list.addItem(item)
00171         for index in range(self.node_list.count()):
00172             self.node_list.item(index).setSelected(False)
00173         node_item_list = unpack(settings.value('nodeitemlist'))
00174         for item in node_item_list:
00175             items = self.node_list.findItems(item, Qt.MatchExactly)
00176             for item in items:
00177                 item.setSelected(True)
00178         self.handle_node_item_changed()


rqt_console
Author(s): Aaron Blasdel
autogenerated on Fri Jan 3 2014 11:54:30