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


rqt_console
Author(s): Aaron Blasdel
autogenerated on Wed Sep 16 2015 06:57:57