time_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 from datetime import datetime
00034 import os
00035 import rospkg
00036 
00037 from python_qt_binding import loadUi
00038 from python_qt_binding.QtCore import QDateTime
00039 from python_qt_binding.QtWidgets import QWidget
00040 
00041 
00042 class TimeFilterWidget(QWidget):
00043 
00044     def __init__(self, parentfilter, rospack, time_range_provider):
00045         """
00046         Widget for displaying interactive data related to time filtering.
00047         :param parentfilter: buddy filter were data is stored, ''TimeFilter''
00048         :param display_list_args: single element list containing one tuple with
00049         the min and max time to be displayed, ''list of tuple''
00050         """
00051         super(TimeFilterWidget, self).__init__()
00052         ui_file = os.path.join(
00053             rospack.get_path('rqt_console'), 'resource/filters', 'time_filter_widget.ui')
00054         loadUi(ui_file, self)
00055         self.setObjectName('TimeFilterWidget')
00056         self._parentfilter = parentfilter  # When data is changed it is stored in the parent filter
00057 
00058         self.start_datetime.dateTimeChanged[QDateTime].connect(self.handle_start_changed)
00059         self.stop_datetime.dateTimeChanged[QDateTime].connect(self.handle_stop_changed)
00060         self.stop_enabled_check_box.clicked[bool].connect(self.handle_stop_enabled_changed)
00061 
00062         # Times are passed in unixtimestamp '.' decimal fraction of a second
00063         mintime, maxtime = time_range_provider()
00064         if mintime != -1:
00065             mintime = str(mintime).split('.')
00066             maxtime = str(maxtime).split('.')
00067 
00068             time = QDateTime()
00069             time.setTime_t(int(mintime[0]))
00070             mintime = time.addMSecs(int(str(mintime[1]).zfill(9)[:3]))
00071             self.start_datetime.setDateTime(mintime)
00072             time.setTime_t(int(maxtime[0]))
00073             maxtime = time.addMSecs(int(str(maxtime[1]).zfill(9)[:3]))
00074             self.stop_datetime.setDateTime(maxtime)
00075         else:
00076             self.start_datetime.setDateTime(datetime.now())
00077             self.stop_datetime.setDateTime(datetime.now())
00078 
00079     def handle_start_changed(self, datetime_):
00080         self._parentfilter.set_start_time(datetime_)
00081 
00082     def handle_stop_changed(self, datetime_):
00083         self._parentfilter.set_stop_time(datetime_)
00084 
00085     def handle_stop_enabled_changed(self, checked):
00086         self._parentfilter.set_stop_time_enabled(checked)
00087         self.stop_datetime.setEnabled(checked)
00088 
00089     def repopulate(self):
00090         """
00091         Stub function.
00092         If the widget had any dynamically adjustable data it would requery it
00093         in this function.
00094         """
00095         pass
00096 
00097     def save_settings(self, settings):
00098         """
00099         Saves the settings for this filter to an ini file.
00100         :param settings: used to write the settings to an ini file ''qt_gui.settings.Settings''
00101         """
00102         settings.set_value(
00103             'start_time', self._parentfilter._start_time.toString('hh:mm:ss.zzz (yyyy-MM-dd)'))
00104         settings.set_value(
00105             'stop_time', self._parentfilter._stop_time.toString('hh:mm:ss.zzz (yyyy-MM-dd)'))
00106         settings.set_value('stop_time_enabled', self._parentfilter._stop_time_enabled)
00107 
00108     def restore_settings(self, settings):
00109         """
00110         Restores the settings for this filter from an ini file.
00111         :param settings: used to extract the settings from an ini file ''qt_gui.settings.Settings''
00112         """
00113         self.handle_stop_enabled_changed(settings.value('stop_time_enabled') in [True, 'true'])
00114         if settings.contains('start_time'):
00115             self.handle_start_changed(
00116                 QDateTime.fromString(settings.value('start_time'), 'hh:mm:ss.zzz (yyyy-MM-dd)'))
00117         else:
00118             self.handle_start_changed(QDateTime(datetime.now()))
00119         if settings.contains('stop_time'):
00120             self.handle_stop_changed(
00121                 QDateTime.fromString(settings.value('stop_time'), 'hh:mm:ss.zzz (yyyy-MM-dd)'))
00122         else:
00123             self.handle_stop_changed(QDateTime(datetime.now()))
00124 
00125         self.stop_datetime.setDateTime(self._parentfilter._stop_time)
00126         self.start_datetime.setDateTime(self._parentfilter._start_time)
00127         self.stop_enabled_check_box.setChecked(self._parentfilter._stop_time_enabled)


rqt_console
Author(s): Aaron Blasdel
autogenerated on Sat Jun 8 2019 20:58:08